From da76450ae7a1c2c3854ef8bbfb2b7ef580fdbce1 Mon Sep 17 00:00:00 2001 From: bwtang Date: Wed, 8 May 2024 16:10:17 +0800 Subject: [PATCH 1/4] add OH_JSVM_IsXXX interfaces for fast js type checking Signed-off-by: bwtang --- ark_runtime/jsvm/jsvm.h | 139 ++++++++++++++++++++++++++++++ ark_runtime/jsvm/libjsvm.ndk.json | 40 +++++++++ 2 files changed, 179 insertions(+) diff --git a/ark_runtime/jsvm/jsvm.h b/ark_runtime/jsvm/jsvm.h index dbf0f8e11..a853b6d0a 100644 --- a/ark_runtime/jsvm/jsvm.h +++ b/ark_runtime/jsvm/jsvm.h @@ -2339,6 +2339,145 @@ 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 an undefined object. + * This equals to `typeof value === 'undefined'` in JS. + * + * @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 a null object. + * This equals to `typeof value === 'null'` in JS. + * + * @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 either a null or an undefined object. + * This is equivalent to `typeof value == 'null'` in JS. + * + * @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 a boolean. + * This equals to `typeof value === 'boolean'` in JS. + * + * @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 a number. + * This equals to `typeof value === 'number'` in JS. + * + * @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 a string. + * This equals to `typeof value === 'string'` in JS. + * + * @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 a symbol. + * This equals to `typeof value === 'symbol'` in JS. + * + * @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 a function. + * This equals to `typeof value === 'function'` in JS. + * + * @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 an 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 a bigInt. + * This equals to `typeof value === 'bigint'` in JS. + * + * @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 From d5f7311290e1ab2de870095eeeabc09b9718e600 Mon Sep 17 00:00:00 2001 From: bwtang Date: Wed, 8 May 2024 16:47:16 +0800 Subject: [PATCH 2/4] fix some comments of the new added interfaces Signed-off-by: bwtang --- ark_runtime/jsvm/jsvm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ark_runtime/jsvm/jsvm.h b/ark_runtime/jsvm/jsvm.h index a853b6d0a..69cd0365b 100644 --- a/ark_runtime/jsvm/jsvm.h +++ b/ark_runtime/jsvm/jsvm.h @@ -2370,7 +2370,7 @@ JSVM_EXTERN JSVM_Status OH_JSVM_IsNull(JSVM_Env env, /** * @brief This API checks if the value passed in is either a null or an undefined object. - * This is equivalent to `typeof value == 'null'` in JS. + * This is equivalent to `value == 'null'` in JS. * * @param env: The VM instance on which to check microtasks. * @param value: The JavaScript value to check. -- Gitee From 3dac714b5c38154daf46a2bf6e8c5c9bb1b1285b Mon Sep 17 00:00:00 2001 From: bwtang Date: Thu, 9 May 2024 09:45:29 +0800 Subject: [PATCH 3/4] fix the comment of the new interface OH_JSVM_IsNullOrUndefined Signed-off-by: bwtang --- ark_runtime/jsvm/jsvm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ark_runtime/jsvm/jsvm.h b/ark_runtime/jsvm/jsvm.h index 69cd0365b..92a095e18 100644 --- a/ark_runtime/jsvm/jsvm.h +++ b/ark_runtime/jsvm/jsvm.h @@ -2370,7 +2370,7 @@ JSVM_EXTERN JSVM_Status OH_JSVM_IsNull(JSVM_Env env, /** * @brief This API checks if the value passed in is either a null or an undefined object. - * This is equivalent to `value == 'null'` in JS. + * This is equivalent to `value == null` in JS. * * @param env: The VM instance on which to check microtasks. * @param value: The JavaScript value to check. -- Gitee From 5f4df7f342ac782e10cb7ed27f40ebdb882d45fe Mon Sep 17 00:00:00 2001 From: bwtang Date: Thu, 9 May 2024 10:42:02 +0800 Subject: [PATCH 4/4] fix the comments of the new interfaces OH_JSVM_IsNull and OH_JSVM_IsUndefined Signed-off-by: bwtang --- ark_runtime/jsvm/jsvm.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ark_runtime/jsvm/jsvm.h b/ark_runtime/jsvm/jsvm.h index 92a095e18..3675773f6 100644 --- a/ark_runtime/jsvm/jsvm.h +++ b/ark_runtime/jsvm/jsvm.h @@ -2341,8 +2341,8 @@ JSVM_EXTERN JSVM_Status OH_JSVM_IsCallable(JSVM_Env env, bool* isCallable); /** - * @brief This API checks if the value passed in is an undefined object. - * This equals to `typeof value === 'undefined'` in JS. + * @brief This API checks if the value passed in is undefined. + * This equals to `value === undefined` in JS. * * @param env: The VM instance on which to check microtasks. * @param value: The JavaScript value to check. @@ -2356,7 +2356,7 @@ JSVM_EXTERN JSVM_Status OH_JSVM_IsUndefined(JSVM_Env env, /** * @brief This API checks if the value passed in is a null object. - * This equals to `typeof value === 'null'` in JS. + * This equals to `value === null` in JS. * * @param env: The VM instance on which to check microtasks. * @param value: The JavaScript value to check. -- Gitee