Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.
JSVM-API provides APIs for quickly determining the wrapper type of an object.
In JSVM-API, the wrapper object APIs provide a quick way to identify five types of wrapper objects.
| API | Description |
|---|---|
| OH_JSVM_IsNumberObject | Checks whether the result is a number object. |
| OH_JSVM_IsBooleanObject | Checks whether the result is a Boolean object. |
| OH_JSVM_IsBigIntObject | Checks whether the result is a BigInt object. |
| OH_JSVM_IsStringObject | Checks whether the result is a string object. |
| OH_JSVM_IsSymbolObject | Checks whether the result is a symbol object. |
If you are just starting out with JSVM-API, see JSVM-API Development Process. The following demonstrates only the C++ code involved in the APIs.
CPP code:
#include <string>
static JSVM_Value WrapperObject(JSVM_Env env, JSVM_CallbackInfo info) {
JSVM_VM vm;
OH_JSVM_GetVM(env, &vm);
JSVM_HandleScope handleScope;
OH_JSVM_OpenHandleScope(env, &handleScope);
std::string src = R"JS(new Number(42))JS";
JSVM_Value jsSrc;
JSVM_Script script;
JSVM_Value result;
OH_JSVM_CreateStringUtf8(env, src.c_str(), JSVM_AUTO_LENGTH, &jsSrc);
OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script);
OH_JSVM_RunScript(env, script, &result);
bool isNumberObject = false;
OH_JSVM_IsNumberObject(env, result, &isNumberObject);
OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_IsNumberObject: %{public}d\n", isNumberObject);
OH_JSVM_CloseHandleScope(env, handleScope);
return nullptr;
}
static JSVM_CallbackStruct param[] = {
{.data = nullptr, .callback = WrapperObject},
};
static JSVM_CallbackStruct *method = param;
// Alias for the wrapperObject method to be called from JS.
static JSVM_PropertyDescriptor descriptor[] = {
{"wrapperObject", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT},
};
// Call the C++ code from JS.
const char *srcCallNative = R"JS(wrapperObject();)JS"; Expected result:
JSVM OH_JSVM_IsNumberObject: 1
Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Quick start
Helps you find desired resources with ease.