diff --git a/runtime/interpreter/ecma-interpreter-inl.h b/runtime/interpreter/ecma-interpreter-inl.h index b56caa07f7e359a1ba781d6b1f68606fee3ebefc..791b32aae0bd0fbd625033947ff6c7d5db3c2bdb 100644 --- a/runtime/interpreter/ecma-interpreter-inl.h +++ b/runtime/interpreter/ecma-interpreter-inl.h @@ -230,6 +230,7 @@ public: } else if (LIKELY(func->IsBase() || acc_in.IsUndefined())) { SetAccFromTaggedValue(GetCurrentThis()); } else { + [[maybe_unused]] EcmaHandleScope handle_scope(this->GetJSThread()); ASSERT(func->IsDerivedConstructor()); JSHandle error = GetFactory()->GetJSError( ErrorType::TYPE_ERROR, "Derived constructor must return object or undefined"); @@ -254,6 +255,7 @@ public: if (LIKELY(func->IsBase() || acc_in.IsUndefined())) { SetAccFromTaggedValue(GetCurrentThis()); } else { + [[maybe_unused]] EcmaHandleScope handle_scope(this->GetJSThread()); ASSERT(func->IsDerivedConstructor()); JSHandle error = GetFactory()->GetJSError( ErrorType::TYPE_ERROR, "Derived constructor must return object or undefined"); @@ -288,6 +290,7 @@ public: uint64_t function = JSGetCalleDyn(js_thread->GetCurrentFrame(), this->GetInst()); if (UNLIKELY(!JSTaggedValue(function).IsCallable())) { + [[maybe_unused]] EcmaHandleScope handle_scope(js_thread); JSHandle error = GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "is not callable"); js_thread->SetException(error.GetTaggedValue()); this->MoveToExceptionHandler(); @@ -331,6 +334,7 @@ public: JSFunction *js_function = JSFunction::Cast(this_func); if (UNLIKELY(js_function->IsClassConstructor())) { + [[maybe_unused]] EcmaHandleScope handle_scope(js_thread); JSHandle error = GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "class constructor cannot be called without 'new'"); js_thread->SetException(error.GetTaggedValue()); diff --git a/runtime/intrinsics-inl.h b/runtime/intrinsics-inl.h index 69887e70f395cb9497aecb3ef029ea9f4859bb31..a27b6ec0f89174eaefc67c693f56250a8490f164 100644 --- a/runtime/intrinsics-inl.h +++ b/runtime/intrinsics-inl.h @@ -50,6 +50,7 @@ template static inline JSTaggedValue HandlerCall(JSThread *thread, EcmaRuntimeCallInfo *info, JSTaggedValue fn_object) { if (UNLIKELY(!fn_object.IsCallable())) { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle error = GetFactory(thread)->GetJSError(ErrorType::TYPE_ERROR, "is not callable"); thread->SetException(error.GetTaggedValue()); return JSTaggedValue(JSTaggedValue::VALUE_EXCEPTION); @@ -83,6 +84,7 @@ static inline JSTaggedValue HandlerCall(JSThread *thread, EcmaRuntimeCallInfo *i JSFunction *js_function = JSFunction::Cast(js_object); if (UNLIKELY(js_function->IsClassConstructor())) { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle error = thread->GetEcmaVM()->GetFactory()->GetJSError( ErrorType::TYPE_ERROR, "class constructor cannot called without 'new'"); thread->SetException(error.GetTaggedValue()); @@ -545,18 +547,21 @@ INLINE_ECMA_INTRINSICS uint64_t Definefuncexpr([[maybe_unused]] JSThread *thread // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t DefinefuncDyn(JSThread *thread, uint32_t method_id, uint64_t env) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle constpool(thread, GetConstantPool(thread)); - JSMutableHandle result(thread, constpool->GetObjectFromCache(method_id)); - JSHandle lex_env(thread, JSTaggedValue(env)); - ASSERT(!result.IsEmpty()); + auto constpool = GetConstantPool(thread); + auto result = JSFunction::Cast(constpool->GetObjectFromCache(method_id).GetHeapObject()); + auto lexenv = JSTaggedValue(env); if (!result->GetLexicalEnv().IsUndefined()) { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle constpool_handle(thread, constpool); + JSHandle lexenv_handle(thread, lexenv); auto res = SlowRuntimeStub::DefinefuncDyn(thread, result->GetCallTarget()); - result.Update(res); - result->SetConstantPool(thread, constpool.GetTaggedValue()); + result = JSFunction::Cast(res.GetHeapObject()); + constpool = *constpool_handle; // May be moved by GC + lexenv = lexenv_handle.GetTaggedValue(); // May be moved by GC + result->SetConstantPool(thread, JSTaggedValue(constpool)); } - result->SetLexicalEnv(thread, lex_env.GetTaggedValue()); - return result.GetTaggedValue().GetRawData(); + result->SetLexicalEnv(thread, lexenv); + return JSTaggedValue(result).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -899,9 +904,6 @@ INLINE_ECMA_INTRINSICS uint64_t Ldglobal(JSThread *thread) INLINE_ECMA_INTRINSICS uint64_t LdObjByValue(JSThread *thread, uint64_t rec, uint64_t pkey, [[maybe_unused]] uint16_t slot_id) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle receiver_handle(thread, JSTaggedValue(rec)); - auto receiver = JSTaggedValue(rec); auto prop_key = JSTaggedValue(pkey); @@ -930,8 +932,6 @@ INLINE_ECMA_INTRINSICS uint64_t LdObjByValue(JSThread *thread, uint64_t rec, uin INLINE_ECMA_INTRINSICS uint64_t StObjByValue(JSThread *thread, uint64_t rec, uint64_t pkey, uint64_t val, [[maybe_unused]] uint16_t slot_id) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto receiver = JSTaggedValue(rec); auto prop_key = JSTaggedValue(pkey); auto value = JSTaggedValue(val); @@ -945,22 +945,24 @@ INLINE_ECMA_INTRINSICS uint64_t StObjByValue(JSThread *thread, uint64_t rec, uin } } #endif - - JSHandle receiver_handle(thread, receiver); - JSHandle prop_key_handle(thread, prop_key); - JSHandle value_handle(thread, value); - - if (receiver.IsHeapObject()) { - res = FastRuntimeStub::SetPropertyByValue(thread, receiver, prop_key, value); - if (!res.IsHole()) { - return res.GetRawData(); + { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle receiver_handle(thread, receiver); + JSHandle prop_key_handle(thread, prop_key); + JSHandle value_handle(thread, value); + + if (receiver.IsHeapObject()) { + res = FastRuntimeStub::SetPropertyByValue(thread, receiver, prop_key, value); + if (!res.IsHole()) { + return res.GetRawData(); + } } - } - // slow path - receiver = receiver_handle.GetTaggedValue(); // May be moved by GC - prop_key = prop_key_handle.GetTaggedValue(); // May be moved by GC - value = value_handle.GetTaggedValue(); // May be moved by GC + // slow path + receiver = receiver_handle.GetTaggedValue(); // May be moved by GC + prop_key = prop_key_handle.GetTaggedValue(); // May be moved by GC + value = value_handle.GetTaggedValue(); // May be moved by GC + } return SlowRuntimeStub::StObjByValue(thread, receiver, prop_key, value).GetRawData(); } @@ -1344,25 +1346,31 @@ INLINE_ECMA_INTRINSICS uint64_t Delobjprop(JSThread *thread, uint64_t obj, uint6 // define not constructor function // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t DefineNCFuncDyn(JSThread *thread, uint32_t method_id, uint64_t env, uint64_t home_obj) +INLINE_ECMA_INTRINSICS uint64_t DefineNCFuncDyn(JSThread *thread, uint32_t method_id, uint64_t env, uint64_t home_objv) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle home_obj_handle(thread, JSTaggedValue(home_obj)); - JSHandle constpool(thread, GetConstantPool(thread)); - JSMutableHandle result(thread, constpool->GetObjectFromCache(method_id)); - JSHandle lex_env(thread, JSTaggedValue(env)); - ASSERT(!result.IsEmpty()); + auto home_obj = JSTaggedValue(home_objv); + auto constpool = GetConstantPool(thread); + auto result = JSFunction::Cast(constpool->GetObjectFromCache(method_id).GetHeapObject()); + auto lexenv = JSTaggedValue(env); + if (!result->GetLexicalEnv().IsUndefined()) { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle home_obj_handle(thread, home_obj); + JSHandle constpool_handle(thread, constpool); + JSHandle lexenv_handle(thread, lexenv); auto res = SlowRuntimeStub::DefineNCFuncDyn(thread, result->GetCallTarget()); if (res.IsException()) { return res.GetRawData(); } - result.Update(res); - result->SetConstantPool(thread, constpool.GetTaggedValue()); + result = JSFunction::Cast(res.GetHeapObject()); + home_obj = home_obj_handle.GetTaggedValue(); // May be moved by GC + constpool = *constpool_handle; // May be moved by GC + lexenv = lexenv_handle.GetTaggedValue(); // May be moved by GC + result->SetConstantPool(thread, JSTaggedValue(constpool)); } - result->SetLexicalEnv(thread, lex_env.GetTaggedValue()); - result->SetHomeObject(thread, home_obj_handle.GetTaggedValue()); - return result.GetTaggedValue().GetRawData(); + result->SetLexicalEnv(thread, lexenv); + result->SetHomeObject(thread, home_obj); + return JSTaggedValue(result).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -1548,20 +1556,21 @@ INLINE_ECMA_INTRINSICS uint64_t GetPropIterator(JSThread *thread, uint64_t obj) // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t DefineGeneratorFunc(JSThread *thread, uint32_t method_id, uint64_t env) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSMutableHandle result(thread, GetConstantPool(thread)->GetObjectFromCache(method_id)); - JSHandle lex_env(thread, JSTaggedValue(env)); - ASSERT(!result.IsEmpty()); + auto result = JSFunction::Cast(GetConstantPool(thread)->GetObjectFromCache(method_id).GetHeapObject()); + auto lexenv = JSTaggedValue(env); if (!result->GetLexicalEnv().IsUndefined()) { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle lexenv_handle(thread, lexenv); auto res = SlowRuntimeStub::DefineGeneratorFunc(thread, result->GetCallTarget()); if (res.IsException()) { return res.GetRawData(); } - result.Update(res); + result = JSFunction::Cast(res.GetHeapObject()); + lexenv = lexenv_handle.GetTaggedValue(); // May be moved by GC result->SetConstantPool(thread, JSTaggedValue(GetConstantPool(thread))); } - result->SetLexicalEnv(thread, lex_env.GetTaggedValue()); - return result.GetTaggedValue().GetRawData(); + result->SetLexicalEnv(thread, lexenv); + return JSTaggedValue(result).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -1605,39 +1614,41 @@ INLINE_ECMA_INTRINSICS uint64_t CreateAsyncGeneratorObj(JSThread *thread, uint64 // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t DefineAsyncFunc(JSThread *thread, uint32_t method_id, uint64_t env) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSMutableHandle result(thread, GetConstantPool(thread)->GetObjectFromCache(method_id)); - JSHandle lex_env(thread, JSTaggedValue(env)); - ASSERT(!result.IsEmpty()); + auto result = JSFunction::Cast(GetConstantPool(thread)->GetObjectFromCache(method_id).GetHeapObject()); + auto lexenv = JSTaggedValue(env); if (!result->GetLexicalEnv().IsUndefined()) { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle lexenv_handle(thread, lexenv); auto res = SlowRuntimeStub::DefineAsyncFunc(thread, result->GetCallTarget()); if (res.IsException()) { return res.GetRawData(); } - result.Update(res); + result = JSFunction::Cast(res.GetHeapObject()); + lexenv = lexenv_handle.GetTaggedValue(); // May be moved by GC result->SetConstantPool(thread, JSTaggedValue(GetConstantPool(thread))); } - result->SetLexicalEnv(thread, lex_env.GetTaggedValue()); - return result.GetTaggedValue().GetRawData(); + result->SetLexicalEnv(thread, lexenv); + return JSTaggedValue(result).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t DefineAsyncGeneratorFunc(JSThread *thread, uint32_t method_id, uint64_t env) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSMutableHandle result(thread, GetConstantPool(thread)->GetObjectFromCache(method_id)); - JSHandle lex_env(thread, JSTaggedValue(env)); - ASSERT(!result.IsEmpty()); + auto result = JSFunction::Cast(GetConstantPool(thread)->GetObjectFromCache(method_id).GetHeapObject()); + auto lexenv = JSTaggedValue(env); if (!result->GetLexicalEnv().IsUndefined()) { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle lexenv_handle(thread, lexenv); auto res = SlowRuntimeStub::DefineAsyncGeneratorFunc(thread, result->GetCallTarget()); if (res.IsException()) { return res.GetRawData(); } - result.Update(res); + result = JSFunction::Cast(res.GetHeapObject()); + lexenv = lexenv_handle.GetTaggedValue(); // May be moved by GC result->SetConstantPool(thread, JSTaggedValue(GetConstantPool(thread))); } - result->SetLexicalEnv(thread, lex_env.GetTaggedValue()); - return result.GetTaggedValue().GetRawData(); + result->SetLexicalEnv(thread, lexenv); + return JSTaggedValue(result).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -1772,59 +1783,61 @@ INLINE_ECMA_INTRINSICS uint64_t CreateRegExpWithLiteral(JSThread *thread, uint32 // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t StOwnByIndex(JSThread *thread, uint64_t object, uint64_t idx, uint64_t val) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle obj_handle(thread, JSTaggedValue(object)); - JSHandle value_handle(thread, JSTaggedValue(val)); - auto obj = JSTaggedValue(object); auto value = JSTaggedValue(val); - if (obj.IsHeapObject() && !obj.IsClassConstructor() && !obj.IsClassPrototype()) { - JSTaggedValue res = FastRuntimeStub::SetPropertyByIndex(thread, obj, idx, value); - if (!res.IsHole()) { - return res.GetRawData(); + { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle obj_handle(thread, JSTaggedValue(object)); + JSHandle value_handle(thread, JSTaggedValue(val)); + + if (obj.IsHeapObject() && !obj.IsClassConstructor() && !obj.IsClassPrototype()) { + JSTaggedValue res = FastRuntimeStub::SetPropertyByIndex(thread, obj, idx, value); + if (!res.IsHole()) { + return res.GetRawData(); + } } - } - obj = obj_handle.GetTaggedValue(); // Maybe moved by GC - value = value_handle.GetTaggedValue(); // Maybe moved by GC + obj = obj_handle.GetTaggedValue(); // Maybe moved by GC + value = value_handle.GetTaggedValue(); // Maybe moved by GC + } return SlowRuntimeStub::StOwnByIndex(thread, obj, idx, value).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t StOwnByName(JSThread *thread, uint32_t string_id, uint64_t object, uint64_t val) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle obj_handle(thread, JSTaggedValue(object)); - JSHandle value_handle(thread, JSTaggedValue(val)); - - auto obj = obj_handle.GetTaggedValue(); - auto value = value_handle.GetTaggedValue(); - + auto obj = JSTaggedValue(object); + auto value = JSTaggedValue(val); JSTaggedValue prop = GetConstantPool(thread)->GetObjectFromCache(string_id); - if (obj.IsJSObject() && !obj.IsClassConstructor() && !obj.IsClassPrototype()) { - JSTaggedValue res = FastRuntimeStub::SetPropertyByName(thread, obj, prop, value); - if (!res.IsHole()) { - return res.GetRawData(); + { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle obj_handle(thread, JSTaggedValue(object)); + JSHandle value_handle(thread, JSTaggedValue(val)); + + if (obj.IsJSObject() && !obj.IsClassConstructor() && !obj.IsClassPrototype()) { + JSTaggedValue res = FastRuntimeStub::SetPropertyByName(thread, obj, prop, value); + if (!res.IsHole()) { + return res.GetRawData(); + } } - } - obj = obj_handle.GetTaggedValue(); // Maybe moved by GC - value = value_handle.GetTaggedValue(); // Maybe moved by GC - GetConstantPool(thread)->GetObjectFromCache(string_id); // Maybe moved by GC + obj = obj_handle.GetTaggedValue(); // Maybe moved by GC + value = value_handle.GetTaggedValue(); // Maybe moved by GC + prop = GetConstantPool(thread)->GetObjectFromCache(string_id); // Maybe moved by GC + } return SlowRuntimeStub::StOwnByName(thread, obj, prop, value).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t StOwnByValue(JSThread *thread, uint64_t rec, uint64_t pkey, uint64_t val) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto receiver = JSTaggedValue(rec); auto prop_key = JSTaggedValue(pkey); auto value = JSTaggedValue(val); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle receiver_handle(thread, receiver); JSHandle prop_handle(thread, prop_key); JSHandle value_handle(thread, value); @@ -2068,24 +2081,28 @@ INLINE_ECMA_INTRINSICS uint64_t SuperCallSpread(JSThread *thread, uint64_t array INLINE_ECMA_INTRINSICS uint64_t DefineMethod(JSThread *thread, uint32_t method_id, uint64_t tagged_cur_env, uint64_t home_object) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle constpool(thread, GetConstantPool(thread)); - JSMutableHandle result(thread, constpool->GetObjectFromCache(method_id)); - JSHandle home(thread, JSTaggedValue(home_object)); - JSHandle env(thread, JSTaggedValue(tagged_cur_env)); - ASSERT(!result.IsEmpty()); + auto constpool = GetConstantPool(thread); + auto result = JSFunction::Cast(constpool->GetObjectFromCache(method_id).GetHeapObject()); + auto home = JSTaggedValue(home_object); + auto env = JSTaggedValue(tagged_cur_env); if (!result->GetLexicalEnv().IsUndefined()) { - auto res = SlowRuntimeStub::DefineMethod(thread, result->GetCallTarget(), home); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle constpool_handle(thread, constpool); + JSHandle home_handle(thread, home); + JSHandle env_handle(thread, env); + auto res = SlowRuntimeStub::DefineMethod(thread, result->GetCallTarget(), home_handle); if (res.IsException()) { return res.GetRawData(); } - result.Update(res); - result->SetConstantPool(thread, constpool.GetTaggedValue()); + result = JSFunction::Cast(res.GetHeapObject()); + constpool = *constpool_handle; // Maybe moved by GC + env = env_handle.GetTaggedValue(); // Maybe moved by GC + result->SetConstantPool(thread, JSTaggedValue(constpool)); } else { - result->SetHomeObject(thread, home.GetTaggedValue()); + result->SetHomeObject(thread, home); } - result->SetLexicalEnv(thread, env.GetTaggedValue()); - return result.GetTaggedValue().GetRawData(); + result->SetLexicalEnv(thread, env); + return JSTaggedValue(result).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers)