diff --git a/interfaces/inner_api/napi/native_node_api.h b/interfaces/inner_api/napi/native_node_api.h index b4381468ead2419636aa377188286d332540c0eb..0d99181406d216fee7fe5203a9d381c55f4508f6 100644 --- a/interfaces/inner_api/napi/native_node_api.h +++ b/interfaces/inner_api/napi/native_node_api.h @@ -50,12 +50,12 @@ NAPI_EXTERN napi_status napi_serialize_inner(napi_env env, napi_value object, na NAPI_EXTERN napi_status napi_run_actor(napi_env env, uint8_t* buffer, size_t bufferSize, const char* descriptor, napi_value* result, char* entryPoint = nullptr); NAPI_EXTERN napi_status napi_wrap_with_size(napi_env env, - napi_value js_object, - void* native_object, - napi_finalize finalize_cb, - void* finalize_hint, - napi_ref* result, - size_t native_binding_size); + napi_value js_object, + void* native_object, + napi_finalize finalize_cb, + void* finalize_hint, + napi_ref* result, + size_t native_binding_size); NAPI_EXTERN napi_status napi_wrap_async_finalizer(napi_env env, napi_value js_object, void* native_object, diff --git a/native_engine/impl/ark/ark_native_deferred.cpp b/native_engine/impl/ark/ark_native_deferred.cpp index 48a986ca4f3e11f190185181cbbd45a38d615ad6..b69e1c3be8518db79d8d04a0bc474dfbdb71e074 100644 --- a/native_engine/impl/ark/ark_native_deferred.cpp +++ b/native_engine/impl/ark/ark_native_deferred.cpp @@ -23,6 +23,8 @@ #endif #include "native_engine/native_utils.h" +using panda::LocalScope; + ArkNativeDeferred::ArkNativeDeferred(ArkNativeEngine* engine, Local deferred) : engine_(engine), deferred_(engine->GetEcmaVm(), deferred) { diff --git a/native_engine/impl/ark/ark_native_engine.cpp b/native_engine/impl/ark/ark_native_engine.cpp index 9c3796d21ed05861de62b3a0b9500e97ad71785b..4da75caeee94967ca7b8b7e21e24b31ff6e97868 100644 --- a/native_engine/impl/ark/ark_native_engine.cpp +++ b/native_engine/impl/ark/ark_native_engine.cpp @@ -73,6 +73,7 @@ static constexpr uint64_t BUF_SIZE = 128; using panda::JsiRuntimeCallInfo; using panda::BooleanRef; +using panda::DFXJSNApi; using panda::ObjectRef; using panda::StringRef; using panda::Global; @@ -80,7 +81,9 @@ using panda::FunctionRef; using panda::PrimitiveRef; using panda::ArrayBufferRef; using panda::TypedArrayRef; +using panda::JSNApi; using panda::PromiseCapabilityRef; +using panda::PropertyAttribute; using panda::NativePointerRef; using panda::SymbolRef; using panda::IntegerRef; @@ -123,13 +126,13 @@ bool ArkNativeEngine::napiProfilerEnabled {false}; bool ArkNativeEngine::napiProfilerParamReaded {false}; PermissionCheckCallback ArkNativeEngine::permissionCheckCallback_ {nullptr}; -// To be delete +// this interface is using by ace_engine napi_value LocalValueToLocalNapiValue(panda::Local local) { return JsValueFromLocalValue(local); } -// To be delete +// this interface is using by ace_engine panda::Local NapiValueToLocalValue(napi_value v) { return LocalValueFromJsValue(v); @@ -297,54 +300,6 @@ Local NapiNativeCreateSendableFunction(napi_env env, return fn; } -PropertyAttribute GetPropertyAttributeFromNapiPropertyDescriptor(napi_env env, - NapiPropertyDescriptor propertyDescriptor) -{ - auto engine = reinterpret_cast(env); - auto vm = engine->GetEcmaVm(); - Local propertyName = LocalValueFromJsValue(propertyDescriptor.name); - if (propertyDescriptor.utf8name != nullptr) { - propertyName = panda::StringRef::NewFromUtf8(vm, propertyDescriptor.utf8name); - } - - bool writable = (propertyDescriptor.attributes & NATIVE_WRITABLE) != 0; - bool enumable = (propertyDescriptor.attributes & NATIVE_ENUMERABLE) != 0; - bool configable = (propertyDescriptor.attributes & NATIVE_CONFIGURABLE) != 0; - - PropertyAttribute attr; - std::string fullName; - if (propertyDescriptor.getter != nullptr || propertyDescriptor.setter != nullptr) { - Local localGetter = panda::JSValueRef::Undefined(vm); - Local localSetter = panda::JSValueRef::Undefined(vm); - - if (propertyDescriptor.getter != nullptr) { - localGetter = NapiNativeCreateSendableFunction(env, (fullName + "getter").c_str(), - propertyDescriptor.getter, propertyDescriptor.data); - } - if (propertyDescriptor.setter != nullptr) { - localSetter = NapiNativeCreateSendableFunction(env, (fullName + "setter").c_str(), - propertyDescriptor.setter, propertyDescriptor.data); - } - Local val = panda::ObjectRef::CreateSendableAccessorData(vm, localGetter, localSetter); - attr = PropertyAttribute(val, false, enumable, configable); - } else if (propertyDescriptor.method != nullptr) { - if (propertyDescriptor.utf8name != nullptr) { - fullName += propertyDescriptor.utf8name; - } else { - fullName += propertyName->IsString() - ? Local(propertyName)->ToString() - : Local(propertyName)->GetDescription(vm)->ToString(); - } - Local func = - NapiNativeCreateSendableFunction(env, fullName.c_str(), propertyDescriptor.method, propertyDescriptor.data); - attr = PropertyAttribute(func, writable, enumable, configable); - } else { - Local val = LocalValueFromJsValue(propertyDescriptor.value); - attr = PropertyAttribute(val, writable, enumable, configable); - } - return attr; -} - panda::Local NapiDefineSendableClass(napi_env env, const char* name, NapiNativeCallback callback, @@ -818,7 +773,7 @@ panda::JSValueRef ArkNativeFunctionCallBack(JsiRuntimeCallInfo *runtimeInfo) return **localRet; } -Local NapiNativeCreateFunction(napi_env env, const char* name, NapiNativeCallback cb, void* value) +static Local NapiNativeCreateFunction(napi_env env, const char* name, NapiNativeCallback cb, void* value) { auto engine = reinterpret_cast(env); auto vm = const_cast(engine->GetEcmaVm()); @@ -1790,7 +1745,7 @@ std::string ArkNativeEngine::GetSourceCodeInfo(napi_value value, ErrorPos pos) } std::string sourceCodeInfo = "SourceCode:\n"; sourceCodeInfo.append(sourceCodeStr).append("\n"); - for (uint32_t k = 0; k < column - 1; k++) { + for (uint32_t k = 1; k < column; k++) { sourceCodeInfo.push_back(' '); } sourceCodeInfo.append("^\n"); diff --git a/native_engine/impl/ark/ark_native_engine.h b/native_engine/impl/ark/ark_native_engine.h index 58b04d8331b2210752c47b6c2ab2049930e6c869..ce1bf41becf51bb6cc0e392646ab24e3fdb1ff60 100644 --- a/native_engine/impl/ark/ark_native_engine.h +++ b/native_engine/impl/ark/ark_native_engine.h @@ -50,20 +50,12 @@ struct ApiCheckContext { } using JsFrameInfo = panda::ecmascript::JsFrameInfo; -using panda::DFXJSNApi; -using panda::Local; -using panda::LocalScope; -using panda::JSNApi; -using panda::JSValueRef; -using panda::JsiRuntimeCallInfo; -using panda::PropertyAttribute; - template -panda::JSValueRef ArkNativeFunctionCallBack(JsiRuntimeCallInfo *runtimeInfo); +panda::JSValueRef ArkNativeFunctionCallBack(panda::JsiRuntimeCallInfo *runtimeInfo); void NapiDefinePropertyInner(napi_env env, - Local &obj, + panda::Local &obj, NapiPropertyDescriptor &propertyDescriptor, - Local &propertyName, + panda::Local &propertyName, bool &result); bool NapiDefineProperty(napi_env env, panda::Local &obj, NapiPropertyDescriptor propertyDescriptor); NAPI_EXPORT panda::Local NapiValueToLocalValue(napi_value v); @@ -73,17 +65,17 @@ void FunctionSetContainerId(const EcmaVM *vm, panda::Local &l #endif panda::Local NapiDefineClass(napi_env env, const char* name, NapiNativeCallback callback, void* data, const NapiPropertyDescriptor* properties, size_t length); -Local NapiDefineSendableClass(napi_env env, - const char* name, - NapiNativeCallback callback, - void* data, - const NapiPropertyDescriptor* properties, - size_t propertiesLength, - napi_value parent); +panda::Local NapiDefineSendableClass(napi_env env, + const char* name, + NapiNativeCallback callback, + void* data, + const NapiPropertyDescriptor* properties, + size_t propertiesLength, + napi_value parent); panda::Local NapiCreateObjectWithProperties(napi_env env, size_t propertyCount, const napi_property_descriptor *properties, - Local *keys, - PropertyAttribute *attrs); + panda::Local *keys, + panda::PropertyAttribute *attrs); enum class ForceExpandState : int32_t { FINISH_COLD_START = 0, @@ -149,8 +141,9 @@ public: void* GetCurrentTaskInfo() const override; void TerminateExecution() const override; // judge_typedarray - NAPI_EXPORT bool Napi_Judge_TypedArray(NativeTypedArrayType typedArrayType, Local typedArray, - const EcmaVM* vm, Local arrayBuf, + NAPI_EXPORT bool Napi_Judge_TypedArray(NativeTypedArrayType typedArrayType, + panda::Local typedArray, + const EcmaVM* vm, panda::Local arrayBuf, size_t byte_offset, size_t length, napi_value* result) override; // Call function napi_value CallFunction(napi_value thisVar, @@ -180,7 +173,7 @@ public: void* CreateRuntime(bool isLimitedWorker = false) override; panda::Local LoadArkModule(const void *buffer, int32_t len, const std::string& fileName); napi_value ValueToNapiValue(JSValueWrapper& value) override; - NAPI_EXPORT static napi_value ArkValueToNapiValue(napi_env env, Local value); + NAPI_EXPORT static napi_value ArkValueToNapiValue(napi_env env, panda::Local value); std::string GetSourceCodeInfo(napi_value value, ErrorPos pos) override; @@ -275,7 +268,7 @@ public: napi_value NapiLoadModule(const char* path, const char* module_info) override; napi_value NapiLoadModuleWithInfo(const char* path, const char* module_info) override; std::string GetOhmurl(std::string str); - Local NapiLoadNativeModule(std::string path); + panda::Local NapiLoadNativeModule(std::string path); ModuleTypes CheckLoadType(const std::string &path); NativeReference* GetPromiseRejectCallBackRef() { diff --git a/native_engine/native_api.cpp b/native_engine/native_api.cpp index 4ab8a2cb84c07383d1a5b1fe8dae8260ad57913c..7696e17f8d643553963f3c87fa2a17f9db8cbd06 100644 --- a/native_engine/native_api.cpp +++ b/native_engine/native_api.cpp @@ -48,6 +48,7 @@ using panda::BooleanRef; using panda::BufferRef; using panda::DateRef; using panda::DataViewRef; +using panda::DFXJSNApi; using panda::EscapeLocalScope; using panda::FunctionRef; using panda::Global; diff --git a/native_engine/native_engine.cpp b/native_engine/native_engine.cpp index 0cce4517bbb52f7bb22184ed64566ebea6d3de02..edb76f0c8bb33367f130887be0b2dd09cf52eb7e 100644 --- a/native_engine/native_engine.cpp +++ b/native_engine/native_engine.cpp @@ -234,13 +234,13 @@ void NativeEngine::SetLastError(int errorCode, uint32_t engineErrorCode, void* e lastError_.reserved = engineReserved; } -void SubEncodeToUtf8(const EcmaVM* vm, - Local& nativeValue, - Local& nativeString, - char* buffer, - int32_t* written, - size_t bufferSize, - int32_t* nchars) +static void SubEncodeToUtf8(const EcmaVM* vm, + Local& nativeValue, + Local& nativeString, + char* buffer, + int32_t* written, + size_t bufferSize, + int32_t* nchars) { int32_t length = static_cast(nativeString->Length()); int32_t pos = 0; @@ -285,18 +285,18 @@ void NativeEngine::EncodeToUtf8(napi_value value, char* buffer, int32_t* written SubEncodeToUtf8(vm, nativeValue, nativeString, buffer, written, bufferSize, nchars); } -void SubEncodeToChinese(const EcmaVM* vm, - Local& nativeValue, - Local& nativeString, - std::string& buffer, - const char* encode) +static void SubEncodeToChinese(const EcmaVM* vm, + Local& nativeValue, + Local& nativeString, + std::string& buffer, + const char* encode) { int32_t length = static_cast(nativeString->Length()); int32_t pos = 0; const int32_t writableSize = 22; // 22 : encode max bytes of the ucnv_convent function; std::string tempBuf = ""; tempBuf.resize(writableSize + 1); - UErrorCode ErrorCode = U_ZERO_ERROR; + UErrorCode errorCode = U_ZERO_ERROR; const char* encFrom = "utf8"; panda::Local strObj = nativeValue->ToObject(vm); for (int32_t i = 0; i < length; i++) { @@ -304,9 +304,9 @@ void SubEncodeToChinese(const EcmaVM* vm, int32_t len = str->Utf8Length(vm) - 1; if ((pos + len) >= writableSize) { char outBuf[writableSize] = {0}; - ucnv_convert(encode, encFrom, outBuf, writableSize, tempBuf.c_str(), pos, &ErrorCode); - if (ErrorCode != U_ZERO_ERROR) { - HILOG_ERROR("ucnv_convert is failed : ErrorCode = %{public}d", static_cast(ErrorCode)); + ucnv_convert(encode, encFrom, outBuf, writableSize, tempBuf.c_str(), pos, &errorCode); + if (errorCode != U_ZERO_ERROR) { + HILOG_ERROR("ucnv_convert is failed : ErrorCode = %{public}d", static_cast(errorCode)); return; } buffer += outBuf; @@ -318,9 +318,9 @@ void SubEncodeToChinese(const EcmaVM* vm, } if (pos > 0) { char outBuf[writableSize] = {0}; - ucnv_convert(encode, encFrom, outBuf, writableSize, tempBuf.c_str(), pos, &ErrorCode); - if (ErrorCode != U_ZERO_ERROR) { - HILOG_ERROR("ucnv_convert is failed : ErrorCode = %{public}d", static_cast(ErrorCode)); + ucnv_convert(encode, encFrom, outBuf, writableSize, tempBuf.c_str(), pos, &errorCode); + if (errorCode != U_ZERO_ERROR) { + HILOG_ERROR("ucnv_convert is failed : ErrorCode = %{public}d", static_cast(errorCode)); return; } buffer += outBuf; diff --git a/native_engine/native_sendable.cpp b/native_engine/native_sendable.cpp index cb7f8156a20f0e3fbbc2acafad19f47405311177..9a0376a0bb35c0fe442cb2ade481ea401ceea539 100644 --- a/native_engine/native_sendable.cpp +++ b/native_engine/native_sendable.cpp @@ -18,7 +18,10 @@ #include "ark_native_engine.h" #include "native_engine/native_utils.h" +using panda::DFXJSNApi; +using panda::JSValueRef; using panda::ObjectRef; +using panda::PropertyAttribute; using panda::StringRef; using panda::SymbolRef;