From 0a9e6bb76c1b8bc180e5e7d1d4ac3089323bb7fe Mon Sep 17 00:00:00 2001 From: "@lixingyang-li" Date: Mon, 1 Apr 2024 10:58:28 +0800 Subject: [PATCH] Add V8 interface Signed-off-by: @lixingyang-li https://gitee.com/openharmony/interface_sdk_c/issues/I9D5AG --- ark_runtime/jsvm/jsvm.h | 33 ++++++++++++++++++ ark_runtime/jsvm/jsvm_types.h | 58 +++++++++++++++++++++++++++++++ ark_runtime/jsvm/libjsvm.ndk.json | 4 +++ 3 files changed, 95 insertions(+) diff --git a/ark_runtime/jsvm/jsvm.h b/ark_runtime/jsvm/jsvm.h index 35fa95c2a..a9ff66555 100644 --- a/ark_runtime/jsvm/jsvm.h +++ b/ark_runtime/jsvm/jsvm.h @@ -2203,6 +2203,39 @@ JSVM_EXTERN JSVM_Status OH_JSVM_CloseInspector(JSVM_Env env); JSVM_EXTERN JSVM_Status OH_JSVM_WaitForDebugger(JSVM_Env env, bool breakNextLine); +/** + * @brief When packaging C++classes, the C++constructor callback passed through the constructor + * triggers the corresponding callback function when getter, setter, deleter,call, and other + * behaviors occur on the instance object, handles the user's custom behavior, and then wraps + * the new C++instance in a JavaScript object and returns the wrapper object. + * + * @param env: The environment that the API is invoked under. + * @param utf8name: Name of the JavaScript constructor function. For clarity, it is + * recommended to use the C++ class name when wrapping a C++ class. + * @param length: The length of the utf8name in bytes, or JSVM_AUTO_LENGTH if it + * is null-terminated. + * @param constructor: Struct include callback function that handles constructing instances of the class. + * When wrapping a C++ class, this method must be a static member with the JSVM_Callback.callback + * signature. A C++ class constructor cannot be used. + * Include Optional data to be passed to the constructor callback as the data + * property of the callback info. JSVM_Callback provides more details. + * @param propertyCount: Number of items in the properties array argument. + * @param properties: Array of property descriptors describing static and instance data + * properties, accessors, and methods on the class See JSVM_PropertyDescriptor. + * @param propertyHandlerCfg: The instance object triggers the corresponding callback function. + * @param result: A JSVM_Value representing the constructor function for the class. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_DefineClassWithPropertyHandler(JSVM_Env env, + const char* utf8name, + size_t length, + JSVM_Callback constructor, + size_t propertyCount, + const JSVM_PropertyDescriptor* properties, + JSVM_PropertyHandlerCfg propertyHandlerCfg, + JSVM_Value* result); + EXTERN_C_END /** @} */ diff --git a/ark_runtime/jsvm/jsvm_types.h b/ark_runtime/jsvm/jsvm_types.h index fadad53b1..cb7af8bd2 100644 --- a/ark_runtime/jsvm/jsvm_types.h +++ b/ark_runtime/jsvm/jsvm_types.h @@ -531,5 +531,63 @@ typedef struct { uint64_t upper; } JSVM_TypeTag; +/** + * @brief When the getter, setter, deleter, call, etc. behavior occurs on the object, the corresponding + * the corresponding callback will be triggered. + * + * @since 12 + */ +typedef struct { + /** A callback function triggered by getting a named property of an instance object. */ + JSVM_Value(JSVM_CDECL* genericNamedPropertyGetterCallback)(JSVM_Env env, + JSVM_Value name, + JSVM_Value thisArg); + + /** A callback function triggered by setting a named property of an instance object. */ + JSVM_Value(JSVM_CDECL* genericNamedPropertySetterCallback)(JSVM_Env env, + JSVM_Value name, + JSVM_Value property, + JSVM_Value thisArg); + + /** A callback function triggered by deletting a named property of an instance object. */ + JSVM_Value(JSVM_CDECL* genericNamedPropertyDeleterCallback)(JSVM_Env env, + JSVM_Value name, + JSVM_Value thisArg); + + /** A callback function triggered by getting all named properties requests on an object. */ + JSVM_Value(JSVM_CDECL* genericNamedPropertyEnumeratorCallback)(JSVM_Env env, + JSVM_Value thisArg); + + /** A callback function triggered by getting an indexed property of an instance object. */ + JSVM_Value(JSVM_CDECL* genericIndexedPropertyGetterCallback)(JSVM_Env env, + JSVM_Value index, + JSVM_Value thisArg); + + /** A callback function triggered by setting an indexed property of an instance object. */ + JSVM_Value(JSVM_CDECL* genericIndexedPropertySetterCallback)(JSVM_Env env, + JSVM_Value index, + JSVM_Value property, + JSVM_Value thisArg); + + /** A callback function triggered by deletting an indexed property of an instance object. */ + JSVM_Value(JSVM_CDECL* genericIndexedPropertyDeleterCallback)(JSVM_Env env, + JSVM_Value index, + JSVM_Value thisArg); + + /** A callback function triggered by getting all indexed properties requests on an object. */ + JSVM_Value(JSVM_CDECL* genericIndexedPropertyEnumeratorCallback)(JSVM_Env env, + JSVM_Value thisArg); + + /** A callback function triggered by a call on an instance object. */ + JSVM_Callback funcCallback; +} JSVM_PropertyHandlerConfigurationStruct; + +/** + * @brief The function pointer type of the callback provided by the instance object, which triggers the + * corresponding callback when getter, setter, deleter, call, and other behaviors occur on the object. + * + * @since 12 + */ +typedef JSVM_PropertyHandlerConfigurationStruct* JSVM_PropertyHandlerCfg; /** @} */ #endif /* ARK_RUNTIME_JSVM_JSVM_TYPE_H */ diff --git a/ark_runtime/jsvm/libjsvm.ndk.json b/ark_runtime/jsvm/libjsvm.ndk.json index 23ba1a5d1..268d2d010 100644 --- a/ark_runtime/jsvm/libjsvm.ndk.json +++ b/ark_runtime/jsvm/libjsvm.ndk.json @@ -566,5 +566,9 @@ { "first_introduced": "12", "name": "OH_JSVM_WaitForDebugger" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_DefineClassWithPropertyHandler" } ] -- Gitee