From 09cfff3f8a91668de9faf008915dc1d739e0b905 Mon Sep 17 00:00:00 2001 From: johnche Date: Mon, 16 Dec 2024 12:17:21 +0800 Subject: [PATCH] =?UTF-8?q?[unity]=E8=A7=A3=E5=86=B3pesapi=5Fcreate=5Ffunc?= =?UTF-8?q?tion=E5=86=85=E5=AD=98=E4=B8=8D=E5=9B=9E=E6=94=B6=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=8E=9F=E5=9B=A0=E8=A7=81=EF=BC=9A?= =?UTF-8?q?=20https://github.com/Tencent/puerts/issues/1945?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unity/native_src/Src/CppObjectMapper.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/unity/native_src/Src/CppObjectMapper.cpp b/unity/native_src/Src/CppObjectMapper.cpp index 6a5d64b5c8..04590a6044 100644 --- a/unity/native_src/Src/CppObjectMapper.cpp +++ b/unity/native_src/Src/CppObjectMapper.cpp @@ -143,13 +143,16 @@ void FCppObjectMapper::CallbackDataGarbageCollected(const v8::WeakCallbackInfo

FCppObjectMapper::CreateFunction(v8::Local Context, pesapi_callback Callback, void* Data, pesapi_function_finalize Finalize) { + auto Isolate = Context->GetIsolate(); auto CallbackData = new PesapiCallbackData {Callback, Data, this}; CallbackData->Finalize = Finalize; - auto V8Data = v8::External::New(Context->GetIsolate(), &CallbackData->Data); - auto Ret = v8::FunctionTemplate::New(Context->GetIsolate(), PesapiFunctionCallback, V8Data)->GetFunction(Context); + auto V8Data = v8::External::New(Isolate, &CallbackData->Data); + auto Template = v8::FunctionTemplate::New(Isolate, PesapiFunctionCallback, V8Data); + Template->Set(Isolate, "__do_not_cache", v8::ObjectTemplate::New(Isolate)); + auto Ret = Template->GetFunction(Context); if (!Ret.IsEmpty()) { - CallbackData->JsFunction.Reset(Context->GetIsolate(), Ret.ToLocalChecked()); + CallbackData->JsFunction.Reset(Isolate, Ret.ToLocalChecked()); CallbackData->JsFunction.SetWeak( CallbackData, CallbackDataGarbageCollected, v8::WeakCallbackType::kInternalFields); FunctionDatas.push_back(CallbackData);