From d9a51eca9644764dde5336ff55c7a71140fda298 Mon Sep 17 00:00:00 2001 From: chenraozhong Date: Tue, 2 Jul 2024 09:58:10 +0800 Subject: [PATCH] Add OH_JSVM_CreateFunctionWithScript Signed-off-by: chenraozhong --- ark_runtime/jsvm/jsvm.h | 26 ++++++++++++++++++++++++++ ark_runtime/jsvm/libjsvm.ndk.json | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/ark_runtime/jsvm/jsvm.h b/ark_runtime/jsvm/jsvm.h index 2f38b4ac9..1de4e6e30 100644 --- a/ark_runtime/jsvm/jsvm.h +++ b/ark_runtime/jsvm/jsvm.h @@ -2651,6 +2651,32 @@ JSVM_EXTERN JSVM_Status OH_JSVM_IsObject(JSVM_Env env, JSVM_EXTERN JSVM_Status OH_JSVM_IsBigInt(JSVM_Env env, JSVM_Value value, bool* isBigInt); + +/** + * @brief Creates a function with a given script as its body. + * + * @param env: The environment that the API is invoked under. + * @param funcName: A string containing the function's name. Pass NULL to create an anonymous function. + * @param length: The length of the funcName in bytes, or JSVM_AUTO_LENGTH if it + * is null-terminated. + * @param argc: The count of elements in the argv array. + * @param argv: Array of JSVM_Values representing JavaScript strings passed in as arguments to the function. + * @param script: A JavaScript string containing the script to use as the function's body. + * @param result: JSVM_Value representing the JavaScript function object for the newly + * created function. + * @return Returns JSVM function's result code. + * {@link JSVM_OK } If the API succeeded. + * {@link JSVM_GENERIC_FAILURE} If the input script fails to be compiled.\n + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_CreateFunctionWithScript(JSVM_Env env, + const char* funcName, + size_t length, + size_t argc, + const JSVM_Value* argv, + JSVM_Value script, + JSVM_Value* result); + EXTERN_C_END /** @} */ diff --git a/ark_runtime/jsvm/libjsvm.ndk.json b/ark_runtime/jsvm/libjsvm.ndk.json index e290f2815..a96763a83 100644 --- a/ark_runtime/jsvm/libjsvm.ndk.json +++ b/ark_runtime/jsvm/libjsvm.ndk.json @@ -642,5 +642,9 @@ { "first_introduced": "12", "name": "OH_JSVM_Equals" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_CreateFunctionWithScript" } ] -- Gitee