diff --git a/ark_runtime/jsvm/jsvm.h b/ark_runtime/jsvm/jsvm.h index 2f38b4ac90fdad1c5577e30333d88e69f890f0b3..1de4e6e302e0638a59ed7509cbdffcfd03da6eb0 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 e290f2815c9dc6dd3958b2c2be17c80201ce6b49..a96763a83eaede374e6e8ff2fe95d9c45df4320c 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" } ]