From 74343325e738bf0ba831e2e154410ae87b3c59e6 Mon Sep 17 00:00:00 2001 From: Chongwei Su Date: Sun, 7 Apr 2024 12:57:27 +0800 Subject: [PATCH] Add JSVM sourcemap&lock&iscallableµtask API issue:https://gitee.com/openharmony/interface_sdk_c/issues/I9EFU5 Signed-off-by: Chongwei Su --- ark_runtime/jsvm/jsvm.h | 87 +++++++++++++++++++++++++++++++ ark_runtime/jsvm/jsvm_types.h | 16 ++++++ ark_runtime/jsvm/libjsvm.ndk.json | 28 ++++++++++ 3 files changed, 131 insertions(+) diff --git a/ark_runtime/jsvm/jsvm.h b/ark_runtime/jsvm/jsvm.h index 2dc39225b..dbf0f8e11 100644 --- a/ark_runtime/jsvm/jsvm.h +++ b/ark_runtime/jsvm/jsvm.h @@ -240,6 +240,30 @@ JSVM_EXTERN JSVM_Status OH_JSVM_CompileScript(JSVM_Env env, bool* cacheRejected, JSVM_Script* result); +/** + * @brief This function compiles a string of JavaScript code with the source code information + * and returns the compiled script. + * + * @param env: The environment that the JSVM-API call is invoked under. + * @param script: A JavaScript string containing the script to be compiled. + * @param cachedData: Optional code cache data for the script. + * @param cacheDataLength: The length of cachedData array. + * @param eagerCompile: Whether to compile the script eagerly. + * @param cacheRejected: Whether the code cache rejected by compilation. + * @param origin: The information of source code. + * @param result: The compiled script. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_CompileScriptWithOrigin(JSVM_Env env, + JSVM_Value script, + const uint8_t* cachedData, + size_t cacheDataLength, + bool eagerCompile, + bool* cacheRejected, + JSVM_ScriptOrigin* origin, + JSVM_Script* result); + /** * @brief This function creates code cache for the compiled script. * @@ -2252,6 +2276,69 @@ JSVM_EXTERN JSVM_Status OH_JSVM_DefineClassWithPropertyHandler(JSVM_Env env, JSVM_Callback callAsFunctionCallback, JSVM_Value* result); +/** + * @brief Determines whether the current thread holds the lock for the specified environment. + * Only threads that hold locks can use the environment. + * + * @param env: The environment that the API is invoked under. + * @param isLocked: Flag indicating whether the current thread holds the lock for the specified environment. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsLocked(JSVM_Env env, + bool* isLocked); + +/** + * @brief Acquire the lock for the specified environment. Only threads that hold locks can use the environment. + * + * @param env: The environment that the API is invoked under. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_AcquireLock(JSVM_Env env); + +/** + * @brief Release the lock for the specified environment. Only threads that hold locks can use the environment. + * + * @param env: The environment that the API is invoked under. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_ReleaseLock(JSVM_Env env); + +/** + * @brief Starts the running of the task queue inside the VM. + * This task queue can be executed by an external event loop. + * + * @param env: The VM instance on which to start the task queue. + * @param result: Whether the task queue was successfully started. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_PumpMessageLoop(JSVM_VM vm, + bool* result); + +/** + * @brief Check to see if there are any microtasks waiting in the queue, and if there are, execute them. + * + * @param env: The VM instance on which to check microtasks. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_PerformMicrotaskCheckpoint(JSVM_VM vm); + +/** + * @brief This API checks if the value passed in is callable. + * + * @param env: The VM instance on which to check microtasks. + * @param value: The JavaScript value to check. + * @param isCallable: Whether the given value is callable. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsCallable(JSVM_Env env, + JSVM_Value value, + bool* isCallable); EXTERN_C_END /** @} */ diff --git a/ark_runtime/jsvm/jsvm_types.h b/ark_runtime/jsvm/jsvm_types.h index 228830d2c..23c482bb7 100644 --- a/ark_runtime/jsvm/jsvm_types.h +++ b/ark_runtime/jsvm/jsvm_types.h @@ -599,5 +599,21 @@ typedef struct { * @since 12 */ typedef JSVM_PropertyHandlerConfigurationStruct* JSVM_PropertyHandlerCfg; + +/** + * @brief Source code information. + * + * @since 12 + */ +typedef struct { + /** Sourcemap url. */ + const char* sourceMapUrl; + /** Resource name. */ + const char* resourceName; + /** Resource line offset. */ + size_t resourceLineOffset; + /** Resource column offset. */ + size_t resourceColumnOffset; +} JSVM_ScriptOrigin; /** @} */ #endif /* ARK_RUNTIME_JSVM_JSVM_TYPE_H */ diff --git a/ark_runtime/jsvm/libjsvm.ndk.json b/ark_runtime/jsvm/libjsvm.ndk.json index 3f828a2cb..acc6c84c6 100644 --- a/ark_runtime/jsvm/libjsvm.ndk.json +++ b/ark_runtime/jsvm/libjsvm.ndk.json @@ -43,6 +43,10 @@ "first_introduced": "11", "name": "OH_JSVM_CompileScript" }, + { + "first_introduced": "12", + "name": "OH_JSVM_CompileScriptWithOrigin" + }, { "first_introduced": "11", "name": "OH_JSVM_CreateCodeCache" @@ -574,5 +578,29 @@ { "first_introduced": "12", "name": "OH_JSVM_Equals" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsLocked" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_AcquireLock" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_ReleaseLock" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_PumpMessageLoop" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_PerformMicrotaskCheckpoint" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsCallable" } ] -- Gitee