From bb1353cb152c926d5e9402764bf6fd73627582c1 Mon Sep 17 00:00:00 2001 From: bwtang Date: Tue, 7 May 2024 14:20:40 +0800 Subject: [PATCH] add OH_JSVM_IsXXX interfaces for fast js type checking Signed-off-by: bwtang --- ark_runtime/jsvm/jsvm.h | 130 ++++++++++++++++++++++++++++++ ark_runtime/jsvm/libjsvm.ndk.json | 40 +++++++++ 2 files changed, 170 insertions(+) diff --git a/ark_runtime/jsvm/jsvm.h b/ark_runtime/jsvm/jsvm.h index dbf0f8e11..9ed5fb1c5 100644 --- a/ark_runtime/jsvm/jsvm.h +++ b/ark_runtime/jsvm/jsvm.h @@ -2339,6 +2339,136 @@ JSVM_EXTERN JSVM_Status OH_JSVM_PerformMicrotaskCheckpoint(JSVM_VM vm); JSVM_EXTERN JSVM_Status OH_JSVM_IsCallable(JSVM_Env env, JSVM_Value value, bool* isCallable); + +/** + * @brief This API checks if the value passed in is Undefined. + * + * @param env: The VM instance on which to check microtasks. + * @param value: The JavaScript value to check. + * @param isUndefined: Whether the given value is Undefined. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsUndefined(JSVM_Env env, + JSVM_Value value, + bool* isUndefined); + +/** + * @brief This API checks if the value passed in is Null. + * + * @param env: The VM instance on which to check microtasks. + * @param value: The JavaScript value to check. + * @param isNull: Whether the given value is Null. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsNull(JSVM_Env env, + JSVM_Value value, + bool* isNull); + +/** + * @brief This API checks if the value passed in is Null or Undefined. + * + * @param env: The VM instance on which to check microtasks. + * @param value: The JavaScript value to check. + * @param isNullOrUndefined: Whether the given value is Null or Undefined. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsNullOrUndefined(JSVM_Env env, + JSVM_Value value, + bool* isNullOrUndefined); + +/** + * @brief This API checks if the value passed in is Boolean. + * + * @param env: The VM instance on which to check microtasks. + * @param value: The JavaScript value to check. + * @param isBoolean: Whether the given value is Boolean. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsBoolean(JSVM_Env env, + JSVM_Value value, + bool* isBoolean); + +/** + * @brief This API checks if the value passed in is Number. + * + * @param env: The VM instance on which to check microtasks. + * @param value: The JavaScript value to check. + * @param isNumber: Whether the given value is Number. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsNumber(JSVM_Env env, + JSVM_Value value, + bool* isNumber); + +/** + * @brief This API checks if the value passed in is String. + * + * @param env: The VM instance on which to check microtasks. + * @param value: The JavaScript value to check. + * @param isString: Whether the given value is String. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsString(JSVM_Env env, + JSVM_Value value, + bool* isString); + +/** + * @brief This API checks if the value passed in is Symbol. + * + * @param env: The VM instance on which to check microtasks. + * @param value: The JavaScript value to check. + * @param isSymbol: Whether the given value is Symbol. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsSymbol(JSVM_Env env, + JSVM_Value value, + bool* isSymbol); + +/** + * @brief This API checks if the value passed in is Function. + * + * @param env: The VM instance on which to check microtasks. + * @param value: The JavaScript value to check. + * @param isFunction: Whether the given value is Function. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsFunction(JSVM_Env env, + JSVM_Value value, + bool* isFunction); + +/** + * @brief This API checks if the value passed in is Object. + * + * @param env: The VM instance on which to check microtasks. + * @param value: The JavaScript value to check. + * @param isObject: Whether the given value is Object. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsObject(JSVM_Env env, + JSVM_Value value, + bool* isObject); + +/** + * @brief This API checks if the value passed in is BigInt. + * + * @param env: The VM instance on which to check microtasks. + * @param value: The JavaScript value to check. + * @param isBigInt: Whether the given value is BigInt. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsBigInt(JSVM_Env env, + JSVM_Value value, + bool* isBigInt); EXTERN_C_END /** @} */ diff --git a/ark_runtime/jsvm/libjsvm.ndk.json b/ark_runtime/jsvm/libjsvm.ndk.json index acc6c84c6..c5317764b 100644 --- a/ark_runtime/jsvm/libjsvm.ndk.json +++ b/ark_runtime/jsvm/libjsvm.ndk.json @@ -602,5 +602,45 @@ { "first_introduced": "12", "name": "OH_JSVM_IsCallable" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsUndefined" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsNull" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsNullOrUndefined" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsBoolean" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsNumber" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsString" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsSymbol" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsFunction" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsObject" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_IsBigInt" } ] -- Gitee