From 17c7fedf8c3a4118a3be8fbf6b335e1078f23b30 Mon Sep 17 00:00:00 2001 From: zhangyukun Date: Tue, 14 Sep 2021 19:11:47 +0800 Subject: [PATCH] Ark adapt for ACE2.0 Signed-off-by: zhangyukun Change-Id: I25881189fde9386fe1a73813ef0b1d1333d97a2d --- ecmascript/js_handle.h | 8 ++++++-- ecmascript/napi/include/jsnapi.h | 4 +++- ecmascript/napi/jsnapi.cpp | 7 ++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ecmascript/js_handle.h b/ecmascript/js_handle.h index dffb90285e..b419f15a7c 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 eb5db58702..4bf334dd88 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 60d3168abc..4ab3e3ad29 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)); } -- Gitee