Bugfix: Create JSHandle in NativeScope

Bugfix: Create JSHandle in NativeScope
Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I98ZB3?from=project-issue

Signed-off-by: lukai <lukai25@huawei.com>
Change-Id: I11a842a5fbfca03f8ec8d617f59b673a1909bfc0
This commit is contained in:
lukai 2024-03-17 16:09:23 +08:00
parent 6502e7035a
commit 2b44b382c0
3 changed files with 37 additions and 2 deletions

View File

@ -94,6 +94,7 @@ public:
} }
~SuspendAllScope() ~SuspendAllScope()
{ {
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "ResumeAll");
Runtime::GetInstance()->ResumeAll(self_); Runtime::GetInstance()->ResumeAll(self_);
} }
private: private:

View File

@ -257,6 +257,7 @@ Local<JSValueRef> JSON::Stringify(const EcmaVM *vm, Local<JSValueRef> json)
Local<StringRef> RegExpRef::GetOriginalSource(const EcmaVM *vm) Local<StringRef> RegExpRef::GetOriginalSource(const EcmaVM *vm)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
JSHandle<JSRegExp> regExp(JSNApiHelper::ToJSHandle(this)); JSHandle<JSRegExp> regExp(JSNApiHelper::ToJSHandle(this));
LOG_IF_SPECIAL(regExp, FATAL); LOG_IF_SPECIAL(regExp, FATAL);
JSTaggedValue source = regExp->GetOriginalSource(); JSTaggedValue source = regExp->GetOriginalSource();
@ -384,6 +385,7 @@ Local<JSValueRef> GeneratorObjectRef::GetGeneratorState(const EcmaVM *vm)
Local<JSValueRef> GeneratorObjectRef::GetGeneratorFunction(const EcmaVM *vm) Local<JSValueRef> GeneratorObjectRef::GetGeneratorFunction(const EcmaVM *vm)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
JSHandle<JSGeneratorObject> jsGenerator(JSNApiHelper::ToJSHandle(this)); JSHandle<JSGeneratorObject> jsGenerator(JSNApiHelper::ToJSHandle(this));
LOG_IF_SPECIAL(jsGenerator, FATAL); LOG_IF_SPECIAL(jsGenerator, FATAL);
JSHandle<GeneratorContext> generatorContext(thread, jsGenerator->GetGeneratorContext()); JSHandle<GeneratorContext> generatorContext(thread, jsGenerator->GetGeneratorContext());
@ -394,6 +396,7 @@ Local<JSValueRef> GeneratorObjectRef::GetGeneratorFunction(const EcmaVM *vm)
Local<JSValueRef> GeneratorObjectRef::GetGeneratorReceiver(const EcmaVM *vm) Local<JSValueRef> GeneratorObjectRef::GetGeneratorReceiver(const EcmaVM *vm)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
JSHandle<JSGeneratorObject> jsGenerator(JSNApiHelper::ToJSHandle(this)); JSHandle<JSGeneratorObject> jsGenerator(JSNApiHelper::ToJSHandle(this));
LOG_IF_SPECIAL(jsGenerator, FATAL); LOG_IF_SPECIAL(jsGenerator, FATAL);
JSHandle<GeneratorContext> generatorContext(thread, jsGenerator->GetGeneratorContext()); JSHandle<GeneratorContext> generatorContext(thread, jsGenerator->GetGeneratorContext());
@ -404,6 +407,7 @@ Local<JSValueRef> GeneratorObjectRef::GetGeneratorReceiver(const EcmaVM *vm)
Local<JSValueRef> CollatorRef::GetCompareFunction(const EcmaVM *vm) Local<JSValueRef> CollatorRef::GetCompareFunction(const EcmaVM *vm)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
#ifdef ARK_SUPPORT_INTL #ifdef ARK_SUPPORT_INTL
JSHandle<JSCollator> jsCollator(JSNApiHelper::ToJSHandle(this)); JSHandle<JSCollator> jsCollator(JSNApiHelper::ToJSHandle(this));
LOG_IF_SPECIAL(jsCollator, FATAL); LOG_IF_SPECIAL(jsCollator, FATAL);
@ -418,6 +422,7 @@ Local<JSValueRef> CollatorRef::GetCompareFunction(const EcmaVM *vm)
Local<JSValueRef> DataTimeFormatRef::GetFormatFunction(const EcmaVM *vm) Local<JSValueRef> DataTimeFormatRef::GetFormatFunction(const EcmaVM *vm)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
#ifdef ARK_SUPPORT_INTL #ifdef ARK_SUPPORT_INTL
JSHandle<JSDateTimeFormat> jsDateTimeFormat(JSNApiHelper::ToJSHandle(this)); JSHandle<JSDateTimeFormat> jsDateTimeFormat(JSNApiHelper::ToJSHandle(this));
LOG_IF_SPECIAL(jsDateTimeFormat, FATAL); LOG_IF_SPECIAL(jsDateTimeFormat, FATAL);
@ -432,6 +437,7 @@ Local<JSValueRef> DataTimeFormatRef::GetFormatFunction(const EcmaVM *vm)
Local<JSValueRef> NumberFormatRef::GetFormatFunction(const EcmaVM *vm) Local<JSValueRef> NumberFormatRef::GetFormatFunction(const EcmaVM *vm)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
#ifdef ARK_SUPPORT_INTL #ifdef ARK_SUPPORT_INTL
JSHandle<JSNumberFormat> jsNumberFormat(JSNApiHelper::ToJSHandle(this)); JSHandle<JSNumberFormat> jsNumberFormat(JSNApiHelper::ToJSHandle(this));
LOG_IF_SPECIAL(jsNumberFormat, FATAL); LOG_IF_SPECIAL(jsNumberFormat, FATAL);

