11cb0ef41Sopenharmony_ci/* 21cb0ef41Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 31cb0ef41Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41cb0ef41Sopenharmony_ci * you may not use this file except in compliance with the License. 51cb0ef41Sopenharmony_ci * You may obtain a copy of the License at 61cb0ef41Sopenharmony_ci * 71cb0ef41Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81cb0ef41Sopenharmony_ci * 91cb0ef41Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101cb0ef41Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111cb0ef41Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121cb0ef41Sopenharmony_ci * See the License for the specific language governing permissions and 131cb0ef41Sopenharmony_ci * limitations under the License. 141cb0ef41Sopenharmony_ci */ 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci#ifndef ARK_RUNTIME_JSVM_JSVM_H 171cb0ef41Sopenharmony_ci#define ARK_RUNTIME_JSVM_JSVM_H 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci/** 201cb0ef41Sopenharmony_ci * @addtogroup JSVM 211cb0ef41Sopenharmony_ci * @{ 221cb0ef41Sopenharmony_ci * 231cb0ef41Sopenharmony_ci * @brief Provides the standard JavaScript engine capabilities. 241cb0ef41Sopenharmony_ci * 251cb0ef41Sopenharmony_ci * Provides API to Provide independent, standard, and complete JavaScript engine capabilities for developers, 261cb0ef41Sopenharmony_ci * including managing the engine lifecycle, compiling and running JS code, implementing JS/C++ cross language calls, 271cb0ef41Sopenharmony_ci * and taking snapshots. 281cb0ef41Sopenharmony_ci * 291cb0ef41Sopenharmony_ci * @since 11 301cb0ef41Sopenharmony_ci */ 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci/** 331cb0ef41Sopenharmony_ci * @file jsvm.h 341cb0ef41Sopenharmony_ci * 351cb0ef41Sopenharmony_ci * @brief Provides the JSVM API define. 361cb0ef41Sopenharmony_ci * 371cb0ef41Sopenharmony_ci * Provides API to Provide independent, standard, and complete JavaScript engine capabilities for developers, 381cb0ef41Sopenharmony_ci * including managing the engine lifecycle, compiling and running JS code, implementing JS/C++ cross language calls, 391cb0ef41Sopenharmony_ci * and taking snapshots. 401cb0ef41Sopenharmony_ci * @library libjsvm.so 411cb0ef41Sopenharmony_ci * @syscap SystemCapability.ArkCompiler.JSVM 421cb0ef41Sopenharmony_ci * @since 11 431cb0ef41Sopenharmony_ci */ 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci// This file needs to be compatible with C compilers. 461cb0ef41Sopenharmony_ci#include <stdbool.h> // NOLINT(modernize-deprecated-headers) 471cb0ef41Sopenharmony_ci#include <stddef.h> // NOLINT(modernize-deprecated-headers) 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci// Use INT_MAX, this should only be consumed by the pre-processor anyway. 501cb0ef41Sopenharmony_ci#define JSVM_VERSION_EXPERIMENTAL 2147483647 511cb0ef41Sopenharmony_ci#ifndef JSVM_VERSION 521cb0ef41Sopenharmony_ci#ifdef JSVM_EXPERIMENTAL 531cb0ef41Sopenharmony_ci#define JSVM_VERSION JSVM_VERSION_EXPERIMENTAL 541cb0ef41Sopenharmony_ci#else 551cb0ef41Sopenharmony_ci// The baseline version for JSVM-API. 561cb0ef41Sopenharmony_ci// The JSVM_VERSION controls which version will be used by default when 571cb0ef41Sopenharmony_ci// compilling a native addon. If the addon developer specifically wants to use 581cb0ef41Sopenharmony_ci// functions available in a new version of JSVM-API that is not yet ported in all 591cb0ef41Sopenharmony_ci// LTS versions, they can set JSVM_VERSION knowing that they have specifically 601cb0ef41Sopenharmony_ci// depended on that version. 611cb0ef41Sopenharmony_ci#define JSVM_VERSION 8 621cb0ef41Sopenharmony_ci#endif 631cb0ef41Sopenharmony_ci#endif 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci#include "jsvm_types.h" 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci#ifndef JSVM_EXTERN 681cb0ef41Sopenharmony_ci#ifdef _WIN32 691cb0ef41Sopenharmony_ci/** 701cb0ef41Sopenharmony_ci * @brief externally visible. 711cb0ef41Sopenharmony_ci * 721cb0ef41Sopenharmony_ci * @since 11 731cb0ef41Sopenharmony_ci */ 741cb0ef41Sopenharmony_ci#define JSVM_EXTERN __declspec(dllexport) 751cb0ef41Sopenharmony_ci#elif defined(__wasm__) 761cb0ef41Sopenharmony_ci#define JSVM_EXTERN \ 771cb0ef41Sopenharmony_ci __attribute__((visibility("default"))) \ 781cb0ef41Sopenharmony_ci __attribute__((__import_module__("jsvm"))) 791cb0ef41Sopenharmony_ci#else 801cb0ef41Sopenharmony_ci#define JSVM_EXTERN __attribute__((visibility("default"))) 811cb0ef41Sopenharmony_ci#endif 821cb0ef41Sopenharmony_ci#endif 831cb0ef41Sopenharmony_ci 841cb0ef41Sopenharmony_ci/** 851cb0ef41Sopenharmony_ci * @brief auto length. 861cb0ef41Sopenharmony_ci * 871cb0ef41Sopenharmony_ci * @since 11 881cb0ef41Sopenharmony_ci */ 891cb0ef41Sopenharmony_ci#define JSVM_AUTO_LENGTH SIZE_MAX 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ci#ifdef __cplusplus 921cb0ef41Sopenharmony_ci#define EXTERN_C_START extern "C" { 931cb0ef41Sopenharmony_ci#define EXTERN_C_END } 941cb0ef41Sopenharmony_ci#else 951cb0ef41Sopenharmony_ci#define EXTERN_C_START 961cb0ef41Sopenharmony_ci#define EXTERN_C_END 971cb0ef41Sopenharmony_ci#endif 981cb0ef41Sopenharmony_ci 991cb0ef41Sopenharmony_ciEXTERN_C_START 1001cb0ef41Sopenharmony_ci 1011cb0ef41Sopenharmony_ci/** 1021cb0ef41Sopenharmony_ci * @brief Init a JavaScript vm. 1031cb0ef41Sopenharmony_ci * 1041cb0ef41Sopenharmony_ci * @param options: The options for initialize the JavaScript VM. 1051cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 1061cb0ef41Sopenharmony_ci * @since 11 1071cb0ef41Sopenharmony_ci */ 1081cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_Init(const JSVM_InitOptions* options); 1091cb0ef41Sopenharmony_ci 1101cb0ef41Sopenharmony_ci/** 1111cb0ef41Sopenharmony_ci * @brief This API create a new VM instance. 1121cb0ef41Sopenharmony_ci * 1131cb0ef41Sopenharmony_ci * @param options: The options for create the VM instance. 1141cb0ef41Sopenharmony_ci * @param result: The new VM instance. 1151cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 1161cb0ef41Sopenharmony_ci * @since 11 1171cb0ef41Sopenharmony_ci */ 1181cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateVM(const JSVM_CreateVMOptions* options, 1191cb0ef41Sopenharmony_ci JSVM_VM* result); 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_ci/** 1221cb0ef41Sopenharmony_ci * @brief Destroys VM instance. 1231cb0ef41Sopenharmony_ci * 1241cb0ef41Sopenharmony_ci * @param vm: The VM instance to be Destroyed. 1251cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 1261cb0ef41Sopenharmony_ci * @since 11 1271cb0ef41Sopenharmony_ci */ 1281cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_DestroyVM(JSVM_VM vm); 1291cb0ef41Sopenharmony_ci 1301cb0ef41Sopenharmony_ci/** 1311cb0ef41Sopenharmony_ci * @brief This API open a new VM scope for the VM instance. 1321cb0ef41Sopenharmony_ci * 1331cb0ef41Sopenharmony_ci * @param vm: The VM instance to open scope for. 1341cb0ef41Sopenharmony_ci * @param result: The new VM scope. 1351cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 1361cb0ef41Sopenharmony_ci * @since 11 1371cb0ef41Sopenharmony_ci */ 1381cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_OpenVMScope(JSVM_VM vm, 1391cb0ef41Sopenharmony_ci JSVM_VMScope* result); 1401cb0ef41Sopenharmony_ci 1411cb0ef41Sopenharmony_ci/** 1421cb0ef41Sopenharmony_ci * @brief This function close the VM scope for the VM instance. 1431cb0ef41Sopenharmony_ci * 1441cb0ef41Sopenharmony_ci * @param vm: The VM instance to close scope for. 1451cb0ef41Sopenharmony_ci * @param scope: The VM scope to be closed. 1461cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 1471cb0ef41Sopenharmony_ci * @since 11 1481cb0ef41Sopenharmony_ci */ 1491cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CloseVMScope(JSVM_VM vm, 1501cb0ef41Sopenharmony_ci JSVM_VMScope scope); 1511cb0ef41Sopenharmony_ci 1521cb0ef41Sopenharmony_ci/** 1531cb0ef41Sopenharmony_ci * @brief This function create a new environment with optional properties for the context of the new environment. 1541cb0ef41Sopenharmony_ci * 1551cb0ef41Sopenharmony_ci * @param vm: The VM instance that the env will be created in. 1561cb0ef41Sopenharmony_ci * @param propertyCount: The number of elements in the properties array. 1571cb0ef41Sopenharmony_ci * @param properties: The array of property descriptor. 1581cb0ef41Sopenharmony_ci * @param result: The new environment created. 1591cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 1601cb0ef41Sopenharmony_ci * @since 11 1611cb0ef41Sopenharmony_ci */ 1621cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateEnv(JSVM_VM vm, 1631cb0ef41Sopenharmony_ci size_t propertyCount, 1641cb0ef41Sopenharmony_ci const JSVM_PropertyDescriptor* properties, 1651cb0ef41Sopenharmony_ci JSVM_Env* result); 1661cb0ef41Sopenharmony_ci 1671cb0ef41Sopenharmony_ci/** 1681cb0ef41Sopenharmony_ci * @brief This function create a new environment from the start snapshot of the vm. 1691cb0ef41Sopenharmony_ci * 1701cb0ef41Sopenharmony_ci * @param vm: The VM instance that the env will be created in. 1711cb0ef41Sopenharmony_ci * @param index: The index of the environment in the snapshot. 1721cb0ef41Sopenharmony_ci * @param result: The new environment created. 1731cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 1741cb0ef41Sopenharmony_ci * @since 11 1751cb0ef41Sopenharmony_ci */ 1761cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateEnvFromSnapshot(JSVM_VM vm, 1771cb0ef41Sopenharmony_ci size_t index, 1781cb0ef41Sopenharmony_ci JSVM_Env* result); 1791cb0ef41Sopenharmony_ci 1801cb0ef41Sopenharmony_ci/** 1811cb0ef41Sopenharmony_ci * @brief This function destroys the environment. 1821cb0ef41Sopenharmony_ci * 1831cb0ef41Sopenharmony_ci * @param env: The environment to be destroyed. 1841cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 1851cb0ef41Sopenharmony_ci * @since 11 1861cb0ef41Sopenharmony_ci */ 1871cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_DestroyEnv(JSVM_Env env); 1881cb0ef41Sopenharmony_ci 1891cb0ef41Sopenharmony_ci/** 1901cb0ef41Sopenharmony_ci * @brief This function open a new environment scope. 1911cb0ef41Sopenharmony_ci * 1921cb0ef41Sopenharmony_ci * @param env: The environment that the JSVM-API call is invoked under. 1931cb0ef41Sopenharmony_ci * @param result: The new environment scope. 1941cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 1951cb0ef41Sopenharmony_ci * @since 11 1961cb0ef41Sopenharmony_ci */ 1971cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_OpenEnvScope(JSVM_Env env, 1981cb0ef41Sopenharmony_ci JSVM_EnvScope* result); 1991cb0ef41Sopenharmony_ci 2001cb0ef41Sopenharmony_ci/** 2011cb0ef41Sopenharmony_ci * @brief This function closes the environment scope of the environment. 2021cb0ef41Sopenharmony_ci * 2031cb0ef41Sopenharmony_ci * @param env: The environment that the JSVM-API call is invoked under. 2041cb0ef41Sopenharmony_ci * @param scope: The environment scope to be closed. 2051cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 2061cb0ef41Sopenharmony_ci * @since 11 2071cb0ef41Sopenharmony_ci */ 2081cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CloseEnvScope(JSVM_Env env, 2091cb0ef41Sopenharmony_ci JSVM_EnvScope scope); 2101cb0ef41Sopenharmony_ci 2111cb0ef41Sopenharmony_ci/** 2121cb0ef41Sopenharmony_ci * @brief This function retrieves the VM instance of the given environment. 2131cb0ef41Sopenharmony_ci * 2141cb0ef41Sopenharmony_ci * @param env: The environment that the JSVM-API call is invoked under. 2151cb0ef41Sopenharmony_ci * @param result: The VM instance of the environment. 2161cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 2171cb0ef41Sopenharmony_ci * @since 12 2181cb0ef41Sopenharmony_ci */ 2191cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetVM(JSVM_Env env, 2201cb0ef41Sopenharmony_ci JSVM_VM* result); 2211cb0ef41Sopenharmony_ci 2221cb0ef41Sopenharmony_ci/** 2231cb0ef41Sopenharmony_ci * @brief This function compiles a string of JavaScript code and returns the compiled script. 2241cb0ef41Sopenharmony_ci * 2251cb0ef41Sopenharmony_ci * @param env: The environment that the JSVM-API call is invoked under. 2261cb0ef41Sopenharmony_ci * @param script: A JavaScript string containing the script yo be compiled. 2271cb0ef41Sopenharmony_ci * @param cachedData: Optional code cache data for the script. 2281cb0ef41Sopenharmony_ci * @param cacheDataLength: The length of cachedData array. 2291cb0ef41Sopenharmony_ci * @param eagerCompile: Whether to compile the script eagerly. 2301cb0ef41Sopenharmony_ci * @param cacheRejected: Whether the code cache rejected by compilation. 2311cb0ef41Sopenharmony_ci * @param result: The compiled script. 2321cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 2331cb0ef41Sopenharmony_ci * @since 11 2341cb0ef41Sopenharmony_ci */ 2351cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CompileScript(JSVM_Env env, 2361cb0ef41Sopenharmony_ci JSVM_Value script, 2371cb0ef41Sopenharmony_ci const uint8_t* cachedData, 2381cb0ef41Sopenharmony_ci size_t cacheDataLength, 2391cb0ef41Sopenharmony_ci bool eagerCompile, 2401cb0ef41Sopenharmony_ci bool* cacheRejected, 2411cb0ef41Sopenharmony_ci JSVM_Script* result); 2421cb0ef41Sopenharmony_ci 2431cb0ef41Sopenharmony_ci/** 2441cb0ef41Sopenharmony_ci * @brief This function compiles a string of JavaScript code with the source code information 2451cb0ef41Sopenharmony_ci * and returns the compiled script. 2461cb0ef41Sopenharmony_ci * 2471cb0ef41Sopenharmony_ci * @param env: The environment that the JSVM-API call is invoked under. 2481cb0ef41Sopenharmony_ci * @param script: A JavaScript string containing the script to be compiled. 2491cb0ef41Sopenharmony_ci * @param cachedData: Optional code cache data for the script. 2501cb0ef41Sopenharmony_ci * @param cacheDataLength: The length of cachedData array. 2511cb0ef41Sopenharmony_ci * @param eagerCompile: Whether to compile the script eagerly. 2521cb0ef41Sopenharmony_ci * @param cacheRejected: Whether the code cache rejected by compilation. 2531cb0ef41Sopenharmony_ci * @param origin: The information of source code. 2541cb0ef41Sopenharmony_ci * @param result: The compiled script. 2551cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 2561cb0ef41Sopenharmony_ci * @since 12 2571cb0ef41Sopenharmony_ci */ 2581cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CompileScriptWithOrigin(JSVM_Env env, 2591cb0ef41Sopenharmony_ci JSVM_Value script, 2601cb0ef41Sopenharmony_ci const uint8_t* cachedData, 2611cb0ef41Sopenharmony_ci size_t cacheDataLength, 2621cb0ef41Sopenharmony_ci bool eagerCompile, 2631cb0ef41Sopenharmony_ci bool* cacheRejected, 2641cb0ef41Sopenharmony_ci JSVM_ScriptOrigin* origin, 2651cb0ef41Sopenharmony_ci JSVM_Script* result); 2661cb0ef41Sopenharmony_ci 2671cb0ef41Sopenharmony_ci/** 2681cb0ef41Sopenharmony_ci * @brief This function compiles a string of JavaScript code with the source code information 2691cb0ef41Sopenharmony_ci * and returns the compiled script. 2701cb0ef41Sopenharmony_ci * 2711cb0ef41Sopenharmony_ci * @param env: The environment that the JSVM-API call is invoked under. 2721cb0ef41Sopenharmony_ci * @param script: A JavaScript string containing the script to be compiled. 2731cb0ef41Sopenharmony_ci * @param optionCount: length of option array. 2741cb0ef41Sopenharmony_ci * @param options: Compile options to be passed. 2751cb0ef41Sopenharmony_ci * @param result: The compiled script. 2761cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 2771cb0ef41Sopenharmony_ci * @since 12 2781cb0ef41Sopenharmony_ci */ 2791cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CompileScriptWithOptions(JSVM_Env env, 2801cb0ef41Sopenharmony_ci JSVM_Value script, 2811cb0ef41Sopenharmony_ci size_t optionCount, 2821cb0ef41Sopenharmony_ci JSVM_CompileOptions options[], 2831cb0ef41Sopenharmony_ci JSVM_Script* result); 2841cb0ef41Sopenharmony_ci 2851cb0ef41Sopenharmony_ci/** 2861cb0ef41Sopenharmony_ci * @brief This function creates code cache for the compiled script. 2871cb0ef41Sopenharmony_ci * 2881cb0ef41Sopenharmony_ci * @param env: The environment that the JSVM-API call is invoked under. 2891cb0ef41Sopenharmony_ci * @param script: A compiled script to create code cache for. 2901cb0ef41Sopenharmony_ci * @param data: The data of the code cache. 2911cb0ef41Sopenharmony_ci * @param length: The length of the code cache data. 2921cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 2931cb0ef41Sopenharmony_ci * @since 11 2941cb0ef41Sopenharmony_ci */ 2951cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateCodeCache(JSVM_Env env, 2961cb0ef41Sopenharmony_ci JSVM_Script script, 2971cb0ef41Sopenharmony_ci const uint8_t** data, 2981cb0ef41Sopenharmony_ci size_t* length); 2991cb0ef41Sopenharmony_ci 3001cb0ef41Sopenharmony_ci/** 3011cb0ef41Sopenharmony_ci * @brief This function executes a string of JavaScript code and returns its result with the following caveats: 3021cb0ef41Sopenharmony_ci * Unlike eval, this function does not allow the script to access the current lexical scope, and therefore also 3031cb0ef41Sopenharmony_ci * does not allow to access the module scope, meaning that pseudo-globals such as require will not be available. 3041cb0ef41Sopenharmony_ci * The script can access the global scope. Function and var declarations in the script will be added to the 3051cb0ef41Sopenharmony_ci * global object. Variable declarations made using let and const will be visible globally, but will not be added 3061cb0ef41Sopenharmony_ci * to the global object.The value of this is global within the script. 3071cb0ef41Sopenharmony_ci * 3081cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 3091cb0ef41Sopenharmony_ci * @param script: A JavaScript string containing the script to execute. 3101cb0ef41Sopenharmony_ci * @param result: The value resulting from having executed the script. 3111cb0ef41Sopenharmony_ci * @since 11 3121cb0ef41Sopenharmony_ci */ 3131cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_RunScript(JSVM_Env env, 3141cb0ef41Sopenharmony_ci JSVM_Script script, 3151cb0ef41Sopenharmony_ci JSVM_Value* result); 3161cb0ef41Sopenharmony_ci 3171cb0ef41Sopenharmony_ci/** 3181cb0ef41Sopenharmony_ci * @brief This API associates data with the currently running JSVM environment. data can later be retrieved 3191cb0ef41Sopenharmony_ci * using OH_JSVM_GetInstanceData(). 3201cb0ef41Sopenharmony_ci * 3211cb0ef41Sopenharmony_ci * @param env: The environment that the JSVM-API call is invoked under. 3221cb0ef41Sopenharmony_ci * @param data: The data item to make available to bindings of this instance. 3231cb0ef41Sopenharmony_ci * @param finalizeCb: The function to call when the environment is being torn down. The function receives 3241cb0ef41Sopenharmony_ci * data so that it might free it. JSVM_Finalize provides more details. 3251cb0ef41Sopenharmony_ci * @param finalizeHint: Optional hint to pass to the finalize callback during collection. 3261cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 3271cb0ef41Sopenharmony_ci * @since 11 3281cb0ef41Sopenharmony_ci */ 3291cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_SetInstanceData(JSVM_Env env, 3301cb0ef41Sopenharmony_ci void* data, 3311cb0ef41Sopenharmony_ci JSVM_Finalize finalizeCb, 3321cb0ef41Sopenharmony_ci void* finalizeHint); 3331cb0ef41Sopenharmony_ci 3341cb0ef41Sopenharmony_ci/** 3351cb0ef41Sopenharmony_ci * @brief This API retrieves data that was previously associated with the currently running JSVM environment 3361cb0ef41Sopenharmony_ci * via OH_JSVM_SetInstanceData(). If no data is set, the call will succeed and data will be set to NULL. 3371cb0ef41Sopenharmony_ci * 3381cb0ef41Sopenharmony_ci * @param env: The environment that the JSVM-API call is invoked under. 3391cb0ef41Sopenharmony_ci * @param data: The data item that was previously associated with the currently running JSVM environment by 3401cb0ef41Sopenharmony_ci * a call to OH_JSVM_SetInstanceData(). 3411cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 3421cb0ef41Sopenharmony_ci * @since 11 3431cb0ef41Sopenharmony_ci */ 3441cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetInstanceData(JSVM_Env env, 3451cb0ef41Sopenharmony_ci void** data); 3461cb0ef41Sopenharmony_ci 3471cb0ef41Sopenharmony_ci/** 3481cb0ef41Sopenharmony_ci * @brief This API retrieves a JSVM_ExtendedErrorInfo structure with information about the last error that 3491cb0ef41Sopenharmony_ci * occurred. 3501cb0ef41Sopenharmony_ci * 3511cb0ef41Sopenharmony_ci * @param env: The environment that the JSVM-API call is invoked under. 3521cb0ef41Sopenharmony_ci * @param result: The JSVM_ExtendedErrorInfo structure with more information about the error. 3531cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 3541cb0ef41Sopenharmony_ci * @since 11 3551cb0ef41Sopenharmony_ci */ 3561cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetLastErrorInfo(JSVM_Env env, 3571cb0ef41Sopenharmony_ci const JSVM_ExtendedErrorInfo** result); 3581cb0ef41Sopenharmony_ci 3591cb0ef41Sopenharmony_ci/** 3601cb0ef41Sopenharmony_ci * @brief This API throws the JavaScript value provided. 3611cb0ef41Sopenharmony_ci * 3621cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 3631cb0ef41Sopenharmony_ci * @param error: The JavaScript value to be thrown. 3641cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 3651cb0ef41Sopenharmony_ci * @since 11 3661cb0ef41Sopenharmony_ci */ 3671cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_Throw(JSVM_Env env, 3681cb0ef41Sopenharmony_ci JSVM_Value error); 3691cb0ef41Sopenharmony_ci 3701cb0ef41Sopenharmony_ci/** 3711cb0ef41Sopenharmony_ci * @brief This API throws a JavaScript Error with the text provided. 3721cb0ef41Sopenharmony_ci * 3731cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 3741cb0ef41Sopenharmony_ci * @param code: Optional error code to be set on the error. 3751cb0ef41Sopenharmony_ci * @param msg: C string representing the text to be associated with the error. 3761cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 3771cb0ef41Sopenharmony_ci * @since 11 3781cb0ef41Sopenharmony_ci */ 3791cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ThrowError(JSVM_Env env, 3801cb0ef41Sopenharmony_ci const char* code, 3811cb0ef41Sopenharmony_ci const char* msg); 3821cb0ef41Sopenharmony_ci 3831cb0ef41Sopenharmony_ci/** 3841cb0ef41Sopenharmony_ci * @brief This API throws a JavaScript TypeError with the text provided. 3851cb0ef41Sopenharmony_ci * 3861cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 3871cb0ef41Sopenharmony_ci * @param code: Optional error code to be set on the error. 3881cb0ef41Sopenharmony_ci * @param msg: C string representing the text to be associated with the error. 3891cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 3901cb0ef41Sopenharmony_ci * @since 11 3911cb0ef41Sopenharmony_ci */ 3921cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ThrowTypeError(JSVM_Env env, 3931cb0ef41Sopenharmony_ci const char* code, 3941cb0ef41Sopenharmony_ci const char* msg); 3951cb0ef41Sopenharmony_ci 3961cb0ef41Sopenharmony_ci/** 3971cb0ef41Sopenharmony_ci * @brief This API throws a JavaScript RangeError with the text provided. 3981cb0ef41Sopenharmony_ci * 3991cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 4001cb0ef41Sopenharmony_ci * @param code: Optional error code to be set on the error. 4011cb0ef41Sopenharmony_ci * @param msg: C string representing the text to be associated with the error. 4021cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 4031cb0ef41Sopenharmony_ci * @since 11 4041cb0ef41Sopenharmony_ci */ 4051cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ThrowRangeError(JSVM_Env env, 4061cb0ef41Sopenharmony_ci const char* code, 4071cb0ef41Sopenharmony_ci const char* msg); 4081cb0ef41Sopenharmony_ci 4091cb0ef41Sopenharmony_ci/** 4101cb0ef41Sopenharmony_ci * @brief This API throws a JavaScript SyntaxError with the text provided. 4111cb0ef41Sopenharmony_ci * 4121cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 4131cb0ef41Sopenharmony_ci * @param code: Optional error code to be set on the error. 4141cb0ef41Sopenharmony_ci * @param msg: C string representing the text to be associated with the error. 4151cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 4161cb0ef41Sopenharmony_ci * @since 11 4171cb0ef41Sopenharmony_ci */ 4181cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ThrowSyntaxError(JSVM_Env env, 4191cb0ef41Sopenharmony_ci const char* code, 4201cb0ef41Sopenharmony_ci const char* msg); 4211cb0ef41Sopenharmony_ci 4221cb0ef41Sopenharmony_ci/** 4231cb0ef41Sopenharmony_ci * @brief This API queries a JSVM_Value to check if it represents an error object. 4241cb0ef41Sopenharmony_ci * 4251cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 4261cb0ef41Sopenharmony_ci * @param value: The JSVM_Value to be checked. 4271cb0ef41Sopenharmony_ci * @param result: Boolean value that is set to true if JSVM_Value represents an error, 4281cb0ef41Sopenharmony_ci * false otherwise. 4291cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 4301cb0ef41Sopenharmony_ci * @since 11 4311cb0ef41Sopenharmony_ci */ 4321cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsError(JSVM_Env env, 4331cb0ef41Sopenharmony_ci JSVM_Value value, 4341cb0ef41Sopenharmony_ci bool* result); 4351cb0ef41Sopenharmony_ci 4361cb0ef41Sopenharmony_ci/** 4371cb0ef41Sopenharmony_ci * @brief This API returns a JavaScript Error with the text provided. 4381cb0ef41Sopenharmony_ci * 4391cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 4401cb0ef41Sopenharmony_ci * @param code: Optional JSVM_Value with the string for the error code to be associated with the error. 4411cb0ef41Sopenharmony_ci * @param msg: JSVM_Value that references a JavaScript string to be used as the message for the Error. 4421cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the error created. 4431cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 4441cb0ef41Sopenharmony_ci * @since 11 4451cb0ef41Sopenharmony_ci */ 4461cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateError(JSVM_Env env, 4471cb0ef41Sopenharmony_ci JSVM_Value code, 4481cb0ef41Sopenharmony_ci JSVM_Value msg, 4491cb0ef41Sopenharmony_ci JSVM_Value* result); 4501cb0ef41Sopenharmony_ci 4511cb0ef41Sopenharmony_ci/** 4521cb0ef41Sopenharmony_ci * @brief This API returns a JavaScript TypeError with the text provided. 4531cb0ef41Sopenharmony_ci * 4541cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 4551cb0ef41Sopenharmony_ci * @param code: Optional JSVM_Value with the string for the error code to be associated with the error. 4561cb0ef41Sopenharmony_ci * @param msg: JSVM_Value that references a JavaScript string to be used as the message for the Error. 4571cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the error created. 4581cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 4591cb0ef41Sopenharmony_ci * @since 11 4601cb0ef41Sopenharmony_ci */ 4611cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateTypeError(JSVM_Env env, 4621cb0ef41Sopenharmony_ci JSVM_Value code, 4631cb0ef41Sopenharmony_ci JSVM_Value msg, 4641cb0ef41Sopenharmony_ci JSVM_Value* result); 4651cb0ef41Sopenharmony_ci 4661cb0ef41Sopenharmony_ci/** 4671cb0ef41Sopenharmony_ci * @brief This API returns a JavaScript RangeError with the text provided. 4681cb0ef41Sopenharmony_ci * 4691cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 4701cb0ef41Sopenharmony_ci * @param code: Optional JSVM_Value with the string for the error code to be associated with the error. 4711cb0ef41Sopenharmony_ci * @param msg: JSVM_Value that references a JavaScript string to be used as the message for the Error. 4721cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the error created. 4731cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 4741cb0ef41Sopenharmony_ci * @since 11 4751cb0ef41Sopenharmony_ci */ 4761cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateRangeError(JSVM_Env env, 4771cb0ef41Sopenharmony_ci JSVM_Value code, 4781cb0ef41Sopenharmony_ci JSVM_Value msg, 4791cb0ef41Sopenharmony_ci JSVM_Value* result); 4801cb0ef41Sopenharmony_ci 4811cb0ef41Sopenharmony_ci/** 4821cb0ef41Sopenharmony_ci * @brief This API returns a JavaScript SyntaxError with the text provided. 4831cb0ef41Sopenharmony_ci * 4841cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 4851cb0ef41Sopenharmony_ci * @param code: Optional JSVM_Value with the string for the error code to be associated with the error. 4861cb0ef41Sopenharmony_ci * @param msg: JSVM_Value that references a JavaScript string to be used as the message for the Error. 4871cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the error created. 4881cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 4891cb0ef41Sopenharmony_ci * @since 11 4901cb0ef41Sopenharmony_ci */ 4911cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateSyntaxError(JSVM_Env env, 4921cb0ef41Sopenharmony_ci JSVM_Value code, 4931cb0ef41Sopenharmony_ci JSVM_Value msg, 4941cb0ef41Sopenharmony_ci JSVM_Value* result); 4951cb0ef41Sopenharmony_ci 4961cb0ef41Sopenharmony_ci/** 4971cb0ef41Sopenharmony_ci * @brief This API returns a JavaScript exception if one is pending, NULL otherwise. 4981cb0ef41Sopenharmony_ci * 4991cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 5001cb0ef41Sopenharmony_ci * @param result: The exception if one is pending, NULL otherwise. 5011cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 5021cb0ef41Sopenharmony_ci * @since 11 5031cb0ef41Sopenharmony_ci */ 5041cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetAndClearLastException(JSVM_Env env, 5051cb0ef41Sopenharmony_ci JSVM_Value* result); 5061cb0ef41Sopenharmony_ci 5071cb0ef41Sopenharmony_ci/** 5081cb0ef41Sopenharmony_ci * @brief This API returns true if an exception is pending, false otherwise. 5091cb0ef41Sopenharmony_ci * 5101cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 5111cb0ef41Sopenharmony_ci * @param result: Boolean value that is set to true if an exception is pending. 5121cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 5131cb0ef41Sopenharmony_ci * @since 11 5141cb0ef41Sopenharmony_ci */ 5151cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsExceptionPending(JSVM_Env env, 5161cb0ef41Sopenharmony_ci bool* result); 5171cb0ef41Sopenharmony_ci 5181cb0ef41Sopenharmony_ci/** 5191cb0ef41Sopenharmony_ci * @brief This API opens a new scope. 5201cb0ef41Sopenharmony_ci * 5211cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 5221cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the new scope. 5231cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 5241cb0ef41Sopenharmony_ci * @since 11 5251cb0ef41Sopenharmony_ci */ 5261cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_OpenHandleScope(JSVM_Env env, 5271cb0ef41Sopenharmony_ci JSVM_HandleScope* result); 5281cb0ef41Sopenharmony_ci 5291cb0ef41Sopenharmony_ci/** 5301cb0ef41Sopenharmony_ci * @brief This API closes the scope passed in. Scopes must be closed in the reverse 5311cb0ef41Sopenharmony_ci * order from which they were created. 5321cb0ef41Sopenharmony_ci * 5331cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 5341cb0ef41Sopenharmony_ci * @param scope: JSVM_Value representing the scope to be closed. 5351cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 5361cb0ef41Sopenharmony_ci * @since 11 5371cb0ef41Sopenharmony_ci */ 5381cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CloseHandleScope(JSVM_Env env, 5391cb0ef41Sopenharmony_ci JSVM_HandleScope scope); 5401cb0ef41Sopenharmony_ci 5411cb0ef41Sopenharmony_ci/** 5421cb0ef41Sopenharmony_ci * @brief This API opens a new scope from which one object can be promoted to the outer scope. 5431cb0ef41Sopenharmony_ci * 5441cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 5451cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the new scope. 5461cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 5471cb0ef41Sopenharmony_ci * @since 11 5481cb0ef41Sopenharmony_ci */ 5491cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_OpenEscapableHandleScope(JSVM_Env env, 5501cb0ef41Sopenharmony_ci JSVM_EscapableHandleScope* result); 5511cb0ef41Sopenharmony_ci 5521cb0ef41Sopenharmony_ci/** 5531cb0ef41Sopenharmony_ci * @brief This API closes the scope passed in. Scopes must be closed in the reverse order 5541cb0ef41Sopenharmony_ci * from which they were created. 5551cb0ef41Sopenharmony_ci * 5561cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 5571cb0ef41Sopenharmony_ci * @param scope: JSVM_Value representing the scope to be closed. 5581cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 5591cb0ef41Sopenharmony_ci * @since 11 5601cb0ef41Sopenharmony_ci */ 5611cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CloseEscapableHandleScope(JSVM_Env env, 5621cb0ef41Sopenharmony_ci JSVM_EscapableHandleScope scope); 5631cb0ef41Sopenharmony_ci 5641cb0ef41Sopenharmony_ci/** 5651cb0ef41Sopenharmony_ci * @brief This API promotes the handle to the JavaScript object so that it is valid for the lifetime 5661cb0ef41Sopenharmony_ci * of the outer scope. It can only be called once per scope. If it is called more than once an error 5671cb0ef41Sopenharmony_ci * will be returned. 5681cb0ef41Sopenharmony_ci * 5691cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 5701cb0ef41Sopenharmony_ci * @param scope: JSVM_Value representing the current scope. 5711cb0ef41Sopenharmony_ci * @param escapee: JSVM_Value representing the JavaScript Object to be escaped. 5721cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the handle to the escaped Object in the outer scope. 5731cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 5741cb0ef41Sopenharmony_ci * @since 11 5751cb0ef41Sopenharmony_ci */ 5761cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_EscapeHandle(JSVM_Env env, 5771cb0ef41Sopenharmony_ci JSVM_EscapableHandleScope scope, 5781cb0ef41Sopenharmony_ci JSVM_Value escapee, 5791cb0ef41Sopenharmony_ci JSVM_Value* result); 5801cb0ef41Sopenharmony_ci 5811cb0ef41Sopenharmony_ci/** 5821cb0ef41Sopenharmony_ci * @brief This API creates a new reference with the specified reference count to the value passed in. 5831cb0ef41Sopenharmony_ci * 5841cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 5851cb0ef41Sopenharmony_ci * @param value: The JSVM_Value for which a reference is being created. 5861cb0ef41Sopenharmony_ci * @param initialRefcount: Initial reference count for the new reference. 5871cb0ef41Sopenharmony_ci * @param result: JSVM_Ref pointing to the new reference. 5881cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 5891cb0ef41Sopenharmony_ci * @since 11 5901cb0ef41Sopenharmony_ci */ 5911cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateReference(JSVM_Env env, 5921cb0ef41Sopenharmony_ci JSVM_Value value, 5931cb0ef41Sopenharmony_ci uint32_t initialRefcount, 5941cb0ef41Sopenharmony_ci JSVM_Ref* result); 5951cb0ef41Sopenharmony_ci 5961cb0ef41Sopenharmony_ci/** 5971cb0ef41Sopenharmony_ci * @brief his API deletes the reference passed in. 5981cb0ef41Sopenharmony_ci * 5991cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 6001cb0ef41Sopenharmony_ci * @param ref: JSVM_Ref to be deleted. 6011cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 6021cb0ef41Sopenharmony_ci * @since 11 6031cb0ef41Sopenharmony_ci */ 6041cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_DeleteReference(JSVM_Env env, 6051cb0ef41Sopenharmony_ci JSVM_Ref ref); 6061cb0ef41Sopenharmony_ci 6071cb0ef41Sopenharmony_ci/** 6081cb0ef41Sopenharmony_ci * @brief his API increments the reference count for the reference passed in and 6091cb0ef41Sopenharmony_ci * returns the resulting reference count. 6101cb0ef41Sopenharmony_ci * 6111cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 6121cb0ef41Sopenharmony_ci * @param ref: JSVM_Ref for which the reference count will be incremented. 6131cb0ef41Sopenharmony_ci * @param result: The new reference count. 6141cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 6151cb0ef41Sopenharmony_ci * @since 11 6161cb0ef41Sopenharmony_ci */ 6171cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ReferenceRef(JSVM_Env env, 6181cb0ef41Sopenharmony_ci JSVM_Ref ref, 6191cb0ef41Sopenharmony_ci uint32_t* result); 6201cb0ef41Sopenharmony_ci 6211cb0ef41Sopenharmony_ci/** 6221cb0ef41Sopenharmony_ci * @brief This API decrements the reference count for the reference passed in and 6231cb0ef41Sopenharmony_ci * returns the resulting reference count. 6241cb0ef41Sopenharmony_ci * 6251cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 6261cb0ef41Sopenharmony_ci * @param ref: JSVM_Ref for which the reference count will be decremented. 6271cb0ef41Sopenharmony_ci * @param result: The new reference count. 6281cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 6291cb0ef41Sopenharmony_ci * @since 11 6301cb0ef41Sopenharmony_ci */ 6311cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ReferenceUnref(JSVM_Env env, 6321cb0ef41Sopenharmony_ci JSVM_Ref ref, 6331cb0ef41Sopenharmony_ci uint32_t* result); 6341cb0ef41Sopenharmony_ci 6351cb0ef41Sopenharmony_ci/** 6361cb0ef41Sopenharmony_ci * @brief If still valid, this API returns the JSVM_Value representing the 6371cb0ef41Sopenharmony_ci * JavaScript value associated with the JSVM_Ref. Otherwise, result will be NULL. 6381cb0ef41Sopenharmony_ci * 6391cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 6401cb0ef41Sopenharmony_ci * @param ref: The JSVM_Ref for which the corresponding value is being requested. 6411cb0ef41Sopenharmony_ci * @param result: The JSVM_Value referenced by the JSVM_Ref. 6421cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 6431cb0ef41Sopenharmony_ci * @since 11 6441cb0ef41Sopenharmony_ci */ 6451cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetReferenceValue(JSVM_Env env, 6461cb0ef41Sopenharmony_ci JSVM_Ref ref, 6471cb0ef41Sopenharmony_ci JSVM_Value* result); 6481cb0ef41Sopenharmony_ci 6491cb0ef41Sopenharmony_ci/** 6501cb0ef41Sopenharmony_ci * @brief This API returns a JSVM-API value corresponding to a JavaScript Array type. 6511cb0ef41Sopenharmony_ci * 6521cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 6531cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript Array. 6541cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 6551cb0ef41Sopenharmony_ci * @since 11 6561cb0ef41Sopenharmony_ci */ 6571cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateArray(JSVM_Env env, 6581cb0ef41Sopenharmony_ci JSVM_Value* result); 6591cb0ef41Sopenharmony_ci 6601cb0ef41Sopenharmony_ci 6611cb0ef41Sopenharmony_ci/** 6621cb0ef41Sopenharmony_ci * @brief This API returns a JSVM-API value corresponding to a JavaScript Array type. The Array's length property 6631cb0ef41Sopenharmony_ci * is set to the passed-in length parameter. However, the underlying buffer is not guaranteed to be pre-allocated 6641cb0ef41Sopenharmony_ci * by the VM when the array is created. That behavior is left to the underlying VM implementation. 6651cb0ef41Sopenharmony_ci * 6661cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 6671cb0ef41Sopenharmony_ci * @param length: The initial length of the Array. 6681cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript Array. 6691cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 6701cb0ef41Sopenharmony_ci * @since 11 6711cb0ef41Sopenharmony_ci */ 6721cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateArrayWithLength(JSVM_Env env, 6731cb0ef41Sopenharmony_ci size_t length, 6741cb0ef41Sopenharmony_ci JSVM_Value* result); 6751cb0ef41Sopenharmony_ci 6761cb0ef41Sopenharmony_ci/** 6771cb0ef41Sopenharmony_ci * @brief This API returns a JSVM-API value corresponding to a JavaScript ArrayBuffer. ArrayBuffers are used to 6781cb0ef41Sopenharmony_ci * represent fixed-length binary data buffers. They are normally used as a backing-buffer for TypedArray objects. 6791cb0ef41Sopenharmony_ci * The ArrayBuffer allocated will have an underlying byte buffer whose size is determined by the length parameter 6801cb0ef41Sopenharmony_ci * that's passed in. The underlying buffer is optionally returned back to the caller in case the caller wants to 6811cb0ef41Sopenharmony_ci * directly manipulate the buffer. This buffer can only be written to directly from native code. To write to this 6821cb0ef41Sopenharmony_ci * buffer from JavaScript, a typed array or DataView object would need to be created. 6831cb0ef41Sopenharmony_ci * 6841cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 6851cb0ef41Sopenharmony_ci * @param byteLength: The length in bytes of the array buffer to create. 6861cb0ef41Sopenharmony_ci * @param data: Pointer to the underlying byte buffer of the ArrayBuffer.data can optionally be ignored by passing NULL. 6871cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript Array. 6881cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 6891cb0ef41Sopenharmony_ci * @since 11 6901cb0ef41Sopenharmony_ci */ 6911cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateArraybuffer(JSVM_Env env, 6921cb0ef41Sopenharmony_ci size_t byteLength, 6931cb0ef41Sopenharmony_ci void** data, 6941cb0ef41Sopenharmony_ci JSVM_Value* result); 6951cb0ef41Sopenharmony_ci 6961cb0ef41Sopenharmony_ci/** 6971cb0ef41Sopenharmony_ci * @brief This API allocate the memory of array buffer backing store. 6981cb0ef41Sopenharmony_ci * 6991cb0ef41Sopenharmony_ci * @param byteLength: size of backing store memory. 7001cb0ef41Sopenharmony_ci * @param initialized: initialization status of the backing store memory. 7011cb0ef41Sopenharmony_ci * @param data: pointer that recieve the backing store memory pointer. 7021cb0ef41Sopenharmony_ci * @return Returns JSVM funtions result code. 7031cb0ef41Sopenharmony_ci * Returns {@link JSVM_OK } if allocation succeed.\n 7041cb0ef41Sopenharmony_ci * Returns {@link JSVM_INVALID_ARG } if data is null pointer.\n 7051cb0ef41Sopenharmony_ci * Returns {@link JSVM_GENERIC_FAILURE } if allocation failed.\n 7061cb0ef41Sopenharmony_ci * @since 12 7071cb0ef41Sopenharmony_ci */ 7081cb0ef41Sopenharmony_ciJSVM_Status JSVM_CDECL OH_JSVM_AllocateArrayBufferBackingStoreData(size_t byteLength, 7091cb0ef41Sopenharmony_ci JSVM_InitializedFlag initialized, 7101cb0ef41Sopenharmony_ci void **data); 7111cb0ef41Sopenharmony_ci 7121cb0ef41Sopenharmony_ci/** 7131cb0ef41Sopenharmony_ci * @brief This API release the memory of an array buffer backing store. 7141cb0ef41Sopenharmony_ci * 7151cb0ef41Sopenharmony_ci * @param data: pointer to the backing store memory. 7161cb0ef41Sopenharmony_ci * @return Returns JSVM funtions result code. 7171cb0ef41Sopenharmony_ci * Returns {@link JSVM_OK } if run succeed.\n 7181cb0ef41Sopenharmony_ci * Returns {@link JSVM_INVALID_ARG } if data is null pointer.\n 7191cb0ef41Sopenharmony_ci * @since 12 7201cb0ef41Sopenharmony_ci */ 7211cb0ef41Sopenharmony_ciJSVM_Status JSVM_CDECL OH_JSVM_FreeArrayBufferBackingStoreData(void *data); 7221cb0ef41Sopenharmony_ci 7231cb0ef41Sopenharmony_ci/** 7241cb0ef41Sopenharmony_ci * @brief This API create an array buffer using the backing store data. 7251cb0ef41Sopenharmony_ci * 7261cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 7271cb0ef41Sopenharmony_ci * @param data: pointer to the backing store memory. 7281cb0ef41Sopenharmony_ci * @param backingStoreSize: size of backing store memory. 7291cb0ef41Sopenharmony_ci * @param offset: start position of the array buffer in the backing store memory. 7301cb0ef41Sopenharmony_ci * @param arrayBufferSize: size of the array buffer. 7311cb0ef41Sopenharmony_ci * @param result: pointer that recieve the array buffer. 7321cb0ef41Sopenharmony_ci * @return Returns JSVM funtions result code. 7331cb0ef41Sopenharmony_ci * Returns {@link JSVM_OK } if creation succeed.\n 7341cb0ef41Sopenharmony_ci * Returns {@link JSVM_INVALID_ARG } if any of the following condition reached:\n 7351cb0ef41Sopenharmony_ci * 1. offset + arrayBufferSize > backingStoreSize\n 7361cb0ef41Sopenharmony_ci * 2. backingStoreSize or arrayBufferSize equals zero 7371cb0ef41Sopenharmony_ci * 3. data or result is null pointer 7381cb0ef41Sopenharmony_ci * @since 12 7391cb0ef41Sopenharmony_ci */ 7401cb0ef41Sopenharmony_ciJSVM_Status JSVM_CDECL OH_JSVM_CreateArrayBufferFromBackingStoreData(JSVM_Env env, 7411cb0ef41Sopenharmony_ci void *data, 7421cb0ef41Sopenharmony_ci size_t backingStoreSize, 7431cb0ef41Sopenharmony_ci size_t offset, 7441cb0ef41Sopenharmony_ci size_t arrayBufferSize, 7451cb0ef41Sopenharmony_ci JSVM_Value *result); 7461cb0ef41Sopenharmony_ci 7471cb0ef41Sopenharmony_ci/** 7481cb0ef41Sopenharmony_ci * @brief This API does not observe leap seconds; they are ignored, as ECMAScript aligns with POSIX time specification. 7491cb0ef41Sopenharmony_ci * This API allocates a JavaScript Date object. 7501cb0ef41Sopenharmony_ci * 7511cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 7521cb0ef41Sopenharmony_ci * @param time: ECMAScript time value in milliseconds since 01 January, 1970 UTC. 7531cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript Date. 7541cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 7551cb0ef41Sopenharmony_ci * @since 11 7561cb0ef41Sopenharmony_ci */ 7571cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateDate(JSVM_Env env, 7581cb0ef41Sopenharmony_ci double time, 7591cb0ef41Sopenharmony_ci JSVM_Value* result); 7601cb0ef41Sopenharmony_ci 7611cb0ef41Sopenharmony_ci/** 7621cb0ef41Sopenharmony_ci * @brief This API allocates a JavaScript value with external data attached to it. This is used to pass external 7631cb0ef41Sopenharmony_ci * data through JavaScript code, so it can be retrieved later by native code using OH_JSVM_GetValueExternal. 7641cb0ef41Sopenharmony_ci * The API adds a JSVM_Finalize callback which will be called when the JavaScript object just created has been garbage 7651cb0ef41Sopenharmony_ci * collected.The created value is not an object, and therefore does not support additional properties. It is considered 7661cb0ef41Sopenharmony_ci * a distinct value type: calling OH_JSVM_Typeof() with an external value yields JSVM_EXTERNAL. 7671cb0ef41Sopenharmony_ci * 7681cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 7691cb0ef41Sopenharmony_ci * @param data: Raw pointer to the external data. 7701cb0ef41Sopenharmony_ci * @param finalizeCb: Optional callback to call when the external value is being collected. JSVM_Finalize provides 7711cb0ef41Sopenharmony_ci * more details. 7721cb0ef41Sopenharmony_ci * @param finalizeHint: Optional hint to pass to the finalize callback during collection. 7731cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing an external value. 7741cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 7751cb0ef41Sopenharmony_ci * @since 11 7761cb0ef41Sopenharmony_ci */ 7771cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateExternal(JSVM_Env env, 7781cb0ef41Sopenharmony_ci void* data, 7791cb0ef41Sopenharmony_ci JSVM_Finalize finalizeCb, 7801cb0ef41Sopenharmony_ci void* finalizeHint, 7811cb0ef41Sopenharmony_ci JSVM_Value* result); 7821cb0ef41Sopenharmony_ci 7831cb0ef41Sopenharmony_ci/** 7841cb0ef41Sopenharmony_ci * @brief This API allocates a default JavaScript Object. It is the equivalent of doing new Object() in JavaScript. 7851cb0ef41Sopenharmony_ci * 7861cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 7871cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript Object. 7881cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 7891cb0ef41Sopenharmony_ci * @since 11 7901cb0ef41Sopenharmony_ci */ 7911cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateObject(JSVM_Env env, 7921cb0ef41Sopenharmony_ci JSVM_Value* result); 7931cb0ef41Sopenharmony_ci 7941cb0ef41Sopenharmony_ci/** 7951cb0ef41Sopenharmony_ci * @brief This API creates a JavaScript symbol value from a UTF8-encoded C string. 7961cb0ef41Sopenharmony_ci * 7971cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 7981cb0ef41Sopenharmony_ci * @param description: Optional JSVM_Value which refers to a JavaScript string to be set as the description 7991cb0ef41Sopenharmony_ci * for the symbol. 8001cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript symbol. 8011cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 8021cb0ef41Sopenharmony_ci * @since 11 8031cb0ef41Sopenharmony_ci */ 8041cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateSymbol(JSVM_Env env, 8051cb0ef41Sopenharmony_ci JSVM_Value description, 8061cb0ef41Sopenharmony_ci JSVM_Value* result); 8071cb0ef41Sopenharmony_ci 8081cb0ef41Sopenharmony_ci/** 8091cb0ef41Sopenharmony_ci * @brief This API searches in the global registry for an existing symbol with the given description. 8101cb0ef41Sopenharmony_ci * If the symbol already exists it will be returned, otherwise a new symbol will be created in the registry. 8111cb0ef41Sopenharmony_ci * 8121cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 8131cb0ef41Sopenharmony_ci * @param utf8description: UTF-8 C string representing the text to be used as the description for the symbol. 8141cb0ef41Sopenharmony_ci * @param length: The length of the description string in bytes, or JSVM_AUTO_LENGTH if it is null-terminated. 8151cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript symbol. 8161cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 8171cb0ef41Sopenharmony_ci * @since 11 8181cb0ef41Sopenharmony_ci */ 8191cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_SymbolFor(JSVM_Env env, 8201cb0ef41Sopenharmony_ci const char* utf8description, 8211cb0ef41Sopenharmony_ci size_t length, 8221cb0ef41Sopenharmony_ci JSVM_Value* result); 8231cb0ef41Sopenharmony_ci 8241cb0ef41Sopenharmony_ci/** 8251cb0ef41Sopenharmony_ci * @brief This API creates a JavaScript TypedArray object over an existing ArrayBuffer. TypedArray 8261cb0ef41Sopenharmony_ci * objects provide an array-like view over an underlying data buffer where each element has the 8271cb0ef41Sopenharmony_ci * same underlying binary scalar datatype.It's required that (length * size_of_element) + byte_offset should 8281cb0ef41Sopenharmony_ci * be <= the size in bytes of the array passed in. If not, a RangeError exception is raised. 8291cb0ef41Sopenharmony_ci * 8301cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 8311cb0ef41Sopenharmony_ci * @param type: Scalar datatype of the elements within the TypedArray. 8321cb0ef41Sopenharmony_ci * @param length: Number of elements in the TypedArray. 8331cb0ef41Sopenharmony_ci * @param arraybuffer: ArrayBuffer underlying the typed array. 8341cb0ef41Sopenharmony_ci * @param byteOffset: The byte offset within the ArrayBuffer from which to start projecting the TypedArray. 8351cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript TypedArray 8361cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 8371cb0ef41Sopenharmony_ci * @since 11 8381cb0ef41Sopenharmony_ci */ 8391cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateTypedarray(JSVM_Env env, 8401cb0ef41Sopenharmony_ci JSVM_TypedarrayType type, 8411cb0ef41Sopenharmony_ci size_t length, 8421cb0ef41Sopenharmony_ci JSVM_Value arraybuffer, 8431cb0ef41Sopenharmony_ci size_t byteOffset, 8441cb0ef41Sopenharmony_ci JSVM_Value* result); 8451cb0ef41Sopenharmony_ci 8461cb0ef41Sopenharmony_ci/** 8471cb0ef41Sopenharmony_ci * @brief This API creates a JavaScript DataView object over an existing ArrayBuffer. DataView 8481cb0ef41Sopenharmony_ci * objects provide an array-like view over an underlying data buffer, but one which allows items 8491cb0ef41Sopenharmony_ci * of different size and type in the ArrayBuffer.It is required that byte_length + byte_offset is 8501cb0ef41Sopenharmony_ci * less than or equal to the size in bytes of the array passed in. If not, a RangeError exception 8511cb0ef41Sopenharmony_ci * is raised. 8521cb0ef41Sopenharmony_ci * 8531cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 8541cb0ef41Sopenharmony_ci * @param length: Number of elements in the DataView. 8551cb0ef41Sopenharmony_ci * @param arraybuffer: ArrayBuffer underlying the DataView. 8561cb0ef41Sopenharmony_ci * @param byteOffset: The byte offset within the ArrayBuffer from which to start projecting the DataView. 8571cb0ef41Sopenharmony_ci * @param result:A JSVM_Value representing a JavaScript DataView. 8581cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 8591cb0ef41Sopenharmony_ci * @since 11 8601cb0ef41Sopenharmony_ci */ 8611cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateDataview(JSVM_Env env, 8621cb0ef41Sopenharmony_ci size_t length, 8631cb0ef41Sopenharmony_ci JSVM_Value arraybuffer, 8641cb0ef41Sopenharmony_ci size_t byteOffset, 8651cb0ef41Sopenharmony_ci JSVM_Value* result); 8661cb0ef41Sopenharmony_ci 8671cb0ef41Sopenharmony_ci/** 8681cb0ef41Sopenharmony_ci * @brief This API is used to convert from the C int32_t type to the JavaScript number type. 8691cb0ef41Sopenharmony_ci * 8701cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 8711cb0ef41Sopenharmony_ci * @param value: Integer value to be represented in JavaScript. 8721cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript number. 8731cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 8741cb0ef41Sopenharmony_ci * @since 11 8751cb0ef41Sopenharmony_ci */ 8761cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateInt32(JSVM_Env env, 8771cb0ef41Sopenharmony_ci int32_t value, 8781cb0ef41Sopenharmony_ci JSVM_Value* result); 8791cb0ef41Sopenharmony_ci 8801cb0ef41Sopenharmony_ci/** 8811cb0ef41Sopenharmony_ci * @brief This API is used to convert from the C uint32_t type to the JavaScript number type. 8821cb0ef41Sopenharmony_ci * 8831cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 8841cb0ef41Sopenharmony_ci * @param value: Unsigned integer value to be represented in JavaScript. 8851cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript number. 8861cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 8871cb0ef41Sopenharmony_ci * @since 11 8881cb0ef41Sopenharmony_ci */ 8891cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateUint32(JSVM_Env env, 8901cb0ef41Sopenharmony_ci uint32_t value, 8911cb0ef41Sopenharmony_ci JSVM_Value* result); 8921cb0ef41Sopenharmony_ci 8931cb0ef41Sopenharmony_ci/** 8941cb0ef41Sopenharmony_ci * @brief This API is used to convert from the C int64_t type to the JavaScript number type. 8951cb0ef41Sopenharmony_ci * 8961cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 8971cb0ef41Sopenharmony_ci * @param value: Integer value to be represented in JavaScript. 8981cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript number. 8991cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 9001cb0ef41Sopenharmony_ci * @since 11 9011cb0ef41Sopenharmony_ci */ 9021cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateInt64(JSVM_Env env, 9031cb0ef41Sopenharmony_ci int64_t value, 9041cb0ef41Sopenharmony_ci JSVM_Value* result); 9051cb0ef41Sopenharmony_ci 9061cb0ef41Sopenharmony_ci/** 9071cb0ef41Sopenharmony_ci * @brief This API is used to convert from the C double type to the JavaScript number type. 9081cb0ef41Sopenharmony_ci * 9091cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 9101cb0ef41Sopenharmony_ci * @param value: Double-precision value to be represented in JavaScript. 9111cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript number. 9121cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 9131cb0ef41Sopenharmony_ci * @since 11 9141cb0ef41Sopenharmony_ci */ 9151cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateDouble(JSVM_Env env, 9161cb0ef41Sopenharmony_ci double value, 9171cb0ef41Sopenharmony_ci JSVM_Value* result); 9181cb0ef41Sopenharmony_ci 9191cb0ef41Sopenharmony_ci/** 9201cb0ef41Sopenharmony_ci * @brief This API converts the C int64_t type to the JavaScript BigInt type. 9211cb0ef41Sopenharmony_ci * 9221cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 9231cb0ef41Sopenharmony_ci * @param value: Integer value to be represented in JavaScript. 9241cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript BigInt. 9251cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 9261cb0ef41Sopenharmony_ci * @since 11 9271cb0ef41Sopenharmony_ci */ 9281cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateBigintInt64(JSVM_Env env, 9291cb0ef41Sopenharmony_ci int64_t value, 9301cb0ef41Sopenharmony_ci JSVM_Value* result); 9311cb0ef41Sopenharmony_ci 9321cb0ef41Sopenharmony_ci/** 9331cb0ef41Sopenharmony_ci * @brief This API converts the C uint64_t type to the JavaScript BigInt type. 9341cb0ef41Sopenharmony_ci * 9351cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 9361cb0ef41Sopenharmony_ci * @param value: Unsigned integer value to be represented in JavaScript. 9371cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript BigInt. 9381cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 9391cb0ef41Sopenharmony_ci * @since 11 9401cb0ef41Sopenharmony_ci */ 9411cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateBigintUint64(JSVM_Env env, 9421cb0ef41Sopenharmony_ci uint64_t value, 9431cb0ef41Sopenharmony_ci JSVM_Value* result); 9441cb0ef41Sopenharmony_ci 9451cb0ef41Sopenharmony_ci/** 9461cb0ef41Sopenharmony_ci * @brief This API converts an array of unsigned 64-bit words into a single BigInt value. 9471cb0ef41Sopenharmony_ci * The resulting BigInt is calculated as: (–1)sign_bit (words[0] × (264)0 + words[1] × (264)1 + …) 9481cb0ef41Sopenharmony_ci * 9491cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 9501cb0ef41Sopenharmony_ci * @param signBit: Determines if the resulting BigInt will be positive or negative. 9511cb0ef41Sopenharmony_ci * @param wordCount: The length of the words array. 9521cb0ef41Sopenharmony_ci * @param words: An array of uint64_t little-endian 64-bit words. 9531cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript BigInt. 9541cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 9551cb0ef41Sopenharmony_ci * @since 11 9561cb0ef41Sopenharmony_ci */ 9571cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateBigintWords(JSVM_Env env, 9581cb0ef41Sopenharmony_ci int signBit, 9591cb0ef41Sopenharmony_ci size_t wordCount, 9601cb0ef41Sopenharmony_ci const uint64_t* words, 9611cb0ef41Sopenharmony_ci JSVM_Value* result); 9621cb0ef41Sopenharmony_ci 9631cb0ef41Sopenharmony_ci/** 9641cb0ef41Sopenharmony_ci * @brief This API creates a JavaScript string value from an ISO-8859-1-encoded C 9651cb0ef41Sopenharmony_ci * string. The native string is copied. 9661cb0ef41Sopenharmony_ci * 9671cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 9681cb0ef41Sopenharmony_ci * @param str: Character buffer representing an ISO-8859-1-encoded string. 9691cb0ef41Sopenharmony_ci * @param length: The length of the string in bytes, or JSVM_AUTO_LENGTH if it is null-terminated. 9701cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript string. 9711cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 9721cb0ef41Sopenharmony_ci * @since 11 9731cb0ef41Sopenharmony_ci */ 9741cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateStringLatin1(JSVM_Env env, 9751cb0ef41Sopenharmony_ci const char* str, 9761cb0ef41Sopenharmony_ci size_t length, 9771cb0ef41Sopenharmony_ci JSVM_Value* result); 9781cb0ef41Sopenharmony_ci 9791cb0ef41Sopenharmony_ci/** 9801cb0ef41Sopenharmony_ci * @brief This API creates a JavaScript string value from a UTF16-LE-encoded C 9811cb0ef41Sopenharmony_ci * string. The native string is copied. 9821cb0ef41Sopenharmony_ci * 9831cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 9841cb0ef41Sopenharmony_ci * @param str: Character buffer representing a UTF16-LE-encoded string. 9851cb0ef41Sopenharmony_ci * @param length: The length of the string in two-byte code units, or JSVM_AUTO_LENGTH 9861cb0ef41Sopenharmony_ci * if it is null-terminated. 9871cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript string. 9881cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 9891cb0ef41Sopenharmony_ci * @since 11 9901cb0ef41Sopenharmony_ci */ 9911cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateStringUtf16(JSVM_Env env, 9921cb0ef41Sopenharmony_ci const char16_t* str, 9931cb0ef41Sopenharmony_ci size_t length, 9941cb0ef41Sopenharmony_ci JSVM_Value* result); 9951cb0ef41Sopenharmony_ci 9961cb0ef41Sopenharmony_ci/** 9971cb0ef41Sopenharmony_ci * @brief This API creates a JavaScript string value from a UTF8-encoded C 9981cb0ef41Sopenharmony_ci * string. The native string is copied. 9991cb0ef41Sopenharmony_ci * 10001cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 10011cb0ef41Sopenharmony_ci * @param str: Character buffer representing a UTF8-encoded string. 10021cb0ef41Sopenharmony_ci * @param length: The length of the string in bytes, or JSVM_AUTO_LENGTH if it is null-terminated. 10031cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript string. 10041cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 10051cb0ef41Sopenharmony_ci * @since 11 10061cb0ef41Sopenharmony_ci */ 10071cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateStringUtf8(JSVM_Env env, 10081cb0ef41Sopenharmony_ci const char* str, 10091cb0ef41Sopenharmony_ci size_t length, 10101cb0ef41Sopenharmony_ci JSVM_Value* result); 10111cb0ef41Sopenharmony_ci 10121cb0ef41Sopenharmony_ci/** 10131cb0ef41Sopenharmony_ci * @brief This API returns the length of an array. 10141cb0ef41Sopenharmony_ci * 10151cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 10161cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing the JavaScript Array whose length is being queried. 10171cb0ef41Sopenharmony_ci * @param result: uint32 representing length of the array. 10181cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 10191cb0ef41Sopenharmony_ci * @since 11 10201cb0ef41Sopenharmony_ci */ 10211cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetArrayLength(JSVM_Env env, 10221cb0ef41Sopenharmony_ci JSVM_Value value, 10231cb0ef41Sopenharmony_ci uint32_t* result); 10241cb0ef41Sopenharmony_ci 10251cb0ef41Sopenharmony_ci/** 10261cb0ef41Sopenharmony_ci * @brief This API is used to retrieve the underlying data buffer of an ArrayBuffer and its length. 10271cb0ef41Sopenharmony_ci * 10281cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 10291cb0ef41Sopenharmony_ci * @param arraybuffer: JSVM_Value representing the ArrayBuffer being queried. 10301cb0ef41Sopenharmony_ci * @param data: The underlying data buffer of the ArrayBuffer. If byte_length is 0, this may be NULL 10311cb0ef41Sopenharmony_ci * or any other pointer value. 10321cb0ef41Sopenharmony_ci * @param byteLength: Length in bytes of the underlying data buffer. 10331cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 10341cb0ef41Sopenharmony_ci * @since 11 10351cb0ef41Sopenharmony_ci */ 10361cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetArraybufferInfo(JSVM_Env env, 10371cb0ef41Sopenharmony_ci JSVM_Value arraybuffer, 10381cb0ef41Sopenharmony_ci void** data, 10391cb0ef41Sopenharmony_ci size_t* byteLength); 10401cb0ef41Sopenharmony_ci 10411cb0ef41Sopenharmony_ci/** 10421cb0ef41Sopenharmony_ci * @brief This API returns the length of an array. 10431cb0ef41Sopenharmony_ci * 10441cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 10451cb0ef41Sopenharmony_ci * @param object: JSVM_Value representing JavaScript Object whose prototype to return. This returns 10461cb0ef41Sopenharmony_ci * the equivalent of Object.getPrototypeOf (which is not the same as the function's prototype property). 10471cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing prototype of the given object. 10481cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 10491cb0ef41Sopenharmony_ci * @since 11 10501cb0ef41Sopenharmony_ci */ 10511cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetPrototype(JSVM_Env env, 10521cb0ef41Sopenharmony_ci JSVM_Value object, 10531cb0ef41Sopenharmony_ci JSVM_Value* result); 10541cb0ef41Sopenharmony_ci 10551cb0ef41Sopenharmony_ci/** 10561cb0ef41Sopenharmony_ci * @brief This API returns various properties of a typed array. 10571cb0ef41Sopenharmony_ci * 10581cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 10591cb0ef41Sopenharmony_ci * @param typedarray: JSVM_Value representing the TypedArray whose properties to query. 10601cb0ef41Sopenharmony_ci * @param type: Scalar datatype of the elements within the TypedArray. 10611cb0ef41Sopenharmony_ci * @param length: The number of elements in the TypedArray. 10621cb0ef41Sopenharmony_ci * @param data: The data buffer underlying the TypedArray adjusted by the byte_offset value so that it 10631cb0ef41Sopenharmony_ci * points to the first element in the TypedArray. If the length of the array is 0, this may be NULL or 10641cb0ef41Sopenharmony_ci * any other pointer value. 10651cb0ef41Sopenharmony_ci * @param arraybuffer: The ArrayBuffer underlying the TypedArray. 10661cb0ef41Sopenharmony_ci * @param byteOffset: The byte offset within the underlying native array at which the first element of 10671cb0ef41Sopenharmony_ci * the arrays is located. The value for the data parameter has already been adjusted so that data points 10681cb0ef41Sopenharmony_ci * to the first element in the array. Therefore, the first byte of the native array would be at data - byte_offset. 10691cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 10701cb0ef41Sopenharmony_ci * @since 11 10711cb0ef41Sopenharmony_ci */ 10721cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetTypedarrayInfo(JSVM_Env env, 10731cb0ef41Sopenharmony_ci JSVM_Value typedarray, 10741cb0ef41Sopenharmony_ci JSVM_TypedarrayType* type, 10751cb0ef41Sopenharmony_ci size_t* length, 10761cb0ef41Sopenharmony_ci void** data, 10771cb0ef41Sopenharmony_ci JSVM_Value* arraybuffer, 10781cb0ef41Sopenharmony_ci size_t* byteOffset); 10791cb0ef41Sopenharmony_ci 10801cb0ef41Sopenharmony_ci/** 10811cb0ef41Sopenharmony_ci * @brief Any of the out parameters may be NULL if that property is unneeded. 10821cb0ef41Sopenharmony_ci * This API returns various properties of a DataView. 10831cb0ef41Sopenharmony_ci * 10841cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 10851cb0ef41Sopenharmony_ci * @param dataview: JSVM_Value representing the DataView whose properties to query. 10861cb0ef41Sopenharmony_ci * @param bytelength: Number of bytes in the DataView. 10871cb0ef41Sopenharmony_ci * @param data: The data buffer underlying the DataView. 10881cb0ef41Sopenharmony_ci * If byte_length is 0, this may be NULL or any other pointer value. 10891cb0ef41Sopenharmony_ci * @param arraybuffer: ArrayBuffer underlying the DataView. 10901cb0ef41Sopenharmony_ci * @param byteOffset: The byte offset within the data buffer from which to start projecting the DataView. 10911cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 10921cb0ef41Sopenharmony_ci * @since 11 10931cb0ef41Sopenharmony_ci */ 10941cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetDataviewInfo(JSVM_Env env, 10951cb0ef41Sopenharmony_ci JSVM_Value dataview, 10961cb0ef41Sopenharmony_ci size_t* bytelength, 10971cb0ef41Sopenharmony_ci void** data, 10981cb0ef41Sopenharmony_ci JSVM_Value* arraybuffer, 10991cb0ef41Sopenharmony_ci size_t* byteOffset); 11001cb0ef41Sopenharmony_ci 11011cb0ef41Sopenharmony_ci/** 11021cb0ef41Sopenharmony_ci * @brief Returns JSVM_OK if the API succeeded. If a non-date JSVM_Value is 11031cb0ef41Sopenharmony_ci * passed in it returns JSVM_date_expected.This API returns the C double 11041cb0ef41Sopenharmony_ci * primitive of time value for the given JavaScript Date. 11051cb0ef41Sopenharmony_ci * 11061cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 11071cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing a JavaScript Date. 11081cb0ef41Sopenharmony_ci * @param result: Time value as a double represented as milliseconds 11091cb0ef41Sopenharmony_ci * since midnight at the beginning of 01 January, 1970 UTC. 11101cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 11111cb0ef41Sopenharmony_ci * @since 11 11121cb0ef41Sopenharmony_ci */ 11131cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetDateValue(JSVM_Env env, 11141cb0ef41Sopenharmony_ci JSVM_Value value, 11151cb0ef41Sopenharmony_ci double* result); 11161cb0ef41Sopenharmony_ci 11171cb0ef41Sopenharmony_ci/** 11181cb0ef41Sopenharmony_ci * @brief This API returns the C boolean primitive equivalent of the given JavaScript Boolean. 11191cb0ef41Sopenharmony_ci * 11201cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 11211cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing JavaScript Boolean. 11221cb0ef41Sopenharmony_ci * @param result: C boolean primitive equivalent of the given JavaScript Boolean. 11231cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 11241cb0ef41Sopenharmony_ci * If a non-boolean JSVM_Value is passed in it returns JSVM_BOOLEAN_EXPECTED. 11251cb0ef41Sopenharmony_ci * @since 11 11261cb0ef41Sopenharmony_ci */ 11271cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetValueBool(JSVM_Env env, 11281cb0ef41Sopenharmony_ci JSVM_Value value, 11291cb0ef41Sopenharmony_ci bool* result); 11301cb0ef41Sopenharmony_ci 11311cb0ef41Sopenharmony_ci/** 11321cb0ef41Sopenharmony_ci * @brief This API returns the C double primitive equivalent of the given JavaScript number. 11331cb0ef41Sopenharmony_ci * 11341cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 11351cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing JavaScript number. 11361cb0ef41Sopenharmony_ci * @param result: C double primitive equivalent of the given JavaScript number. 11371cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 11381cb0ef41Sopenharmony_ci * If a non-number JSVM_Value is passed in it returns JSVM_NUMBER_EXPECTED. 11391cb0ef41Sopenharmony_ci * @since 11 11401cb0ef41Sopenharmony_ci */ 11411cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetValueDouble(JSVM_Env env, 11421cb0ef41Sopenharmony_ci JSVM_Value value, 11431cb0ef41Sopenharmony_ci double* result); 11441cb0ef41Sopenharmony_ci 11451cb0ef41Sopenharmony_ci/** 11461cb0ef41Sopenharmony_ci * @brief This API returns the C int64_t primitive equivalent of the given JavaScript BigInt. 11471cb0ef41Sopenharmony_ci * If needed it will truncate the value, setting lossless to false. 11481cb0ef41Sopenharmony_ci * 11491cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 11501cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing JavaScript BigInt. 11511cb0ef41Sopenharmony_ci * @param result: C int64_t primitive equivalent of the given JavaScript BigInt. 11521cb0ef41Sopenharmony_ci * @param lossless: Indicates whether the BigInt value was converted losslessly. 11531cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. If a non-BigInt is passed in it returns JSVM_BIGINT_EXPECTED. 11541cb0ef41Sopenharmony_ci * @since 11 11551cb0ef41Sopenharmony_ci */ 11561cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetValueBigintInt64(JSVM_Env env, 11571cb0ef41Sopenharmony_ci JSVM_Value value, 11581cb0ef41Sopenharmony_ci int64_t* result, 11591cb0ef41Sopenharmony_ci bool* lossless); 11601cb0ef41Sopenharmony_ci 11611cb0ef41Sopenharmony_ci/** 11621cb0ef41Sopenharmony_ci * @brief This API returns the C uint64_t primitive equivalent of the given JavaScript BigInt. 11631cb0ef41Sopenharmony_ci * If needed it will truncate the value, setting lossless to false. 11641cb0ef41Sopenharmony_ci * 11651cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 11661cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing JavaScript BigInt. 11671cb0ef41Sopenharmony_ci * @param result: C uint64_t primitive equivalent of the given JavaScript BigInt. 11681cb0ef41Sopenharmony_ci * @param lossless: Indicates whether the BigInt value was converted losslessly. 11691cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. If a non-BigInt is passed in it returns JSVM_BIGINT_EXPECTED. 11701cb0ef41Sopenharmony_ci * @since 11 11711cb0ef41Sopenharmony_ci */ 11721cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetValueBigintUint64(JSVM_Env env, 11731cb0ef41Sopenharmony_ci JSVM_Value value, 11741cb0ef41Sopenharmony_ci uint64_t* result, 11751cb0ef41Sopenharmony_ci bool* lossless); 11761cb0ef41Sopenharmony_ci 11771cb0ef41Sopenharmony_ci/** 11781cb0ef41Sopenharmony_ci * @brief This API converts a single BigInt value into a sign bit, 64-bit little-endian array, and the number 11791cb0ef41Sopenharmony_ci * of elements in the array. signBit and words may be both set to NULL, in order to get only wordCount. 11801cb0ef41Sopenharmony_ci * 11811cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 11821cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing JavaScript BigInt. 11831cb0ef41Sopenharmony_ci * @param signBit: Integer representing if the JavaScript BigInt is positive or negative. 11841cb0ef41Sopenharmony_ci * @param wordCount: Must be initialized to the length of the words array. Upon return, it will be set to 11851cb0ef41Sopenharmony_ci * the actual number of words that would be needed to store this BigInt. 11861cb0ef41Sopenharmony_ci * @param words: Pointer to a pre-allocated 64-bit word array. 11871cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 11881cb0ef41Sopenharmony_ci * @since 11 11891cb0ef41Sopenharmony_ci */ 11901cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetValueBigintWords(JSVM_Env env, 11911cb0ef41Sopenharmony_ci JSVM_Value value, 11921cb0ef41Sopenharmony_ci int* signBit, 11931cb0ef41Sopenharmony_ci size_t* wordCount, 11941cb0ef41Sopenharmony_ci uint64_t* words); 11951cb0ef41Sopenharmony_ci 11961cb0ef41Sopenharmony_ci/** 11971cb0ef41Sopenharmony_ci * @brief This API retrieves the external data pointer that was previously passed to OH_JSVM_CreateExternal(). 11981cb0ef41Sopenharmony_ci * 11991cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 12001cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing JavaScript external value. 12011cb0ef41Sopenharmony_ci * @param result: Pointer to the data wrapped by the JavaScript external value. 12021cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. If a non-external JSVM_Value is passed in it returns JSVM_INVALID_ARG. 12031cb0ef41Sopenharmony_ci * @since 11 12041cb0ef41Sopenharmony_ci */ 12051cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetValueExternal(JSVM_Env env, 12061cb0ef41Sopenharmony_ci JSVM_Value value, 12071cb0ef41Sopenharmony_ci void** result); 12081cb0ef41Sopenharmony_ci 12091cb0ef41Sopenharmony_ci/** 12101cb0ef41Sopenharmony_ci * @brief This API returns the C int32 primitive equivalent of the given JavaScript number. 12111cb0ef41Sopenharmony_ci * 12121cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 12131cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing JavaScript number. 12141cb0ef41Sopenharmony_ci * @param result: C int32 primitive equivalent of the given JavaScript number. 12151cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. If a non-number JSVM_Value is passed in JSVM_NUMBER_EXPECTED. 12161cb0ef41Sopenharmony_ci * @since 11 12171cb0ef41Sopenharmony_ci */ 12181cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetValueInt32(JSVM_Env env, 12191cb0ef41Sopenharmony_ci JSVM_Value value, 12201cb0ef41Sopenharmony_ci int32_t* result); 12211cb0ef41Sopenharmony_ci 12221cb0ef41Sopenharmony_ci/** 12231cb0ef41Sopenharmony_ci * @brief This API returns the C int64 primitive equivalent of the given JavaScript number. 12241cb0ef41Sopenharmony_ci * 12251cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 12261cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing JavaScript number. 12271cb0ef41Sopenharmony_ci * @param result: C int64 primitive equivalent of the given JavaScript number. 12281cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. If a non-number JSVM_Value is passed in JSVM_NUMBER_EXPECTED. 12291cb0ef41Sopenharmony_ci * @since 11 12301cb0ef41Sopenharmony_ci */ 12311cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetValueInt64(JSVM_Env env, 12321cb0ef41Sopenharmony_ci JSVM_Value value, 12331cb0ef41Sopenharmony_ci int64_t* result); 12341cb0ef41Sopenharmony_ci 12351cb0ef41Sopenharmony_ci/** 12361cb0ef41Sopenharmony_ci * @brief This API returns the ISO-8859-1-encoded string corresponding the value passed in. 12371cb0ef41Sopenharmony_ci * 12381cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 12391cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing JavaScript string. 12401cb0ef41Sopenharmony_ci * @param buf: Buffer to write the ISO-8859-1-encoded string into. If NULL is passed in, the 12411cb0ef41Sopenharmony_ci * length of the string in bytes and excluding the null terminator is returned in result. 12421cb0ef41Sopenharmony_ci * @param bufsize: Size of the destination buffer. When this value is insufficient, the returned string 12431cb0ef41Sopenharmony_ci * is truncated and null-terminated. 12441cb0ef41Sopenharmony_ci * @param result: Number of bytes copied into the buffer, excluding the null terminator. 12451cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. If a non-number JSVM_Value is passed in JSVM_NUMBER_EXPECTED. 12461cb0ef41Sopenharmony_ci * @since 11 12471cb0ef41Sopenharmony_ci */ 12481cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetValueStringLatin1(JSVM_Env env, 12491cb0ef41Sopenharmony_ci JSVM_Value value, 12501cb0ef41Sopenharmony_ci char* buf, 12511cb0ef41Sopenharmony_ci size_t bufsize, 12521cb0ef41Sopenharmony_ci size_t* result); 12531cb0ef41Sopenharmony_ci 12541cb0ef41Sopenharmony_ci/** 12551cb0ef41Sopenharmony_ci * @brief This API returns the UTF8-encoded string corresponding the value passed in. 12561cb0ef41Sopenharmony_ci * 12571cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 12581cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing JavaScript string. 12591cb0ef41Sopenharmony_ci * @param buf: Buffer to write the UTF8-encoded string into. If NULL is passed in, the length 12601cb0ef41Sopenharmony_ci * of the string in bytes and excluding the null terminator is returned in result. 12611cb0ef41Sopenharmony_ci * @param bufsize: Size of the destination buffer. When this value is insufficient, the returned 12621cb0ef41Sopenharmony_ci * string is truncated and null-terminated. 12631cb0ef41Sopenharmony_ci * @param result: Number of bytes copied into the buffer, excluding the null terminator. 12641cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. If a non-number JSVM_Value is passed in JSVM_NUMBER_EXPECTED. 12651cb0ef41Sopenharmony_ci * @since 11 12661cb0ef41Sopenharmony_ci */ 12671cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetValueStringUtf8(JSVM_Env env, 12681cb0ef41Sopenharmony_ci JSVM_Value value, 12691cb0ef41Sopenharmony_ci char* buf, 12701cb0ef41Sopenharmony_ci size_t bufsize, 12711cb0ef41Sopenharmony_ci size_t* result); 12721cb0ef41Sopenharmony_ci 12731cb0ef41Sopenharmony_ci/** 12741cb0ef41Sopenharmony_ci * @brief This API returns the UTF16-encoded string corresponding the value passed in. 12751cb0ef41Sopenharmony_ci * 12761cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 12771cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing JavaScript string. 12781cb0ef41Sopenharmony_ci * @param buf: Buffer to write the UTF16-LE-encoded string into. If NULL is passed in, 12791cb0ef41Sopenharmony_ci * the length of the string in 2-byte code units and excluding the null terminator is returned. 12801cb0ef41Sopenharmony_ci * @param bufsize: Size of the destination buffer. When this value is insufficient, 12811cb0ef41Sopenharmony_ci * the returned string is truncated and null-terminated. 12821cb0ef41Sopenharmony_ci * @param result: Number of 2-byte code units copied into the buffer, excluding the null terminator. 12831cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. If a non-number JSVM_Value is passed in JSVM_NUMBER_EXPECTED. 12841cb0ef41Sopenharmony_ci * @since 11 12851cb0ef41Sopenharmony_ci */ 12861cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetValueStringUtf16(JSVM_Env env, 12871cb0ef41Sopenharmony_ci JSVM_Value value, 12881cb0ef41Sopenharmony_ci char16_t* buf, 12891cb0ef41Sopenharmony_ci size_t bufsize, 12901cb0ef41Sopenharmony_ci size_t* result); 12911cb0ef41Sopenharmony_ci 12921cb0ef41Sopenharmony_ci/** 12931cb0ef41Sopenharmony_ci * @brief This API returns the C primitive equivalent of the given JSVM_Value as a uint32_t. 12941cb0ef41Sopenharmony_ci * 12951cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 12961cb0ef41Sopenharmony_ci * @param value: JSVM_Value representing JavaScript number. 12971cb0ef41Sopenharmony_ci * @param result: C primitive equivalent of the given JSVM_Value as a uint32_t. 12981cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 12991cb0ef41Sopenharmony_ci * If a non-number JSVM_Value is passed in it returns JSVM_NUMBER_EXPECTED. 13001cb0ef41Sopenharmony_ci * @since 11 13011cb0ef41Sopenharmony_ci */ 13021cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetValueUint32(JSVM_Env env, 13031cb0ef41Sopenharmony_ci JSVM_Value value, 13041cb0ef41Sopenharmony_ci uint32_t* result); 13051cb0ef41Sopenharmony_ci 13061cb0ef41Sopenharmony_ci/** 13071cb0ef41Sopenharmony_ci * @brief This API is used to return the JavaScript singleton object that is used to represent the given boolean value. 13081cb0ef41Sopenharmony_ci * 13091cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 13101cb0ef41Sopenharmony_ci * @param value: The value of the boolean to retrieve. 13111cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing JavaScript Boolean singleton to retrieve. 13121cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 13131cb0ef41Sopenharmony_ci * @since 11 13141cb0ef41Sopenharmony_ci */ 13151cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetBoolean(JSVM_Env env, 13161cb0ef41Sopenharmony_ci bool value, 13171cb0ef41Sopenharmony_ci JSVM_Value* result); 13181cb0ef41Sopenharmony_ci 13191cb0ef41Sopenharmony_ci/** 13201cb0ef41Sopenharmony_ci * @brief This API returns the global object. 13211cb0ef41Sopenharmony_ci * 13221cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 13231cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing JavaScript global object. 13241cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 13251cb0ef41Sopenharmony_ci * @since 11 13261cb0ef41Sopenharmony_ci */ 13271cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetGlobal(JSVM_Env env, 13281cb0ef41Sopenharmony_ci JSVM_Value* result); 13291cb0ef41Sopenharmony_ci 13301cb0ef41Sopenharmony_ci/** 13311cb0ef41Sopenharmony_ci * @brief This API returns the null object. 13321cb0ef41Sopenharmony_ci * 13331cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 13341cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing JavaScript null object. 13351cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 13361cb0ef41Sopenharmony_ci * @since 11 13371cb0ef41Sopenharmony_ci */ 13381cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetNull(JSVM_Env env, 13391cb0ef41Sopenharmony_ci JSVM_Value* result); 13401cb0ef41Sopenharmony_ci 13411cb0ef41Sopenharmony_ci/** 13421cb0ef41Sopenharmony_ci * @brief This API returns the Undefined object. 13431cb0ef41Sopenharmony_ci * 13441cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 13451cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing JavaScript Undefined value. 13461cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 13471cb0ef41Sopenharmony_ci * @since 11 13481cb0ef41Sopenharmony_ci */ 13491cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetUndefined(JSVM_Env env, 13501cb0ef41Sopenharmony_ci JSVM_Value* result); 13511cb0ef41Sopenharmony_ci 13521cb0ef41Sopenharmony_ci/** 13531cb0ef41Sopenharmony_ci * @brief This API implements the abstract operation ToBoolean() 13541cb0ef41Sopenharmony_ci * 13551cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 13561cb0ef41Sopenharmony_ci * @param value: The JavaScript value to coerce. 13571cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the coerced JavaScript Boolean. 13581cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 13591cb0ef41Sopenharmony_ci * @since 11 13601cb0ef41Sopenharmony_ci */ 13611cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CoerceToBool(JSVM_Env env, 13621cb0ef41Sopenharmony_ci JSVM_Value value, 13631cb0ef41Sopenharmony_ci JSVM_Value* result); 13641cb0ef41Sopenharmony_ci 13651cb0ef41Sopenharmony_ci/** 13661cb0ef41Sopenharmony_ci * @brief This API implements the abstract operation ToNumber() as defined. This 13671cb0ef41Sopenharmony_ci * function potentially runs JS code if the passed-in value is an object. 13681cb0ef41Sopenharmony_ci * 13691cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 13701cb0ef41Sopenharmony_ci * @param value: The JavaScript value to coerce. 13711cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the coerced JavaScript number. 13721cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 13731cb0ef41Sopenharmony_ci * @since 11 13741cb0ef41Sopenharmony_ci */ 13751cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CoerceToNumber(JSVM_Env env, 13761cb0ef41Sopenharmony_ci JSVM_Value value, 13771cb0ef41Sopenharmony_ci JSVM_Value* result); 13781cb0ef41Sopenharmony_ci 13791cb0ef41Sopenharmony_ci/** 13801cb0ef41Sopenharmony_ci * @brief This API implements the abstract operation ToObject(). 13811cb0ef41Sopenharmony_ci * 13821cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 13831cb0ef41Sopenharmony_ci * @param value: The JavaScript value to coerce. 13841cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the coerced JavaScript Object. 13851cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 13861cb0ef41Sopenharmony_ci * @since 11 13871cb0ef41Sopenharmony_ci */ 13881cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CoerceToObject(JSVM_Env env, 13891cb0ef41Sopenharmony_ci JSVM_Value value, 13901cb0ef41Sopenharmony_ci JSVM_Value* result); 13911cb0ef41Sopenharmony_ci 13921cb0ef41Sopenharmony_ci/** 13931cb0ef41Sopenharmony_ci * @brief This API implements the abstract operation ToString().This 13941cb0ef41Sopenharmony_ci * function potentially runs JS code if the passed-in value is an object. 13951cb0ef41Sopenharmony_ci * 13961cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 13971cb0ef41Sopenharmony_ci * @param value: The JavaScript value to coerce. 13981cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the coerced JavaScript string. 13991cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 14001cb0ef41Sopenharmony_ci * @since 11 14011cb0ef41Sopenharmony_ci */ 14021cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CoerceToString(JSVM_Env env, 14031cb0ef41Sopenharmony_ci JSVM_Value value, 14041cb0ef41Sopenharmony_ci JSVM_Value* result); 14051cb0ef41Sopenharmony_ci 14061cb0ef41Sopenharmony_ci/** 14071cb0ef41Sopenharmony_ci * @brief This API represents behavior similar to invoking the typeof Operator 14081cb0ef41Sopenharmony_ci * on the object as defined. However, there are some differences:It has support 14091cb0ef41Sopenharmony_ci * for detecting an External value.It detects null as a separate type, while 14101cb0ef41Sopenharmony_ci * ECMAScript typeof would detect object.If value has a type that is invalid, 14111cb0ef41Sopenharmony_ci * an error is returned. 14121cb0ef41Sopenharmony_ci * 14131cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 14141cb0ef41Sopenharmony_ci * @param value: The JavaScript value whose type to query. 14151cb0ef41Sopenharmony_ci * @param result: The type of the JavaScript value. 14161cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 14171cb0ef41Sopenharmony_ci * @since 11 14181cb0ef41Sopenharmony_ci */ 14191cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_Typeof(JSVM_Env env, 14201cb0ef41Sopenharmony_ci JSVM_Value value, 14211cb0ef41Sopenharmony_ci JSVM_ValueType* result); 14221cb0ef41Sopenharmony_ci 14231cb0ef41Sopenharmony_ci/** 14241cb0ef41Sopenharmony_ci * @brief This API represents invoking the instanceof Operator on the object. 14251cb0ef41Sopenharmony_ci * 14261cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 14271cb0ef41Sopenharmony_ci * @param object: The JavaScript value to check. 14281cb0ef41Sopenharmony_ci * @param constructor: The JavaScript function object of the constructor function 14291cb0ef41Sopenharmony_ci * to check against. 14301cb0ef41Sopenharmony_ci * @param result: Boolean that is set to true if object instanceof constructor is true. 14311cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 14321cb0ef41Sopenharmony_ci * @since 11 14331cb0ef41Sopenharmony_ci */ 14341cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_Instanceof(JSVM_Env env, 14351cb0ef41Sopenharmony_ci JSVM_Value object, 14361cb0ef41Sopenharmony_ci JSVM_Value constructor, 14371cb0ef41Sopenharmony_ci bool* result); 14381cb0ef41Sopenharmony_ci 14391cb0ef41Sopenharmony_ci/** 14401cb0ef41Sopenharmony_ci * @brief This API represents invoking the IsArray operation on the object 14411cb0ef41Sopenharmony_ci * 14421cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 14431cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 14441cb0ef41Sopenharmony_ci * @param result: Whether the given object is an array. 14451cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 14461cb0ef41Sopenharmony_ci * @since 11 14471cb0ef41Sopenharmony_ci */ 14481cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsArray(JSVM_Env env, 14491cb0ef41Sopenharmony_ci JSVM_Value value, 14501cb0ef41Sopenharmony_ci bool* result); 14511cb0ef41Sopenharmony_ci 14521cb0ef41Sopenharmony_ci/** 14531cb0ef41Sopenharmony_ci * @brief This API checks if the Object passed in is an array buffer. 14541cb0ef41Sopenharmony_ci * 14551cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 14561cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 14571cb0ef41Sopenharmony_ci * @param result: Whether the given object is an ArrayBuffer. 14581cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 14591cb0ef41Sopenharmony_ci * @since 11 14601cb0ef41Sopenharmony_ci */ 14611cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsArraybuffer(JSVM_Env env, 14621cb0ef41Sopenharmony_ci JSVM_Value value, 14631cb0ef41Sopenharmony_ci bool* result); 14641cb0ef41Sopenharmony_ci 14651cb0ef41Sopenharmony_ci/** 14661cb0ef41Sopenharmony_ci * @brief This API checks if the Object passed in is a date. 14671cb0ef41Sopenharmony_ci * 14681cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 14691cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 14701cb0ef41Sopenharmony_ci * @param result: Whether the given JSVM_Value represents a JavaScript Date object. 14711cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 14721cb0ef41Sopenharmony_ci * @since 11 14731cb0ef41Sopenharmony_ci */ 14741cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsDate(JSVM_Env env, 14751cb0ef41Sopenharmony_ci JSVM_Value value, 14761cb0ef41Sopenharmony_ci bool* isDate); 14771cb0ef41Sopenharmony_ci 14781cb0ef41Sopenharmony_ci/** 14791cb0ef41Sopenharmony_ci * @brief This API checks if the Object passed in is a typed array. 14801cb0ef41Sopenharmony_ci * 14811cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 14821cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 14831cb0ef41Sopenharmony_ci * @param result: Whether the given JSVM_Value represents a TypedArray. 14841cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 14851cb0ef41Sopenharmony_ci * @since 11 14861cb0ef41Sopenharmony_ci */ 14871cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsTypedarray(JSVM_Env env, 14881cb0ef41Sopenharmony_ci JSVM_Value value, 14891cb0ef41Sopenharmony_ci bool* result); 14901cb0ef41Sopenharmony_ci 14911cb0ef41Sopenharmony_ci/** 14921cb0ef41Sopenharmony_ci * @brief This API checks if the Object passed in is a DataView. 14931cb0ef41Sopenharmony_ci * 14941cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 14951cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 14961cb0ef41Sopenharmony_ci * @param result: Whether the given JSVM_Value represents a DataView. 14971cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 14981cb0ef41Sopenharmony_ci * @since 11 14991cb0ef41Sopenharmony_ci */ 15001cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsDataview(JSVM_Env env, 15011cb0ef41Sopenharmony_ci JSVM_Value value, 15021cb0ef41Sopenharmony_ci bool* result); 15031cb0ef41Sopenharmony_ci 15041cb0ef41Sopenharmony_ci/** 15051cb0ef41Sopenharmony_ci * @brief This API represents the invocation of the Strict Equality algorithm. 15061cb0ef41Sopenharmony_ci * Returns true only when both the type and value are equal. 15071cb0ef41Sopenharmony_ci * 15081cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 15091cb0ef41Sopenharmony_ci * @param lhs: The JavaScript value to check. 15101cb0ef41Sopenharmony_ci * @param rhs: The JavaScript value to check against. 15111cb0ef41Sopenharmony_ci * @param result: Whether the two JSVM_Value objects are equal. 15121cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 15131cb0ef41Sopenharmony_ci * @since 11 15141cb0ef41Sopenharmony_ci */ 15151cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_StrictEquals(JSVM_Env env, 15161cb0ef41Sopenharmony_ci JSVM_Value lhs, 15171cb0ef41Sopenharmony_ci JSVM_Value rhs, 15181cb0ef41Sopenharmony_ci bool* result); 15191cb0ef41Sopenharmony_ci 15201cb0ef41Sopenharmony_ci/** 15211cb0ef41Sopenharmony_ci * @brief This API represents the invocation of the Relaxed Equality algorithm. 15221cb0ef41Sopenharmony_ci * Returns true as long as the values are equal, regardless of type. 15231cb0ef41Sopenharmony_ci * 15241cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 15251cb0ef41Sopenharmony_ci * @param lhs: The JavaScript value to check. 15261cb0ef41Sopenharmony_ci * @param rhs: The JavaScript value to check against. 15271cb0ef41Sopenharmony_ci * @param result: Whether the two JSVM_Value objects are relaxed equal. 15281cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 15291cb0ef41Sopenharmony_ci * @since 12 15301cb0ef41Sopenharmony_ci */ 15311cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_Equals(JSVM_Env env, 15321cb0ef41Sopenharmony_ci JSVM_Value lhs, 15331cb0ef41Sopenharmony_ci JSVM_Value rhs, 15341cb0ef41Sopenharmony_ci bool* result); 15351cb0ef41Sopenharmony_ci 15361cb0ef41Sopenharmony_ci/** 15371cb0ef41Sopenharmony_ci * @brief This API represents the invocation of the ArrayBuffer detach operation. 15381cb0ef41Sopenharmony_ci * 15391cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 15401cb0ef41Sopenharmony_ci * @param arraybuffer: The JavaScript ArrayBuffer to be detached. 15411cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded.If a non-detachable ArrayBuffer 15421cb0ef41Sopenharmony_ci * is passed in it returns JSVM_DETACHABLE_ARRAYBUFFER_EXPECTED. 15431cb0ef41Sopenharmony_ci * @since 11 15441cb0ef41Sopenharmony_ci */ 15451cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_DetachArraybuffer(JSVM_Env env, 15461cb0ef41Sopenharmony_ci JSVM_Value arraybuffer); 15471cb0ef41Sopenharmony_ci 15481cb0ef41Sopenharmony_ci/** 15491cb0ef41Sopenharmony_ci * @brief This API represents the invocation of the ArrayBuffer IsDetachedBuffer operation. 15501cb0ef41Sopenharmony_ci * 15511cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 15521cb0ef41Sopenharmony_ci * @param value: The JavaScript ArrayBuffer to be checked. 15531cb0ef41Sopenharmony_ci * @param result: Whether the arraybuffer is detached. 15541cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 15551cb0ef41Sopenharmony_ci * @since 11 15561cb0ef41Sopenharmony_ci */ 15571cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsDetachedArraybuffer(JSVM_Env env, 15581cb0ef41Sopenharmony_ci JSVM_Value value, 15591cb0ef41Sopenharmony_ci bool* result); 15601cb0ef41Sopenharmony_ci 15611cb0ef41Sopenharmony_ci/** 15621cb0ef41Sopenharmony_ci * @brief This API returns the names of the enumerable properties of object as an array of 15631cb0ef41Sopenharmony_ci * strings. The properties of object whose key is a symbol will not be included. 15641cb0ef41Sopenharmony_ci * 15651cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 15661cb0ef41Sopenharmony_ci * @param object: The object from which to retrieve the properties. 15671cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing an array of JavaScript values that represent 15681cb0ef41Sopenharmony_ci * the property names of the object. The API can be used to iterate over result using 15691cb0ef41Sopenharmony_ci * OH_JSVM_GetArrayLength and OH_JSVM_GetElement. 15701cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 15711cb0ef41Sopenharmony_ci * @since 11 15721cb0ef41Sopenharmony_ci */ 15731cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetPropertyNames(JSVM_Env env, 15741cb0ef41Sopenharmony_ci JSVM_Value object, 15751cb0ef41Sopenharmony_ci JSVM_Value* result); 15761cb0ef41Sopenharmony_ci 15771cb0ef41Sopenharmony_ci/** 15781cb0ef41Sopenharmony_ci * @brief This API returns an array containing the names of the available properties 15791cb0ef41Sopenharmony_ci * of this object. 15801cb0ef41Sopenharmony_ci * 15811cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 15821cb0ef41Sopenharmony_ci * @param object: The object from which to retrieve the properties. 15831cb0ef41Sopenharmony_ci * @param keyMode: Whether to retrieve prototype properties as well. 15841cb0ef41Sopenharmony_ci * @param keyFilter: Which properties to retrieve (enumerable/readable/writable). 15851cb0ef41Sopenharmony_ci * @param keyConversion: Whether to convert numbered property keys to strings. 15861cb0ef41Sopenharmony_ci * @param result: result: A JSVM_Value representing an array of JavaScript values 15871cb0ef41Sopenharmony_ci * that represent the property names of the object. OH_JSVM_GetArrayLength and 15881cb0ef41Sopenharmony_ci * OH_JSVM_GetElement can be used to iterate over result. 15891cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 15901cb0ef41Sopenharmony_ci * @since 11 15911cb0ef41Sopenharmony_ci */ 15921cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetAllPropertyNames(JSVM_Env env, 15931cb0ef41Sopenharmony_ci JSVM_Value object, 15941cb0ef41Sopenharmony_ci JSVM_KeyCollectionMode keyMode, 15951cb0ef41Sopenharmony_ci JSVM_KeyFilter keyFilter, 15961cb0ef41Sopenharmony_ci JSVM_KeyConversion keyConversion, 15971cb0ef41Sopenharmony_ci JSVM_Value* result); 15981cb0ef41Sopenharmony_ci 15991cb0ef41Sopenharmony_ci/** 16001cb0ef41Sopenharmony_ci * @brief This API set a property on the Object passed in. 16011cb0ef41Sopenharmony_ci * 16021cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 16031cb0ef41Sopenharmony_ci * @param object: The object on which to set the property. 16041cb0ef41Sopenharmony_ci * @param key: The name of the property to set. 16051cb0ef41Sopenharmony_ci * @param value: The property value. 16061cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 16071cb0ef41Sopenharmony_ci * @since 11 16081cb0ef41Sopenharmony_ci */ 16091cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_SetProperty(JSVM_Env env, 16101cb0ef41Sopenharmony_ci JSVM_Value object, 16111cb0ef41Sopenharmony_ci JSVM_Value key, 16121cb0ef41Sopenharmony_ci JSVM_Value value); 16131cb0ef41Sopenharmony_ci 16141cb0ef41Sopenharmony_ci/** 16151cb0ef41Sopenharmony_ci * @brief This API gets the requested property from the Object passed in. 16161cb0ef41Sopenharmony_ci * 16171cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 16181cb0ef41Sopenharmony_ci * @param object: The object from which to retrieve the property. 16191cb0ef41Sopenharmony_ci * @param key: The name of the property to retrieve. 16201cb0ef41Sopenharmony_ci * @param result: The value of the property. 16211cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 16221cb0ef41Sopenharmony_ci * @since 11 16231cb0ef41Sopenharmony_ci */ 16241cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetProperty(JSVM_Env env, 16251cb0ef41Sopenharmony_ci JSVM_Value object, 16261cb0ef41Sopenharmony_ci JSVM_Value key, 16271cb0ef41Sopenharmony_ci JSVM_Value* result); 16281cb0ef41Sopenharmony_ci 16291cb0ef41Sopenharmony_ci/** 16301cb0ef41Sopenharmony_ci * @brief This API checks if the Object passed in has the named property. 16311cb0ef41Sopenharmony_ci * 16321cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 16331cb0ef41Sopenharmony_ci * @param object: The object to query. 16341cb0ef41Sopenharmony_ci * @param key: The name of the property whose existence to check. 16351cb0ef41Sopenharmony_ci * @param result: Whether the property exists on the object or not. 16361cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 16371cb0ef41Sopenharmony_ci * @since 11 16381cb0ef41Sopenharmony_ci */ 16391cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_HasProperty(JSVM_Env env, 16401cb0ef41Sopenharmony_ci JSVM_Value object, 16411cb0ef41Sopenharmony_ci JSVM_Value key, 16421cb0ef41Sopenharmony_ci bool* result); 16431cb0ef41Sopenharmony_ci 16441cb0ef41Sopenharmony_ci/** 16451cb0ef41Sopenharmony_ci * @brief This API attempts to delete the key own property from object. 16461cb0ef41Sopenharmony_ci * 16471cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 16481cb0ef41Sopenharmony_ci * @param object: The object to query. 16491cb0ef41Sopenharmony_ci * @param key: The name of the property to delete. 16501cb0ef41Sopenharmony_ci * @param result: Whether the property deletion succeeded or not. result 16511cb0ef41Sopenharmony_ci * can optionally be ignored by passing NULL. 16521cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 16531cb0ef41Sopenharmony_ci * @since 11 16541cb0ef41Sopenharmony_ci */ 16551cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_DeleteProperty(JSVM_Env env, 16561cb0ef41Sopenharmony_ci JSVM_Value object, 16571cb0ef41Sopenharmony_ci JSVM_Value key, 16581cb0ef41Sopenharmony_ci bool* result); 16591cb0ef41Sopenharmony_ci 16601cb0ef41Sopenharmony_ci/** 16611cb0ef41Sopenharmony_ci * @brief This API checks if the Object passed in has the named own property. 16621cb0ef41Sopenharmony_ci * key must be a string or a symbol, or an error will be thrown. JSVM-API will 16631cb0ef41Sopenharmony_ci * not perform any conversion between data types. 16641cb0ef41Sopenharmony_ci * 16651cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 16661cb0ef41Sopenharmony_ci * @param object: The object to query. 16671cb0ef41Sopenharmony_ci * @param key: The name of the own property whose existence to check. 16681cb0ef41Sopenharmony_ci * @param result: Whether the own property exists on the object or not. 16691cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 16701cb0ef41Sopenharmony_ci * @since 11 16711cb0ef41Sopenharmony_ci */ 16721cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_HasOwnProperty(JSVM_Env env, 16731cb0ef41Sopenharmony_ci JSVM_Value object, 16741cb0ef41Sopenharmony_ci JSVM_Value key, 16751cb0ef41Sopenharmony_ci bool* result); 16761cb0ef41Sopenharmony_ci 16771cb0ef41Sopenharmony_ci/** 16781cb0ef41Sopenharmony_ci * @brief This method is equivalent to calling OH_JSVM_SetProperty with 16791cb0ef41Sopenharmony_ci * a JSVM_Value created from the string passed in as utf8Name. 16801cb0ef41Sopenharmony_ci * 16811cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 16821cb0ef41Sopenharmony_ci * @param object: The object on which to set the property. 16831cb0ef41Sopenharmony_ci * @param utf8Name: The name of the property to set. 16841cb0ef41Sopenharmony_ci * @param value: The property value. 16851cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 16861cb0ef41Sopenharmony_ci * @since 11 16871cb0ef41Sopenharmony_ci */ 16881cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_SetNamedProperty(JSVM_Env env, 16891cb0ef41Sopenharmony_ci JSVM_Value object, 16901cb0ef41Sopenharmony_ci const char* utf8name, 16911cb0ef41Sopenharmony_ci JSVM_Value value); 16921cb0ef41Sopenharmony_ci 16931cb0ef41Sopenharmony_ci/** 16941cb0ef41Sopenharmony_ci * @brief This method is equivalent to calling OH_JSVM_SetProperty with 16951cb0ef41Sopenharmony_ci * a JSVM_Value created from the string passed in as utf8Name. 16961cb0ef41Sopenharmony_ci * 16971cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 16981cb0ef41Sopenharmony_ci * @param object: The object from which to retrieve the property. 16991cb0ef41Sopenharmony_ci * @param utf8Name: The name of the property to get. 17001cb0ef41Sopenharmony_ci * @param result: The value of the property. 17011cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 17021cb0ef41Sopenharmony_ci * @since 11 17031cb0ef41Sopenharmony_ci */ 17041cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetNamedProperty(JSVM_Env env, 17051cb0ef41Sopenharmony_ci JSVM_Value object, 17061cb0ef41Sopenharmony_ci const char* utf8name, 17071cb0ef41Sopenharmony_ci JSVM_Value* result); 17081cb0ef41Sopenharmony_ci 17091cb0ef41Sopenharmony_ci/** 17101cb0ef41Sopenharmony_ci * @brief This method is equivalent to calling OH_JSVM_SetProperty with 17111cb0ef41Sopenharmony_ci * a JSVM_Value created from the string passed in as utf8Name. 17121cb0ef41Sopenharmony_ci * 17131cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 17141cb0ef41Sopenharmony_ci * @param object: The object to query. 17151cb0ef41Sopenharmony_ci * @param utf8Name: The name of the property whose existence to check. 17161cb0ef41Sopenharmony_ci * @param result: Whether the property exists on the object or not. 17171cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 17181cb0ef41Sopenharmony_ci * @since 11 17191cb0ef41Sopenharmony_ci */ 17201cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_HasNamedProperty(JSVM_Env env, 17211cb0ef41Sopenharmony_ci JSVM_Value object, 17221cb0ef41Sopenharmony_ci const char* utf8name, 17231cb0ef41Sopenharmony_ci bool* result); 17241cb0ef41Sopenharmony_ci 17251cb0ef41Sopenharmony_ci/** 17261cb0ef41Sopenharmony_ci * @brief This API sets an element on the Object passed in. 17271cb0ef41Sopenharmony_ci * 17281cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 17291cb0ef41Sopenharmony_ci * @param object: The object from which to set the properties. 17301cb0ef41Sopenharmony_ci * @param index: The index of the property to set. 17311cb0ef41Sopenharmony_ci * @param value: The property value. 17321cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 17331cb0ef41Sopenharmony_ci * @since 11 17341cb0ef41Sopenharmony_ci */ 17351cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_SetElement(JSVM_Env env, 17361cb0ef41Sopenharmony_ci JSVM_Value object, 17371cb0ef41Sopenharmony_ci uint32_t index, 17381cb0ef41Sopenharmony_ci JSVM_Value value); 17391cb0ef41Sopenharmony_ci 17401cb0ef41Sopenharmony_ci/** 17411cb0ef41Sopenharmony_ci * @brief This API gets the element at the requested index. 17421cb0ef41Sopenharmony_ci * 17431cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 17441cb0ef41Sopenharmony_ci * @param object: The object from which to retrieve the property. 17451cb0ef41Sopenharmony_ci * @param index: The index of the property to get. 17461cb0ef41Sopenharmony_ci * @param result: The value of the property. 17471cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 17481cb0ef41Sopenharmony_ci * @since 11 17491cb0ef41Sopenharmony_ci */ 17501cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetElement(JSVM_Env env, 17511cb0ef41Sopenharmony_ci JSVM_Value object, 17521cb0ef41Sopenharmony_ci uint32_t index, 17531cb0ef41Sopenharmony_ci JSVM_Value* result); 17541cb0ef41Sopenharmony_ci 17551cb0ef41Sopenharmony_ci/** 17561cb0ef41Sopenharmony_ci * @brief This API returns if the Object passed in has an element 17571cb0ef41Sopenharmony_ci * at the requested index. 17581cb0ef41Sopenharmony_ci * 17591cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 17601cb0ef41Sopenharmony_ci * @param object: The object to query. 17611cb0ef41Sopenharmony_ci * @param index: The index of the property whose existence to check. 17621cb0ef41Sopenharmony_ci * @param result: Whether the property exists on the object or not. 17631cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 17641cb0ef41Sopenharmony_ci * @since 11 17651cb0ef41Sopenharmony_ci */ 17661cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_HasElement(JSVM_Env env, 17671cb0ef41Sopenharmony_ci JSVM_Value object, 17681cb0ef41Sopenharmony_ci uint32_t index, 17691cb0ef41Sopenharmony_ci bool* result); 17701cb0ef41Sopenharmony_ci 17711cb0ef41Sopenharmony_ci/** 17721cb0ef41Sopenharmony_ci * @brief This API attempts to delete the specified index from object. 17731cb0ef41Sopenharmony_ci * 17741cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 17751cb0ef41Sopenharmony_ci * @param object: The object to query. 17761cb0ef41Sopenharmony_ci * @param index: The index of the property to delete. 17771cb0ef41Sopenharmony_ci * @param result: Whether the element deletion succeeded or not. result 17781cb0ef41Sopenharmony_ci * can optionally be ignored by passing NULL. 17791cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 17801cb0ef41Sopenharmony_ci * @since 11 17811cb0ef41Sopenharmony_ci */ 17821cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_DeleteElement(JSVM_Env env, 17831cb0ef41Sopenharmony_ci JSVM_Value object, 17841cb0ef41Sopenharmony_ci uint32_t index, 17851cb0ef41Sopenharmony_ci bool* result); 17861cb0ef41Sopenharmony_ci 17871cb0ef41Sopenharmony_ci/** 17881cb0ef41Sopenharmony_ci * @brief This method allows the efficient definition of multiple properties 17891cb0ef41Sopenharmony_ci * on a given object. The properties are defined using property descriptors. 17901cb0ef41Sopenharmony_ci * Given an array of such property descriptors, this API will set the properties 17911cb0ef41Sopenharmony_ci * on the object one at a time, as defined by DefineOwnProperty(). 17921cb0ef41Sopenharmony_ci * 17931cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 17941cb0ef41Sopenharmony_ci * @param object: The object from which to retrieve the properties. 17951cb0ef41Sopenharmony_ci * @param propertyCount: The number of elements in the properties array. 17961cb0ef41Sopenharmony_ci * @param properties: The array of property descriptors. 17971cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 17981cb0ef41Sopenharmony_ci * @since 11 17991cb0ef41Sopenharmony_ci */ 18001cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_DefineProperties(JSVM_Env env, 18011cb0ef41Sopenharmony_ci JSVM_Value object, 18021cb0ef41Sopenharmony_ci size_t propertyCount, 18031cb0ef41Sopenharmony_ci const JSVM_PropertyDescriptor* properties); 18041cb0ef41Sopenharmony_ci 18051cb0ef41Sopenharmony_ci/** 18061cb0ef41Sopenharmony_ci * @brief This method freezes a given object. This prevents new properties 18071cb0ef41Sopenharmony_ci * from being added to it, existing properties from being removed, prevents 18081cb0ef41Sopenharmony_ci * changing the enumerability, configurability, or writability of existing 18091cb0ef41Sopenharmony_ci * properties, and prevents the values of existing properties from being changed. 18101cb0ef41Sopenharmony_ci * It also prevents the object's prototype from being changed. 18111cb0ef41Sopenharmony_ci * 18121cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 18131cb0ef41Sopenharmony_ci * @param object: The object to freeze. 18141cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 18151cb0ef41Sopenharmony_ci * @since 11 18161cb0ef41Sopenharmony_ci */ 18171cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ObjectFreeze(JSVM_Env env, 18181cb0ef41Sopenharmony_ci JSVM_Value object); 18191cb0ef41Sopenharmony_ci 18201cb0ef41Sopenharmony_ci/** 18211cb0ef41Sopenharmony_ci * @brief This method seals a given object. This prevents new properties 18221cb0ef41Sopenharmony_ci * from being added to it, as well as marking all existing properties as non-configurable. 18231cb0ef41Sopenharmony_ci * 18241cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 18251cb0ef41Sopenharmony_ci * @param object: The object to seal. 18261cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 18271cb0ef41Sopenharmony_ci * @since 11 18281cb0ef41Sopenharmony_ci */ 18291cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ObjectSeal(JSVM_Env env, 18301cb0ef41Sopenharmony_ci JSVM_Value object); 18311cb0ef41Sopenharmony_ci 18321cb0ef41Sopenharmony_ci/** 18331cb0ef41Sopenharmony_ci * @brief This method allows a JavaScript function object to be called from 18341cb0ef41Sopenharmony_ci * a native add-on. This is the primary mechanism of calling back from the 18351cb0ef41Sopenharmony_ci * add-on's native code into JavaScript. 18361cb0ef41Sopenharmony_ci * 18371cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 18381cb0ef41Sopenharmony_ci * @param recv: The this value passed to the called function. 18391cb0ef41Sopenharmony_ci * @param func: JSVM_Value representing the JavaScript function to be invoked. 18401cb0ef41Sopenharmony_ci * @param argc: The count of elements in the argv array. 18411cb0ef41Sopenharmony_ci * @param argv: Array of JSVM_values representing JavaScript values passed in as arguments to the function. 18421cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the JavaScript object returned. 18431cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 18441cb0ef41Sopenharmony_ci * @since 11 18451cb0ef41Sopenharmony_ci */ 18461cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CallFunction(JSVM_Env env, 18471cb0ef41Sopenharmony_ci JSVM_Value recv, 18481cb0ef41Sopenharmony_ci JSVM_Value func, 18491cb0ef41Sopenharmony_ci size_t argc, 18501cb0ef41Sopenharmony_ci const JSVM_Value* argv, 18511cb0ef41Sopenharmony_ci JSVM_Value* result); 18521cb0ef41Sopenharmony_ci 18531cb0ef41Sopenharmony_ci /** 18541cb0ef41Sopenharmony_ci * @brief This API allows an add-on author to create a function object in native 18551cb0ef41Sopenharmony_ci * code. This is the primary mechanism to allow calling into the add-on's native 18561cb0ef41Sopenharmony_ci * code from JavaScript.The newly created function is not automatically visible 18571cb0ef41Sopenharmony_ci * from script after this call. Instead, a property must be explicitly set on any 18581cb0ef41Sopenharmony_ci * object that is visible to JavaScript, in order for the function to be accessible 18591cb0ef41Sopenharmony_ci * from script. 18601cb0ef41Sopenharmony_ci * 18611cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 18621cb0ef41Sopenharmony_ci * @param utf8Name: Optional name of the function encoded as UTF8. This is visible 18631cb0ef41Sopenharmony_ci * within JavaScript as the new function object's name property. 18641cb0ef41Sopenharmony_ci * @param length: The length of the utf8name in bytes, or JSVM_AUTO_LENGTH if it 18651cb0ef41Sopenharmony_ci * is null-terminated. 18661cb0ef41Sopenharmony_ci * @param cb: The native function which should be called when this function 18671cb0ef41Sopenharmony_ci * object is invoked and data. JSVM_Callback provides more details. 18681cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the JavaScript function object for the newly 18691cb0ef41Sopenharmony_ci * created function. 18701cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 18711cb0ef41Sopenharmony_ci * @since 11 18721cb0ef41Sopenharmony_ci */ 18731cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateFunction(JSVM_Env env, 18741cb0ef41Sopenharmony_ci const char* utf8name, 18751cb0ef41Sopenharmony_ci size_t length, 18761cb0ef41Sopenharmony_ci JSVM_Callback cb, 18771cb0ef41Sopenharmony_ci JSVM_Value* result); 18781cb0ef41Sopenharmony_ci 18791cb0ef41Sopenharmony_ci /** 18801cb0ef41Sopenharmony_ci * @brief This method is used within a callback function to retrieve details about 18811cb0ef41Sopenharmony_ci * the call like the arguments and the this pointer from a given callback info. 18821cb0ef41Sopenharmony_ci * 18831cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 18841cb0ef41Sopenharmony_ci * @param cbinfo: The callback info passed into the callback function. 18851cb0ef41Sopenharmony_ci * @param argc: Specifies the length of the provided argv array and receives the 18861cb0ef41Sopenharmony_ci * actual count of arguments. argc can optionally be ignored by passing NULL. 18871cb0ef41Sopenharmony_ci * @param argv: C array of JSVM_values to which the arguments will be copied. If 18881cb0ef41Sopenharmony_ci * there are more arguments than the provided count, only the requested number of 18891cb0ef41Sopenharmony_ci * arguments are copied. If there are fewer arguments provided than claimed, the 18901cb0ef41Sopenharmony_ci * rest of argv is filled with JSVM_Value values that represent undefined. argv 18911cb0ef41Sopenharmony_ci * can optionally be ignored by passing NULL. 18921cb0ef41Sopenharmony_ci * @param thisArg: Receives the JavaScript this argument for the call. thisArg 18931cb0ef41Sopenharmony_ci * can optionally be ignored by passing NULL. 18941cb0ef41Sopenharmony_ci * @param data: Receives the data pointer for the callback. data can optionally 18951cb0ef41Sopenharmony_ci * be ignored by passing NULL. 18961cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 18971cb0ef41Sopenharmony_ci * @since 11 18981cb0ef41Sopenharmony_ci */ 18991cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetCbInfo(JSVM_Env env, 19001cb0ef41Sopenharmony_ci JSVM_CallbackInfo cbinfo, 19011cb0ef41Sopenharmony_ci size_t* argc, 19021cb0ef41Sopenharmony_ci JSVM_Value* argv, 19031cb0ef41Sopenharmony_ci JSVM_Value* thisArg, 19041cb0ef41Sopenharmony_ci void** data); 19051cb0ef41Sopenharmony_ci 19061cb0ef41Sopenharmony_ci/** 19071cb0ef41Sopenharmony_ci * @brief This API returns the new.target of the constructor call. If the 19081cb0ef41Sopenharmony_ci * current callback is not a constructor call, the result is NULL. 19091cb0ef41Sopenharmony_ci * 19101cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 19111cb0ef41Sopenharmony_ci * @param cbinfo: The callback info passed into the callback function. 19121cb0ef41Sopenharmony_ci * @param result: The new.target of the constructor call. 19131cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 19141cb0ef41Sopenharmony_ci * @since 11 19151cb0ef41Sopenharmony_ci */ 19161cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetNewTarget(JSVM_Env env, 19171cb0ef41Sopenharmony_ci JSVM_CallbackInfo cbinfo, 19181cb0ef41Sopenharmony_ci JSVM_Value* result); 19191cb0ef41Sopenharmony_ci 19201cb0ef41Sopenharmony_ci/** 19211cb0ef41Sopenharmony_ci * @brief his method is used to instantiate a new JavaScript value using 19221cb0ef41Sopenharmony_ci * a given JSVM_Value that represents the constructor for the object. 19231cb0ef41Sopenharmony_ci * 19241cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 19251cb0ef41Sopenharmony_ci * @param constructor: JSVM_Value representing the JavaScript function to be invoked as a constructor. 19261cb0ef41Sopenharmony_ci * @param argc: The count of elements in the argv array. 19271cb0ef41Sopenharmony_ci * @param argv: Array of JavaScript values as JSVM_Value representing the arguments to 19281cb0ef41Sopenharmony_ci * the constructor. If argc is zero this parameter may be omitted by passing in NULL. 19291cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the JavaScript object returned, which 19301cb0ef41Sopenharmony_ci * in this case is the constructed object. 19311cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 19321cb0ef41Sopenharmony_ci * @since 11 19331cb0ef41Sopenharmony_ci */ 19341cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_NewInstance(JSVM_Env env, 19351cb0ef41Sopenharmony_ci JSVM_Value constructor, 19361cb0ef41Sopenharmony_ci size_t argc, 19371cb0ef41Sopenharmony_ci const JSVM_Value* argv, 19381cb0ef41Sopenharmony_ci JSVM_Value* result); 19391cb0ef41Sopenharmony_ci 19401cb0ef41Sopenharmony_ci/** 19411cb0ef41Sopenharmony_ci * @brief When wrapping a C++ class, the C++ constructor callback passed via constructor 19421cb0ef41Sopenharmony_ci * should be a static method on the class that calls the actual class constructor, then 19431cb0ef41Sopenharmony_ci * wraps the new C++ instance in a JavaScript object, and returns the wrapper object. 19441cb0ef41Sopenharmony_ci * 19451cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 19461cb0ef41Sopenharmony_ci * @param utf8name: Name of the JavaScript constructor function. For clarity, it is 19471cb0ef41Sopenharmony_ci * recommended to use the C++ class name when wrapping a C++ class. 19481cb0ef41Sopenharmony_ci * @param length: The length of the utf8name in bytes, or JSVM_AUTO_LENGTH if it 19491cb0ef41Sopenharmony_ci * is null-terminated. 19501cb0ef41Sopenharmony_ci * @param constructor: Struct include callback function that handles constructing instances of the class. 19511cb0ef41Sopenharmony_ci * When wrapping a C++ class, this method must be a static member with the JSVM_Callback.callback 19521cb0ef41Sopenharmony_ci * signature. A C++ class constructor cannot be used. 19531cb0ef41Sopenharmony_ci * Include Optional data to be passed to the constructor callback as the data 19541cb0ef41Sopenharmony_ci * property of the callback info. JSVM_Callback provides more details. 19551cb0ef41Sopenharmony_ci * @param propertyCount: Number of items in the properties array argument. 19561cb0ef41Sopenharmony_ci * @param properties: Array of property descriptors describing static and instance data 19571cb0ef41Sopenharmony_ci * properties, accessors, and methods on the class See JSVM_PropertyDescriptor. 19581cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing the constructor function for the class. 19591cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 19601cb0ef41Sopenharmony_ci * @since 11 19611cb0ef41Sopenharmony_ci */ 19621cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_DefineClass(JSVM_Env env, 19631cb0ef41Sopenharmony_ci const char* utf8name, 19641cb0ef41Sopenharmony_ci size_t length, 19651cb0ef41Sopenharmony_ci JSVM_Callback constructor, 19661cb0ef41Sopenharmony_ci size_t propertyCount, 19671cb0ef41Sopenharmony_ci const JSVM_PropertyDescriptor* properties, 19681cb0ef41Sopenharmony_ci JSVM_Value* result); 19691cb0ef41Sopenharmony_ci 19701cb0ef41Sopenharmony_ci/** 19711cb0ef41Sopenharmony_ci * @brief Wraps a native instance in a JavaScript object. The native instance can 19721cb0ef41Sopenharmony_ci * be retrieved later using OH_JSVM_Unwrap(). 19731cb0ef41Sopenharmony_ci * 19741cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 19751cb0ef41Sopenharmony_ci * @param jsObject: The JavaScript object that will be the wrapper for the native object. 19761cb0ef41Sopenharmony_ci * @param nativeObject: The native instance that will be wrapped in the JavaScript object. 19771cb0ef41Sopenharmony_ci * @param finalizeCb: Optional native callback that can be used to free the native instance 19781cb0ef41Sopenharmony_ci * when the JavaScript object has been garbage-collected. 19791cb0ef41Sopenharmony_ci * @param finalizeHint: Optional contextual hint that is passed to the finalize callback. 19801cb0ef41Sopenharmony_ci * properties, accessors, and methods on the class See JSVM_PropertyDescriptor. 19811cb0ef41Sopenharmony_ci * @param result: Optional reference to the wrapped object. 19821cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 19831cb0ef41Sopenharmony_ci * @since 11 19841cb0ef41Sopenharmony_ci */ 19851cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_Wrap(JSVM_Env env, 19861cb0ef41Sopenharmony_ci JSVM_Value jsObject, 19871cb0ef41Sopenharmony_ci void* nativeObject, 19881cb0ef41Sopenharmony_ci JSVM_Finalize finalizeCb, 19891cb0ef41Sopenharmony_ci void* finalizeHint, 19901cb0ef41Sopenharmony_ci JSVM_Ref* result); 19911cb0ef41Sopenharmony_ci 19921cb0ef41Sopenharmony_ci/** 19931cb0ef41Sopenharmony_ci * @brief When JavaScript code invokes a method or property accessor on the class, the corresponding 19941cb0ef41Sopenharmony_ci * JSVM_Callback is invoked. If the callback is for an instance method or accessor, then the this 19951cb0ef41Sopenharmony_ci * argument to the callback is the wrapper object; the wrapped C++ instance that is the target of 19961cb0ef41Sopenharmony_ci * the call can be obtained then by calling OH_JSVM_Unwrap() on the wrapper object. 19971cb0ef41Sopenharmony_ci * 19981cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 19991cb0ef41Sopenharmony_ci * @param jsObject: The object associated with the native instance. 20001cb0ef41Sopenharmony_ci * @param result: Pointer to the wrapped native instance. 20011cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 20021cb0ef41Sopenharmony_ci * @since 11 20031cb0ef41Sopenharmony_ci */ 20041cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_Unwrap(JSVM_Env env, 20051cb0ef41Sopenharmony_ci JSVM_Value jsObject, 20061cb0ef41Sopenharmony_ci void** result); 20071cb0ef41Sopenharmony_ci 20081cb0ef41Sopenharmony_ci/** 20091cb0ef41Sopenharmony_ci * @brief Retrieves a native instance that was previously wrapped in the JavaScript object jsObject 20101cb0ef41Sopenharmony_ci * using OH_JSVM_Wrap() and removes the wrapping. If a finalize callback was associated with the wrapping, 20111cb0ef41Sopenharmony_ci * it will no longer be called when the JavaScript object becomes garbage-collected. 20121cb0ef41Sopenharmony_ci * 20131cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 20141cb0ef41Sopenharmony_ci * @param jsObject: The object associated with the native instance. 20151cb0ef41Sopenharmony_ci * @param result: Pointer to the wrapped native instance. 20161cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 20171cb0ef41Sopenharmony_ci * @since 11 20181cb0ef41Sopenharmony_ci */ 20191cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_RemoveWrap(JSVM_Env env, 20201cb0ef41Sopenharmony_ci JSVM_Value jsObject, 20211cb0ef41Sopenharmony_ci void** result); 20221cb0ef41Sopenharmony_ci 20231cb0ef41Sopenharmony_ci/** 20241cb0ef41Sopenharmony_ci * @brief Associates the value of the typeTag pointer with the JavaScript object or external. 20251cb0ef41Sopenharmony_ci * OH_JSVM_CheckObjectTypeTag() can then be used to compare the tag that was attached to the 20261cb0ef41Sopenharmony_ci * object with one owned by the addon to ensure that the object has the right type. 20271cb0ef41Sopenharmony_ci * If the object already has an associated type tag, this API will return JSVM_INVALID_ARG. 20281cb0ef41Sopenharmony_ci * 20291cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 20301cb0ef41Sopenharmony_ci * @param value: The JavaScript object or external to be marked. 20311cb0ef41Sopenharmony_ci * @param typeTag: The tag with which the object is to be marked. 20321cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 20331cb0ef41Sopenharmony_ci * @since 11 20341cb0ef41Sopenharmony_ci */ 20351cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_TypeTagObject(JSVM_Env env, 20361cb0ef41Sopenharmony_ci JSVM_Value value, 20371cb0ef41Sopenharmony_ci const JSVM_TypeTag* typeTag); 20381cb0ef41Sopenharmony_ci 20391cb0ef41Sopenharmony_ci/** 20401cb0ef41Sopenharmony_ci * @brief Compares the pointer given as typeTag with any that can be found on js object. 20411cb0ef41Sopenharmony_ci * If no tag is found on js object or, if a tag is found but it does not match typeTag, 20421cb0ef41Sopenharmony_ci * then result is set to false. If a tag is found and it matches typeTag, then result is set to true. 20431cb0ef41Sopenharmony_ci * 20441cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 20451cb0ef41Sopenharmony_ci * @param value: The JavaScript object or external whose type tag to examine. 20461cb0ef41Sopenharmony_ci * @param typeTag: The tag with which to compare any tag found on the object. 20471cb0ef41Sopenharmony_ci * @param result: Whether the type tag given matched the type tag on the object. false is also returned 20481cb0ef41Sopenharmony_ci * if no type tag was found on the object. 20491cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 20501cb0ef41Sopenharmony_ci * @since 11 20511cb0ef41Sopenharmony_ci */ 20521cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CheckObjectTypeTag(JSVM_Env env, 20531cb0ef41Sopenharmony_ci JSVM_Value value, 20541cb0ef41Sopenharmony_ci const JSVM_TypeTag* typeTag, 20551cb0ef41Sopenharmony_ci bool* result); 20561cb0ef41Sopenharmony_ci 20571cb0ef41Sopenharmony_ci/** 20581cb0ef41Sopenharmony_ci * @brief This API can be called multiple times on a single JavaScript object. 20591cb0ef41Sopenharmony_ci * 20601cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 20611cb0ef41Sopenharmony_ci * @param jsObject: The JavaScript object to which the native data will be attached. 20621cb0ef41Sopenharmony_ci * @param finalizeData: Optional data to be passed to finalizeCb. 20631cb0ef41Sopenharmony_ci * @param finalizeCb: Native callback that will be used to free the native data when the 20641cb0ef41Sopenharmony_ci * JavaScript object has been garbage-collected. JSVM_Finalize provides more details. 20651cb0ef41Sopenharmony_ci * @param finalizeHint: Optional contextual hint that is passed to the finalize callback. 20661cb0ef41Sopenharmony_ci * @param result: Optional reference to the JavaScript object. 20671cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 20681cb0ef41Sopenharmony_ci * @since 11 20691cb0ef41Sopenharmony_ci */ 20701cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_AddFinalizer(JSVM_Env env, 20711cb0ef41Sopenharmony_ci JSVM_Value jsObject, 20721cb0ef41Sopenharmony_ci void* finalizeData, 20731cb0ef41Sopenharmony_ci JSVM_Finalize finalizeCb, 20741cb0ef41Sopenharmony_ci void* finalizeHint, 20751cb0ef41Sopenharmony_ci JSVM_Ref* result); 20761cb0ef41Sopenharmony_ci 20771cb0ef41Sopenharmony_ci/** 20781cb0ef41Sopenharmony_ci * @brief This API returns the highest JSVM-API version supported by the JSVM runtime. 20791cb0ef41Sopenharmony_ci * 20801cb0ef41Sopenharmony_ci * JSVM-API is planned to be additive such that newer releases of JSVM may support additional 20811cb0ef41Sopenharmony_ci * API functions. In order to allow an addon to use a newer function when running with versions 20821cb0ef41Sopenharmony_ci * of JSVM that support it, while providing fallback behavior when running with JSVM 20831cb0ef41Sopenharmony_ci * versions that don't support it. 20841cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 20851cb0ef41Sopenharmony_ci * @param result: The highest version of JSVM-API supported. 20861cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 20871cb0ef41Sopenharmony_ci * @since 11 20881cb0ef41Sopenharmony_ci */ 20891cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetVersion(JSVM_Env env, 20901cb0ef41Sopenharmony_ci uint32_t* result); 20911cb0ef41Sopenharmony_ci 20921cb0ef41Sopenharmony_ci/** 20931cb0ef41Sopenharmony_ci * @brief Return information of the VM. 20941cb0ef41Sopenharmony_ci * 20951cb0ef41Sopenharmony_ci * @param result: The information of the VM. 20961cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 20971cb0ef41Sopenharmony_ci * @since 11 20981cb0ef41Sopenharmony_ci */ 20991cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetVMInfo(JSVM_VMInfo* result); 21001cb0ef41Sopenharmony_ci 21011cb0ef41Sopenharmony_ci/** 21021cb0ef41Sopenharmony_ci * @brief This function gives V8 an indication of the amount of externally 21031cb0ef41Sopenharmony_ci * allocated memory that is kept alive by JavaScript objects (i.e. a JavaScript 21041cb0ef41Sopenharmony_ci * object that points to its own memory allocated by a native addon). Registering 21051cb0ef41Sopenharmony_ci * externally allocated memory will trigger global garbage collections more often 21061cb0ef41Sopenharmony_ci * than it would otherwise. 21071cb0ef41Sopenharmony_ci * 21081cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 21091cb0ef41Sopenharmony_ci * @param changeInBytes: The change in externally allocated memory that is kept 21101cb0ef41Sopenharmony_ci * alive by JavaScript objects. 21111cb0ef41Sopenharmony_ci * @param result: The adjusted value 21121cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 21131cb0ef41Sopenharmony_ci * @since 11 21141cb0ef41Sopenharmony_ci */ 21151cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_AdjustExternalMemory(JSVM_Env env, 21161cb0ef41Sopenharmony_ci int64_t changeInBytes, 21171cb0ef41Sopenharmony_ci int64_t* result); 21181cb0ef41Sopenharmony_ci 21191cb0ef41Sopenharmony_ci/** 21201cb0ef41Sopenharmony_ci * @brief This function notifies the VM that the system is running low on memory 21211cb0ef41Sopenharmony_ci * and optionally triggers a garbage collection. 21221cb0ef41Sopenharmony_ci * 21231cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 21241cb0ef41Sopenharmony_ci * @param level: The memory pressure level set to the current VM. 21251cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 21261cb0ef41Sopenharmony_ci * @since 11 21271cb0ef41Sopenharmony_ci */ 21281cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_MemoryPressureNotification(JSVM_Env env, 21291cb0ef41Sopenharmony_ci JSVM_MemoryPressureLevel level); 21301cb0ef41Sopenharmony_ci 21311cb0ef41Sopenharmony_ci/** 21321cb0ef41Sopenharmony_ci * @brief This API creates a deferred object and a JavaScript promise. 21331cb0ef41Sopenharmony_ci * 21341cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 21351cb0ef41Sopenharmony_ci * @param deferred: A newly created deferred object which can later be 21361cb0ef41Sopenharmony_ci * passed to OH_JSVM_ResolveDeferred() or OH_JSVM_RejectDeferred() to resolve 21371cb0ef41Sopenharmony_ci * resp. reject the associated promise. 21381cb0ef41Sopenharmony_ci * @param promise: The JavaScript promise associated with the deferred object. 21391cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 21401cb0ef41Sopenharmony_ci * @since 11 21411cb0ef41Sopenharmony_ci */ 21421cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreatePromise(JSVM_Env env, 21431cb0ef41Sopenharmony_ci JSVM_Deferred* deferred, 21441cb0ef41Sopenharmony_ci JSVM_Value* promise); 21451cb0ef41Sopenharmony_ci 21461cb0ef41Sopenharmony_ci/** 21471cb0ef41Sopenharmony_ci * @brief This API resolves a JavaScript promise by way of the deferred object with 21481cb0ef41Sopenharmony_ci * which it is associated. Thus, it can only be used to resolve JavaScript promises 21491cb0ef41Sopenharmony_ci * for which the corresponding deferred object is available. This effectively means 21501cb0ef41Sopenharmony_ci * that the promise must have been created using OH_JSVM_CreatePromise() and the deferred 21511cb0ef41Sopenharmony_ci * object returned from that call must have been retained in order to be passed to this API. 21521cb0ef41Sopenharmony_ci * 21531cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 21541cb0ef41Sopenharmony_ci * @param deferred: The deferred object whose associated promise to resolve. 21551cb0ef41Sopenharmony_ci * @param resolution: The value with which to resolve the promise. 21561cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 21571cb0ef41Sopenharmony_ci * @since 11 21581cb0ef41Sopenharmony_ci */ 21591cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ResolveDeferred(JSVM_Env env, 21601cb0ef41Sopenharmony_ci JSVM_Deferred deferred, 21611cb0ef41Sopenharmony_ci JSVM_Value resolution); 21621cb0ef41Sopenharmony_ci 21631cb0ef41Sopenharmony_ci/** 21641cb0ef41Sopenharmony_ci * @brief This API rejects a JavaScript promise by way of the deferred object with 21651cb0ef41Sopenharmony_ci * which it is associated. Thus, it can only be used to reject JavaScript promises 21661cb0ef41Sopenharmony_ci * for which the corresponding deferred object is available. This effectively means 21671cb0ef41Sopenharmony_ci * that the promise must have been created using OH_JSVM_CreatePromise() and the deferred 21681cb0ef41Sopenharmony_ci * object returned from that call must have been retained in order to be passed to this API. 21691cb0ef41Sopenharmony_ci * 21701cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 21711cb0ef41Sopenharmony_ci * @param deferred: The deferred object whose associated promise to resolve. 21721cb0ef41Sopenharmony_ci * @param rejection: The value with which to reject the promise. 21731cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 21741cb0ef41Sopenharmony_ci * @since 11 21751cb0ef41Sopenharmony_ci */ 21761cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_RejectDeferred(JSVM_Env env, 21771cb0ef41Sopenharmony_ci JSVM_Deferred deferred, 21781cb0ef41Sopenharmony_ci JSVM_Value rejection); 21791cb0ef41Sopenharmony_ci 21801cb0ef41Sopenharmony_ci/** 21811cb0ef41Sopenharmony_ci * @brief This API return indicating whether promise is a native promise object. 21821cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 21831cb0ef41Sopenharmony_ci * @param value: The value to examine 21841cb0ef41Sopenharmony_ci * @param isPromise: Flag indicating whether promise is a native promise object 21851cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 21861cb0ef41Sopenharmony_ci * @since 11 21871cb0ef41Sopenharmony_ci */ 21881cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsPromise(JSVM_Env env, 21891cb0ef41Sopenharmony_ci JSVM_Value value, 21901cb0ef41Sopenharmony_ci bool* isPromise); 21911cb0ef41Sopenharmony_ci 21921cb0ef41Sopenharmony_ci/** 21931cb0ef41Sopenharmony_ci * @brief This API parses a JSON string and returns it as value if successful. 21941cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 21951cb0ef41Sopenharmony_ci * @param jsonString: The string to parse. 21961cb0ef41Sopenharmony_ci * @param result: The parse value if successful. 21971cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 21981cb0ef41Sopenharmony_ci * @since 11 21991cb0ef41Sopenharmony_ci */ 22001cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_JsonParse(JSVM_Env env, 22011cb0ef41Sopenharmony_ci JSVM_Value jsonString, 22021cb0ef41Sopenharmony_ci JSVM_Value* result); 22031cb0ef41Sopenharmony_ci 22041cb0ef41Sopenharmony_ci/** 22051cb0ef41Sopenharmony_ci * @brief This API stringifies the object and returns it as string if successful. 22061cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 22071cb0ef41Sopenharmony_ci * @param jsonObject: The object to stringify. 22081cb0ef41Sopenharmony_ci * @param result: The string if successfully stringified. 22091cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 22101cb0ef41Sopenharmony_ci * @since 11 22111cb0ef41Sopenharmony_ci */ 22121cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_JsonStringify(JSVM_Env env, 22131cb0ef41Sopenharmony_ci JSVM_Value jsonObject, 22141cb0ef41Sopenharmony_ci JSVM_Value* result); 22151cb0ef41Sopenharmony_ci 22161cb0ef41Sopenharmony_ci/** 22171cb0ef41Sopenharmony_ci * @brief This API create the startup snapshot of the VM. 22181cb0ef41Sopenharmony_ci * @param vm: The environment that the API is invoked under. 22191cb0ef41Sopenharmony_ci * @param contextCount: The object to stringify. 22201cb0ef41Sopenharmony_ci * @param contexts: The array of contexts to add to the snapshot. 22211cb0ef41Sopenharmony_ci * @param blobData: The snapshot data. 22221cb0ef41Sopenharmony_ci * @param blobSize: The size of snapshot data. 22231cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 22241cb0ef41Sopenharmony_ci * @since 11 22251cb0ef41Sopenharmony_ci */ 22261cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateSnapshot(JSVM_VM vm, 22271cb0ef41Sopenharmony_ci size_t contextCount, 22281cb0ef41Sopenharmony_ci const JSVM_Env* contexts, 22291cb0ef41Sopenharmony_ci const char** blobData, 22301cb0ef41Sopenharmony_ci size_t* blobSize); 22311cb0ef41Sopenharmony_ci 22321cb0ef41Sopenharmony_ci/** 22331cb0ef41Sopenharmony_ci * @brief This function returns a set of statistics data of the heap of the VM. 22341cb0ef41Sopenharmony_ci * 22351cb0ef41Sopenharmony_ci * @param vm: The VM whose heap statistics are returned. 22361cb0ef41Sopenharmony_ci * @param result: The heap statistics data. 22371cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 22381cb0ef41Sopenharmony_ci * @since 12 22391cb0ef41Sopenharmony_ci */ 22401cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_GetHeapStatistics(JSVM_VM vm, 22411cb0ef41Sopenharmony_ci JSVM_HeapStatistics* result); 22421cb0ef41Sopenharmony_ci 22431cb0ef41Sopenharmony_ci/** 22441cb0ef41Sopenharmony_ci * @brief This function creates and starts a CPU profiler. 22451cb0ef41Sopenharmony_ci * 22461cb0ef41Sopenharmony_ci * @param vm: The VM to start CPU profiler for. 22471cb0ef41Sopenharmony_ci * @param result: The pointer to the CPU profiler. 22481cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 22491cb0ef41Sopenharmony_ci * @since 12 22501cb0ef41Sopenharmony_ci */ 22511cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_StartCpuProfiler(JSVM_VM vm, 22521cb0ef41Sopenharmony_ci JSVM_CpuProfiler* result); 22531cb0ef41Sopenharmony_ci 22541cb0ef41Sopenharmony_ci/** 22551cb0ef41Sopenharmony_ci * @brief This function stops the CPU profiler and output to the stream. 22561cb0ef41Sopenharmony_ci * 22571cb0ef41Sopenharmony_ci * @param vm: THe VM to start CPU profiler for. 22581cb0ef41Sopenharmony_ci * @param profiler: The CPU profiler to stop. 22591cb0ef41Sopenharmony_ci * @param stream: The output stream callback for receiving the data. 22601cb0ef41Sopenharmony_ci * @param streamData: Optional data to be passed to the stream callback. 22611cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 22621cb0ef41Sopenharmony_ci * @since 12 22631cb0ef41Sopenharmony_ci */ 22641cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_StopCpuProfiler(JSVM_VM vm, 22651cb0ef41Sopenharmony_ci JSVM_CpuProfiler profiler, 22661cb0ef41Sopenharmony_ci JSVM_OutputStream stream, 22671cb0ef41Sopenharmony_ci void* streamData); 22681cb0ef41Sopenharmony_ci 22691cb0ef41Sopenharmony_ci/** 22701cb0ef41Sopenharmony_ci * @brief This funciton takes the current heap snapshot and output to the stream. 22711cb0ef41Sopenharmony_ci * 22721cb0ef41Sopenharmony_ci * @param vm: The VM whose heap snapshot is taken. 22731cb0ef41Sopenharmony_ci * @param stream: The output stream callback for receiving the data. 22741cb0ef41Sopenharmony_ci * @param streamData: Optional data to be passed to the stream callback. 22751cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 22761cb0ef41Sopenharmony_ci * @since 12 22771cb0ef41Sopenharmony_ci */ 22781cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_TakeHeapSnapshot(JSVM_VM vm, 22791cb0ef41Sopenharmony_ci JSVM_OutputStream stream, 22801cb0ef41Sopenharmony_ci void* streamData); 22811cb0ef41Sopenharmony_ci 22821cb0ef41Sopenharmony_ci/** 22831cb0ef41Sopenharmony_ci * @brief This functiong activates insepctor on host and port. 22841cb0ef41Sopenharmony_ci * 22851cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 22861cb0ef41Sopenharmony_ci * @param host: The host to listen to for inspector connections. 22871cb0ef41Sopenharmony_ci * @param port: The port to listen to for inspector connections. 22881cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 22891cb0ef41Sopenharmony_ci * @since 12 22901cb0ef41Sopenharmony_ci */ 22911cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_OpenInspector(JSVM_Env env, 22921cb0ef41Sopenharmony_ci const char* host, 22931cb0ef41Sopenharmony_ci uint16_t port); 22941cb0ef41Sopenharmony_ci 22951cb0ef41Sopenharmony_ci/** 22961cb0ef41Sopenharmony_ci * @brief This function attempts to close all remaining inspector connections. 22971cb0ef41Sopenharmony_ci * 22981cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 22991cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 23001cb0ef41Sopenharmony_ci * @since 12 23011cb0ef41Sopenharmony_ci */ 23021cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CloseInspector(JSVM_Env env); 23031cb0ef41Sopenharmony_ci 23041cb0ef41Sopenharmony_ci/** 23051cb0ef41Sopenharmony_ci * @brief This function will block until a client (existing or connected later) 23061cb0ef41Sopenharmony_ci * has sent Runtime.runIfWaitingForDebugger command. 23071cb0ef41Sopenharmony_ci * 23081cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 23091cb0ef41Sopenharmony_ci * @param breakNextLine: Whether break on the next line of JavaScript code. 23101cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 23111cb0ef41Sopenharmony_ci * @since 12 23121cb0ef41Sopenharmony_ci */ 23131cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_WaitForDebugger(JSVM_Env env, 23141cb0ef41Sopenharmony_ci bool breakNextLine); 23151cb0ef41Sopenharmony_ci 23161cb0ef41Sopenharmony_ci/** 23171cb0ef41Sopenharmony_ci * @brief When packaging C++classes, the C++constructor callback passed through the constructor 23181cb0ef41Sopenharmony_ci * triggers the corresponding callback function when getter, setter, call, and other 23191cb0ef41Sopenharmony_ci * behaviors occur on the instance object, handles the user's custom behavior, and then wraps 23201cb0ef41Sopenharmony_ci * the new C++instance in a JavaScript object and returns the wrapper object. 23211cb0ef41Sopenharmony_ci * 23221cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 23231cb0ef41Sopenharmony_ci * @param utf8name: Name of the JavaScript constructor function. For clarity, it is 23241cb0ef41Sopenharmony_ci * recommended to use the C++ class name when wrapping a C++ class. 23251cb0ef41Sopenharmony_ci * @param length: The length of the utf8name in bytes, or JSVM_AUTO_LENGTH if it 23261cb0ef41Sopenharmony_ci * is null-terminated. 23271cb0ef41Sopenharmony_ci * @param constructor: Struct include callback function that handles constructing instances of the class. 23281cb0ef41Sopenharmony_ci * When wrapping a C++ class, this method must be a static member with the JSVM_Callback.callback 23291cb0ef41Sopenharmony_ci * signature. A C++ class constructor cannot be used. 23301cb0ef41Sopenharmony_ci * Include Optional data to be passed to the constructor callback as the data 23311cb0ef41Sopenharmony_ci * property of the callback info. JSVM_Callback provides more details. 23321cb0ef41Sopenharmony_ci * @param propertyCount: Number of items in the properties array argument. 23331cb0ef41Sopenharmony_ci * @param properties: Array of property descriptors describing static and instance data 23341cb0ef41Sopenharmony_ci * properties, accessors, and methods on the class See JSVM_PropertyDescriptor. 23351cb0ef41Sopenharmony_ci * @param propertyHandlerCfg: The instance object triggers the corresponding callback function. 23361cb0ef41Sopenharmony_ci * @param callAsFunctionCallback: Calling an instance object as a function will trigger this callback. 23371cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing the constructor function for the class. 23381cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 23391cb0ef41Sopenharmony_ci * @since 12 23401cb0ef41Sopenharmony_ci */ 23411cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_DefineClassWithPropertyHandler(JSVM_Env env, 23421cb0ef41Sopenharmony_ci const char* utf8name, 23431cb0ef41Sopenharmony_ci size_t length, 23441cb0ef41Sopenharmony_ci JSVM_Callback constructor, 23451cb0ef41Sopenharmony_ci size_t propertyCount, 23461cb0ef41Sopenharmony_ci const JSVM_PropertyDescriptor* properties, 23471cb0ef41Sopenharmony_ci JSVM_PropertyHandlerCfg propertyHandlerCfg, 23481cb0ef41Sopenharmony_ci JSVM_Callback callAsFunctionCallback, 23491cb0ef41Sopenharmony_ci JSVM_Value* result); 23501cb0ef41Sopenharmony_ci 23511cb0ef41Sopenharmony_ci/** 23521cb0ef41Sopenharmony_ci * @brief Determines whether the current thread holds the lock for the specified environment. 23531cb0ef41Sopenharmony_ci * Only threads that hold locks can use the environment. 23541cb0ef41Sopenharmony_ci * 23551cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 23561cb0ef41Sopenharmony_ci * @param isLocked: Flag indicating whether the current thread holds the lock for the specified environment. 23571cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 23581cb0ef41Sopenharmony_ci * @since 12 23591cb0ef41Sopenharmony_ci */ 23601cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsLocked(JSVM_Env env, 23611cb0ef41Sopenharmony_ci bool* isLocked); 23621cb0ef41Sopenharmony_ci 23631cb0ef41Sopenharmony_ci/** 23641cb0ef41Sopenharmony_ci * @brief Acquire the lock for the specified environment. Only threads that hold locks can use the environment. 23651cb0ef41Sopenharmony_ci * 23661cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 23671cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 23681cb0ef41Sopenharmony_ci * @since 12 23691cb0ef41Sopenharmony_ci */ 23701cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_AcquireLock(JSVM_Env env); 23711cb0ef41Sopenharmony_ci 23721cb0ef41Sopenharmony_ci/** 23731cb0ef41Sopenharmony_ci * @brief Release the lock for the specified environment. Only threads that hold locks can use the environment. 23741cb0ef41Sopenharmony_ci * 23751cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 23761cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 23771cb0ef41Sopenharmony_ci * @since 12 23781cb0ef41Sopenharmony_ci */ 23791cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ReleaseLock(JSVM_Env env); 23801cb0ef41Sopenharmony_ci 23811cb0ef41Sopenharmony_ci/** 23821cb0ef41Sopenharmony_ci * @brief Starts the running of the task queue inside the VM. 23831cb0ef41Sopenharmony_ci * This task queue can be executed by an external event loop. 23841cb0ef41Sopenharmony_ci * 23851cb0ef41Sopenharmony_ci * @param env: The VM instance on which to start the task queue. 23861cb0ef41Sopenharmony_ci * @param result: Whether the task queue was successfully started. 23871cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 23881cb0ef41Sopenharmony_ci * @since 12 23891cb0ef41Sopenharmony_ci */ 23901cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_PumpMessageLoop(JSVM_VM vm, 23911cb0ef41Sopenharmony_ci bool* result); 23921cb0ef41Sopenharmony_ci 23931cb0ef41Sopenharmony_ci/** 23941cb0ef41Sopenharmony_ci * @brief Check to see if there are any microtasks waiting in the queue, and if there are, execute them. 23951cb0ef41Sopenharmony_ci * 23961cb0ef41Sopenharmony_ci * @param env: The VM instance on which to check microtasks. 23971cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 23981cb0ef41Sopenharmony_ci * @since 12 23991cb0ef41Sopenharmony_ci */ 24001cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_PerformMicrotaskCheckpoint(JSVM_VM vm); 24011cb0ef41Sopenharmony_ci 24021cb0ef41Sopenharmony_ci/** 24031cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is callable. 24041cb0ef41Sopenharmony_ci * 24051cb0ef41Sopenharmony_ci * @param env: The VM instance on which to check microtasks. 24061cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 24071cb0ef41Sopenharmony_ci * @param isCallable: Whether the given value is callable. 24081cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 24091cb0ef41Sopenharmony_ci * @since 12 24101cb0ef41Sopenharmony_ci */ 24111cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsCallable(JSVM_Env env, 24121cb0ef41Sopenharmony_ci JSVM_Value value, 24131cb0ef41Sopenharmony_ci bool* isCallable); 24141cb0ef41Sopenharmony_ci 24151cb0ef41Sopenharmony_ci/** 24161cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is undefined. 24171cb0ef41Sopenharmony_ci * This equals to `value === undefined` in JS. 24181cb0ef41Sopenharmony_ci * 24191cb0ef41Sopenharmony_ci * @param env: The VM instance on which to check microtasks. 24201cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 24211cb0ef41Sopenharmony_ci * @param isUndefined: Whether the given value is Undefined. 24221cb0ef41Sopenharmony_ci * @return Only returns JSVM_OK, because this API will not trigger any exception. 24231cb0ef41Sopenharmony_ci * @since 12 24241cb0ef41Sopenharmony_ci */ 24251cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsUndefined(JSVM_Env env, 24261cb0ef41Sopenharmony_ci JSVM_Value value, 24271cb0ef41Sopenharmony_ci bool* isUndefined); 24281cb0ef41Sopenharmony_ci 24291cb0ef41Sopenharmony_ci/** 24301cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is a null object. 24311cb0ef41Sopenharmony_ci * This equals to `value === null` in JS. 24321cb0ef41Sopenharmony_ci * 24331cb0ef41Sopenharmony_ci * @param env: The VM instance on which to check microtasks. 24341cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 24351cb0ef41Sopenharmony_ci * @param isNull: Whether the given value is Null. 24361cb0ef41Sopenharmony_ci * @return Only returns JSVM_OK, because this API will not trigger any exception. 24371cb0ef41Sopenharmony_ci * @since 12 24381cb0ef41Sopenharmony_ci */ 24391cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsNull(JSVM_Env env, 24401cb0ef41Sopenharmony_ci JSVM_Value value, 24411cb0ef41Sopenharmony_ci bool* isNull); 24421cb0ef41Sopenharmony_ci 24431cb0ef41Sopenharmony_ci/** 24441cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is either a null or an undefined object. 24451cb0ef41Sopenharmony_ci * This is equivalent to `value == null` in JS. 24461cb0ef41Sopenharmony_ci * 24471cb0ef41Sopenharmony_ci * @param env: The VM instance on which to check microtasks. 24481cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 24491cb0ef41Sopenharmony_ci * @param isNullOrUndefined: Whether the given value is Null or Undefined. 24501cb0ef41Sopenharmony_ci * @return Only returns JSVM_OK, because this API will not trigger any exception. 24511cb0ef41Sopenharmony_ci * @since 12 24521cb0ef41Sopenharmony_ci */ 24531cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsNullOrUndefined(JSVM_Env env, 24541cb0ef41Sopenharmony_ci JSVM_Value value, 24551cb0ef41Sopenharmony_ci bool* isNullOrUndefined); 24561cb0ef41Sopenharmony_ci 24571cb0ef41Sopenharmony_ci/** 24581cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is a boolean. 24591cb0ef41Sopenharmony_ci * This equals to `typeof value === 'boolean'` in JS. 24601cb0ef41Sopenharmony_ci * 24611cb0ef41Sopenharmony_ci * @param env: The VM instance on which to check microtasks. 24621cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 24631cb0ef41Sopenharmony_ci * @param isBoolean: Whether the given value is Boolean. 24641cb0ef41Sopenharmony_ci * @return Only returns JSVM_OK, because this API will not trigger any exception. 24651cb0ef41Sopenharmony_ci * @since 12 24661cb0ef41Sopenharmony_ci */ 24671cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsBoolean(JSVM_Env env, 24681cb0ef41Sopenharmony_ci JSVM_Value value, 24691cb0ef41Sopenharmony_ci bool* isBoolean); 24701cb0ef41Sopenharmony_ci 24711cb0ef41Sopenharmony_ci/** 24721cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is a number. 24731cb0ef41Sopenharmony_ci * This equals to `typeof value === 'number'` in JS. 24741cb0ef41Sopenharmony_ci * 24751cb0ef41Sopenharmony_ci * @param env: The VM instance on which to check microtasks. 24761cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 24771cb0ef41Sopenharmony_ci * @param isNumber: Whether the given value is Number. 24781cb0ef41Sopenharmony_ci * @return Only returns JSVM_OK, because this API will not trigger any exception. 24791cb0ef41Sopenharmony_ci * @since 12 24801cb0ef41Sopenharmony_ci */ 24811cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsNumber(JSVM_Env env, 24821cb0ef41Sopenharmony_ci JSVM_Value value, 24831cb0ef41Sopenharmony_ci bool* isNumber); 24841cb0ef41Sopenharmony_ci 24851cb0ef41Sopenharmony_ci/** 24861cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is a string. 24871cb0ef41Sopenharmony_ci * This equals to `typeof value === 'string'` in JS. 24881cb0ef41Sopenharmony_ci * 24891cb0ef41Sopenharmony_ci * @param env: The VM instance on which to check microtasks. 24901cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 24911cb0ef41Sopenharmony_ci * @param isString: Whether the given value is String. 24921cb0ef41Sopenharmony_ci * @return Only returns JSVM_OK, because this API will not trigger any exception. 24931cb0ef41Sopenharmony_ci * @since 12 24941cb0ef41Sopenharmony_ci */ 24951cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsString(JSVM_Env env, 24961cb0ef41Sopenharmony_ci JSVM_Value value, 24971cb0ef41Sopenharmony_ci bool* isString); 24981cb0ef41Sopenharmony_ci 24991cb0ef41Sopenharmony_ci/** 25001cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is a symbol. 25011cb0ef41Sopenharmony_ci * This equals to `typeof value === 'symbol'` in JS. 25021cb0ef41Sopenharmony_ci * 25031cb0ef41Sopenharmony_ci * @param env: The VM instance on which to check microtasks. 25041cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 25051cb0ef41Sopenharmony_ci * @param isSymbol: Whether the given value is Symbol. 25061cb0ef41Sopenharmony_ci * @return Only returns JSVM_OK, because this API will not trigger any exception. 25071cb0ef41Sopenharmony_ci * @since 12 25081cb0ef41Sopenharmony_ci */ 25091cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsSymbol(JSVM_Env env, 25101cb0ef41Sopenharmony_ci JSVM_Value value, 25111cb0ef41Sopenharmony_ci bool* isSymbol); 25121cb0ef41Sopenharmony_ci 25131cb0ef41Sopenharmony_ci/** 25141cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is a function. 25151cb0ef41Sopenharmony_ci * This equals to `typeof value === 'function'` in JS. 25161cb0ef41Sopenharmony_ci * 25171cb0ef41Sopenharmony_ci * @param env: The VM instance on which to check microtasks. 25181cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 25191cb0ef41Sopenharmony_ci * @param isFunction: Whether the given value is Function. 25201cb0ef41Sopenharmony_ci * @return Only returns JSVM_OK, because this API will not trigger any exception. 25211cb0ef41Sopenharmony_ci * @since 12 25221cb0ef41Sopenharmony_ci */ 25231cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsFunction(JSVM_Env env, 25241cb0ef41Sopenharmony_ci JSVM_Value value, 25251cb0ef41Sopenharmony_ci bool* isFunction); 25261cb0ef41Sopenharmony_ci 25271cb0ef41Sopenharmony_ci/** 25281cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is an object. 25291cb0ef41Sopenharmony_ci * 25301cb0ef41Sopenharmony_ci * @param env: The VM instance on which to check microtasks. 25311cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 25321cb0ef41Sopenharmony_ci * @param isObject: Whether the given value is Object. 25331cb0ef41Sopenharmony_ci * @return Only returns JSVM_OK, because this API will not trigger any exception. 25341cb0ef41Sopenharmony_ci * @since 12 25351cb0ef41Sopenharmony_ci */ 25361cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsObject(JSVM_Env env, 25371cb0ef41Sopenharmony_ci JSVM_Value value, 25381cb0ef41Sopenharmony_ci bool* isObject); 25391cb0ef41Sopenharmony_ci 25401cb0ef41Sopenharmony_ci/** 25411cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is a bigInt. 25421cb0ef41Sopenharmony_ci * This equals to `typeof value === 'bigint'` in JS. 25431cb0ef41Sopenharmony_ci * 25441cb0ef41Sopenharmony_ci * @param env: The VM instance on which to check microtasks. 25451cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 25461cb0ef41Sopenharmony_ci * @param isBigInt: Whether the given value is BigInt. 25471cb0ef41Sopenharmony_ci * @return Only returns JSVM_OK, because this API will not trigger any exception. 25481cb0ef41Sopenharmony_ci * @since 12 25491cb0ef41Sopenharmony_ci */ 25501cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsBigInt(JSVM_Env env, 25511cb0ef41Sopenharmony_ci JSVM_Value value, 25521cb0ef41Sopenharmony_ci bool* isBigInt); 25531cb0ef41Sopenharmony_ci 25541cb0ef41Sopenharmony_ci/** 25551cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is a constructor. 25561cb0ef41Sopenharmony_ci * 25571cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 25581cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 25591cb0ef41Sopenharmony_ci * @param isConstructor: Whether the given value is Constructor. 25601cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. Returns JSVM_INVALID_ARG if the API failed. 25611cb0ef41Sopenharmony_ci * @since 12 25621cb0ef41Sopenharmony_ci */ 25631cb0ef41Sopenharmony_ciJSVM_Status JSVM_CDECL OH_JSVM_IsConstructor(JSVM_Env env, 25641cb0ef41Sopenharmony_ci JSVM_Value value, 25651cb0ef41Sopenharmony_ci bool* isConstructor); 25661cb0ef41Sopenharmony_ci 25671cb0ef41Sopenharmony_ci/** 25681cb0ef41Sopenharmony_ci * @brief This API returns the JavaScript value of the regular expression 25691cb0ef41Sopenharmony_ci * corresponding to the input. 25701cb0ef41Sopenharmony_ci * The interface may throw an exception. 25711cb0ef41Sopenharmony_ci * 25721cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 25731cb0ef41Sopenharmony_ci * @param value: The JavaScript string to convert to a regular expression. 25741cb0ef41Sopenharmony_ci * @param flags: Regular expression flag bits. 25751cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript RegExp. 25761cb0ef41Sopenharmony_ci * @return Only returns JSVM function's result code. 25771cb0ef41Sopenharmony_ci * {@link JSVM_OK } If the API succeeded.\n 25781cb0ef41Sopenharmony_ci * {@link JSVM_INVALID_ARG } If the input parameter is invalid.\n 25791cb0ef41Sopenharmony_ci * {@link JSVM_STRING_EXPECTED } If the value of 'value' is not a string.\n 25801cb0ef41Sopenharmony_ci * {@link JSVM_GENERIC_FAILURE } If create RegExp failed.\n 25811cb0ef41Sopenharmony_ci * {@link JSVM_PENDING_EXCEPTION } If the API throws an exception during runtime.\n 25821cb0ef41Sopenharmony_ci * @since 12 25831cb0ef41Sopenharmony_ci */ 25841cb0ef41Sopenharmony_ciJSVM_Status JSVM_CDECL OH_JSVM_CreateRegExp(JSVM_Env env, 25851cb0ef41Sopenharmony_ci JSVM_Value value, 25861cb0ef41Sopenharmony_ci JSVM_RegExpFlags flags, 25871cb0ef41Sopenharmony_ci JSVM_Value* result); 25881cb0ef41Sopenharmony_ci 25891cb0ef41Sopenharmony_ci/** 25901cb0ef41Sopenharmony_ci * @brief This API returns a JSVM-API value corresponding to a JavaScript Map type. 25911cb0ef41Sopenharmony_ci * 25921cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 25931cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript Map. 25941cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. Returns JSVM_INVALID_ARG if the API failed. 25951cb0ef41Sopenharmony_ci * @since 12 25961cb0ef41Sopenharmony_ci */ 25971cb0ef41Sopenharmony_ciJSVM_Status JSVM_CDECL OH_JSVM_CreateMap(JSVM_Env env, JSVM_Value* result); 25981cb0ef41Sopenharmony_ci 25991cb0ef41Sopenharmony_ci/** 26001cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is a Map. 26011cb0ef41Sopenharmony_ci * 26021cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 26031cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 26041cb0ef41Sopenharmony_ci * @param isMap: Whether the given value is Map. 26051cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. Returns JSVM_INVALID_ARG if the API failed. 26061cb0ef41Sopenharmony_ci * @since 12 26071cb0ef41Sopenharmony_ci */ 26081cb0ef41Sopenharmony_ciJSVM_Status JSVM_CDECL OH_JSVM_IsMap(JSVM_Env env, 26091cb0ef41Sopenharmony_ci JSVM_Value value, 26101cb0ef41Sopenharmony_ci bool* isMap); 26111cb0ef41Sopenharmony_ci 26121cb0ef41Sopenharmony_ci/** 26131cb0ef41Sopenharmony_ci * @brief This API returns a JSVM-API value corresponding to a JavaScript Set type. 26141cb0ef41Sopenharmony_ci * 26151cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 26161cb0ef41Sopenharmony_ci * @param result: A JSVM_Value representing a JavaScript Set. 26171cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 26181cb0ef41Sopenharmony_ci * @since 12 26191cb0ef41Sopenharmony_ci */ 26201cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateSet(JSVM_Env env, 26211cb0ef41Sopenharmony_ci JSVM_Value* result); 26221cb0ef41Sopenharmony_ci 26231cb0ef41Sopenharmony_ci/** 26241cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is a Set. 26251cb0ef41Sopenharmony_ci * 26261cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 26271cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 26281cb0ef41Sopenharmony_ci * @param isSet: Whether the given value is Set. 26291cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 26301cb0ef41Sopenharmony_ci * @since 12 26311cb0ef41Sopenharmony_ci */ 26321cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsSet(JSVM_Env env, 26331cb0ef41Sopenharmony_ci JSVM_Value value, 26341cb0ef41Sopenharmony_ci bool* isSet); 26351cb0ef41Sopenharmony_ci 26361cb0ef41Sopenharmony_ci/** 26371cb0ef41Sopenharmony_ci * @brief This API returns the Object prototype. 26381cb0ef41Sopenharmony_ci * 26391cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 26401cb0ef41Sopenharmony_ci * @param object: JSVM_Value representing JavaScript Object whose prototype to return. 26411cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing prototype of the given object. 26421cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 26431cb0ef41Sopenharmony_ci * @since 12 26441cb0ef41Sopenharmony_ci */ 26451cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ObjectGetPrototypeOf(JSVM_Env env, 26461cb0ef41Sopenharmony_ci JSVM_Value object, 26471cb0ef41Sopenharmony_ci JSVM_Value* result); 26481cb0ef41Sopenharmony_ci 26491cb0ef41Sopenharmony_ci/** 26501cb0ef41Sopenharmony_ci * @brief This API set the prototype on the Object passed in. 26511cb0ef41Sopenharmony_ci * 26521cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 26531cb0ef41Sopenharmony_ci * @param object: The object on which to set the prototype. 26541cb0ef41Sopenharmony_ci * @param prototype: The prototype value. 26551cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 26561cb0ef41Sopenharmony_ci * @since 12 26571cb0ef41Sopenharmony_ci */ 26581cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ObjectSetPrototypeOf(JSVM_Env env, 26591cb0ef41Sopenharmony_ci JSVM_Value object, 26601cb0ef41Sopenharmony_ci JSVM_Value prototype); 26611cb0ef41Sopenharmony_ci 26621cb0ef41Sopenharmony_ci/** 26631cb0ef41Sopenharmony_ci * @brief This API implements the abstract operation `ToBigInt()`. 26641cb0ef41Sopenharmony_ci * 26651cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 26661cb0ef41Sopenharmony_ci * @param value: The JavaScript value to coerce. 26671cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the coerced JavaScript BigInt. 26681cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. Returns JSVM_BIGINT_EXPECTED if the 26691cb0ef41Sopenharmony_ci * JavaScript value fails to coerce. 26701cb0ef41Sopenharmony_ci * @since 12 26711cb0ef41Sopenharmony_ci */ 26721cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CoerceToBigInt(JSVM_Env env, 26731cb0ef41Sopenharmony_ci JSVM_Value value, 26741cb0ef41Sopenharmony_ci JSVM_Value* result); 26751cb0ef41Sopenharmony_ci 26761cb0ef41Sopenharmony_ci/** 26771cb0ef41Sopenharmony_ci * @brief This API checks if the value passed in is a JavaScript RegExp object. 26781cb0ef41Sopenharmony_ci * 26791cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 26801cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 26811cb0ef41Sopenharmony_ci * @param result: Whether the given value is RegExp. 26821cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. 26831cb0ef41Sopenharmony_ci * @since 12 26841cb0ef41Sopenharmony_ci */ 26851cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsRegExp(JSVM_Env env, 26861cb0ef41Sopenharmony_ci JSVM_Value value, 26871cb0ef41Sopenharmony_ci bool* result); 26881cb0ef41Sopenharmony_ci 26891cb0ef41Sopenharmony_ci/** 26901cb0ef41Sopenharmony_ci * @brief Creates a function with a given script as its body. 26911cb0ef41Sopenharmony_ci * 26921cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 26931cb0ef41Sopenharmony_ci * @param funcName: A string containing the function's name. Pass NULL to create an anonymous function. 26941cb0ef41Sopenharmony_ci * @param length: The length of the funcName in bytes, or JSVM_AUTO_LENGTH if it 26951cb0ef41Sopenharmony_ci * is null-terminated. 26961cb0ef41Sopenharmony_ci * @param argc: The count of elements in the argv array. 26971cb0ef41Sopenharmony_ci * @param argv: Array of JSVM_Values representing JavaScript strings passed in as arguments to the function. 26981cb0ef41Sopenharmony_ci * @param script: A JavaScript string containing the script to use as the function's body. 26991cb0ef41Sopenharmony_ci * @param result: JSVM_Value representing the JavaScript function object for the newly 27001cb0ef41Sopenharmony_ci * created function. 27011cb0ef41Sopenharmony_ci * @return Returns JSVM_OK if the API succeeded. Returns JSVM_GENERIC_FAILURE if the input script fails to 27021cb0ef41Sopenharmony_ci * be compiled. 27031cb0ef41Sopenharmony_ci * @since 12 27041cb0ef41Sopenharmony_ci */ 27051cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateFunctionWithScript(JSVM_Env env, 27061cb0ef41Sopenharmony_ci const char* funcName, 27071cb0ef41Sopenharmony_ci size_t length, 27081cb0ef41Sopenharmony_ci size_t argc, 27091cb0ef41Sopenharmony_ci const JSVM_Value* argv, 27101cb0ef41Sopenharmony_ci JSVM_Value script, 27111cb0ef41Sopenharmony_ci JSVM_Value* result); 27121cb0ef41Sopenharmony_ci 27131cb0ef41Sopenharmony_ci/** 27141cb0ef41Sopenharmony_ci * @brief This function keep persistently save a JSVM_Script and extend its lifecycle 27151cb0ef41Sopenharmony_ci * beyond the current scope. 27161cb0ef41Sopenharmony_ci * 27171cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 27181cb0ef41Sopenharmony_ci * @param script: A JavaScript string containing the script to be retained. 27191cb0ef41Sopenharmony_ci * @return Returns JSVM functions result code 27201cb0ef41Sopenharmony_ci * {@link JSVM_OK } if the API succeeded. \n 27211cb0ef41Sopenharmony_ci * {@link JSVM_INVALID_ARG } if the script is empty or already retained. \n 27221cb0ef41Sopenharmony_ci * @since 12 27231cb0ef41Sopenharmony_ci */ 27241cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_RetainScript(JSVM_Env env, JSVM_Script script); 27251cb0ef41Sopenharmony_ci 27261cb0ef41Sopenharmony_ci/** 27271cb0ef41Sopenharmony_ci * @brief This function release the script retained by OH_JSVM_RetainScript 27281cb0ef41Sopenharmony_ci * 27291cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 27301cb0ef41Sopenharmony_ci * @param script: A JavaScript string containing the script to be retained. 27311cb0ef41Sopenharmony_ci * @return Returns JSVM functions result code 27321cb0ef41Sopenharmony_ci * {@link JSVM_OK } if the API succeeded. \n 27331cb0ef41Sopenharmony_ci * {@link JSVM_INVALID_ARG } if the script is empty or not retained. \n 27341cb0ef41Sopenharmony_ci * @since 12 27351cb0ef41Sopenharmony_ci */ 27361cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ReleaseScript(JSVM_Env env, JSVM_Script script); 27371cb0ef41Sopenharmony_ci 27381cb0ef41Sopenharmony_ci/** 27391cb0ef41Sopenharmony_ci * @brief This function activates insepctor with pid and alias it. 27401cb0ef41Sopenharmony_ci * 27411cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 27421cb0ef41Sopenharmony_ci * @param pid: A process id to identify the inspector connection. 27431cb0ef41Sopenharmony_ci * @param name: An alias for the inspector that under a specific pid. 27441cb0ef41Sopenharmony_ci * default name is jsvm if a nullptr is passed in. 27451cb0ef41Sopenharmony_ci * @return Returns JSVM funtions result code. 27461cb0ef41Sopenharmony_ci * Returns {@link JSVM_OK } if the function executed successfully.\n 27471cb0ef41Sopenharmony_ci * Returns {@link JSVM_PENDING_EXCEPTION } if an exception occurs.\n 27481cb0ef41Sopenharmony_ci * @since 12 27491cb0ef41Sopenharmony_ci */ 27501cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_OpenInspectorWithName(JSVM_Env env, 27511cb0ef41Sopenharmony_ci int pid, 27521cb0ef41Sopenharmony_ci const char* name); 27531cb0ef41Sopenharmony_ci 27541cb0ef41Sopenharmony_ci/** 27551cb0ef41Sopenharmony_ci * @brief Compile WebAssembly bytecode into a WebAssembly module. 27561cb0ef41Sopenharmony_ci * If WebAssembly cache provided, deserialization will be performed. 27571cb0ef41Sopenharmony_ci * 27581cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 27591cb0ef41Sopenharmony_ci * @param wasmBytecode: WebAssembly bytecode. 27601cb0ef41Sopenharmony_ci * @param wasmBytecodeLength: WebAssembly bytecode length in byte. 27611cb0ef41Sopenharmony_ci * @param cacheData: Optional WebAssembly cache. 27621cb0ef41Sopenharmony_ci * @param cacheDataLength: Optional WebAssembly cache length in byte. 27631cb0ef41Sopenharmony_ci * @param cacheRejected: Output parameter representing whether the provided cacheData is rejected. 27641cb0ef41Sopenharmony_ci * @param wasmModule: Output parameter representing compiled WebAssembly module. 27651cb0ef41Sopenharmony_ci * @return Returns JSVM funtions result code. 27661cb0ef41Sopenharmony_ci * Returns {@link JSVM_OK } if the function executed successfully.\n 27671cb0ef41Sopenharmony_ci * Returns {@link JSVM_INVALID_ARG } if any of env, wasmBytecode is NULL, or data length is invalid.\n 27681cb0ef41Sopenharmony_ci * Returns {@link JSVM_GENERIC_FAILURE } if compile failed.\n 27691cb0ef41Sopenharmony_ci * Returns {@link JSVM_PENDING_EXCEPTION } if an exception occurs.\n 27701cb0ef41Sopenharmony_ci * 27711cb0ef41Sopenharmony_ci * @since 12 27721cb0ef41Sopenharmony_ci */ 27731cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CompileWasmModule(JSVM_Env env, 27741cb0ef41Sopenharmony_ci const uint8_t *wasmBytecode, 27751cb0ef41Sopenharmony_ci size_t wasmBytecodeLength, 27761cb0ef41Sopenharmony_ci const uint8_t *cacheData, 27771cb0ef41Sopenharmony_ci size_t cacheDataLength, 27781cb0ef41Sopenharmony_ci bool *cacheRejected, 27791cb0ef41Sopenharmony_ci JSVM_Value *wasmModule); 27801cb0ef41Sopenharmony_ci 27811cb0ef41Sopenharmony_ci/** 27821cb0ef41Sopenharmony_ci * @brief Compile the function with the specified index in the WebAssembly module 27831cb0ef41Sopenharmony_ci * into the specified optimization level. 27841cb0ef41Sopenharmony_ci * 27851cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 27861cb0ef41Sopenharmony_ci * @param wasmModule: The WebAssembly module to which the function to compiled belongs. 27871cb0ef41Sopenharmony_ci * @param functionIndex: The index of the function to be compiled, should never be out of range. 27881cb0ef41Sopenharmony_ci * @param optLevel: Optimization level the function will be compiled with. 27891cb0ef41Sopenharmony_ci * @return Returns JSVM funtions result code. 27901cb0ef41Sopenharmony_ci * Returns {@link JSVM_OK } if the function executed successfully.\n 27911cb0ef41Sopenharmony_ci * Returns {@link JSVM_INVALID_ARG } if env is NULL, or wasmModule is NULL or is not a WebAssembly module.\n 27921cb0ef41Sopenharmony_ci * Returns {@link JSVM_GENERIC_FAILURE } if functionIndex out of range or compile failed.\n 27931cb0ef41Sopenharmony_ci * Returns {@link JSVM_PENDING_EXCEPTION } if an exception occurs.\n 27941cb0ef41Sopenharmony_ci * 27951cb0ef41Sopenharmony_ci * @since 12 27961cb0ef41Sopenharmony_ci */ 27971cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CompileWasmFunction(JSVM_Env env, 27981cb0ef41Sopenharmony_ci JSVM_Value wasmModule, 27991cb0ef41Sopenharmony_ci uint32_t functionIndex, 28001cb0ef41Sopenharmony_ci JSVM_WasmOptLevel optLevel); 28011cb0ef41Sopenharmony_ci 28021cb0ef41Sopenharmony_ci/** 28031cb0ef41Sopenharmony_ci * @brief Check whether the given JSVM_Value is a WebAssembly module. 28041cb0ef41Sopenharmony_ci * 28051cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 28061cb0ef41Sopenharmony_ci * @param value: The JavaScript value to check. 28071cb0ef41Sopenharmony_ci * @param result: Whether the given value is a WebAssembly module. 28081cb0ef41Sopenharmony_ci * @return Returns JSVM funtions result code. 28091cb0ef41Sopenharmony_ci * Returns {@link JSVM_OK } if the function executed successfully.\n 28101cb0ef41Sopenharmony_ci * Returns {@link JSVM_INVALID_ARG } if any of the input arguments is NULL.\n 28111cb0ef41Sopenharmony_ci * 28121cb0ef41Sopenharmony_ci * @since 12 28131cb0ef41Sopenharmony_ci */ 28141cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_IsWasmModuleObject(JSVM_Env env, 28151cb0ef41Sopenharmony_ci JSVM_Value value, 28161cb0ef41Sopenharmony_ci bool* result); 28171cb0ef41Sopenharmony_ci 28181cb0ef41Sopenharmony_ci/** 28191cb0ef41Sopenharmony_ci * @brief Create cache for compiled WebAssembly module. 28201cb0ef41Sopenharmony_ci * 28211cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 28221cb0ef41Sopenharmony_ci * @param wasmModule: The compiled WebAssembly module. 28231cb0ef41Sopenharmony_ci * @param data: Output parameter representing generated WebAssembly module cache. 28241cb0ef41Sopenharmony_ci * @param length: Output parameter representing byte length of generated WebAssembly module cache. 28251cb0ef41Sopenharmony_ci * @return Returns JSVM funtions result code. 28261cb0ef41Sopenharmony_ci * Returns {@link JSVM_OK } if the function executed successfully.\n 28271cb0ef41Sopenharmony_ci * Returns {@link JSVM_INVALID_ARG } if any of the input arguments is NULL.\n 28281cb0ef41Sopenharmony_ci * Returns {@link JSVM_GENERIC_FAILURE } if create wasm cache failed.\n 28291cb0ef41Sopenharmony_ci * 28301cb0ef41Sopenharmony_ci * @since 12 28311cb0ef41Sopenharmony_ci */ 28321cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_CreateWasmCache(JSVM_Env env, 28331cb0ef41Sopenharmony_ci JSVM_Value wasmModule, 28341cb0ef41Sopenharmony_ci const uint8_t** data, 28351cb0ef41Sopenharmony_ci size_t* length); 28361cb0ef41Sopenharmony_ci 28371cb0ef41Sopenharmony_ci/** 28381cb0ef41Sopenharmony_ci * @brief Release cache data with specified cache type. 28391cb0ef41Sopenharmony_ci * 28401cb0ef41Sopenharmony_ci * @param env: The environment that the API is invoked under. 28411cb0ef41Sopenharmony_ci * @param cacheData: The cache data to be released, double free is undefined behaviors. 28421cb0ef41Sopenharmony_ci * @param cacheType: The type of cache data. 28431cb0ef41Sopenharmony_ci * @return Returns JSVM funtions result code. 28441cb0ef41Sopenharmony_ci * Returns {@link JSVM_OK } if the function executed successfully.\n 28451cb0ef41Sopenharmony_ci * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL or cacheType is illegal.\n 28461cb0ef41Sopenharmony_ci * 28471cb0ef41Sopenharmony_ci * @since 12 28481cb0ef41Sopenharmony_ci */ 28491cb0ef41Sopenharmony_ciJSVM_EXTERN JSVM_Status OH_JSVM_ReleaseCache(JSVM_Env env, 28501cb0ef41Sopenharmony_ci const uint8_t* cacheData, 28511cb0ef41Sopenharmony_ci JSVM_CacheType cacheType); 28521cb0ef41Sopenharmony_ci 28531cb0ef41Sopenharmony_ciEXTERN_C_END 28541cb0ef41Sopenharmony_ci 28551cb0ef41Sopenharmony_ci/** @} */ 28561cb0ef41Sopenharmony_ci#endif /* ARK_RUNTIME_JSVM_JSVM_H */ 28571cb0ef41Sopenharmony_ci 2858