Skip to content

Commit

Permalink
[unity]确保HandleScope前都加locker
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Sep 13, 2024
1 parent 7834901 commit f7c0869
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions unity/native_src/Src/BackendEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,9 @@ static void DoHostImportModuleDynamically(void* import_data_)

v8::Isolate* isolate(import_data->isolate);
auto backend_env = FBackendEnv::Get(isolate);
#ifdef THREAD_SAFE
v8::Locker Locker(isolate);
#endif
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = backend_env->MainContext.Get(isolate);
v8::Context::Scope context_scope(context);
Expand Down Expand Up @@ -1073,6 +1076,9 @@ v8::MaybeLocal<v8::Promise> esmodule::HostImportModuleDynamically(
v8::Local<v8::Value> referrer_name = referrer->GetResourceName();
#endif
auto isolate = context->GetIsolate();
#ifdef THREAD_SAFE
v8::Locker Locker(isolate);
#endif
v8::HandleScope handle_scope(isolate);
v8::Context::Scope context_scope(context);
v8::Local<v8::Promise::Resolver> resolver;
Expand Down Expand Up @@ -1112,6 +1118,9 @@ void esmodule::HostInitializeImportMetaObject(v8::Local<v8::Context> Context, v8
std::string FBackendEnv::GetJSStackTrace()
{
v8::Isolate* Isolate = MainIsolate;
#ifdef THREAD_SAFE
v8::Locker Locker(Isolate);
#endif
v8::HandleScope HandleScope(Isolate);
v8::Local<v8::Context> Context = MainContext.Get(Isolate);
v8::Context::Scope ContextScope(Context);
Expand Down
3 changes: 3 additions & 0 deletions unity/native_src_il2cpp/Src/CppObjectMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ v8::Local<v8::FunctionTemplate> FCppObjectMapper::GetTemplateOfClass(v8::Isolate
{
return v8::Local<v8::FunctionTemplate>();
}
#ifdef THREAD_SAFE
v8::Locker Locker(Isolate);
#endif
v8::EscapableHandleScope HandleScope(Isolate);

auto Template = v8::FunctionTemplate::New(
Expand Down
6 changes: 6 additions & 0 deletions unity/native_src_il2cpp/Src/Puerts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ static v8::Value* GetModuleExecutor(v8::Context* env)
static void* GetJSObjectValue(const PersistentObjectInfo* objectInfo, const char* key, const void* Typeid)
{
auto Isolate = objectInfo->EnvInfo->Isolate;
#ifdef THREAD_SAFE
v8::Locker Locker(Isolate);
#endif
v8::Isolate::Scope Isolatescope(Isolate);
v8::HandleScope HandleScope(Isolate);
auto LocalContext = objectInfo->EnvInfo->Context.Get(Isolate);
Expand Down Expand Up @@ -718,6 +721,9 @@ struct JSEnv

auto Isolate = MainIsolate;

#ifdef THREAD_SAFE
v8::Locker Locker(Isolate);
#endif
v8::Isolate::Scope Isolatescope(Isolate);
v8::HandleScope HandleScope(Isolate);

Expand Down

0 comments on commit f7c0869

Please sign in to comment.