From 59f5263ae2cfe35d94e5fa8aee7e1e53566893d2 Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Wed, 20 Mar 2024 14:34:26 +0300 Subject: [PATCH] fix: string lifetime --- shared/helpers/Serialization.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/shared/helpers/Serialization.cpp b/shared/helpers/Serialization.cpp index 6858bf13..9bd23f80 100644 --- a/shared/helpers/Serialization.cpp +++ b/shared/helpers/Serialization.cpp @@ -35,7 +35,11 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val, bool allowFunction) if(val->IsNumber()) return core.CreateMValueDouble(val->NumberValue(ctx).ToChecked()); - if(val->IsString()) return core.CreateMValueString(*v8::String::Utf8Value(isolate, val)); + if(val->IsString()) + { + auto jsStr = v8::String::Utf8Value(isolate, val); + return core.CreateMValueString(*jsStr); + } if(val->IsObject()) { @@ -154,8 +158,8 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val, bool allowFunction) V8_CHECK_RETN(v8Obj->Get(ctx, v8Key).ToLocal(&value), "Failed to convert object to MValue", core.CreateMValueNil()); if(value->IsUndefined()) continue; - auto key = *v8::String::Utf8Value(isolate, v8Key); - dict->Set(key, V8ToMValue(value, allowFunction)); + auto key = v8::String::Utf8Value(isolate, v8Key); + dict->Set(*key, V8ToMValue(value, allowFunction)); } return dict;