From 003e7bace1d2b89bccf2ebd4831b0a2781b8bf94 Mon Sep 17 00:00:00 2001 From: wengchangcheng Date: Mon, 13 May 2024 17:10:48 +0800 Subject: [PATCH] modify sendable api and optimize napi performence 1. use napi_wrap instead of napi_wrap_sendable 2. optimize napi_wrap performence https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I9OOKP Signed-off-by: wengchangcheng Change-Id: I574a2dffd442dedf77bd7b2a6066d7a5a0f85282 --- ecmascript/jsnapi_sendable.cpp | 1 + ecmascript/napi/include/jsnapi_expo.h | 12 ++++++------ ecmascript/napi/jsnapi.cpp | 2 +- ecmascript/napi/jsnapi_expo.cpp | 25 ++++++++++++++++--------- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/ecmascript/jsnapi_sendable.cpp b/ecmascript/jsnapi_sendable.cpp index 0163c3163c..2d9f5ad329 100644 --- a/ecmascript/jsnapi_sendable.cpp +++ b/ecmascript/jsnapi_sendable.cpp @@ -102,6 +102,7 @@ void JSNapiSendable::InitWithPropertiesInfo(JSThread *thread, desc.SetValue(JSNApiHelper::ToJSHandle(info.attributes[i].GetValue(vm))); descs.push_back(desc); } + InitInstanceDescription(thread, descs); } SharedFieldType JSNapiSendable::GetSharedFieldType(JSThread *thread, diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index 812a539953..e90012c83f 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -1032,7 +1032,7 @@ public: class ECMA_PUBLIC_API SharedInt8ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; @@ -1043,7 +1043,7 @@ public: class ECMA_PUBLIC_API SharedUint8ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; @@ -1060,7 +1060,7 @@ public: class ECMA_PUBLIC_API SharedInt16ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; @@ -1072,7 +1072,7 @@ public: class ECMA_PUBLIC_API SharedUint16ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; @@ -1083,7 +1083,7 @@ public: class ECMA_PUBLIC_API SharedInt32ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; @@ -1095,7 +1095,7 @@ public: class ECMA_PUBLIC_API SharedUint32ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; diff --git a/ecmascript/napi/jsnapi.cpp b/ecmascript/napi/jsnapi.cpp index a36a5e0c00..0a71158a8f 100644 --- a/ecmascript/napi/jsnapi.cpp +++ b/ecmascript/napi/jsnapi.cpp @@ -230,7 +230,7 @@ TYPED_ARRAY_ALL(TYPED_ARRAY_NEW) #define SENDABLE_TYPED_ARRAY_NEW(Type) \ Local Type##Ref::New( \ - const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length) \ + const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length) \ { \ CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); \ ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); \ diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 07a8480f1f..8557639299 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -944,7 +944,7 @@ bool JSValueRef::IsVector() bool JSValueRef::IsSharedObject() { - return JSNApiHelper::ToJSTaggedValue(this).IsJSSharedObject(); + return IsJSShared() && IsObject(); } bool JSValueRef::IsSharedFunction() @@ -1019,16 +1019,23 @@ bool JSValueRef::IsDetachedArraybuffer(bool &isArrayBuffer) void JSValueRef::DetachedArraybuffer(const EcmaVM *vm, bool &isArrayBuffer) { - if (!IsArrayBuffer()) { + if (IsArrayBuffer()) { + JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); + if (arrayBuffer->IsDetach()) { + return; + } + arrayBuffer->Detach(vm->GetJSThread()); + isArrayBuffer = true; + } else if (IsSendableArrayBuffer()) { + JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); + if (arrayBuffer->IsDetach()) { + return; + } + arrayBuffer->Detach(vm->GetJSThread()); + isArrayBuffer = true; + } else { isArrayBuffer = false; - return; - } - isArrayBuffer = true; - JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); - if (arrayBuffer->IsDetach()) { - return; } - arrayBuffer->Detach(vm->GetJSThread()); } void JSValueRef::GetDataViewInfo(const EcmaVM *vm, -- Gitee