View File

@ -1526,6 +1526,7 @@ uint32_t BigIntRef::GetWordsArraySize()
// ----------------------------------- HandleScope ------------------------------------- // ----------------------------------- HandleScope -------------------------------------
LocalScope::LocalScope(const EcmaVM *vm) : thread_(vm->GetJSThread()) LocalScope::LocalScope(const EcmaVM *vm) : thread_(vm->GetJSThread())
{ {
ecmascript::ThreadManagedScope managedScope(reinterpret_cast<JSThread *>(thread_));
auto context = reinterpret_cast<JSThread *>(thread_)->GetCurrentEcmaContext(); auto context = reinterpret_cast<JSThread *>(thread_)->GetCurrentEcmaContext();
prevNext_ = context->GetHandleScopeStorageNext(); prevNext_ = context->GetHandleScopeStorageNext();
prevEnd_ = context->GetHandleScopeStorageEnd(); prevEnd_ = context->GetHandleScopeStorageEnd();
@ -1535,6 +1536,7 @@ LocalScope::LocalScope(const EcmaVM *vm) : thread_(vm->GetJSThread())
LocalScope::LocalScope(const EcmaVM *vm, JSTaggedType value) : thread_(vm->GetJSThread()) LocalScope::LocalScope(const EcmaVM *vm, JSTaggedType value) : thread_(vm->GetJSThread())
{ {
ecmascript::ThreadManagedScope managedScope(reinterpret_cast<JSThread *>(thread_));
auto context = reinterpret_cast<JSThread *>(thread_)->GetCurrentEcmaContext(); auto context = reinterpret_cast<JSThread *>(thread_)->GetCurrentEcmaContext();
ecmascript::EcmaHandleScope::NewHandle(reinterpret_cast<JSThread *>(thread_), value); ecmascript::EcmaHandleScope::NewHandle(reinterpret_cast<JSThread *>(thread_), value);
prevNext_ = context->GetHandleScopeStorageNext(); prevNext_ = context->GetHandleScopeStorageNext();
@ -1545,6 +1547,7 @@ LocalScope::LocalScope(const EcmaVM *vm, JSTaggedType value) : thread_(vm->GetJS
LocalScope::~LocalScope() LocalScope::~LocalScope()
{ {
ecmascript::ThreadManagedScope managedScope(reinterpret_cast<JSThread *>(thread_));
auto context = reinterpret_cast<JSThread *>(thread_)->GetCurrentEcmaContext(); auto context = reinterpret_cast<JSThread *>(thread_)->GetCurrentEcmaContext();
context->HandleScopeCountDec(); context->HandleScopeCountDec();
context->SetHandleScopeStorageNext(static_cast<JSTaggedType *>(prevNext_)); context->SetHandleScopeStorageNext(static_cast<JSTaggedType *>(prevNext_));
@ -1568,6 +1571,7 @@ Local<IntegerRef> IntegerRef::New(const EcmaVM *vm, int input)
// Omit exception check because ark calls here may not // Omit exception check because ark calls here may not
// cause side effect even pending exception exists. // cause side effect even pending exception exists.
CROSS_THREAD_CHECK(vm); CROSS_THREAD_CHECK(vm);
ecmascript::ThreadManagedScope managedScope(thread);
JSHandle<JSTaggedValue> integer(thread, JSTaggedValue(input)); JSHandle<JSTaggedValue> integer(thread, JSTaggedValue(input));
return JSNApiHelper::ToLocal<IntegerRef>(integer); return JSNApiHelper::ToLocal<IntegerRef>(integer);
} }
@ -1577,6 +1581,7 @@ Local<IntegerRef> IntegerRef::NewFromUnsigned(const EcmaVM *vm, unsigned int inp
// Omit exception check because ark calls here may not // Omit exception check because ark calls here may not
// cause side effect even pending exception exists. // cause side effect even pending exception exists.
CROSS_THREAD_CHECK(vm); CROSS_THREAD_CHECK(vm);
ecmascript::ThreadManagedScope managedScope(thread);
JSHandle<JSTaggedValue> integer(thread, JSTaggedValue(input)); JSHandle<JSTaggedValue> integer(thread, JSTaggedValue(input));
return JSNApiHelper::ToLocal<IntegerRef>(integer); return JSNApiHelper::ToLocal<IntegerRef>(integer);
} }
@ -2157,6 +2162,7 @@ uint32_t TypedArrayRef::ArrayLength([[maybe_unused]] const EcmaVM *vm)
Local<ArrayBufferRef> TypedArrayRef::GetArrayBuffer(const EcmaVM *vm) Local<ArrayBufferRef> TypedArrayRef::GetArrayBuffer(const EcmaVM *vm)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
JSHandle<JSTypedArray> typeArray(JSNApiHelper::ToJSHandle(this)); JSHandle<JSTypedArray> typeArray(JSNApiHelper::ToJSHandle(this));
LOG_IF_SPECIAL(typeArray, ERROR); LOG_IF_SPECIAL(typeArray, ERROR);
JSHandle<JSTaggedValue> arrayBuffer(thread, JSTypedArray::GetOffHeapBuffer(thread, typeArray)); JSHandle<JSTaggedValue> arrayBuffer(thread, JSTypedArray::GetOffHeapBuffer(thread, typeArray));
@ -2198,6 +2204,7 @@ Local<FunctionRef> FunctionRef::NewSendable(EcmaVM *vm,
size_t nativeBindingsize) size_t nativeBindingsize)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
ObjectFactory *factory = vm->GetFactory(); ObjectFactory *factory = vm->GetFactory();
JSHandle<GlobalEnv> env = vm->GetGlobalEnv(); JSHandle<GlobalEnv> env = vm->GetGlobalEnv();
JSHandle<JSFunction> current(factory->NewSFunction(env, reinterpret_cast<void *>(nativeFunc))); JSHandle<JSFunction> current(factory->NewSFunction(env, reinterpret_cast<void *>(nativeFunc)));
@ -2428,6 +2435,7 @@ Local<FunctionRef> FunctionRef::NewSendableClassFunction(const EcmaVM *vm,
size_t nativeBindingSize) size_t nativeBindingSize)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
EscapeLocalScope scope(vm); EscapeLocalScope scope(vm);
ObjectFactory *factory = vm->GetFactory(); ObjectFactory *factory = vm->GetFactory();
const GlobalEnvConstants *globalConst = thread->GlobalConstants(); const GlobalEnvConstants *globalConst = thread->GlobalConstants();
@ -2511,11 +2519,11 @@ JSValueRef* FunctionRef::CallForNapi(const EcmaVM *vm, JSValueRef *thisObj,
int32_t length) int32_t length)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, *JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, *JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
JSTaggedValue result; JSTaggedValue result;
FunctionCallScope callScope(EcmaVM::ConstCast(vm)); FunctionCallScope callScope(EcmaVM::ConstCast(vm));
ASSERT(IsFunction()); // IsFunction check has been done in napi. ASSERT(IsFunction()); // IsFunction check has been done in napi.
{ {
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
LocalScope scope(vm); LocalScope scope(vm);
ecmascript::tooling::JsDebuggerManager *dm = vm->GetJsDebuggerManager(); ecmascript::tooling::JsDebuggerManager *dm = vm->GetJsDebuggerManager();
if (dm->IsDebugApp()) { if (dm->IsDebugApp()) {
@ -2737,7 +2745,7 @@ void* FunctionRef::GetData(const EcmaVM *vm)
if (!extraInfoValue.IsNativePointer()) { if (!extraInfoValue.IsNativePointer()) {
return nullptr; return nullptr;
} }
JSHandle<JSNativePointer> extraInfo(thread, extraInfoValue); auto extraInfo = JSNativePointer::Cast(extraInfoValue.GetTaggedObject());
return extraInfo->GetData(); return extraInfo->GetData();
} }
@ -2980,6 +2988,7 @@ bool JSNApi::InitForConcurrentFunction(EcmaVM *vm, Local<JSValueRef> function, v
void* JSNApi::GetCurrentTaskInfo(const EcmaVM *vm) void* JSNApi::GetCurrentTaskInfo(const EcmaVM *vm)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, nullptr); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, nullptr);
ecmascript::ThreadManagedScope managedScope(thread);
JSTaggedType *current = const_cast<JSTaggedType *>(thread->GetCurrentFrame()); JSTaggedType *current = const_cast<JSTaggedType *>(thread->GetCurrentFrame());
ecmascript::FrameIterator it(current, thread); ecmascript::FrameIterator it(current, thread);
for (; !it.Done(); it.Advance<ecmascript::GCVisitedFlag::VISITED>()) { for (; !it.Done(); it.Advance<ecmascript::GCVisitedFlag::VISITED>()) {
@ -3085,6 +3094,7 @@ void JSNApi::GetStackBeforeCallNapiSuccess([[maybe_unused]] EcmaVM *vm,
{ {
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER) #if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
JSThread *thread = vm->GetJSThread(); JSThread *thread = vm->GetJSThread();
ecmascript::ThreadManagedScope managedScope(thread);
if (thread->GetIsProfiling()) { if (thread->GetIsProfiling()) {
getStackBeforeCallNapiSuccess = vm->GetProfiler()->GetStackBeforeCallNapi(thread); getStackBeforeCallNapiSuccess = vm->GetProfiler()->GetStackBeforeCallNapi(thread);
} }
@ -3095,6 +3105,7 @@ void JSNApi::GetStackAfterCallNapi([[maybe_unused]] EcmaVM *vm)
{ {
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER) #if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
JSThread *thread = vm->GetJSThread(); JSThread *thread = vm->GetJSThread();
ecmascript::ThreadManagedScope managedScope(thread);
if (thread->GetIsProfiling()) { if (thread->GetIsProfiling()) {
vm->GetProfiler()->GetStackAfterCallNapi(thread); vm->GetProfiler()->GetStackAfterCallNapi(thread);
} }
@ -3846,11 +3857,13 @@ bool JSNApi::DeleteWorker(EcmaVM *hostVm, EcmaVM *workerVm)
Local<ObjectRef> JSNApi::GetUncaughtException(const EcmaVM *vm) Local<ObjectRef> JSNApi::GetUncaughtException(const EcmaVM *vm)
{ {
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
return JSNApiHelper::ToLocal<ObjectRef>(vm->GetEcmaUncaughtException()); return JSNApiHelper::ToLocal<ObjectRef>(vm->GetEcmaUncaughtException());
} }
Local<ObjectRef> JSNApi::GetAndClearUncaughtException(const EcmaVM *vm) Local<ObjectRef> JSNApi::GetAndClearUncaughtException(const EcmaVM *vm)
{ {
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
return JSNApiHelper::ToLocal<ObjectRef>(vm->GetAndClearEcmaUncaughtException()); return JSNApiHelper::ToLocal<ObjectRef>(vm->GetAndClearEcmaUncaughtException());
} }
@ -3866,6 +3879,7 @@ bool JSNApi::IsExecutingPendingJob(const EcmaVM *vm)
bool JSNApi::HasPendingJob(const EcmaVM *vm) bool JSNApi::HasPendingJob(const EcmaVM *vm)
{ {
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
return vm->GetAssociatedJSThread()->GetCurrentEcmaContext()->HasPendingJob(); return vm->GetAssociatedJSThread()->GetCurrentEcmaContext()->HasPendingJob();
} }
@ -4173,6 +4187,7 @@ Local<ObjectRef> JSNApi::ExecuteNativeModule(EcmaVM *vm, const std::string &key)
Local<ObjectRef> JSNApi::GetModuleNameSpaceFromFile(EcmaVM *vm, const std::string &file, const std::string &module_path) Local<ObjectRef> JSNApi::GetModuleNameSpaceFromFile(EcmaVM *vm, const std::string &file, const std::string &module_path)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
std::string recordNameStr; std::string recordNameStr;
std::string abcFilePath; std::string abcFilePath;
if (module_path.size() != 0) { if (module_path.size() != 0) {
@ -4197,6 +4212,7 @@ Local<ObjectRef> JSNApi::GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, const std:
const std::string &module_path) const std::string &module_path)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
ecmascript::CString moduleStr = ModulePathHelper::GetModuleNameWithPath(module_path.c_str()); ecmascript::CString moduleStr = ModulePathHelper::GetModuleNameWithPath(module_path.c_str());
ecmascript::CString srcPrefix = moduleStr + ModulePathHelper::PHYCICAL_FILE_PATH; ecmascript::CString srcPrefix = moduleStr + ModulePathHelper::PHYCICAL_FILE_PATH;
std::string prefix = ConvertToStdString(srcPrefix); std::string prefix = ConvertToStdString(srcPrefix);
@ -4374,6 +4390,7 @@ int32_t SetRef::GetTotalElements()
Local<JSValueRef> SetRef::GetValue(const EcmaVM *vm, int entry) Local<JSValueRef> SetRef::GetValue(const EcmaVM *vm, int entry)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
JSHandle<JSSet> set(JSNApiHelper::ToJSHandle(this)); JSHandle<JSSet> set(JSNApiHelper::ToJSHandle(this));
LOG_IF_SPECIAL(set, FATAL); LOG_IF_SPECIAL(set, FATAL);
return JSNApiHelper::ToLocal<JSValueRef>(JSHandle<JSTaggedValue>(thread, set->GetValue(entry))); return JSNApiHelper::ToLocal<JSValueRef>(JSHandle<JSTaggedValue>(thread, set->GetValue(entry)));
@ -4382,6 +4399,7 @@ Local<JSValueRef> SetRef::GetValue(const EcmaVM *vm, int entry)
Local<SetRef> SetRef::New(const EcmaVM *vm) Local<SetRef> SetRef::New(const EcmaVM *vm)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
ObjectFactory *factory = vm->GetJSThread()->GetEcmaVM()->GetFactory(); ObjectFactory *factory = vm->GetJSThread()->GetEcmaVM()->GetFactory();
JSHandle<GlobalEnv> env = vm->GetJSThread()->GetEcmaVM()->GetGlobalEnv(); JSHandle<GlobalEnv> env = vm->GetJSThread()->GetEcmaVM()->GetGlobalEnv();
JSHandle<JSTaggedValue> constructor = env->GetBuiltinsSetFunction(); JSHandle<JSTaggedValue> constructor = env->GetBuiltinsSetFunction();
@ -4396,6 +4414,7 @@ Local<SetRef> SetRef::New(const EcmaVM *vm)
void SetRef::Add(const EcmaVM *vm, Local<JSValueRef> value) void SetRef::Add(const EcmaVM *vm, Local<JSValueRef> value)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK(vm); CROSS_THREAD_AND_EXCEPTION_CHECK(vm);
ecmascript::ThreadManagedScope managedScope(thread);
JSHandle<JSSet> set(JSNApiHelper::ToJSHandle(this)); JSHandle<JSSet> set(JSNApiHelper::ToJSHandle(this));
LOG_IF_SPECIAL(set, ERROR); LOG_IF_SPECIAL(set, ERROR);
JSSet::Add(vm->GetJSThread(), set, JSNApiHelper::ToJSHandle(value)); JSSet::Add(vm->GetJSThread(), set, JSNApiHelper::ToJSHandle(value));
@ -4420,6 +4439,7 @@ int32_t WeakMapRef::GetTotalElements()
Local<JSValueRef> WeakMapRef::GetKey(const EcmaVM *vm, int entry) Local<JSValueRef> WeakMapRef::GetKey(const EcmaVM *vm, int entry)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
JSHandle<JSWeakMap> weakMap(JSNApiHelper::ToJSHandle(this)); JSHandle<JSWeakMap> weakMap(JSNApiHelper::ToJSHandle(this));
LOG_IF_SPECIAL(weakMap, FATAL); LOG_IF_SPECIAL(weakMap, FATAL);
JSTaggedValue key = weakMap->GetKey(entry); JSTaggedValue key = weakMap->GetKey(entry);
@ -4437,6 +4457,7 @@ Local<JSValueRef> WeakMapRef::GetValue(const EcmaVM *vm, int entry)
Local<WeakMapRef> WeakMapRef::New(const EcmaVM *vm) Local<WeakMapRef> WeakMapRef::New(const EcmaVM *vm)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
ObjectFactory *factory = vm->GetJSThread()->GetEcmaVM()->GetFactory(); ObjectFactory *factory = vm->GetJSThread()->GetEcmaVM()->GetFactory();
JSHandle<GlobalEnv> env = vm->GetJSThread()->GetEcmaVM()->GetGlobalEnv(); JSHandle<GlobalEnv> env = vm->GetJSThread()->GetEcmaVM()->GetGlobalEnv();
JSHandle<JSTaggedValue> constructor = env->GetBuiltinsWeakMapFunction(); JSHandle<JSTaggedValue> constructor = env->GetBuiltinsWeakMapFunction();
@ -4451,6 +4472,7 @@ Local<WeakMapRef> WeakMapRef::New(const EcmaVM *vm)
void WeakMapRef::Set(const EcmaVM *vm, const Local<JSValueRef> &key, const Local<JSValueRef> &value) void WeakMapRef::Set(const EcmaVM *vm, const Local<JSValueRef> &key, const Local<JSValueRef> &value)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK(vm); CROSS_THREAD_AND_EXCEPTION_CHECK(vm);
ecmascript::ThreadManagedScope managedScope(thread);
JSHandle<JSWeakMap> weakMap(JSNApiHelper::ToJSHandle(this)); JSHandle<JSWeakMap> weakMap(JSNApiHelper::ToJSHandle(this));
LOG_IF_SPECIAL(weakMap, FATAL); LOG_IF_SPECIAL(weakMap, FATAL);
JSWeakMap::Set(vm->GetJSThread(), weakMap, JSNApiHelper::ToJSHandle(key), JSNApiHelper::ToJSHandle(value)); JSWeakMap::Set(vm->GetJSThread(), weakMap, JSNApiHelper::ToJSHandle(key), JSNApiHelper::ToJSHandle(value));
@ -4460,6 +4482,7 @@ bool WeakMapRef::Has(const EcmaVM *vm, Local<JSValueRef> key)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, false); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, false);
DCHECK_SPECIAL_VALUE_WITH_RETURN(this, false); DCHECK_SPECIAL_VALUE_WITH_RETURN(this, false);
ecmascript::ThreadManagedScope managedScope(thread);
JSHandle<JSWeakMap> weakMap(JSNApiHelper::ToJSHandle(this)); JSHandle<JSWeakMap> weakMap(JSNApiHelper::ToJSHandle(this));
return weakMap->Has(thread, JSNApiHelper::ToJSTaggedValue(*key)); return weakMap->Has(thread, JSNApiHelper::ToJSTaggedValue(*key));
} }
@ -4483,6 +4506,7 @@ int32_t WeakSetRef::GetTotalElements()
Local<JSValueRef> WeakSetRef::GetValue(const EcmaVM *vm, int entry) Local<JSValueRef> WeakSetRef::GetValue(const EcmaVM *vm, int entry)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
JSHandle<JSWeakSet> weakSet(JSNApiHelper::ToJSHandle(this)); JSHandle<JSWeakSet> weakSet(JSNApiHelper::ToJSHandle(this));
LOG_IF_SPECIAL(weakSet, FATAL); LOG_IF_SPECIAL(weakSet, FATAL);
JSTaggedValue value = weakSet->GetValue(entry); JSTaggedValue value = weakSet->GetValue(entry);
@ -4492,6 +4516,7 @@ Local<JSValueRef> WeakSetRef::GetValue(const EcmaVM *vm, int entry)
Local<WeakSetRef> WeakSetRef::New(const EcmaVM *vm) Local<WeakSetRef> WeakSetRef::New(const EcmaVM *vm)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(thread);
ObjectFactory *factory = vm->GetJSThread()->GetEcmaVM()->GetFactory(); ObjectFactory *factory = vm->GetJSThread()->GetEcmaVM()->GetFactory();
JSHandle<GlobalEnv> env = vm->GetJSThread()->GetEcmaVM()->GetGlobalEnv(); JSHandle<GlobalEnv> env = vm->GetJSThread()->GetEcmaVM()->GetGlobalEnv();
JSHandle<JSTaggedValue> constructor = env->GetBuiltinsSetFunction(); JSHandle<JSTaggedValue> constructor = env->GetBuiltinsSetFunction();
@ -4506,6 +4531,7 @@ Local<WeakSetRef> WeakSetRef::New(const EcmaVM *vm)
void WeakSetRef::Add(const EcmaVM *vm, Local<JSValueRef> value) void WeakSetRef::Add(const EcmaVM *vm, Local<JSValueRef> value)
{ {
CROSS_THREAD_AND_EXCEPTION_CHECK(vm); CROSS_THREAD_AND_EXCEPTION_CHECK(vm);
ecmascript::ThreadManagedScope managedScope(thread);
JSHandle<JSWeakSet> weakSet(JSNApiHelper::ToJSHandle(this)); JSHandle<JSWeakSet> weakSet(JSNApiHelper::ToJSHandle(this));
LOG_IF_SPECIAL(weakSet, ERROR); LOG_IF_SPECIAL(weakSet, ERROR);
JSWeakSet::Add(vm->GetJSThread(), weakSet, JSNApiHelper::ToJSHandle(value)); JSWeakSet::Add(vm->GetJSThread(), weakSet, JSNApiHelper::ToJSHandle(value));
@ -4525,11 +4551,13 @@ void TryCatch::Rethrow()
Local<ObjectRef> TryCatch::GetAndClearException() Local<ObjectRef> TryCatch::GetAndClearException()
{ {
ecmascript::ThreadManagedScope managedScope(ecmaVm_->GetJSThread());
return JSNApiHelper::ToLocal<ObjectRef>(ecmaVm_->GetAndClearEcmaUncaughtException()); return JSNApiHelper::ToLocal<ObjectRef>(ecmaVm_->GetAndClearEcmaUncaughtException());
} }
Local<ObjectRef> TryCatch::GetException() Local<ObjectRef> TryCatch::GetException()
{ {
ecmascript::ThreadManagedScope managedScope(ecmaVm_->GetJSThread());
return JSNApiHelper::ToLocal<ObjectRef>(ecmaVm_->GetEcmaUncaughtException()); return JSNApiHelper::ToLocal<ObjectRef>(ecmaVm_->GetEcmaUncaughtException());
} }