From 159f7542dc989f7a080f340598b5f2047c048504 Mon Sep 17 00:00:00 2001 From: liuweili Date: Tue, 26 Nov 2024 20:48:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ewell=20know=20symbols=20and?= =?UTF-8?q?=20wrapper=20object=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuweili --- src/js_native_api_v8.cc | 165 +++++++++++++++++++++++++++++ src/jsvm.h | 223 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 388 insertions(+) diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index a61038398..59d268495 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -1394,6 +1394,171 @@ static bool ProcessBundleName(std::string& bundleName) return true; } +JSVM_Status OH_JSVM_IsBooleanObject(JSVM_Env env, JSVM_Value value, bool* result) { + CHECK_ENV(env); + CHECK_ARG(env, value); + CHECK_ARG(env, result); + + v8::Local v = v8impl::V8LocalValueFromJsValue(value); + *result = v->IsBooleanObject(); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_IsBigIntObject(JSVM_Env env, JSVM_Value value, bool* result) { + CHECK_ENV(env); + CHECK_ARG(env, value); + CHECK_ARG(env, result); + + v8::Local v = v8impl::V8LocalValueFromJsValue(value); + *result = v->IsBigIntObject(); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_IsStringObject(JSVM_Env env, JSVM_Value value, bool* result) { + CHECK_ENV(env); + CHECK_ARG(env, value); + CHECK_ARG(env, result); + + v8::Local v = v8impl::V8LocalValueFromJsValue(value); + *result = v->IsStringObject(); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_IsNumberObject(JSVM_Env env, JSVM_Value value, bool* result) { + CHECK_ENV(env); + CHECK_ARG(env, value); + CHECK_ARG(env, result); + + v8::Local v = v8impl::V8LocalValueFromJsValue(value); + *result = v->IsNumberObject(); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_IsSymbolObject(JSVM_Env env, JSVM_Value value, bool* result) { + CHECK_ENV(env); + CHECK_ARG(env, value); + CHECK_ARG(env, result); + + v8::Local v = v8impl::V8LocalValueFromJsValue(value); + *result = v->IsSymbolObject(); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_GetSymbolToStringTag(JSVM_Env env, JSVM_Value* result) { + CHECK_ENV(env); + CHECK_ARG(env, result); + + v8::Local symbolToStringTag = v8::Symbol::GetToStringTag(env->isolate); + *result = v8impl::JsValueFromV8LocalValue(symbolToStringTag); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_GetSymbolIterator(JSVM_Env env, JSVM_Value* result) { + CHECK_ENV(env); + CHECK_ARG(env, result); + + v8::Local symbolIterator = v8::Symbol::GetIterator(env->isolate); + *result = v8impl::JsValueFromV8LocalValue(symbolIterator); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_GetSymbolAsyncIterator(JSVM_Env env, JSVM_Value* result) { + CHECK_ENV(env); + CHECK_ARG(env, result); + + v8::Local symbolAsyncIterator = v8::Symbol::GetAsyncIterator(env->isolate); + *result = v8impl::JsValueFromV8LocalValue(symbolAsyncIterator); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_GetSymbolHasInstance(JSVM_Env env, JSVM_Value* result) { + CHECK_ENV(env); + CHECK_ARG(env, result); + + v8::Local symbolHasInstance = v8::Symbol::GetHasInstance(env->isolate); + *result = v8impl::JsValueFromV8LocalValue(symbolHasInstance); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_GetSymbolUnscopables(JSVM_Env env, JSVM_Value* result) { + CHECK_ENV(env); + CHECK_ARG(env, result); + + v8::Local symbolUnscopables = v8::Symbol::GetUnscopables(env->isolate); + *result = v8impl::JsValueFromV8LocalValue(symbolUnscopables); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_GetSymbolIsConcatSpreadable(JSVM_Env env, JSVM_Value* result) { + CHECK_ENV(env); + CHECK_ARG(env, result); + + v8::Local symbolIsConcatSpreadable = v8::Symbol::GetIsConcatSpreadable(env->isolate); + *result = v8impl::JsValueFromV8LocalValue(symbolIsConcatSpreadable); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_GetSymbolMatch(JSVM_Env env, JSVM_Value* result) { + CHECK_ENV(env); + CHECK_ARG(env, result); + + v8::Local symbolMatch = v8::Symbol::GetMatch(env->isolate); + *result = v8impl::JsValueFromV8LocalValue(symbolMatch); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_GetSymbolReplace(JSVM_Env env, JSVM_Value* result) { + CHECK_ENV(env); + CHECK_ARG(env, result); + + v8::Local symbolReplace = v8::Symbol::GetReplace(env->isolate); + *result = v8impl::JsValueFromV8LocalValue(symbolReplace); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_GetSymbolSearch(JSVM_Env env, JSVM_Value* result) { + CHECK_ENV(env); + CHECK_ARG(env, result); + + v8::Local symbolSearch = v8::Symbol::GetSearch(env->isolate); + *result = v8impl::JsValueFromV8LocalValue(symbolSearch); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_GetSymbolSplit(JSVM_Env env, JSVM_Value* result) { + CHECK_ENV(env); + CHECK_ARG(env, result); + + v8::Local symbolSplit = v8::Symbol::GetSplit(env->isolate); + *result = v8impl::JsValueFromV8LocalValue(symbolSplit); + + return jsvm_clear_last_error(env); +} + +JSVM_Status OH_JSVM_GetSymbolToPrimitive(JSVM_Env env, JSVM_Value* result) { + CHECK_ENV(env); + CHECK_ARG(env, result); + + v8::Local symbolToPrimitive = v8::Symbol::GetToPrimitive(env->isolate); + *result = v8impl::JsValueFromV8LocalValue(symbolToPrimitive); + + return jsvm_clear_last_error(env); +} + JSVM_Status JSVM_CDECL OH_JSVM_Init(const JSVM_InitOptions* options) { static std::atomic initialized(false); diff --git a/src/jsvm.h b/src/jsvm.h index b5771f107..ac349426f 100644 --- a/src/jsvm.h +++ b/src/jsvm.h @@ -99,6 +99,229 @@ EXTERN_C_START +/** + * @brief Check whether the given JSVM_Value is a BigInt Object. + * + * @param env The environment that the API is invoked under. + * @param value The JavaScript value to check. + * @param result Whether the given value is a BigInt Object. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsBigIntObject(JSVM_Env env, + JSVM_Value value, + bool* result); + +/** + * @brief Check whether the given JSVM_Value is a Boolean Object. + * + * @param env The environment that the API is invoked under. + * @param value The JavaScript value to check. + * @param result Whether the given value is a Boolean Object. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsBooleanObject(JSVM_Env env, + JSVM_Value value, + bool* result); + +/** + * @brief Check whether the given JSVM_Value is a String Object. + * + * @param env The environment that the API is invoked under. + * @param value The JavaScript value to check. + * @param result Whether the given value is a String Object. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsStringObject(JSVM_Env env, + JSVM_Value value, + bool* result); + +/** + * @brief Check whether the given JSVM_Value is a Number Object. + * + * @param env The environment that the API is invoked under. + * @param value The JavaScript value to check. + * @param result Whether the given value is a Number Object. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsNumberObject(JSVM_Env env, + JSVM_Value value, + bool* result); + +/** + * @brief Check whether the given JSVM_Value is a Symbol Object. + * + * @param env The environment that the API is invoked under. + * @param value The JavaScript value to check. + * @param result Whether the given value is a Symbol Object. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_IsSymbolObject(JSVM_Env env, + JSVM_Value value, + bool* result); + +/** + * @brief This API returns the Symbol.asyncIterator of Well-Known Symbols. + * + * @param env The environment that the API is invoked under. + * @param result The Symbol.asyncIterator of Well-Known Symbols. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolAsyncIterator(JSVM_Env env, JSVM_Value* result); + +/** + * @brief This API returns the Symbol.hasInstance of Well-Known Symbols. + * + * @param env The environment that the API is invoked under. + * @param result The Symbol.hasInstance of Well-Known Symbols. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolHasInstance(JSVM_Env env, JSVM_Value* result); + +/** + * @brief This API returns the Symbol.isConcatSpreadable of Well-Known Symbols + * + * @param env The environment that the API is invoked under. + * @param result The Symbol.isConcatSpreadable of Well-Known Symbols. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolIsConcatSpreadable(JSVM_Env env, JSVM_Value* result); + +/** + * @brief This API returns the Symbol.match of Well-Known Symbols + * + * @param env The environment that the API is invoked under. + * @param result The Symbol.match of Well-Known Symbols. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolMatch(JSVM_Env env, JSVM_Value* result); + +/** + * @brief This API returns the Symbol.replace of Well-Known Symbols + * + * @param env The environment that the API is invoked under. + * @param result The Symbol.replace of Well-Known Symbols. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolReplace(JSVM_Env env, JSVM_Value* result); + +/** + * @brief This API returns the Symbol.search of Well-Known Symbols + * + * @param env The environment that the API is invoked under. + * @param result The Symbol.search of Well-Known Symbols. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolSearch(JSVM_Env env, JSVM_Value* result); + +/** + * @brief This API returns the Symbol.split of Well-Known Symbols + * + * @param env The environment that the API is invoked under. + * @param result The Symbol.split of Well-Known Symbols. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolSplit(JSVM_Env env, JSVM_Value* result); + +/** + * @brief This API returns the Symbol.toPrimitive of Well-Known Symbols + * + * @param env The environment that the API is invoked under. + * @param result The Symbol.toPrimitive of Well-Known Symbols. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolToPrimitive(JSVM_Env env, JSVM_Value* result); + +/** + * @brief This API returns the Symbol.unscopables of Well-Known Symbols + * + * @param env The environment that the API is invoked under. + * @param result The Symbol.unscopables of Well-Known Symbols. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolUnscopables(JSVM_Env env, JSVM_Value* result); + +/** + * @brief This API returns the Symbol.toStringTag of Well-Known Symbols + * + * @param env The environment that the API is invoked under. + * @param result The Symbol.toStringTag of Well-Known Symbols. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolToStringTag(JSVM_Env env, JSVM_Value* result); + +/** + * @brief This API returns the Symbol.iterator of Well-Known Symbols + * + * @param env The environment that the API is invoked under. + * @param result The Symbol.iterator of Well-Known Symbols. + * @return Returns JSVM funtions result code. + * Returns {@link JSVM_OK } if the function executed successfully.\n + * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n + * + * @since 16 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolIterator(JSVM_Env env, JSVM_Value* result); + /** * @brief Init a JavaScript vm. * -- Gitee