diff --git a/ecmascript/js_handle.h b/ecmascript/js_handle.h index dffb90285e0d8eb57fa9117474f500d98e050bbe..b419f15a7cc7e57c0fd75b2facbfafb049897f46 100644 --- a/ecmascript/js_handle.h +++ b/ecmascript/js_handle.h @@ -69,13 +69,17 @@ public: inline JSTaggedValue GetTaggedValue() const { - ASSERT(GetAddress() != 0U); + if (GetAddress() == 0U) { + return JSTaggedValue::Undefined(); + } return *(reinterpret_cast(GetAddress())); // NOLINT(clang-analyzer-core.NullDereference) } inline JSTaggedType GetTaggedType() const { - ASSERT(GetAddress() != 0U); + if (GetAddress() == 0U) { + return JSTaggedValue::Undefined().GetRawData(); + } return *reinterpret_cast(GetAddress()); // NOLINT(clang-analyzer-core.NullDereference) } diff --git a/ecmascript/napi/include/jsnapi.h b/ecmascript/napi/include/jsnapi.h index eb5db58702e9e671d55329bb3207b404ece0aac0..4bf334dd88b8f6f6a223b5ce6004fb519431c144 100644 --- a/ecmascript/napi/include/jsnapi.h +++ b/ecmascript/napi/include/jsnapi.h @@ -835,7 +835,9 @@ template template Global::Global(const EcmaVM *vm, const Local ¤t) : vm_(vm) { - address_ = JSNApi::GetGlobalHandleAddr(vm_, reinterpret_cast(*current)); + if (!current.IsEmpty()) { + address_ = JSNApi::GetGlobalHandleAddr(vm_, reinterpret_cast(*current)); + } } template diff --git a/ecmascript/napi/jsnapi.cpp b/ecmascript/napi/jsnapi.cpp index 60d3168abc9a7b7658a59748c2d7e35a7df2ed93..4ab3e3ad293b811593eb9c4ee31c9cf95affc24a 100644 --- a/ecmascript/napi/jsnapi.cpp +++ b/ecmascript/napi/jsnapi.cpp @@ -777,7 +777,12 @@ Local FunctionRef::NewClassFunction(EcmaVM *vm, FunctionCallbackWit JSHandle clsPrototype = JSObject::ObjectCreate(thread, JSHandle(env->GetObjectFunctionPrototype())); - current->SetFunctionPrototype(thread, clsPrototype.GetTaggedValue()); + clsPrototype.GetTaggedValue().GetTaggedObject()->GetClass()->SetClassPrototype(true); + JSHandle::Cast(current)->GetTaggedObject()->GetClass()->SetClassConstructor(true); + current->SetClassConstructor(thread, true); + JSHandle parent = env->GetFunctionPrototype(); + JSObject::SetPrototype(thread, JSHandle::Cast(current), parent); + JSFunction::MakeClassConstructor(thread, JSHandle::Cast(current), clsPrototype); return JSNApiHelper::ToLocal(JSHandle(current)); }