From 49af076c17ebf9a357fc8bcb664b02f4ac819265 Mon Sep 17 00:00:00 2001 From: jiang-qunchao Date: Sat, 29 Jun 2024 15:12:18 +0800 Subject: [PATCH] =?UTF-8?q?JSVM=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiang-qunchao --- ark_runtime/jsvm/jsvm.h | 108 ++++++++++++++++++++++++++++++ ark_runtime/jsvm/jsvm_types.h | 71 ++++++++++++++++++++ ark_runtime/jsvm/libjsvm.ndk.json | 28 ++++++++ 3 files changed, 207 insertions(+) diff --git a/ark_runtime/jsvm/jsvm.h b/ark_runtime/jsvm/jsvm.h index 462e0203d..6e980ed74 100644 --- a/ark_runtime/jsvm/jsvm.h +++ b/ark_runtime/jsvm/jsvm.h @@ -2639,6 +2639,114 @@ 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 This API returns a JSVM-API value corresponding to a JavaScript Map type. + * + * @param env: The environment that the API is invoked under. + * @param result: A JSVM_Value representing a JavaScript Map. + * @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_CreateMap(JSVM_Env env, JSVM_Value* result); + +/** + * @brief This API checks if the value passed in is a Map. + * + * @param env: The environment that the API is invoked under. + * @param value: The JavaScript value to check. + * @param isMap: Whether the given value is Map. + * @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_IsMap(JSVM_Env env, + JSVM_Value value, + bool* isMap); + +/** + * @brief This API returns a JSVM-API value corresponding to a JavaScript Set type. + * + * @param env: The environment that the API is invoked under. + * @param result: A JSVM_Value representing a JavaScript Set. + * @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_CreateSet(JSVM_Env env, + JSVM_Value* result); + +/** + * @brief This API checks if the value passed in is a Set. + * + * @param env: The environment that the API is invoked under. + * @param value: The JavaScript value to check. + * @param isSet: Whether the given value is Set. + * @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_IsSet(JSVM_Env env, + JSVM_Value value, + bool* isSet); + +/** + * @brief This function compiles a string of JavaScript code with the compile options + * 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 optionCount: length of option array. + * @param options: Compile options to be passed. + * @param result: The compiled script. + * @return Returns JSVM functions 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_CompileScriptWithOptions(JSVM_Env env, + JSVM_Value script, + size_t optionCount, + JSVM_CompileOptions options[], + JSVM_Value* result); + +/** + * @brief This API implements the abstract operation ToBigInt(). + * + * @param env: The environment that the API is invoked under. + * @param value: The JavaScript value to coerce. + * @param result: JSVM_Value representing the coerced JavaScript BigInt. + * @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_BIGINT_EXPECTED} If the JavaScript value fails to coerce.\n + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_CoerceToBigInt(JSVM_Env env, + JSVM_Value value, + JSVM_Value* result); + +/** + * @brief This API checks if the value passed in is a regExp. + * This equals to `value instanceof RegExp` in JS. + * + * @param env: The environment that the API is invoked under. + * @param value: The JavaScript value to check. + * @param result: Whether the given value is RegExp. + * @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_IsRegExp(JSVM_Env env, + JSVM_Value value, + bool* result); + EXTERN_C_END /** @} */ diff --git a/ark_runtime/jsvm/jsvm_types.h b/ark_runtime/jsvm/jsvm_types.h index 23c482bb7..d0edb97a3 100644 --- a/ark_runtime/jsvm/jsvm_types.h +++ b/ark_runtime/jsvm/jsvm_types.h @@ -44,6 +44,7 @@ #include // NOLINT(modernize-deprecated-headers) #include // NOLINT(modernize-deprecated-headers) +#include // NOLINT(modernize-deprecated-headers) #if !defined __cplusplus || (defined(_MSC_VER) && _MSC_VER < 1900) typedef uint16_t char16_t; @@ -376,6 +377,43 @@ typedef enum { JSVM_MEMORY_PRESSURE_LEVEL_CRITICAL, } JSVM_MemoryPressureLevel; +/** + * + * @brief Compile mode + * + * @since 12 + */ +typedef enum { + /** default mode. */ + JSVM_COMPILE_MODE_DEFAULT, + /** consume code cache. */ + JSVM_COMPILE_MODE_CONSUME_CODE_CACHE, + /** apply eager compile. */ + JSVM_COMPILE_MODE_EAGER_COMPILE, + /** preset for compile profile. */ + JSVM_COMPILE_MODE_PRODUCE_COMPILE_PROFILE, + /** consume compile profile. */ + JSVM_COMPILE_MODE_CONSUME_COMPILE_PROFILE, +} JSVM_CompileMode; + +/** + * @brief Compile option id + * + * @since 12 + */ +typedef enum { + /** compile mode. */ + JSVM_COMPILE_MODE, + /** code cache content. */ + JSVM_COMPILE_CODE_CACHE, + /** script origin. */ + JSVM_COMPILE_SCRIPT_ORIGIN, + /** compile profile content. */ + JSVM_COMPILE_COMPILE_PROFILE, + /** switch for source map support. */ + JSVM_COMPILE_ENABLE_SOURCE_MAP, +} JSVM_CompileOptionId; + /** * @brief Heap statisics. * @@ -615,5 +653,38 @@ typedef struct { /** Resource column offset. */ size_t resourceColumnOffset; } JSVM_ScriptOrigin; + +/** + * @brief Compile Options + * + * @since 12 + */ +typedef struct { + /** compile option id. */ + JSVM_CompileOptionId id; + /** option content. */ + union { + /** ptr type. */ + void *ptr; + /** int type. */ + int num; + /** bool type. */ + _Bool boolean; + } content; +} JSVM_CompileOptions; + +/** + * @brief code cache passed with JSVM_COMPILE_CODE_CACHE + * + * @since 12 + */ +typedef const uint8_t* JSVM_CodeCache; + +/** + * @brief compile profile passed with JSVM_COMPILE_COMPILE_PROFILE + * + * @since 12 + */ +typedef const int* JSVM_CompileProfile; /** @} */ #endif /* ARK_RUNTIME_JSVM_JSVM_TYPE_H */ diff --git a/ark_runtime/jsvm/libjsvm.ndk.json b/ark_runtime/jsvm/libjsvm.ndk.json index e290f2815..a3abb81f8 100644 --- a/ark_runtime/jsvm/libjsvm.ndk.json +++ b/ark_runtime/jsvm/libjsvm.ndk.json @@ -642,5 +642,33 @@ { "first_introduced": "12", "name": "OH_JSVM_Equals" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_CreateMap" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsMap" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_CreateSet" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsSet" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_CompileScriptWithOptions" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_CoerceToBigInt" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsRegExp" } ]