diff --git a/ark_runtime/jsvm/jsvm.h b/ark_runtime/jsvm/jsvm.h index 467cc6d412c2bc1669421c26f3e32547024460c7..a7530de2a3d083c07abce8c66253198f4427745c 100644 --- a/ark_runtime/jsvm/jsvm.h +++ b/ark_runtime/jsvm/jsvm.h @@ -2759,6 +2759,99 @@ JSVM_EXTERN JSVM_Status OH_JSVM_IsRegExp(JSVM_Env env, JSVM_Value value, bool* result); + +/** + * @brief This API checks if the value passed in is a constructor. + * + * @param env: The environment that the API is invoked under. + * @param value: The JavaScript value to check. + * @param isConstructor: Whether the given value is Constructor. + * @return Only returns JSVM function's result code. + * {@link JSVM_OK } If the API succeeded.\n + * {@link JSVM_INVALID_ARG } If the input parameter is invalid.\n + * @since 12 + */ +JSVM_Status JSVM_CDECL OH_JSVM_IsConstructor(JSVM_Env env, + JSVM_Value value, + bool* isConstructor); + +/** + * @brief This API returns the JavaScript value of the regular expression + * corresponding to the input. + * The interface may throw an exception. + * + * @param env: The environment that the API is invoked under. + * @param value: The JavaScript string to convert to a regular expression. + * @param flags: Regular expression flag bits. + * @param result: A JSVM_Value representing a JavaScript RegExp. + * @return Only returns JSVM function's result code. + * {@link JSVM_OK } If the API succeeded.\n + * {@link JSVM_INVALID_ARG } If the input parameter is invalid.\n + * {@link JSVM_PENDING_EXCPTION } If the API throws an exception during runtime.\n + * @since 12 + */ +JSVM_Status JSVM_CDECL OH_JSVM_CreateRegExp(JSVM_Env env, + JSVM_Value value, + JSVM_RegExpFlags flags, + JSVM_Value* result); + +/** + * @brief This API returns the Object prototype. + * + * @param env: The environment that the API is invoked under. + * @param object: JSVM_Value representing JavaScript Object whose prototype to return. This returns + * the equivalent of Object.getPrototypeOf (which is not the same as the function's prototype property). + * @param result: JSVM_Value representing prototype of the given object. + * @return Returns JSVM function's result code. + * {@link JSVM_OK } If the API succeeded.\n + * {@link JSVM_INVALID_ARG } If the input parameter is invalid.\n + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_ObjectGetPrototypeOf(JSVM_Env env, + JSVM_Value object, + JSVM_Value* result); + +/** + * @brief This API set the prototype on the Object passed in. + * + * @param env: The environment that the API is invoked under. + * @param object: The object on which to set the prototype. + * @param prototype: The prototype value. + * @return Returns JSVM function's result code. + * {@link JSVM_OK } If the API succeeded.\n + * {@link JSVM_INVALID_ARG } If the input parameter is invalid.\n + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_ObjectSetPrototypeOf(JSVM_Env env, + JSVM_Value object, + JSVM_Value prototype); + +/** + * @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_INVALID_ARG } If the input parameter is invalid.\n + * {@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/jsvm_types.h b/ark_runtime/jsvm/jsvm_types.h index d0edb97a3796a684695389d9841416a502592bf6..a1ae8a5095670e02b3d923c0abb4f01f259bbaaf 100644 --- a/ark_runtime/jsvm/jsvm_types.h +++ b/ark_runtime/jsvm/jsvm_types.h @@ -686,5 +686,33 @@ typedef const uint8_t* JSVM_CodeCache; * @since 12 */ typedef const int* JSVM_CompileProfile; + +/** + * @brief Regular expression flag bits. They can be or'ed to enable a set of flags. + * + * @since 12 + */ +typedef enum { + /** None mode. */ + JSVM_REGEXP_NONE = 0, + /** Global mode. */ + JSVM_REGEXP_GLOBAL = 1 << 0, + /** Ignore Case mode. */ + JSVM_REGEXP_IGNORE_CASE = 1 << 1, + /** Multiline mode. */ + JSVM_REGEXP_MULTILINE = 1 << 2, + /** Sticky mode. */ + JSVM_REGEXP_STICKY = 1 << 3, + /** Unicode mode. */ + JSVM_REGEXP_UNICODE = 1 << 4, + /** dotAll mode. */ + JSVM_REGEXP_DOT_ALL = 1 << 5, + /** Linear mode. */ + JSVM_REGEXP_LINEAR = 1 << 6, + /** Has Indices mode. */ + JSVM_REGEXP_HAS_INDICES = 1 << 7, + /** Unicode Sets mode. */ + JSVM_REGEXP_UNICODE_SETS = 1 << 8, +} JSVM_RegExpFlags; /** @} */ #endif /* ARK_RUNTIME_JSVM_JSVM_TYPE_H */ diff --git a/ark_runtime/jsvm/libjsvm.ndk.json b/ark_runtime/jsvm/libjsvm.ndk.json index a3abb81f87b2181df8c16b5d9f38a373fe626f9b..37f66255e7d03e9c844e08197cbf9ee7d7fa49e5 100644 --- a/ark_runtime/jsvm/libjsvm.ndk.json +++ b/ark_runtime/jsvm/libjsvm.ndk.json @@ -670,5 +670,25 @@ { "first_introduced": "12", "name": "OH_JSVM_IsRegExp" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_CreateRegExp" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsConstructor" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_ObjectGetPrototypeOf" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_ObjectSetPrototypeOf" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_CreateFunctionWithScript" } ]