From d6e2603ad0911c908b131a659fc50d42943da7eb Mon Sep 17 00:00:00 2001 From: MockMockBlack Date: Mon, 25 Aug 2025 10:02:13 +0800 Subject: [PATCH] [Interop] saves a raw pointer to Xref Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICUGI1 Change-Id: I4bc9f2f7a999c4c352b644dc2050a79f95c8ab80 Signed-off-by: MockMockBlack --- ecmascript/cross_vm/global_env_constants_hybrid.h | 2 ++ ecmascript/cross_vm/jsnapi_expo_hybrid.cpp | 10 ++++++++++ ecmascript/cross_vm/jsnapi_expo_hybrid.h | 2 +- ecmascript/napi/include/jsnapi_expo.h | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ecmascript/cross_vm/global_env_constants_hybrid.h b/ecmascript/cross_vm/global_env_constants_hybrid.h index 944fa7174d..ab1ca1a65e 100644 --- a/ecmascript/cross_vm/global_env_constants_hybrid.h +++ b/ecmascript/cross_vm/global_env_constants_hybrid.h @@ -17,6 +17,8 @@ #define SHARED_GLOBAL_ENV_CONSTANT_STRING_HYBRID(V) \ V(ProxyNapiWrapperString, PROXY_NAPI_WRAPPER_INDEX, "_proxynapiwrapper") \ + V(SharedReferencePointer, SHARED_REFERENCE_POINTER_INDEX, \ + "_shared_reference_pointer") \ V(UnifiedGcCause, UNIFIED_GC_CAUSE, "unified") #define GLOBAL_ENV_CONSTANT_CLASS_HYBRID(V) \ diff --git a/ecmascript/cross_vm/jsnapi_expo_hybrid.cpp b/ecmascript/cross_vm/jsnapi_expo_hybrid.cpp index 69b8ff7939..d2b2fec538 100644 --- a/ecmascript/cross_vm/jsnapi_expo_hybrid.cpp +++ b/ecmascript/cross_vm/jsnapi_expo_hybrid.cpp @@ -40,6 +40,16 @@ Local StringRef::GetProxyNapiWrapperString(const EcmaVM *vm) return JSNApiHelper::ToLocal(proxyNapiWapperString); } +Local StringRef::GetSharedReferencePointer(const EcmaVM *vm) { + // Omit exception check because ark calls here may not + // cause side effect even pending exception exists. + CROSS_THREAD_CHECK(vm); + ecmascript::ThreadManagedScope managedScope(thread); + JSHandle proxyNapiWapperString = + thread->GlobalConstants()->GetHandledSharedReferencePointer(); + return JSNApiHelper::ToLocal(proxyNapiWapperString); +} + Local ObjectRef::NewJSXRefObject(const EcmaVM *vm) { CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); diff --git a/ecmascript/cross_vm/jsnapi_expo_hybrid.h b/ecmascript/cross_vm/jsnapi_expo_hybrid.h index ce2821898e..c86b4e20bd 100644 --- a/ecmascript/cross_vm/jsnapi_expo_hybrid.h +++ b/ecmascript/cross_vm/jsnapi_expo_hybrid.h @@ -29,7 +29,7 @@ #define OBJECTREF_PUBLIC_HYBRID_EXTENSION() \ static Local NewJSXRefObject(const EcmaVM *vm) -#define STRINGREF_PUBLIC_HYBRID_EXTENSION() \ +#define STRINGREF_PUBLIC_HYBRID_EXTENSION() \ static Local GetProxyNapiWrapperString(const EcmaVM *vm) #define JSNAPI_PUBLIC_HYBRID_EXTENSION() \ diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index 42418faaf2..8376199909 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -1055,6 +1055,7 @@ public: static Local GetNapiWrapperString(const EcmaVM *vm); Local EncodeIntoUint8Array(const EcmaVM *vm); STRINGREF_PUBLIC_HYBRID_EXTENSION(); + static Local GetSharedReferencePointer(const EcmaVM *vm); }; class PUBLIC_API PromiseRejectInfo { -- Gitee