diff --git a/native/cocos/bindings/jswrapper/jsvm/Object.cpp b/native/cocos/bindings/jswrapper/jsvm/Object.cpp index 02560a20aa1..b12ffb5ce9a 100644 --- a/native/cocos/bindings/jswrapper/jsvm/Object.cpp +++ b/native/cocos/bindings/jswrapper/jsvm/Object.cpp @@ -104,7 +104,7 @@ void Object::setPrivateObject(PrivateObjectBase* data) { auto tmpThis = _objRef.getValue(_env); JSVM_Ref result = nullptr; NODE_API_CALL(status, _env, - OH_JSVM_Wrap(_env, tmpThis, this, sendWeakCallback, + OH_JSVM_Wrap(_env, tmpThis, this, weakCallback, (void*)this /* finalize_hint */, &result)); //_objRef.setWeakref(_env, result); setProperty("__native_ptr__", se::Value(static_cast(reinterpret_cast(data)))); @@ -423,19 +423,8 @@ Object* Object::createTypedArrayWithBuffer(TypedArrayType type, const Object *ob Object* Object::createExternalArrayBufferObject(void* contents, size_t byteLength, BufferContentsFreeFunc freeFunc, void* freeUserData) { JSVM_Status status; JSVM_Value result; - if (freeFunc) { - struct ExternalArrayBufferCallbackParams* param = new (struct ExternalArrayBufferCallbackParams); - param->func = freeFunc; - param->contents = contents; - param->byteLength = byteLength; - param->userData = freeUserData; - NODE_API_CALL(status, ScriptEngine::getEnv(), OH_JSVM_CreateArraybuffer(ScriptEngine::getEnv(), byteLength, &contents, &result)); - param->func(param->contents, param->byteLength, param->userData); - delete param; - } else { - NODE_API_CALL(status, ScriptEngine::getEnv(), OH_JSVM_CreateArraybuffer(ScriptEngine::getEnv(), byteLength, &contents, &result)); - } - + // JSVM does not support the napi_create_external_arraybuffer interface like in NAPI. + NODE_API_CALL(status, ScriptEngine::getEnv(), OH_JSVM_CreateArrayBufferFromBackingStoreData(ScriptEngine::getEnv(), contents, byteLength, 0, byteLength, &result)); Object* obj = Object::_createJSObject(ScriptEngine::getEnv(), result, nullptr); return obj; } @@ -703,6 +692,7 @@ void Object::sendWeakCallback(JSVM_Env env, void* nativeObject, void* finalizeHi } void Object::weakCallback(JSVM_Env env, void* nativeObject, void* finalizeHint /*finalize_hint*/) { + if (finalizeHint) { if (nativeObject == nullptr) { return; @@ -710,9 +700,6 @@ void Object::weakCallback(JSVM_Env env, void* nativeObject, void* finalizeHint / void *rawPtr = reinterpret_cast(finalizeHint)->_privateData; Object* seObj = reinterpret_cast(finalizeHint); Object* rawPtrObj = reinterpret_cast(rawPtr); - if(rawPtrObj->getRefCount() == 0) { - return; - } if (seObj->_onCleaingPrivateData) { //called by cleanPrivateData, not release seObj; return; } @@ -726,11 +713,11 @@ void Object::weakCallback(JSVM_Env env, void* nativeObject, void* finalizeHint / } if (seObj->_finalizeCb != nullptr) { - seObj->_finalizeCb(env, rawPtr, rawPtr); + seObj->_finalizeCb(env, finalizeHint, finalizeHint); } else { assert(seObj->_getClass() != nullptr); if (seObj->_getClass()->_getFinalizeFunction() != nullptr) { - seObj->_getClass()->_getFinalizeFunction()(env, rawPtr, rawPtr); + seObj->_getClass()->_getFinalizeFunction()(env, finalizeHint, finalizeHint); } } seObj->decRef(); diff --git a/native/cocos/bindings/jswrapper/jsvm/Object.h b/native/cocos/bindings/jswrapper/jsvm/Object.h index c6238130d3b..4f83928025b 100644 --- a/native/cocos/bindings/jswrapper/jsvm/Object.h +++ b/native/cocos/bindings/jswrapper/jsvm/Object.h @@ -189,10 +189,10 @@ class Object : public RefCounter { /** - * @brief Delete a property of an object. - * @param[in] name A utf-8 string containing the property's name. - * @return true if the property is deleted successfully, otherwise false. - */ + * @brief Delete a property of an object. + * @param[in] name A utf-8 string containing the property's name. + * @return true if the property is deleted successfully, otherwise false. + */ bool deleteProperty(const char *name); /** diff --git a/native/cocos/bindings/jswrapper/napi/Object.cpp b/native/cocos/bindings/jswrapper/napi/Object.cpp index 732d1403570..2d50ccac80b 100644 --- a/native/cocos/bindings/jswrapper/napi/Object.cpp +++ b/native/cocos/bindings/jswrapper/napi/Object.cpp @@ -662,11 +662,11 @@ void Object::weakCallback(napi_env env, void* nativeObject, void* finalizeHint / } if (seObj->_finalizeCb != nullptr) { - seObj->_finalizeCb(env, rawPtr, rawPtr); + seObj->_finalizeCb(env, finalizeHint, finalizeHint); } else { assert(seObj->_getClass() != nullptr); if (seObj->_getClass()->_getFinalizeFunction() != nullptr) { - seObj->_getClass()->_getFinalizeFunction()(env, rawPtr, rawPtr); + seObj->_getClass()->_getFinalizeFunction()(env, finalizeHint, finalizeHint); } } seObj->decRef(); diff --git a/native/cocos/bindings/manual/jsb_global.cpp b/native/cocos/bindings/manual/jsb_global.cpp index 41685fb68eb..338ad1a72bd 100644 --- a/native/cocos/bindings/manual/jsb_global.cpp +++ b/native/cocos/bindings/manual/jsb_global.cpp @@ -979,7 +979,7 @@ static bool jsb_createExternalArrayBuffer(se::State &s) { // NOLINT SE_PRECONDITION2(ok, false, "Error processing arguments"); if (byteLength > 0) { // NOTE: Currently V8 use shared_ptr which has different abi on win64-debug and win64-release -#if CC_PLATFORM == CC_PLATFORM_WINDOWS && SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_V8 +#if (CC_PLATFORM == CC_PLATFORM_WINDOWS && SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_V8) || (SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSVM) se::HandleObject arrayBuffer{se::Object::createArrayBufferObject(nullptr, byteLength)}; #else void *buffer = malloc(byteLength);