1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ARK_RUNTIME_JSVM_JSVM_H 17 #define ARK_RUNTIME_JSVM_JSVM_H 18 19 /** 20 * @addtogroup JSVM 21 * @{ 22 * 23 * @brief Provides the standard JavaScript engine capabilities. 24 * 25 * Provides API to Provide independent, standard, and complete JavaScript engine capabilities for developers, 26 * including managing the engine lifecycle, compiling and running JS code, implementing JS/C++ cross language calls, 27 * and taking snapshots. 28 * 29 * @since 11 30 */ 31 32 /** 33 * @file jsvm.h 34 * 35 * @brief Provides the JSVM API define. 36 * 37 * Provides API to Provide independent, standard, and complete JavaScript engine capabilities for developers, 38 * including managing the engine lifecycle, compiling and running JS code, implementing JS/C++ cross language calls, 39 * and taking snapshots. 40 * @library libjsvm.so 41 * @syscap SystemCapability.ArkCompiler.JSVM 42 * @since 11 43 */ 44 45 // This file needs to be compatible with C compilers. 46 #include <stdbool.h> // NOLINT(modernize-deprecated-headers) 47 #include <stddef.h> // NOLINT(modernize-deprecated-headers) 48 49 // Use INT_MAX, this should only be consumed by the pre-processor anyway. 50 #define JSVM_VERSION_EXPERIMENTAL 2147483647 51 #ifndef JSVM_VERSION 52 #ifdef JSVM_EXPERIMENTAL 53 #define JSVM_VERSION JSVM_VERSION_EXPERIMENTAL 54 #else 55 // The baseline version for JSVM-API. 56 // The JSVM_VERSION controls which version will be used by default when 57 // compilling a native addon. If the addon developer specifically wants to use 58 // functions available in a new version of JSVM-API that is not yet ported in all 59 // LTS versions, they can set JSVM_VERSION knowing that they have specifically 60 // depended on that version. 61 #define JSVM_VERSION 8 62 #endif 63 #endif 64 65 #include "jsvm_types.h" 66 67 #ifndef JSVM_EXTERN 68 #ifdef _WIN32 69 /** 70 * @brief externally visible. 71 * 72 * @since 11 73 */ 74 #define JSVM_EXTERN __declspec(dllexport) 75 #elif defined(__wasm__) 76 #define JSVM_EXTERN __attribute__((visibility("default"))) __attribute__((__import_module__("jsvm"))) 77 #else 78 #define JSVM_EXTERN __attribute__((visibility("default"))) 79 #endif 80 #endif 81 82 /** 83 * @brief auto length. 84 * 85 * @since 11 86 */ 87 #define JSVM_AUTO_LENGTH SIZE_MAX 88 89 #ifdef __cplusplus 90 #define EXTERN_C_START extern "C" { 91 #define EXTERN_C_END } 92 #else 93 #define EXTERN_C_START 94 #define EXTERN_C_END 95 #endif 96 97 EXTERN_C_START 98 // clang-format off 99 100 /** 101 * @brief Check whether the given JSVM_Value is a BigInt Object. 102 * 103 * @param env The environment that the API is invoked under. 104 * @param value The JavaScript value to check. 105 * @param result Whether the given value is a BigInt Object. 106 * @return Returns JSVM funtions result code. 107 * {@link JSVM_OK } if the function executed successfully.\n 108 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 109 * 110 * @since 16 111 */ 112 JSVM_EXTERN JSVM_Status OH_JSVM_IsBigIntObject(JSVM_Env env, JSVM_Value value, bool* result); 113 114 /** 115 * @brief Check whether the given JSVM_Value is a Boolean Object. 116 * 117 * @param env The environment that the API is invoked under. 118 * @param value The JavaScript value to check. 119 * @param result Whether the given value is a Boolean Object. 120 * @return Returns JSVM funtions result code. 121 * {@link JSVM_OK } if the function executed successfully.\n 122 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 123 * 124 * @since 16 125 */ 126 JSVM_EXTERN JSVM_Status OH_JSVM_IsBooleanObject(JSVM_Env env, JSVM_Value value, bool* result); 127 128 /** 129 * @brief Check whether the given JSVM_Value is a String Object. 130 * 131 * @param env The environment that the API is invoked under. 132 * @param value The JavaScript value to check. 133 * @param result Whether the given value is a String Object. 134 * @return Returns JSVM funtions result code. 135 * {@link JSVM_OK } if the function executed successfully.\n 136 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 137 * 138 * @since 16 139 */ 140 JSVM_EXTERN JSVM_Status OH_JSVM_IsStringObject(JSVM_Env env, JSVM_Value value, bool* result); 141 142 /** 143 * @brief Check whether the given JSVM_Value is a Number Object. 144 * 145 * @param env The environment that the API is invoked under. 146 * @param value The JavaScript value to check. 147 * @param result Whether the given value is a Number Object. 148 * @return Returns JSVM funtions result code. 149 * {@link JSVM_OK } if the function executed successfully.\n 150 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 151 * 152 * @since 16 153 */ 154 JSVM_EXTERN JSVM_Status OH_JSVM_IsNumberObject(JSVM_Env env, JSVM_Value value, bool* result); 155 156 /** 157 * @brief Check whether the given JSVM_Value is a Symbol Object. 158 * 159 * @param env The environment that the API is invoked under. 160 * @param value The JavaScript value to check. 161 * @param result Whether the given value is a Symbol Object. 162 * @return Returns JSVM funtions result code. 163 * {@link JSVM_OK } if the function executed successfully.\n 164 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 165 * 166 * @since 16 167 */ 168 JSVM_EXTERN JSVM_Status OH_JSVM_IsSymbolObject(JSVM_Env env, JSVM_Value value, bool* result); 169 170 /** 171 * @brief This API returns the Symbol.asyncIterator of Well-Known Symbols. 172 * 173 * @param env The environment that the API is invoked under. 174 * @param result The Symbol.asyncIterator of Well-Known Symbols. 175 * @return Returns JSVM funtions result code. 176 * {@link JSVM_OK } if the function executed successfully.\n 177 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 178 * 179 * @since 16 180 */ 181 JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolAsyncIterator(JSVM_Env env, JSVM_Value* result); 182 183 /** 184 * @brief This API returns the Symbol.hasInstance of Well-Known Symbols. 185 * 186 * @param env The environment that the API is invoked under. 187 * @param result The Symbol.hasInstance of Well-Known Symbols. 188 * @return Returns JSVM funtions result code. 189 * {@link JSVM_OK } if the function executed successfully.\n 190 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 191 * 192 * @since 16 193 */ 194 JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolHasInstance(JSVM_Env env, JSVM_Value* result); 195 196 /** 197 * @brief This API returns the Symbol.isConcatSpreadable of Well-Known Symbols 198 * 199 * @param env The environment that the API is invoked under. 200 * @param result The Symbol.isConcatSpreadable of Well-Known Symbols. 201 * @return Returns JSVM funtions result code. 202 * {@link JSVM_OK } if the function executed successfully.\n 203 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 204 * 205 * @since 16 206 */ 207 JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolIsConcatSpreadable(JSVM_Env env, JSVM_Value* result); 208 209 /** 210 * @brief This API returns the Symbol.match of Well-Known Symbols 211 * 212 * @param env The environment that the API is invoked under. 213 * @param result The Symbol.match of Well-Known Symbols. 214 * @return Returns JSVM funtions result code. 215 * {@link JSVM_OK } if the function executed successfully.\n 216 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 217 * 218 * @since 16 219 */ 220 JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolMatch(JSVM_Env env, JSVM_Value* result); 221 222 /** 223 * @brief This API returns the Symbol.replace of Well-Known Symbols 224 * 225 * @param env The environment that the API is invoked under. 226 * @param result The Symbol.replace of Well-Known Symbols. 227 * @return Returns JSVM funtions result code. 228 * {@link JSVM_OK } if the function executed successfully.\n 229 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 230 * 231 * @since 16 232 */ 233 JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolReplace(JSVM_Env env, JSVM_Value* result); 234 235 /** 236 * @brief This API returns the Symbol.search of Well-Known Symbols 237 * 238 * @param env The environment that the API is invoked under. 239 * @param result The Symbol.search of Well-Known Symbols. 240 * @return Returns JSVM funtions result code. 241 * {@link JSVM_OK } if the function executed successfully.\n 242 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 243 * 244 * @since 16 245 */ 246 JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolSearch(JSVM_Env env, JSVM_Value* result); 247 248 /** 249 * @brief This API returns the Symbol.split of Well-Known Symbols 250 * 251 * @param env The environment that the API is invoked under. 252 * @param result The Symbol.split of Well-Known Symbols. 253 * @return Returns JSVM funtions result code. 254 * {@link JSVM_OK } if the function executed successfully.\n 255 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 256 * 257 * @since 16 258 */ 259 JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolSplit(JSVM_Env env, JSVM_Value* result); 260 261 /** 262 * @brief This API returns the Symbol.toPrimitive of Well-Known Symbols 263 * 264 * @param env The environment that the API is invoked under. 265 * @param result The Symbol.toPrimitive of Well-Known Symbols. 266 * @return Returns JSVM funtions result code. 267 * {@link JSVM_OK } if the function executed successfully.\n 268 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 269 * 270 * @since 16 271 */ 272 JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolToPrimitive(JSVM_Env env, JSVM_Value* result); 273 274 /** 275 * @brief This API returns the Symbol.unscopables of Well-Known Symbols 276 * 277 * @param env The environment that the API is invoked under. 278 * @param result The Symbol.unscopables of Well-Known Symbols. 279 * @return Returns JSVM funtions result code. 280 * {@link JSVM_OK } if the function executed successfully.\n 281 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 282 * 283 * @since 16 284 */ 285 JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolUnscopables(JSVM_Env env, JSVM_Value* result); 286 287 /** 288 * @brief This API returns the Symbol.toStringTag of Well-Known Symbols 289 * 290 * @param env The environment that the API is invoked under. 291 * @param result The Symbol.toStringTag of Well-Known Symbols. 292 * @return Returns JSVM funtions result code. 293 * {@link JSVM_OK } if the function executed successfully.\n 294 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 295 * 296 * @since 16 297 */ 298 JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolToStringTag(JSVM_Env env, JSVM_Value* result); 299 300 /** 301 * @brief This API returns the Symbol.iterator of Well-Known Symbols 302 * 303 * @param env The environment that the API is invoked under. 304 * @param result The Symbol.iterator of Well-Known Symbols. 305 * @return Returns JSVM funtions result code. 306 * {@link JSVM_OK } if the function executed successfully.\n 307 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL.\n 308 * 309 * @since 16 310 */ 311 JSVM_EXTERN JSVM_Status OH_JSVM_GetSymbolIterator(JSVM_Env env, JSVM_Value* result); 312 313 /** 314 * @brief Init a JavaScript vm. 315 * 316 * @param options: The options for initialize the JavaScript VM. 317 * @return Returns JSVM_OK if the API succeeded. 318 * @since 11 319 */ 320 JSVM_EXTERN JSVM_Status OH_JSVM_Init(const JSVM_InitOptions* options); 321 322 /** 323 * @brief This API create a new VM instance. 324 * 325 * @param options: The options for create the VM instance. 326 * @param result: The new VM instance. 327 * @return Returns JSVM_OK if the API succeeded. 328 * @since 11 329 */ 330 JSVM_EXTERN JSVM_Status OH_JSVM_CreateVM(const JSVM_CreateVMOptions* options, JSVM_VM* result); 331 332 /** 333 * @brief This function controls how Microtasks are invoked of the vm. If the method is not 334 * called, the default microtask policy of vm is JSVM_MicrotaskPolicy::JSVM_MICROTASK_AUTO. 335 * 336 * @param vm The VM instance to set mircrotasks policy. 337 * @param policy Policy for running microtasks. 338 * @return Returns JSVM_OK if the API succeeded. 339 * @since 16 340 */ 341 JSVM_EXTERN JSVM_Status OH_JSVM_SetMicrotaskPolicy(JSVM_VM vm, JSVM_MicrotaskPolicy policy); 342 343 /** 344 * @brief Destroys VM instance. 345 * 346 * @param vm: The VM instance to be Destroyed. 347 * @return Returns JSVM_OK if the API succeeded. 348 * @since 11 349 */ 350 JSVM_EXTERN JSVM_Status OH_JSVM_DestroyVM(JSVM_VM vm); 351 352 /** 353 * @brief This API allocates a default JavaScript Proxy. It is the equivalent of 354 * doing new Proxy(target, handler) in JavaScript. 355 * 356 * @param env The environment that the API is invoked under. 357 * @param target A JSVM_Value representing the JavaScript Object which you want to proxy. 358 * @param handler A JSVM_Value representing the JavaScript Object that defines which 359 * operations will be intercepted and how to redefine intercepted operations. 360 * @param result A JSVM_Value representing a JavaScript Proxy. 361 * @return Returns JSVM functions result code. 362 * {@link JSVM_OK } if the API succeeded. \n 363 * {@link JSVM_INVALID_ARG } if the any of the input arguments is NULL. \n 364 * {@link JSVM_OBJECT_EXPECTED} if target or handler is not Javascript Object. \n 365 * {@link JSVM_PENDING_EXCEPTION} if an exception occurs. \n 366 * 367 * @since 16 368 */ 369 JSVM_EXTERN JSVM_Status OH_JSVM_CreateProxy(JSVM_Env env, JSVM_Value target, JSVM_Value handler, JSVM_Value* result); 370 371 /** 372 * @brief This API checks if the value passed in is a Proxy. 373 * 374 * @param env The environment that the API is invoked under. 375 * @param value The JavaScript value to check. 376 * @param isProxy Whether the given value is Proxy. 377 * @return Returns JSVM functions result code. 378 * {@link JSVM_OK } if the API succeeded. \n 379 * {@link JSVM_INVALID_ARG } if the any of the input arguments is NULL. \n 380 * 381 * @since 16 382 */ 383 JSVM_EXTERN JSVM_Status OH_JSVM_IsProxy(JSVM_Env env, JSVM_Value value, bool* isProxy); 384 385 /** 386 * @brief This API gets target from proxy. 387 * 388 * @param env The environment that the API is invoked under. 389 * @param value JSVM_Value representing JavaScript Proxy whose target to return. 390 * @param result Target of the given proxy. 391 * @return Returns JSVM functions result code. 392 * {@link JSVM_OK } if the API succeeded. \n 393 * {@link JSVM_INVALID_ARG } if the any of the input arguments is NULL. \n 394 * {@link JSVM_INVALID_TYPE} if value is not a Javascript Proxy. \n 395 * 396 * @since 16 397 */ 398 JSVM_EXTERN JSVM_Status OH_JSVM_ProxyGetTarget(JSVM_Env env, JSVM_Value value, JSVM_Value* result); 399 400 /** 401 * @brief This API open a new VM scope for the VM instance. 402 * 403 * @param vm: The VM instance to open scope for. 404 * @param result: The new VM scope. 405 * @return Returns JSVM_OK if the API succeeded. 406 * @since 11 407 */ 408 JSVM_EXTERN JSVM_Status OH_JSVM_OpenVMScope(JSVM_VM vm, JSVM_VMScope* result); 409 410 /** 411 * @brief This function close the VM scope for the VM instance. 412 * 413 * @param vm: The VM instance to close scope for. 414 * @param scope: The VM scope to be closed. 415 * @return Returns JSVM_OK if the API succeeded. 416 * @since 11 417 */ 418 JSVM_EXTERN JSVM_Status OH_JSVM_CloseVMScope(JSVM_VM vm, JSVM_VMScope scope); 419 420 /** 421 * @brief This function create a new environment with optional properties for the context of the new environment. 422 * 423 * @param vm: The VM instance that the env will be created in. 424 * @param propertyCount: The number of elements in the properties array. 425 * @param properties: The array of property descriptor. 426 * @param result: The new environment created. 427 * @return Returns JSVM_OK if the API succeeded. 428 * @since 11 429 */ 430 JSVM_EXTERN JSVM_Status OH_JSVM_CreateEnv(JSVM_VM vm, 431 size_t propertyCount, 432 const JSVM_PropertyDescriptor* properties, 433 JSVM_Env* result); 434 435 /** 436 * @brief This function create a new environment from the start snapshot of the vm. 437 * 438 * @param vm: The VM instance that the env will be created in. 439 * @param index: The index of the environment in the snapshot. 440 * @param result: The new environment created. 441 * @return Returns JSVM_OK if the API succeeded. 442 * @since 11 443 */ 444 JSVM_EXTERN JSVM_Status OH_JSVM_CreateEnvFromSnapshot(JSVM_VM vm, size_t index, JSVM_Env* result); 445 446 /** 447 * @brief This function destroys the environment. 448 * 449 * @param env: The environment to be destroyed. 450 * @return Returns JSVM_OK if the API succeeded. 451 * @since 11 452 */ 453 JSVM_EXTERN JSVM_Status OH_JSVM_DestroyEnv(JSVM_Env env); 454 455 /** 456 * @brief This function open a new environment scope. 457 * 458 * @param env: The environment that the JSVM-API call is invoked under. 459 * @param result: The new environment scope. 460 * @return Returns JSVM_OK if the API succeeded. 461 * @since 11 462 */ 463 JSVM_EXTERN JSVM_Status OH_JSVM_OpenEnvScope(JSVM_Env env, JSVM_EnvScope* result); 464 465 /** 466 * @brief This function closes the environment scope of the environment. 467 * 468 * @param env: The environment that the JSVM-API call is invoked under. 469 * @param scope: The environment scope to be closed. 470 * @return Returns JSVM_OK if the API succeeded. 471 * @since 11 472 */ 473 JSVM_EXTERN JSVM_Status OH_JSVM_CloseEnvScope(JSVM_Env env, JSVM_EnvScope scope); 474 475 /** 476 * @brief This function retrieves the VM instance of the given environment. 477 * 478 * @param env: The environment that the JSVM-API call is invoked under. 479 * @param result: The VM instance of the environment. 480 * @return Returns JSVM_OK if the API succeeded. 481 * @since 12 482 */ 483 JSVM_EXTERN JSVM_Status OH_JSVM_GetVM(JSVM_Env env, JSVM_VM* result); 484 485 /** 486 * @brief This function compiles a string of JavaScript code and returns the compiled script. 487 * 488 * @param env: The environment that the JSVM-API call is invoked under. 489 * @param script: A JavaScript string containing the script yo be compiled. 490 * @param cachedData: Optional code cache data for the script. 491 * @param cacheDataLength: The length of cachedData array. 492 * @param eagerCompile: Whether to compile the script eagerly. 493 * @param cacheRejected: Whether the code cache rejected by compilation. 494 * @param result: The compiled script. 495 * @return Returns JSVM_OK if the API succeeded. 496 * @since 11 497 */ 498 JSVM_EXTERN JSVM_Status OH_JSVM_CompileScript(JSVM_Env env, 499 JSVM_Value script, 500 const uint8_t* cachedData, 501 size_t cacheDataLength, 502 bool eagerCompile, 503 bool* cacheRejected, 504 JSVM_Script* result); 505 506 /** 507 * @brief This function compiles a string of JavaScript code with the source code information 508 * and returns the compiled script. 509 * 510 * @param env: The environment that the JSVM-API call is invoked under. 511 * @param script: A JavaScript string containing the script to be compiled. 512 * @param cachedData: Optional code cache data for the script. 513 * @param cacheDataLength: The length of cachedData array. 514 * @param eagerCompile: Whether to compile the script eagerly. 515 * @param cacheRejected: Whether the code cache rejected by compilation. 516 * @param origin: The information of source code. 517 * @param result: The compiled script. 518 * @return Returns JSVM_OK if the API succeeded. 519 * @since 12 520 */ 521 JSVM_EXTERN JSVM_Status OH_JSVM_CompileScriptWithOrigin(JSVM_Env env, 522 JSVM_Value script, 523 const uint8_t* cachedData, 524 size_t cacheDataLength, 525 bool eagerCompile, 526 bool* cacheRejected, 527 JSVM_ScriptOrigin* origin, 528 JSVM_Script* result); 529 530 /** 531 * @brief This function compiles a string of JavaScript code with the source code information 532 * and returns the compiled script. 533 * 534 * @param env: The environment that the JSVM-API call is invoked under. 535 * @param script: A JavaScript string containing the script to be compiled. 536 * @param optionCount: length of option array. 537 * @param options: Compile options to be passed. 538 * @param result: The compiled script. 539 * @return Returns JSVM_OK if the API succeeded. 540 * @since 12 541 */ 542 JSVM_EXTERN JSVM_Status OH_JSVM_CompileScriptWithOptions(JSVM_Env env, 543 JSVM_Value script, 544 size_t optionCount, 545 JSVM_CompileOptions options[], 546 JSVM_Script* result); 547 548 /** 549 * @brief This function creates code cache for the compiled script. 550 * 551 * @param env: The environment that the JSVM-API call is invoked under. 552 * @param script: A compiled script to create code cache for. 553 * @param data: The data of the code cache. 554 * @param length: The length of the code cache data. 555 * @return Returns JSVM_OK if the API succeeded. 556 * @since 11 557 */ 558 JSVM_EXTERN JSVM_Status OH_JSVM_CreateCodeCache(JSVM_Env env, JSVM_Script script, const uint8_t** data, size_t* length); 559 560 /** 561 * @brief This function executes a string of JavaScript code and returns its result with the following caveats: 562 * Unlike eval, this function does not allow the script to access the current lexical scope, and therefore also 563 * does not allow to access the module scope, meaning that pseudo-globals such as require will not be available. 564 * The script can access the global scope. Function and var declarations in the script will be added to the 565 * global object. Variable declarations made using let and const will be visible globally, but will not be added 566 * to the global object.The value of this is global within the script. 567 * 568 * @param env: The environment that the API is invoked under. 569 * @param script: A JavaScript string containing the script to execute. 570 * @param result: The value resulting from having executed the script. 571 * @since 11 572 */ 573 JSVM_EXTERN JSVM_Status OH_JSVM_RunScript(JSVM_Env env, JSVM_Script script, JSVM_Value* result); 574 575 /** 576 * @brief This API associates data with the currently running JSVM environment. data can later be retrieved 577 * using OH_JSVM_GetInstanceData(). 578 * 579 * @param env: The environment that the JSVM-API call is invoked under. 580 * @param data: The data item to make available to bindings of this instance. 581 * @param finalizeCb: The function to call when the environment is being torn down. The function receives 582 * data so that it might free it. JSVM_Finalize provides more details. 583 * @param finalizeHint: Optional hint to pass to the finalize callback during collection. 584 * @return Returns JSVM_OK if the API succeeded. 585 * @since 11 586 */ 587 JSVM_EXTERN JSVM_Status OH_JSVM_SetInstanceData(JSVM_Env env, void* data, JSVM_Finalize finalizeCb, void* finalizeHint); 588 589 /** 590 * @brief This API retrieves data that was previously associated with the currently running JSVM environment 591 * via OH_JSVM_SetInstanceData(). If no data is set, the call will succeed and data will be set to NULL. 592 * 593 * @param env: The environment that the JSVM-API call is invoked under. 594 * @param data: The data item that was previously associated with the currently running JSVM environment by 595 * a call to OH_JSVM_SetInstanceData(). 596 * @return Returns JSVM_OK if the API succeeded. 597 * @since 11 598 */ 599 JSVM_EXTERN JSVM_Status OH_JSVM_GetInstanceData(JSVM_Env env, void** data); 600 601 /** 602 * @brief This API retrieves a JSVM_ExtendedErrorInfo structure with information about the last error that 603 * occurred. 604 * 605 * @param env: The environment that the JSVM-API call is invoked under. 606 * @param result: The JSVM_ExtendedErrorInfo structure with more information about the error. 607 * @return Returns JSVM_OK if the API succeeded. 608 * @since 11 609 */ 610 JSVM_EXTERN JSVM_Status OH_JSVM_GetLastErrorInfo(JSVM_Env env, const JSVM_ExtendedErrorInfo** result); 611 612 /** 613 * @brief This API throws the JavaScript value provided. 614 * 615 * @param env: The environment that the API is invoked under. 616 * @param error: The JavaScript value to be thrown. 617 * @return Returns JSVM_OK if the API succeeded. 618 * @since 11 619 */ 620 JSVM_EXTERN JSVM_Status OH_JSVM_Throw(JSVM_Env env, JSVM_Value error); 621 622 /** 623 * @brief This API throws a JavaScript Error with the text provided. 624 * 625 * @param env: The environment that the API is invoked under. 626 * @param code: Optional error code to be set on the error. 627 * @param msg: C string representing the text to be associated with the error. 628 * @return Returns JSVM_OK if the API succeeded. 629 * @since 11 630 */ 631 JSVM_EXTERN JSVM_Status OH_JSVM_ThrowError(JSVM_Env env, const char* code, const char* msg); 632 633 /** 634 * @brief This API throws a JavaScript TypeError with the text provided. 635 * 636 * @param env: The environment that the API is invoked under. 637 * @param code: Optional error code to be set on the error. 638 * @param msg: C string representing the text to be associated with the error. 639 * @return Returns JSVM_OK if the API succeeded. 640 * @since 11 641 */ 642 JSVM_EXTERN JSVM_Status OH_JSVM_ThrowTypeError(JSVM_Env env, const char* code, const char* msg); 643 644 /** 645 * @brief This API throws a JavaScript RangeError with the text provided. 646 * 647 * @param env: The environment that the API is invoked under. 648 * @param code: Optional error code to be set on the error. 649 * @param msg: C string representing the text to be associated with the error. 650 * @return Returns JSVM_OK if the API succeeded. 651 * @since 11 652 */ 653 JSVM_EXTERN JSVM_Status OH_JSVM_ThrowRangeError(JSVM_Env env, const char* code, const char* msg); 654 655 /** 656 * @brief This API throws a JavaScript SyntaxError with the text provided. 657 * 658 * @param env: The environment that the API is invoked under. 659 * @param code: Optional error code to be set on the error. 660 * @param msg: C string representing the text to be associated with the error. 661 * @return Returns JSVM_OK if the API succeeded. 662 * @since 11 663 */ 664 JSVM_EXTERN JSVM_Status OH_JSVM_ThrowSyntaxError(JSVM_Env env, const char* code, const char* msg); 665 666 /** 667 * @brief This API queries a JSVM_Value to check if it represents an error object. 668 * 669 * @param env: The environment that the API is invoked under. 670 * @param value: The JSVM_Value to be checked. 671 * @param result: Boolean value that is set to true if JSVM_Value represents an error, 672 * false otherwise. 673 * @return Returns JSVM_OK if the API succeeded. 674 * @since 11 675 */ 676 JSVM_EXTERN JSVM_Status OH_JSVM_IsError(JSVM_Env env, JSVM_Value value, bool* result); 677 678 /** 679 * @brief This API returns a JavaScript Error with the text provided. 680 * 681 * @param env: The environment that the API is invoked under. 682 * @param code: Optional JSVM_Value with the string for the error code to be associated with the error. 683 * @param msg: JSVM_Value that references a JavaScript string to be used as the message for the Error. 684 * @param result: JSVM_Value representing the error created. 685 * @return Returns JSVM_OK if the API succeeded. 686 * @since 11 687 */ 688 JSVM_EXTERN JSVM_Status OH_JSVM_CreateError(JSVM_Env env, JSVM_Value code, JSVM_Value msg, JSVM_Value* result); 689 690 /** 691 * @brief This API returns a JavaScript TypeError with the text provided. 692 * 693 * @param env: The environment that the API is invoked under. 694 * @param code: Optional JSVM_Value with the string for the error code to be associated with the error. 695 * @param msg: JSVM_Value that references a JavaScript string to be used as the message for the Error. 696 * @param result: JSVM_Value representing the error created. 697 * @return Returns JSVM_OK if the API succeeded. 698 * @since 11 699 */ 700 JSVM_EXTERN JSVM_Status OH_JSVM_CreateTypeError(JSVM_Env env, JSVM_Value code, JSVM_Value msg, JSVM_Value* result); 701 702 /** 703 * @brief This API returns a JavaScript RangeError with the text provided. 704 * 705 * @param env: The environment that the API is invoked under. 706 * @param code: Optional JSVM_Value with the string for the error code to be associated with the error. 707 * @param msg: JSVM_Value that references a JavaScript string to be used as the message for the Error. 708 * @param result: JSVM_Value representing the error created. 709 * @return Returns JSVM_OK if the API succeeded. 710 * @since 11 711 */ 712 JSVM_EXTERN JSVM_Status OH_JSVM_CreateRangeError(JSVM_Env env, JSVM_Value code, JSVM_Value msg, JSVM_Value* result); 713 714 /** 715 * @brief This API returns a JavaScript SyntaxError with the text provided. 716 * 717 * @param env: The environment that the API is invoked under. 718 * @param code: Optional JSVM_Value with the string for the error code to be associated with the error. 719 * @param msg: JSVM_Value that references a JavaScript string to be used as the message for the Error. 720 * @param result: JSVM_Value representing the error created. 721 * @return Returns JSVM_OK if the API succeeded. 722 * @since 11 723 */ 724 JSVM_EXTERN JSVM_Status OH_JSVM_CreateSyntaxError(JSVM_Env env, JSVM_Value code, JSVM_Value msg, JSVM_Value* result); 725 726 /** 727 * @brief This API returns a JavaScript exception if one is pending, NULL otherwise. 728 * 729 * @param env: The environment that the API is invoked under. 730 * @param result: The exception if one is pending, NULL otherwise. 731 * @return Returns JSVM_OK if the API succeeded. 732 * @since 11 733 */ 734 JSVM_EXTERN JSVM_Status OH_JSVM_GetAndClearLastException(JSVM_Env env, JSVM_Value* result); 735 736 /** 737 * @brief This API returns true if an exception is pending, false otherwise. 738 * 739 * @param env: The environment that the API is invoked under. 740 * @param result: Boolean value that is set to true if an exception is pending. 741 * @return Returns JSVM_OK if the API succeeded. 742 * @since 11 743 */ 744 JSVM_EXTERN JSVM_Status OH_JSVM_IsExceptionPending(JSVM_Env env, bool* result); 745 746 /** 747 * @brief This API opens a new scope. 748 * 749 * @param env: The environment that the API is invoked under. 750 * @param result: JSVM_Value representing the new scope. 751 * @return Returns JSVM_OK if the API succeeded. 752 * @since 11 753 */ 754 JSVM_EXTERN JSVM_Status OH_JSVM_OpenHandleScope(JSVM_Env env, JSVM_HandleScope* result); 755 756 /** 757 * @brief This API closes the scope passed in. Scopes must be closed in the reverse 758 * order from which they were created. 759 * 760 * @param env: The environment that the API is invoked under. 761 * @param scope: JSVM_Value representing the scope to be closed. 762 * @return Returns JSVM_OK if the API succeeded. 763 * @since 11 764 */ 765 JSVM_EXTERN JSVM_Status OH_JSVM_CloseHandleScope(JSVM_Env env, JSVM_HandleScope scope); 766 767 /** 768 * @brief This API opens a new scope from which one object can be promoted to the outer scope. 769 * 770 * @param env: The environment that the API is invoked under. 771 * @param result: JSVM_Value representing the new scope. 772 * @return Returns JSVM_OK if the API succeeded. 773 * @since 11 774 */ 775 JSVM_EXTERN JSVM_Status OH_JSVM_OpenEscapableHandleScope(JSVM_Env env, JSVM_EscapableHandleScope* result); 776 777 /** 778 * @brief This API closes the scope passed in. Scopes must be closed in the reverse order 779 * from which they were created. 780 * 781 * @param env: The environment that the API is invoked under. 782 * @param scope: JSVM_Value representing the scope to be closed. 783 * @return Returns JSVM_OK if the API succeeded. 784 * @since 11 785 */ 786 JSVM_EXTERN JSVM_Status OH_JSVM_CloseEscapableHandleScope(JSVM_Env env, JSVM_EscapableHandleScope scope); 787 788 /** 789 * @brief This API promotes the handle to the JavaScript object so that it is valid for the lifetime 790 * of the outer scope. It can only be called once per scope. If it is called more than once an error 791 * will be returned. 792 * 793 * @param env: The environment that the API is invoked under. 794 * @param scope: JSVM_Value representing the current scope. 795 * @param escapee: JSVM_Value representing the JavaScript Object to be escaped. 796 * @param result: JSVM_Value representing the handle to the escaped Object in the outer scope. 797 * @return Returns JSVM_OK if the API succeeded. 798 * @since 11 799 */ 800 JSVM_EXTERN JSVM_Status OH_JSVM_EscapeHandle(JSVM_Env env, 801 JSVM_EscapableHandleScope scope, 802 JSVM_Value escapee, 803 JSVM_Value* result); 804 805 /** 806 * @brief This API creates a new reference with the specified reference count to the value passed in. 807 * 808 * @param env: The environment that the API is invoked under. 809 * @param value: The JSVM_Value for which a reference is being created. 810 * @param initialRefcount: Initial reference count for the new reference. 811 * @param result: JSVM_Ref pointing to the new reference. 812 * @return Returns JSVM_OK if the API succeeded. 813 * @since 11 814 */ 815 JSVM_EXTERN JSVM_Status OH_JSVM_CreateReference(JSVM_Env env, 816 JSVM_Value value, 817 uint32_t initialRefcount, 818 JSVM_Ref* result); 819 820 /** 821 * @brief This API creates a new reference with the specified reference count to the data passed in. 822 * 823 * @param env The environment that the API is invoked under. 824 * @param value The JSVM_Data for which a reference is being created. 825 * @param initialRefcount Initial reference count for the new reference. 826 * @param result JSVM_Ref pointing to the new reference. 827 * @return Returns JSVM funtions result code. 828 * {@link JSVM_OK } if the function executed successfully.\n 829 * {@link JSVM_INVALID_ARG } if any parameter is null or the value of initialRefcount is 0.\n 830 * @since 16 831 */ 832 JSVM_EXTERN JSVM_Status OH_JSVM_CreateDataReference(JSVM_Env env, 833 JSVM_Data data, 834 uint32_t initialRefcount, 835 JSVM_Ref* result); 836 837 /** 838 * @brief his API deletes the reference passed in. 839 * 840 * @param env: The environment that the API is invoked under. 841 * @param ref: JSVM_Ref to be deleted. 842 * @return Returns JSVM_OK if the API succeeded. 843 * @since 11 844 */ 845 JSVM_EXTERN JSVM_Status OH_JSVM_DeleteReference(JSVM_Env env, JSVM_Ref ref); 846 847 /** 848 * @brief his API increments the reference count for the reference passed in and 849 * returns the resulting reference count. 850 * 851 * @param env: The environment that the API is invoked under. 852 * @param ref: JSVM_Ref for which the reference count will be incremented. 853 * @param result: The new reference count. 854 * @return Returns JSVM_OK if the API succeeded. 855 * @since 11 856 */ 857 JSVM_EXTERN JSVM_Status OH_JSVM_ReferenceRef(JSVM_Env env, JSVM_Ref ref, uint32_t* result); 858 859 /** 860 * @brief This API decrements the reference count for the reference passed in and 861 * returns the resulting reference count. 862 * 863 * @param env: The environment that the API is invoked under. 864 * @param ref: JSVM_Ref for which the reference count will be decremented. 865 * @param result: The new reference count. 866 * @return Returns JSVM_OK if the API succeeded. 867 * @since 11 868 */ 869 JSVM_EXTERN JSVM_Status OH_JSVM_ReferenceUnref(JSVM_Env env, JSVM_Ref ref, uint32_t* result); 870 871 /** 872 * @brief If still valid, this API returns the JSVM_Value representing the 873 * JavaScript value associated with the JSVM_Ref. Otherwise, result will be NULL. 874 * 875 * @param env: The environment that the API is invoked under. 876 * @param ref: The JSVM_Ref for which the corresponding value is being requested. 877 * @param result: The JSVM_Value referenced by the JSVM_Ref. 878 * @return Returns JSVM_OK if the API succeeded. 879 * @since 11 880 */ 881 JSVM_EXTERN JSVM_Status OH_JSVM_GetReferenceValue(JSVM_Env env, JSVM_Ref ref, JSVM_Value* result); 882 883 /** 884 * @brief If still valid, this API returns the JSVM_Data representing the 885 * JavaScript data associated with the JSVM_Ref. Otherwise, result will be NULL. 886 * 887 * @param env The environment that the API is invoked under. 888 * @param ref The JSVM_Ref for which the corresponding value is being requested. 889 * @param result The JSVM_Data referenced by the JSVM_Ref. 890 * @return Returns JSVM funtions result code. 891 * {@link JSVM_OK } if the function executed successfully.\n 892 * {@link JSVM_INVALID_ARG } if any parameter is null or the ref is not a reference to JSVM_Data.\n 893 * 894 * @since 16 895 */ 896 JSVM_EXTERN JSVM_Status OH_JSVM_GetReferenceData(JSVM_Env env, JSVM_Ref ref, JSVM_Data* result); 897 898 /** 899 * @brief This API returns a JSVM-API value corresponding to a JavaScript Array type. 900 * 901 * @param env: The environment that the API is invoked under. 902 * @param result: A JSVM_Value representing a JavaScript Array. 903 * @return Returns JSVM_OK if the API succeeded. 904 * @since 11 905 */ 906 JSVM_EXTERN JSVM_Status OH_JSVM_CreateArray(JSVM_Env env, JSVM_Value* result); 907 908 /** 909 * @brief This API returns a JSVM-API value corresponding to a JavaScript Array type. The Array's length property 910 * is set to the passed-in length parameter. However, the underlying buffer is not guaranteed to be pre-allocated 911 * by the VM when the array is created. That behavior is left to the underlying VM implementation. 912 * 913 * @param env: The environment that the API is invoked under. 914 * @param length: The initial length of the Array. 915 * @param result: A JSVM_Value representing a JavaScript Array. 916 * @return Returns JSVM_OK if the API succeeded. 917 * @since 11 918 */ 919 JSVM_EXTERN JSVM_Status OH_JSVM_CreateArrayWithLength(JSVM_Env env, size_t length, JSVM_Value* result); 920 921 /** 922 * @brief This API returns a JSVM-API value corresponding to a JavaScript ArrayBuffer. ArrayBuffers are used to 923 * represent fixed-length binary data buffers. They are normally used as a backing-buffer for TypedArray objects. 924 * The ArrayBuffer allocated will have an underlying byte buffer whose size is determined by the length parameter 925 * that's passed in. The underlying buffer is optionally returned back to the caller in case the caller wants to 926 * directly manipulate the buffer. This buffer can only be written to directly from native code. To write to this 927 * buffer from JavaScript, a typed array or DataView object would need to be created. 928 * 929 * @param env: The environment that the API is invoked under. 930 * @param byteLength: The length in bytes of the array buffer to create. 931 * @param data: Pointer to the underlying byte buffer of the ArrayBuffer.data can optionally be ignored by passing NULL. 932 * @param result: A JSVM_Value representing a JavaScript Array. 933 * @return Returns JSVM_OK if the API succeeded. 934 * @since 11 935 */ 936 JSVM_EXTERN JSVM_Status OH_JSVM_CreateArraybuffer(JSVM_Env env, size_t byteLength, void** data, JSVM_Value* result); 937 938 /** 939 * @brief This API allocate the memory of array buffer backing store. 940 * 941 * @param byteLength: size of backing store memory. 942 * @param initialized: initialization status of the backing store memory. 943 * @param data: pointer that recieve the backing store memory pointer. 944 * @return Returns JSVM funtions result code. 945 * Returns {@link JSVM_OK } if allocation succeed.\n 946 * Returns {@link JSVM_INVALID_ARG } if data is null pointer.\n 947 * Returns {@link JSVM_GENERIC_FAILURE } if allocation failed.\n 948 * @since 12 949 */ 950 JSVM_EXTERN JSVM_Status OH_JSVM_AllocateArrayBufferBackingStoreData(size_t byteLength, 951 JSVM_InitializedFlag initialized, 952 void** data); 953 954 /** 955 * @brief This API release the memory of an array buffer backing store. 956 * 957 * @param data: pointer to the backing store memory. 958 * @return Returns JSVM funtions result code. 959 * Returns {@link JSVM_OK } if run succeed.\n 960 * Returns {@link JSVM_INVALID_ARG } if data is null pointer.\n 961 * @since 12 962 */ 963 JSVM_EXTERN JSVM_Status OH_JSVM_FreeArrayBufferBackingStoreData(void* data); 964 965 /** 966 * @brief This API create an array buffer using the backing store data. 967 * 968 * @param env: The environment that the API is invoked under. 969 * @param data: pointer to the backing store memory. 970 * @param backingStoreSize: size of backing store memory. 971 * @param offset: start position of the array buffer in the backing store memory. 972 * @param arrayBufferSize: size of the array buffer. 973 * @param result: pointer that recieve the array buffer. 974 * @return Returns JSVM funtions result code. 975 * Returns {@link JSVM_OK } if creation succeed.\n 976 * Returns {@link JSVM_INVALID_ARG } if any of the following condition reached:\n 977 * 1. offset + arrayBufferSize > backingStoreSize\n 978 * 2. backingStoreSize or arrayBufferSize equals zero 979 * 3. data or result is null pointer 980 * @since 12 981 */ 982 JSVM_EXTERN JSVM_Status OH_JSVM_CreateArrayBufferFromBackingStoreData(JSVM_Env env, 983 void* data, 984 size_t backingStoreSize, 985 size_t offset, 986 size_t arrayBufferSize, 987 JSVM_Value* result); 988 989 /** 990 * @brief This API does not observe leap seconds; they are ignored, as ECMAScript aligns with POSIX time specification. 991 * This API allocates a JavaScript Date object. 992 * 993 * @param env: The environment that the API is invoked under. 994 * @param time: ECMAScript time value in milliseconds since 01 January, 1970 UTC. 995 * @param result: A JSVM_Value representing a JavaScript Date. 996 * @return Returns JSVM_OK if the API succeeded. 997 * @since 11 998 */ 999 JSVM_EXTERN JSVM_Status OH_JSVM_CreateDate(JSVM_Env env, double time, JSVM_Value* result); 1000 1001 /** 1002 * @brief This API allocates a JavaScript value with external data attached to it. This is used to pass external 1003 * data through JavaScript code, so it can be retrieved later by native code using OH_JSVM_GetValueExternal. 1004 * The API adds a JSVM_Finalize callback which will be called when the JavaScript object just created has been garbage 1005 * collected.The created value is not an object, and therefore does not support additional properties. It is considered 1006 * a distinct value type: calling OH_JSVM_Typeof() with an external value yields JSVM_EXTERNAL. 1007 * 1008 * @param env: The environment that the API is invoked under. 1009 * @param data: Raw pointer to the external data. 1010 * @param finalizeCb: Optional callback to call when the external value is being collected. JSVM_Finalize provides 1011 * more details. 1012 * @param finalizeHint: Optional hint to pass to the finalize callback during collection. 1013 * @param result: A JSVM_Value representing an external value. 1014 * @return Returns JSVM_OK if the API succeeded. 1015 * @since 11 1016 */ 1017 JSVM_EXTERN JSVM_Status OH_JSVM_CreateExternal(JSVM_Env env, 1018 void* data, 1019 JSVM_Finalize finalizeCb, 1020 void* finalizeHint, 1021 JSVM_Value* result); 1022 1023 /** 1024 * @brief This API allocates a default JavaScript Object. It is the equivalent of doing new Object() in JavaScript. 1025 * 1026 * @param env: The environment that the API is invoked under. 1027 * @param result: A JSVM_Value representing a JavaScript Object. 1028 * @return Returns JSVM_OK if the API succeeded. 1029 * @since 11 1030 */ 1031 JSVM_EXTERN JSVM_Status OH_JSVM_CreateObject(JSVM_Env env, JSVM_Value* result); 1032 1033 /** 1034 * @brief This API creates a JavaScript symbol value from a UTF8-encoded C string. 1035 * 1036 * @param env: The environment that the API is invoked under. 1037 * @param description: Optional JSVM_Value which refers to a JavaScript string to be set as the description 1038 * for the symbol. 1039 * @param result: A JSVM_Value representing a JavaScript symbol. 1040 * @return Returns JSVM_OK if the API succeeded. 1041 * @since 11 1042 */ 1043 JSVM_EXTERN JSVM_Status OH_JSVM_CreateSymbol(JSVM_Env env, JSVM_Value description, JSVM_Value* result); 1044 1045 /** 1046 * @brief This API searches in the global registry for an existing symbol with the given description. 1047 * If the symbol already exists it will be returned, otherwise a new symbol will be created in the registry. 1048 * 1049 * @param env: The environment that the API is invoked under. 1050 * @param utf8description: UTF-8 C string representing the text to be used as the description for the symbol. 1051 * @param length: The length of the description string in bytes, or JSVM_AUTO_LENGTH if it is null-terminated. 1052 * @param result: A JSVM_Value representing a JavaScript symbol. 1053 * @return Returns JSVM_OK if the API succeeded. 1054 * @since 11 1055 */ 1056 JSVM_EXTERN JSVM_Status OH_JSVM_SymbolFor(JSVM_Env env, const char* utf8description, size_t length, JSVM_Value* result); 1057 1058 /** 1059 * @brief This API creates a JavaScript private key. 1060 * 1061 * @param env The environment that the API is invoked under. 1062 * @param description Optional JSVM_Value which refers to a JavaScript string to be set as the description 1063 * for the private key. 1064 * @param result A JSVM_Data representing a JavaScript private key. 1065 * @return Returns JSVM funtions result code. 1066 * {@link JSVM_OK } if the function executed successfully.\n 1067 * {@link JSVM_INVALID_ARG } if env or result is NULL.\n 1068 * {@link JSVM_STRING_EXPECTED } if the description is not a string.\n 1069 * @since 16 1070 */ 1071 JSVM_EXTERN JSVM_Status OH_JSVM_CreatePrivate(JSVM_Env env, JSVM_Value description, JSVM_Data* result); 1072 1073 /** 1074 * @brief This API set a private property on the Object passed in. 1075 * 1076 * @param env The environment that the API is invoked under. 1077 * @param object The object on which to set the private property. 1078 * @param key The private key of the property. 1079 * @param value The private property value. 1080 * @return Returns JSVM funtions result code. 1081 * {@link JSVM_OK } if the function executed successfully.\n 1082 * {@link JSVM_INVALID_ARG } if any of the arguments is NULL or the key is not a private key.\n 1083 * {@link JSVM_OBJECT_EXPECTED } object passed in is not a real object.\n 1084 * {@link JSVM_GENERIC_FAILURE } if failed to set the private key but no exception is pending.\n 1085 * {@link JSVM_PENDING_EXCPTION } if an exception occurs.\n 1086 * @since 16 1087 */ 1088 JSVM_EXTERN JSVM_Status OH_JSVM_SetPrivate(JSVM_Env env, JSVM_Value object, JSVM_Data key, JSVM_Value value); 1089 1090 /** 1091 * @brief This API gets the requested private property from the Object passed in. 1092 * 1093 * @param env The environment that the API is invoked under. 1094 * @param object The object from which to retrieve the private property. 1095 * @param key The private key of the property. 1096 * @param result The value of the private property. 1097 * @return Returns JSVM funtions result code. 1098 * {@link JSVM_OK } if the function executed successfully.\n 1099 * {@link JSVM_INVALID_ARG } if any of the arguments is NULL or the key is not a private key.\n 1100 * {@link JSVM_OBJECT_EXPECTED } object passed in is not a real object.\n 1101 * {@link JSVM_GENERIC_FAILURE } if failed to get the private key but no exception is pending.\n 1102 * {@link JSVM_PENDING_EXCPTION } if an exception occurs.\n 1103 * @since 16 1104 */ 1105 JSVM_EXTERN JSVM_Status OH_JSVM_GetPrivate(JSVM_Env env, JSVM_Value object, JSVM_Data key, JSVM_Value* result); 1106 1107 /** 1108 * @brief This API attempts to delete the property of the private key from object. 1109 * 1110 * @param env The environment that the API is invoked under. 1111 * @param object The object to query. 1112 * @param key The private key of the property to delete. 1113 * @return Returns JSVM funtions result code. 1114 * {@link JSVM_OK } if the function executed successfully.\n 1115 * {@link JSVM_INVALID_ARG } if any of the arguments is NULL or the key is not a private key.\n 1116 * {@link JSVM_OBJECT_EXPECTED } object passed in is not a real object.\n 1117 * {@link JSVM_GENERIC_FAILURE } if failed to delete the private key but no exception is pending.\n 1118 * {@link JSVM_PENDING_EXCPTION } if an exception occurs.\n 1119 * @since 16 1120 */ 1121 JSVM_EXTERN JSVM_Status OH_JSVM_DeletePrivate(JSVM_Env env, JSVM_Value object, JSVM_Data key); 1122 1123 /** 1124 * @brief This API creates a JavaScript TypedArray object over an existing ArrayBuffer. TypedArray 1125 * objects provide an array-like view over an underlying data buffer where each element has the 1126 * same underlying binary scalar datatype.It's required that (length * size_of_element) + byte_offset should 1127 * be <= the size in bytes of the array passed in. If not, a RangeError exception is raised. 1128 * 1129 * @param env: The environment that the API is invoked under. 1130 * @param type: Scalar datatype of the elements within the TypedArray. 1131 * @param length: Number of elements in the TypedArray. 1132 * @param arraybuffer: ArrayBuffer underlying the typed array. 1133 * @param byteOffset: The byte offset within the ArrayBuffer from which to start projecting the TypedArray. 1134 * @param result: A JSVM_Value representing a JavaScript TypedArray 1135 * @return Returns JSVM_OK if the API succeeded. 1136 * @since 11 1137 */ 1138 JSVM_EXTERN JSVM_Status OH_JSVM_CreateTypedarray(JSVM_Env env, 1139 JSVM_TypedarrayType type, 1140 size_t length, 1141 JSVM_Value arraybuffer, 1142 size_t byteOffset, 1143 JSVM_Value* result); 1144 1145 /** 1146 * @brief This API creates a JavaScript DataView object over an existing ArrayBuffer. DataView 1147 * objects provide an array-like view over an underlying data buffer, but one which allows items 1148 * of different size and type in the ArrayBuffer.It is required that byte_length + byte_offset is 1149 * less than or equal to the size in bytes of the array passed in. If not, a RangeError exception 1150 * is raised. 1151 * 1152 * @param env: The environment that the API is invoked under. 1153 * @param length: Number of elements in the DataView. 1154 * @param arraybuffer: ArrayBuffer underlying the DataView. 1155 * @param byteOffset: The byte offset within the ArrayBuffer from which to start projecting the DataView. 1156 * @param result:A JSVM_Value representing a JavaScript DataView. 1157 * @return Returns JSVM_OK if the API succeeded. 1158 * @since 11 1159 */ 1160 JSVM_EXTERN JSVM_Status OH_JSVM_CreateDataview(JSVM_Env env, 1161 size_t length, 1162 JSVM_Value arraybuffer, 1163 size_t byteOffset, 1164 JSVM_Value* result); 1165 1166 /** 1167 * @brief This API is used to convert from the C int32_t type to the JavaScript number type. 1168 * 1169 * @param env: The environment that the API is invoked under. 1170 * @param value: Integer value to be represented in JavaScript. 1171 * @param result: A JSVM_Value representing a JavaScript number. 1172 * @return Returns JSVM_OK if the API succeeded. 1173 * @since 11 1174 */ 1175 JSVM_EXTERN JSVM_Status OH_JSVM_CreateInt32(JSVM_Env env, int32_t value, JSVM_Value* result); 1176 1177 /** 1178 * @brief This API is used to convert from the C uint32_t type to the JavaScript number type. 1179 * 1180 * @param env: The environment that the API is invoked under. 1181 * @param value: Unsigned integer value to be represented in JavaScript. 1182 * @param result: A JSVM_Value representing a JavaScript number. 1183 * @return Returns JSVM_OK if the API succeeded. 1184 * @since 11 1185 */ 1186 JSVM_EXTERN JSVM_Status OH_JSVM_CreateUint32(JSVM_Env env, uint32_t value, JSVM_Value* result); 1187 1188 /** 1189 * @brief This API is used to convert from the C int64_t type to the JavaScript number type. 1190 * 1191 * @param env: The environment that the API is invoked under. 1192 * @param value: Integer value to be represented in JavaScript. 1193 * @param result: A JSVM_Value representing a JavaScript number. 1194 * @return Returns JSVM_OK if the API succeeded. 1195 * @since 11 1196 */ 1197 JSVM_EXTERN JSVM_Status OH_JSVM_CreateInt64(JSVM_Env env, int64_t value, JSVM_Value* result); 1198 1199 /** 1200 * @brief This API is used to convert from the C double type to the JavaScript number type. 1201 * 1202 * @param env: The environment that the API is invoked under. 1203 * @param value: Double-precision value to be represented in JavaScript. 1204 * @param result: A JSVM_Value representing a JavaScript number. 1205 * @return Returns JSVM_OK if the API succeeded. 1206 * @since 11 1207 */ 1208 JSVM_EXTERN JSVM_Status OH_JSVM_CreateDouble(JSVM_Env env, double value, JSVM_Value* result); 1209 1210 /** 1211 * @brief This API converts the C int64_t type to the JavaScript BigInt type. 1212 * 1213 * @param env: The environment that the API is invoked under. 1214 * @param value: Integer value to be represented in JavaScript. 1215 * @param result: A JSVM_Value representing a JavaScript BigInt. 1216 * @return Returns JSVM_OK if the API succeeded. 1217 * @since 11 1218 */ 1219 JSVM_EXTERN JSVM_Status OH_JSVM_CreateBigintInt64(JSVM_Env env, int64_t value, JSVM_Value* result); 1220 1221 /** 1222 * @brief This API converts the C uint64_t type to the JavaScript BigInt type. 1223 * 1224 * @param env: The environment that the API is invoked under. 1225 * @param value: Unsigned integer value to be represented in JavaScript. 1226 * @param result: A JSVM_Value representing a JavaScript BigInt. 1227 * @return Returns JSVM_OK if the API succeeded. 1228 * @since 11 1229 */ 1230 JSVM_EXTERN JSVM_Status OH_JSVM_CreateBigintUint64(JSVM_Env env, uint64_t value, JSVM_Value* result); 1231 1232 /** 1233 * @brief This API converts an array of unsigned 64-bit words into a single BigInt value. 1234 * The resulting BigInt is calculated as: (–1)sign_bit (words[0] × (264)0 + words[1] × (264)1 + …) 1235 * 1236 * @param env: The environment that the API is invoked under. 1237 * @param signBit: Determines if the resulting BigInt will be positive or negative. 1238 * @param wordCount: The length of the words array. 1239 * @param words: An array of uint64_t little-endian 64-bit words. 1240 * @param result: A JSVM_Value representing a JavaScript BigInt. 1241 * @return Returns JSVM_OK if the API succeeded. 1242 * @since 11 1243 */ 1244 JSVM_EXTERN JSVM_Status OH_JSVM_CreateBigintWords(JSVM_Env env, 1245 int signBit, 1246 size_t wordCount, 1247 const uint64_t* words, 1248 JSVM_Value* result); 1249 1250 /** 1251 * @brief This API creates a JavaScript string value from an ISO-8859-1-encoded C 1252 * string. The native string is copied. 1253 * 1254 * @param env: The environment that the API is invoked under. 1255 * @param str: Character buffer representing an ISO-8859-1-encoded string. 1256 * @param length: The length of the string in bytes, or JSVM_AUTO_LENGTH if it is null-terminated. 1257 * @param result: A JSVM_Value representing a JavaScript string. 1258 * @return Returns JSVM_OK if the API succeeded. 1259 * @since 11 1260 */ 1261 JSVM_EXTERN JSVM_Status OH_JSVM_CreateStringLatin1(JSVM_Env env, const char* str, size_t length, JSVM_Value* result); 1262 1263 /** 1264 * @brief This API creates a JavaScript string value from a UTF16-LE-encoded C 1265 * string. The native string is copied. 1266 * 1267 * @param env: The environment that the API is invoked under. 1268 * @param str: Character buffer representing a UTF16-LE-encoded string. 1269 * @param length: The length of the string in two-byte code units, or JSVM_AUTO_LENGTH 1270 * if it is null-terminated. 1271 * @param result: A JSVM_Value representing a JavaScript string. 1272 * @return Returns JSVM_OK if the API succeeded. 1273 * @since 11 1274 */ 1275 JSVM_EXTERN JSVM_Status OH_JSVM_CreateStringUtf16(JSVM_Env env, const char16_t* str, size_t length, JSVM_Value* result); 1276 1277 /** 1278 * @brief This API creates a JavaScript string value from a UTF8-encoded C 1279 * string. The native string is copied. 1280 * 1281 * @param env: The environment that the API is invoked under. 1282 * @param str: Character buffer representing a UTF8-encoded string. 1283 * @param length: The length of the string in bytes, or JSVM_AUTO_LENGTH if it is null-terminated. 1284 * @param result: A JSVM_Value representing a JavaScript string. 1285 * @return Returns JSVM_OK if the API succeeded. 1286 * @since 11 1287 */ 1288 JSVM_EXTERN JSVM_Status OH_JSVM_CreateStringUtf8(JSVM_Env env, const char* str, size_t length, JSVM_Value* result); 1289 /** 1290 * @brief This API creates an external JavaScript string value from an ISO-8859-1-encoded C 1291 * string. The native string is copied when failed to create external string. 1292 * 1293 * @param env The environment that the API is invoked under. 1294 * @param str Character buffer representing an ISO-8859-1-encoded string. 1295 * @param length The length of the string in bytes, or JSVM_AUTO_LENGTH if it is null-terminated. 1296 * @param finalizeCallback Optional callback to call when the external value is being collected. 1297 * JSVM_Finalize provides more details. 1298 * @param finalizeHint Optional hint to pass to the finalize callback during collection. 1299 * @param result A JSVM_Value representing a JavaScript external string. 1300 * @param copied flag indicate whether the external string is successfully created, 1301 * true for faild to create external ones and fall back to non-external strings, false for success. 1302 * @return Returns JSVM funtions result code. 1303 * Returns {@link JSVM_OK } if the function executed successfully.\n 1304 * Returns {@link JSVM_INVALID_ARG } if one of env, str and copied is NULL.\n 1305 * @since 16 1306 */ 1307 JSVM_EXTERN JSVM_Status OH_JSVM_CreateExternalStringLatin1(JSVM_Env env, 1308 char* str, 1309 size_t length, 1310 JSVM_Finalize finalizeCallback, 1311 void* finalizeHint, 1312 JSVM_Value* result, 1313 bool* copied); 1314 1315 /** 1316 * @brief This API creates an external JavaScript string value from an UTF16-LE-encoded C 1317 * string. The native string is copied when failed to create external string. 1318 * 1319 * @param env The environment that the API is invoked under. 1320 * @param str Character buffer representing an UTF16-LE-encoded string. 1321 * @param length The length of the string in bytes, or JSVM_AUTO_LENGTH if it is null-terminated. 1322 * @param finalizeCallback Optional callback to call when the external value is being collected. 1323 * JSVM_Finalize provides more details. 1324 * @param finalizeHint Optional hint to pass to the finalize callback during collection. 1325 * @param result A JSVM_Value representing a JavaScript external string. 1326 * @param copied flag indicate whether the external string is successfully created, 1327 * true for faild to create external ones and fall back to non-external strings, false for success. 1328 * @return Returns JSVM funtions result code. 1329 * Returns {@link JSVM_OK } if the function executed successfully.\n 1330 * Returns {@link JSVM_INVALID_ARG } if one of env, str and copied is NULL.\n 1331 * @since 16 1332 */ 1333 1334 JSVM_EXTERN JSVM_Status OH_JSVM_CreateExternalStringUtf16(JSVM_Env env, 1335 char16_t* str, 1336 size_t length, 1337 JSVM_Finalize finalizeCallback, 1338 void* finalizeHint, 1339 JSVM_Value* result, 1340 bool* copied); 1341 1342 /** 1343 * @brief This API returns the length of an array. 1344 * 1345 * @param env: The environment that the API is invoked under. 1346 * @param value: JSVM_Value representing the JavaScript Array whose length is being queried. 1347 * @param result: uint32 representing length of the array. 1348 * @return Returns JSVM_OK if the API succeeded. 1349 * @since 11 1350 */ 1351 JSVM_EXTERN JSVM_Status OH_JSVM_GetArrayLength(JSVM_Env env, JSVM_Value value, uint32_t* result); 1352 1353 /** 1354 * @brief This API is used to retrieve the underlying data buffer of an ArrayBuffer and its length. 1355 * 1356 * @param env: The environment that the API is invoked under. 1357 * @param arraybuffer: JSVM_Value representing the ArrayBuffer being queried. 1358 * @param data: The underlying data buffer of the ArrayBuffer. If byte_length is 0, this may be NULL 1359 * or any other pointer value. 1360 * @param byteLength: Length in bytes of the underlying data buffer. 1361 * @return Returns JSVM_OK if the API succeeded. 1362 * @since 11 1363 */ 1364 JSVM_EXTERN JSVM_Status OH_JSVM_GetArraybufferInfo(JSVM_Env env, 1365 JSVM_Value arraybuffer, 1366 void** data, 1367 size_t* byteLength); 1368 1369 /** 1370 * @brief This API returns the length of an array. 1371 * 1372 * @param env: The environment that the API is invoked under. 1373 * @param object: JSVM_Value representing JavaScript Object whose prototype to return. This returns 1374 * the equivalent of Object.getPrototypeOf (which is not the same as the function's prototype property). 1375 * @param result: JSVM_Value representing prototype of the given object. 1376 * @return Returns JSVM_OK if the API succeeded. 1377 * @since 11 1378 */ 1379 JSVM_EXTERN JSVM_Status OH_JSVM_GetPrototype(JSVM_Env env, JSVM_Value object, JSVM_Value* result); 1380 1381 /** 1382 * @brief This API returns various properties of a typed array. 1383 * 1384 * @param env: The environment that the API is invoked under. 1385 * @param typedarray: JSVM_Value representing the TypedArray whose properties to query. 1386 * @param type: Scalar datatype of the elements within the TypedArray. 1387 * @param length: The number of elements in the TypedArray. 1388 * @param data: The data buffer underlying the TypedArray adjusted by the byte_offset value so that it 1389 * points to the first element in the TypedArray. If the length of the array is 0, this may be NULL or 1390 * any other pointer value. 1391 * @param arraybuffer: The ArrayBuffer underlying the TypedArray. 1392 * @param byteOffset: The byte offset within the underlying native array at which the first element of 1393 * the arrays is located. The value for the data parameter has already been adjusted so that data points 1394 * to the first element in the array. Therefore, the first byte of the native array would be at data - byte_offset. 1395 * @return Returns JSVM_OK if the API succeeded. 1396 * @since 11 1397 */ 1398 JSVM_EXTERN JSVM_Status OH_JSVM_GetTypedarrayInfo(JSVM_Env env, 1399 JSVM_Value typedarray, 1400 JSVM_TypedarrayType* type, 1401 size_t* length, 1402 void** data, 1403 JSVM_Value* arraybuffer, 1404 size_t* byteOffset); 1405 1406 /** 1407 * @brief Any of the out parameters may be NULL if that property is unneeded. 1408 * This API returns various properties of a DataView. 1409 * 1410 * @param env: The environment that the API is invoked under. 1411 * @param dataview: JSVM_Value representing the DataView whose properties to query. 1412 * @param bytelength: Number of bytes in the DataView. 1413 * @param data: The data buffer underlying the DataView. 1414 * If byte_length is 0, this may be NULL or any other pointer value. 1415 * @param arraybuffer: ArrayBuffer underlying the DataView. 1416 * @param byteOffset: The byte offset within the data buffer from which to start projecting the DataView. 1417 * @return Returns JSVM_OK if the API succeeded. 1418 * @since 11 1419 */ 1420 JSVM_EXTERN JSVM_Status OH_JSVM_GetDataviewInfo(JSVM_Env env, 1421 JSVM_Value dataview, 1422 size_t* bytelength, 1423 void** data, 1424 JSVM_Value* arraybuffer, 1425 size_t* byteOffset); 1426 1427 /** 1428 * @brief Returns JSVM_OK if the API succeeded. If a non-date JSVM_Value is 1429 * passed in it returns JSVM_date_expected.This API returns the C double 1430 * primitive of time value for the given JavaScript Date. 1431 * 1432 * @param env: The environment that the API is invoked under. 1433 * @param value: JSVM_Value representing a JavaScript Date. 1434 * @param result: Time value as a double represented as milliseconds 1435 * since midnight at the beginning of 01 January, 1970 UTC. 1436 * @return Returns JSVM_OK if the API succeeded. 1437 * @since 11 1438 */ 1439 JSVM_EXTERN JSVM_Status OH_JSVM_GetDateValue(JSVM_Env env, JSVM_Value value, double* result); 1440 1441 /** 1442 * @brief This API returns the C boolean primitive equivalent of the given JavaScript Boolean. 1443 * 1444 * @param env: The environment that the API is invoked under. 1445 * @param value: JSVM_Value representing JavaScript Boolean. 1446 * @param result: C boolean primitive equivalent of the given JavaScript Boolean. 1447 * @return Returns JSVM_OK if the API succeeded. 1448 * If a non-boolean JSVM_Value is passed in it returns JSVM_BOOLEAN_EXPECTED. 1449 * @since 11 1450 */ 1451 JSVM_EXTERN JSVM_Status OH_JSVM_GetValueBool(JSVM_Env env, JSVM_Value value, bool* result); 1452 1453 /** 1454 * @brief This API returns the C double primitive equivalent of the given JavaScript number. 1455 * 1456 * @param env: The environment that the API is invoked under. 1457 * @param value: JSVM_Value representing JavaScript number. 1458 * @param result: C double primitive equivalent of the given JavaScript number. 1459 * @return Returns JSVM_OK if the API succeeded. 1460 * If a non-number JSVM_Value is passed in it returns JSVM_NUMBER_EXPECTED. 1461 * @since 11 1462 */ 1463 JSVM_EXTERN JSVM_Status OH_JSVM_GetValueDouble(JSVM_Env env, JSVM_Value value, double* result); 1464 1465 /** 1466 * @brief This API returns the C int64_t primitive equivalent of the given JavaScript BigInt. 1467 * If needed it will truncate the value, setting lossless to false. 1468 * 1469 * @param env: The environment that the API is invoked under. 1470 * @param value: JSVM_Value representing JavaScript BigInt. 1471 * @param result: C int64_t primitive equivalent of the given JavaScript BigInt. 1472 * @param lossless: Indicates whether the BigInt value was converted losslessly. 1473 * @return Returns JSVM_OK if the API succeeded. If a non-BigInt is passed in it returns JSVM_BIGINT_EXPECTED. 1474 * @since 11 1475 */ 1476 JSVM_EXTERN JSVM_Status OH_JSVM_GetValueBigintInt64(JSVM_Env env, JSVM_Value value, int64_t* result, bool* lossless); 1477 1478 /** 1479 * @brief This API returns the C uint64_t primitive equivalent of the given JavaScript BigInt. 1480 * If needed it will truncate the value, setting lossless to false. 1481 * 1482 * @param env: The environment that the API is invoked under. 1483 * @param value: JSVM_Value representing JavaScript BigInt. 1484 * @param result: C uint64_t primitive equivalent of the given JavaScript BigInt. 1485 * @param lossless: Indicates whether the BigInt value was converted losslessly. 1486 * @return Returns JSVM_OK if the API succeeded. If a non-BigInt is passed in it returns JSVM_BIGINT_EXPECTED. 1487 * @since 11 1488 */ 1489 JSVM_EXTERN JSVM_Status OH_JSVM_GetValueBigintUint64(JSVM_Env env, JSVM_Value value, uint64_t* result, bool* lossless); 1490 1491 /** 1492 * @brief This API converts a single BigInt value into a sign bit, 64-bit little-endian array, and the number 1493 * of elements in the array. signBit and words may be both set to NULL, in order to get only wordCount. 1494 * 1495 * @param env: The environment that the API is invoked under. 1496 * @param value: JSVM_Value representing JavaScript BigInt. 1497 * @param signBit: Integer representing if the JavaScript BigInt is positive or negative. 1498 * @param wordCount: Must be initialized to the length of the words array. Upon return, it will be set to 1499 * the actual number of words that would be needed to store this BigInt. 1500 * @param words: Pointer to a pre-allocated 64-bit word array. 1501 * @return Returns JSVM_OK if the API succeeded. 1502 * @since 11 1503 */ 1504 JSVM_EXTERN JSVM_Status OH_JSVM_GetValueBigintWords(JSVM_Env env, 1505 JSVM_Value value, 1506 int* signBit, 1507 size_t* wordCount, 1508 uint64_t* words); 1509 1510 /** 1511 * @brief This API retrieves the external data pointer that was previously passed to OH_JSVM_CreateExternal(). 1512 * 1513 * @param env: The environment that the API is invoked under. 1514 * @param value: JSVM_Value representing JavaScript external value. 1515 * @param result: Pointer to the data wrapped by the JavaScript external value. 1516 * @return Returns JSVM_OK if the API succeeded. If a non-external JSVM_Value is passed in it returns JSVM_INVALID_ARG. 1517 * @since 11 1518 */ 1519 JSVM_EXTERN JSVM_Status OH_JSVM_GetValueExternal(JSVM_Env env, JSVM_Value value, void** result); 1520 1521 /** 1522 * @brief This API returns the C int32 primitive equivalent of the given JavaScript number. 1523 * 1524 * @param env: The environment that the API is invoked under. 1525 * @param value: JSVM_Value representing JavaScript number. 1526 * @param result: C int32 primitive equivalent of the given JavaScript number. 1527 * @return Returns JSVM_OK if the API succeeded. If a non-number JSVM_Value is passed in JSVM_NUMBER_EXPECTED. 1528 * @since 11 1529 */ 1530 JSVM_EXTERN JSVM_Status OH_JSVM_GetValueInt32(JSVM_Env env, JSVM_Value value, int32_t* result); 1531 1532 /** 1533 * @brief This API returns the C int64 primitive equivalent of the given JavaScript number. 1534 * 1535 * @param env: The environment that the API is invoked under. 1536 * @param value: JSVM_Value representing JavaScript number. 1537 * @param result: C int64 primitive equivalent of the given JavaScript number. 1538 * @return Returns JSVM_OK if the API succeeded. If a non-number JSVM_Value is passed in JSVM_NUMBER_EXPECTED. 1539 * @since 11 1540 */ 1541 JSVM_EXTERN JSVM_Status OH_JSVM_GetValueInt64(JSVM_Env env, JSVM_Value value, int64_t* result); 1542 1543 /** 1544 * @brief This API returns the ISO-8859-1-encoded string corresponding the value passed in. 1545 * 1546 * @param env: The environment that the API is invoked under. 1547 * @param value: JSVM_Value representing JavaScript string. 1548 * @param buf: Buffer to write the ISO-8859-1-encoded string into. If NULL is passed in, the 1549 * length of the string in bytes and excluding the null terminator is returned in result. 1550 * @param bufsize: Size of the destination buffer. When this value is insufficient, the returned string 1551 * is truncated and null-terminated. 1552 * @param result: Number of bytes copied into the buffer, excluding the null terminator. 1553 * @return Returns JSVM_OK if the API succeeded. If a non-number JSVM_Value is passed in JSVM_NUMBER_EXPECTED. 1554 * @since 11 1555 */ 1556 JSVM_EXTERN JSVM_Status OH_JSVM_GetValueStringLatin1(JSVM_Env env, 1557 JSVM_Value value, 1558 char* buf, 1559 size_t bufsize, 1560 size_t* result); 1561 1562 /** 1563 * @brief This API returns the UTF8-encoded string corresponding the value passed in. 1564 * 1565 * @param env: The environment that the API is invoked under. 1566 * @param value: JSVM_Value representing JavaScript string. 1567 * @param buf: Buffer to write the UTF8-encoded string into. If NULL is passed in, the length 1568 * of the string in bytes and excluding the null terminator is returned in result. 1569 * @param bufsize: Size of the destination buffer. When this value is insufficient, the returned 1570 * string is truncated and null-terminated. 1571 * @param result: Number of bytes copied into the buffer, excluding the null terminator. 1572 * @return Returns JSVM_OK if the API succeeded. If a non-number JSVM_Value is passed in JSVM_NUMBER_EXPECTED. 1573 * @since 11 1574 */ 1575 JSVM_EXTERN JSVM_Status OH_JSVM_GetValueStringUtf8(JSVM_Env env, 1576 JSVM_Value value, 1577 char* buf, 1578 size_t bufsize, 1579 size_t* result); 1580 1581 /** 1582 * @brief This API returns the UTF16-encoded string corresponding the value passed in. 1583 * 1584 * @param env: The environment that the API is invoked under. 1585 * @param value: JSVM_Value representing JavaScript string. 1586 * @param buf: Buffer to write the UTF16-LE-encoded string into. If NULL is passed in, 1587 * the length of the string in 2-byte code units and excluding the null terminator is returned. 1588 * @param bufsize: Size of the destination buffer. When this value is insufficient, 1589 * the returned string is truncated and null-terminated. 1590 * @param result: Number of 2-byte code units copied into the buffer, excluding the null terminator. 1591 * @return Returns JSVM_OK if the API succeeded. If a non-number JSVM_Value is passed in JSVM_NUMBER_EXPECTED. 1592 * @since 11 1593 */ 1594 JSVM_EXTERN JSVM_Status OH_JSVM_GetValueStringUtf16(JSVM_Env env, 1595 JSVM_Value value, 1596 char16_t* buf, 1597 size_t bufsize, 1598 size_t* result); 1599 1600 /** 1601 * @brief This API returns the C primitive equivalent of the given JSVM_Value as a uint32_t. 1602 * 1603 * @param env: The environment that the API is invoked under. 1604 * @param value: JSVM_Value representing JavaScript number. 1605 * @param result: C primitive equivalent of the given JSVM_Value as a uint32_t. 1606 * @return Returns JSVM_OK if the API succeeded. 1607 * If a non-number JSVM_Value is passed in it returns JSVM_NUMBER_EXPECTED. 1608 * @since 11 1609 */ 1610 JSVM_EXTERN JSVM_Status OH_JSVM_GetValueUint32(JSVM_Env env, JSVM_Value value, uint32_t* result); 1611 1612 /** 1613 * @brief This API is used to return the JavaScript singleton object that is used to represent the given boolean value. 1614 * 1615 * @param env: The environment that the API is invoked under. 1616 * @param value: The value of the boolean to retrieve. 1617 * @param result: JSVM_Value representing JavaScript Boolean singleton to retrieve. 1618 * @return Returns JSVM_OK if the API succeeded. 1619 * @since 11 1620 */ 1621 JSVM_EXTERN JSVM_Status OH_JSVM_GetBoolean(JSVM_Env env, bool value, JSVM_Value* result); 1622 1623 /** 1624 * @brief This API returns the global object. 1625 * 1626 * @param env: The environment that the API is invoked under. 1627 * @param result: JSVM_Value representing JavaScript global object. 1628 * @return Returns JSVM_OK if the API succeeded. 1629 * @since 11 1630 */ 1631 JSVM_EXTERN JSVM_Status OH_JSVM_GetGlobal(JSVM_Env env, JSVM_Value* result); 1632 1633 /** 1634 * @brief This API returns the null object. 1635 * 1636 * @param env: The environment that the API is invoked under. 1637 * @param result: JSVM_Value representing JavaScript null object. 1638 * @return Returns JSVM_OK if the API succeeded. 1639 * @since 11 1640 */ 1641 JSVM_EXTERN JSVM_Status OH_JSVM_GetNull(JSVM_Env env, JSVM_Value* result); 1642 1643 /** 1644 * @brief This API returns the Undefined object. 1645 * 1646 * @param env: The environment that the API is invoked under. 1647 * @param result: JSVM_Value representing JavaScript Undefined value. 1648 * @return Returns JSVM_OK if the API succeeded. 1649 * @since 11 1650 */ 1651 JSVM_EXTERN JSVM_Status OH_JSVM_GetUndefined(JSVM_Env env, JSVM_Value* result); 1652 1653 /** 1654 * @brief This API implements the abstract operation ToBoolean() 1655 * 1656 * @param env: The environment that the API is invoked under. 1657 * @param value: The JavaScript value to coerce. 1658 * @param result: JSVM_Value representing the coerced JavaScript Boolean. 1659 * @return Returns JSVM_OK if the API succeeded. 1660 * @since 11 1661 */ 1662 JSVM_EXTERN JSVM_Status OH_JSVM_CoerceToBool(JSVM_Env env, JSVM_Value value, JSVM_Value* result); 1663 1664 /** 1665 * @brief This API implements the abstract operation ToNumber() as defined. This 1666 * function potentially runs JS code if the passed-in value is an object. 1667 * 1668 * @param env: The environment that the API is invoked under. 1669 * @param value: The JavaScript value to coerce. 1670 * @param result: JSVM_Value representing the coerced JavaScript number. 1671 * @return Returns JSVM_OK if the API succeeded. 1672 * @since 11 1673 */ 1674 JSVM_EXTERN JSVM_Status OH_JSVM_CoerceToNumber(JSVM_Env env, JSVM_Value value, JSVM_Value* result); 1675 1676 /** 1677 * @brief This API implements the abstract operation ToObject(). 1678 * 1679 * @param env: The environment that the API is invoked under. 1680 * @param value: The JavaScript value to coerce. 1681 * @param result: JSVM_Value representing the coerced JavaScript Object. 1682 * @return Returns JSVM_OK if the API succeeded. 1683 * @since 11 1684 */ 1685 JSVM_EXTERN JSVM_Status OH_JSVM_CoerceToObject(JSVM_Env env, JSVM_Value value, JSVM_Value* result); 1686 1687 /** 1688 * @brief This API implements the abstract operation ToString().This 1689 * function potentially runs JS code if the passed-in value is an object. 1690 * 1691 * @param env: The environment that the API is invoked under. 1692 * @param value: The JavaScript value to coerce. 1693 * @param result: JSVM_Value representing the coerced JavaScript string. 1694 * @return Returns JSVM_OK if the API succeeded. 1695 * @since 11 1696 */ 1697 JSVM_EXTERN JSVM_Status OH_JSVM_CoerceToString(JSVM_Env env, JSVM_Value value, JSVM_Value* result); 1698 1699 /** 1700 * @brief This API represents behavior similar to invoking the typeof Operator 1701 * on the object as defined. However, there are some differences:It has support 1702 * for detecting an External value.It detects null as a separate type, while 1703 * ECMAScript typeof would detect object.If value has a type that is invalid, 1704 * an error is returned. 1705 * 1706 * @param env: The environment that the API is invoked under. 1707 * @param value: The JavaScript value whose type to query. 1708 * @param result: The type of the JavaScript value. 1709 * @return Returns JSVM_OK if the API succeeded. 1710 * @since 11 1711 */ 1712 JSVM_EXTERN JSVM_Status OH_JSVM_Typeof(JSVM_Env env, JSVM_Value value, JSVM_ValueType* result); 1713 1714 /** 1715 * @brief This API represents invoking the instanceof Operator on the object. 1716 * 1717 * @param env: The environment that the API is invoked under. 1718 * @param object: The JavaScript value to check. 1719 * @param constructor: The JavaScript function object of the constructor function 1720 * to check against. 1721 * @param result: Boolean that is set to true if object instanceof constructor is true. 1722 * @return Returns JSVM_OK if the API succeeded. 1723 * @since 11 1724 */ 1725 JSVM_EXTERN JSVM_Status OH_JSVM_Instanceof(JSVM_Env env, JSVM_Value object, JSVM_Value constructor, bool* result); 1726 1727 /** 1728 * @brief Add VM GC Callback. 1729 * 1730 * @param vm The environment that the API is invoked under. 1731 * @param triggerTime The timing of GC callback trigger. 1732 * @param handler When Trigger gc, the callback function will be called. 1733 * @param gcType The type of gc. 1734 * @param userData The native pointer data. 1735 * @return Returns JSVM funtions result code. 1736 * {@link JSVM_OK } if the function executed successfully.\n 1737 * {@link JSVM_INVALID_ARG } if the vm or the handler is NULL or the handler has been added before.\n 1738 * 1739 * @since 16 1740 */ 1741 JSVM_EXTERN JSVM_Status OH_JSVM_AddHandlerForGC(JSVM_VM vm, 1742 JSVM_CBTriggerTimeForGC triggerTime, 1743 JSVM_HandlerForGC handler, 1744 JSVM_GCType gcType, 1745 void* userData); 1746 1747 /** 1748 * @brief Remove VM GC Callback. 1749 * 1750 * @param vm The environment that the API is invoked under. 1751 * @param triggerTime The timing of GC callback trigger. 1752 * @param handler When Trigger gc, the callback function will be called. 1753 * @param userData The native pointer data. 1754 * @return Returns JSVM funtions result code. 1755 * {@link JSVM_OK } if the function executed successfully.\n 1756 * {@link JSVM_INVALID_ARG } if the vm or the handler is NULL, or the handler has been removed, 1757 * or the handler has never been added.\n 1758 * 1759 * @since 16 1760 */ 1761 JSVM_EXTERN JSVM_Status OH_JSVM_RemoveHandlerForGC(JSVM_VM vm, 1762 JSVM_CBTriggerTimeForGC triggerTime, 1763 JSVM_HandlerForGC handler, 1764 void* userData); 1765 1766 /** 1767 * @brief Set Handler For OOM Error. If this function is invoked repeatedly, 1768 * only the last time takes effect. When handler is null, the previous setting is canceled. 1769 * 1770 * @param vm The environment that the API is invoked under. 1771 * @param handler The handler for OOM Error. 1772 * @return Returns JSVM funtions result code. 1773 * {@link JSVM_OK } if the function executed successfully.\n 1774 * {@link JSVM_INVALID_ARG } if vm is NULL.\n 1775 * 1776 * @since 16 1777 */ 1778 JSVM_EXTERN JSVM_Status OH_JSVM_SetHandlerForOOMError(JSVM_VM vm, JSVM_HandlerForOOMError handler); 1779 1780 /** 1781 * @brief Set Handler For Fatal Error. If this function is invoked repeatedly, 1782 * only the last time takes effect. When handler is null, the previous setting is canceled. 1783 * 1784 * @param vm The environment that the API is invoked under. 1785 * @param handler The handler for Fatal Error. 1786 * @return Returns JSVM funtions result code. 1787 * {@link JSVM_OK } if the function executed successfully.\n 1788 * {@link JSVM_INVALID_ARG } if vm is NULL.\n 1789 * 1790 * @since 16 1791 */ 1792 JSVM_EXTERN JSVM_Status OH_JSVM_SetHandlerForFatalError(JSVM_VM vm, JSVM_HandlerForFatalError handler); 1793 1794 /** 1795 * @brief Set Handler For Promise Reject. If this function is invoked repeatedly, 1796 * only the last time takes effect. When handler is null, the previous setting is canceled. 1797 * 1798 * @param vm The environment that the API is invoked under. 1799 * @param handler The handler for Promise Reject. 1800 * @return Returns JSVM funtions result code. 1801 * {@link JSVM_OK } if the function executed successfully.\n 1802 * {@link JSVM_INVALID_ARG } if vm is NULL.\n 1803 * 1804 * @since 16 1805 */ 1806 JSVM_EXTERN JSVM_Status OH_JSVM_SetHandlerForPromiseReject(JSVM_VM vm, JSVM_HandlerForPromiseReject handler); 1807 1808 /** 1809 * @brief This API represents invoking the IsArray operation on the object 1810 * 1811 * @param env: The environment that the API is invoked under. 1812 * @param value: The JavaScript value to check. 1813 * @param result: Whether the given object is an array. 1814 * @return Returns JSVM_OK if the API succeeded. 1815 * @since 11 1816 */ 1817 JSVM_EXTERN JSVM_Status OH_JSVM_IsArray(JSVM_Env env, JSVM_Value value, bool* result); 1818 1819 /** 1820 * @brief This API checks if the Object passed in is an array buffer. 1821 * 1822 * @param env: The environment that the API is invoked under. 1823 * @param value: The JavaScript value to check. 1824 * @param result: Whether the given object is an ArrayBuffer. 1825 * @return Returns JSVM_OK if the API succeeded. 1826 * @since 11 1827 */ 1828 JSVM_EXTERN JSVM_Status OH_JSVM_IsArraybuffer(JSVM_Env env, JSVM_Value value, bool* result); 1829 1830 /** 1831 * @brief This API checks if the Object passed in is a date. 1832 * 1833 * @param env: The environment that the API is invoked under. 1834 * @param value: The JavaScript value to check. 1835 * @param result: Whether the given JSVM_Value represents a JavaScript Date object. 1836 * @return Returns JSVM_OK if the API succeeded. 1837 * @since 11 1838 */ 1839 JSVM_EXTERN JSVM_Status OH_JSVM_IsDate(JSVM_Env env, JSVM_Value value, bool* isDate); 1840 1841 /** 1842 * @brief This API checks if the Object passed in is a typed array. 1843 * 1844 * @param env: The environment that the API is invoked under. 1845 * @param value: The JavaScript value to check. 1846 * @param result: Whether the given JSVM_Value represents a TypedArray. 1847 * @return Returns JSVM_OK if the API succeeded. 1848 * @since 11 1849 */ 1850 JSVM_EXTERN JSVM_Status OH_JSVM_IsTypedarray(JSVM_Env env, JSVM_Value value, bool* result); 1851 1852 /** 1853 * @brief This API checks if the Object passed in is a DataView. 1854 * 1855 * @param env: The environment that the API is invoked under. 1856 * @param value: The JavaScript value to check. 1857 * @param result: Whether the given JSVM_Value represents a DataView. 1858 * @return Returns JSVM_OK if the API succeeded. 1859 * @since 11 1860 */ 1861 JSVM_EXTERN JSVM_Status OH_JSVM_IsDataview(JSVM_Env env, JSVM_Value value, bool* result); 1862 1863 /** 1864 * @brief This API represents the invocation of the Strict Equality algorithm. 1865 * Returns true only when both the type and value are equal. 1866 * 1867 * @param env: The environment that the API is invoked under. 1868 * @param lhs: The JavaScript value to check. 1869 * @param rhs: The JavaScript value to check against. 1870 * @param result: Whether the two JSVM_Value objects are equal. 1871 * @return Returns JSVM_OK if the API succeeded. 1872 * @since 11 1873 */ 1874 JSVM_EXTERN JSVM_Status OH_JSVM_StrictEquals(JSVM_Env env, JSVM_Value lhs, JSVM_Value rhs, bool* result); 1875 1876 /** 1877 * @brief This API represents the invocation of the Relaxed Equality algorithm. 1878 * Returns true as long as the values are equal, regardless of type. 1879 * 1880 * @param env: The environment that the API is invoked under. 1881 * @param lhs: The JavaScript value to check. 1882 * @param rhs: The JavaScript value to check against. 1883 * @param result: Whether the two JSVM_Value objects are relaxed equal. 1884 * @return Returns JSVM_OK if the API succeeded. 1885 * @since 12 1886 */ 1887 JSVM_EXTERN JSVM_Status OH_JSVM_Equals(JSVM_Env env, JSVM_Value lhs, JSVM_Value rhs, bool* result); 1888 1889 /** 1890 * @brief This API represents the invocation of the ArrayBuffer detach operation. 1891 * 1892 * @param env: The environment that the API is invoked under. 1893 * @param arraybuffer: The JavaScript ArrayBuffer to be detached. 1894 * @return Returns JSVM_OK if the API succeeded.If a non-detachable ArrayBuffer 1895 * is passed in it returns JSVM_DETACHABLE_ARRAYBUFFER_EXPECTED. 1896 * @since 11 1897 */ 1898 JSVM_EXTERN JSVM_Status OH_JSVM_DetachArraybuffer(JSVM_Env env, JSVM_Value arraybuffer); 1899 1900 /** 1901 * @brief This API represents the invocation of the ArrayBuffer IsDetachedBuffer operation. 1902 * 1903 * @param env: The environment that the API is invoked under. 1904 * @param value: The JavaScript ArrayBuffer to be checked. 1905 * @param result: Whether the arraybuffer is detached. 1906 * @return Returns JSVM_OK if the API succeeded. 1907 * @since 11 1908 */ 1909 JSVM_EXTERN JSVM_Status OH_JSVM_IsDetachedArraybuffer(JSVM_Env env, JSVM_Value value, bool* result); 1910 1911 /** 1912 * @brief This API returns the names of the enumerable properties of object as an array of 1913 * strings. The properties of object whose key is a symbol will not be included. 1914 * 1915 * @param env: The environment that the API is invoked under. 1916 * @param object: The object from which to retrieve the properties. 1917 * @param result: A JSVM_Value representing an array of JavaScript values that represent 1918 * the property names of the object. The API can be used to iterate over result using 1919 * OH_JSVM_GetArrayLength and OH_JSVM_GetElement. 1920 * @return Returns JSVM_OK if the API succeeded. 1921 * @since 11 1922 */ 1923 JSVM_EXTERN JSVM_Status OH_JSVM_GetPropertyNames(JSVM_Env env, JSVM_Value object, JSVM_Value* result); 1924 1925 /** 1926 * @brief This API returns an array containing the names of the available properties 1927 * of this object. 1928 * 1929 * @param env: The environment that the API is invoked under. 1930 * @param object: The object from which to retrieve the properties. 1931 * @param keyMode: Whether to retrieve prototype properties as well. 1932 * @param keyFilter: Which properties to retrieve (enumerable/readable/writable). 1933 * @param keyConversion: Whether to convert numbered property keys to strings. 1934 * @param result: result: A JSVM_Value representing an array of JavaScript values 1935 * that represent the property names of the object. OH_JSVM_GetArrayLength and 1936 * OH_JSVM_GetElement can be used to iterate over result. 1937 * @return Returns JSVM_OK if the API succeeded. 1938 * @since 11 1939 */ 1940 JSVM_EXTERN JSVM_Status OH_JSVM_GetAllPropertyNames(JSVM_Env env, 1941 JSVM_Value object, 1942 JSVM_KeyCollectionMode keyMode, 1943 JSVM_KeyFilter keyFilter, 1944 JSVM_KeyConversion keyConversion, 1945 JSVM_Value* result); 1946 1947 /** 1948 * @brief This API set a property on the Object passed in. 1949 * 1950 * @param env: The environment that the API is invoked under. 1951 * @param object: The object on which to set the property. 1952 * @param key: The name of the property to set. 1953 * @param value: The property value. 1954 * @return Returns JSVM_OK if the API succeeded. 1955 * @since 11 1956 */ 1957 JSVM_EXTERN JSVM_Status OH_JSVM_SetProperty(JSVM_Env env, JSVM_Value object, JSVM_Value key, JSVM_Value value); 1958 1959 /** 1960 * @brief This API gets the requested property from the Object passed in. 1961 * 1962 * @param env: The environment that the API is invoked under. 1963 * @param object: The object from which to retrieve the property. 1964 * @param key: The name of the property to retrieve. 1965 * @param result: The value of the property. 1966 * @return Returns JSVM_OK if the API succeeded. 1967 * @since 11 1968 */ 1969 JSVM_EXTERN JSVM_Status OH_JSVM_GetProperty(JSVM_Env env, JSVM_Value object, JSVM_Value key, JSVM_Value* result); 1970 1971 /** 1972 * @brief This API checks if the Object passed in has the named property. 1973 * 1974 * @param env: The environment that the API is invoked under. 1975 * @param object: The object to query. 1976 * @param key: The name of the property whose existence to check. 1977 * @param result: Whether the property exists on the object or not. 1978 * @return Returns JSVM_OK if the API succeeded. 1979 * @since 11 1980 */ 1981 JSVM_EXTERN JSVM_Status OH_JSVM_HasProperty(JSVM_Env env, JSVM_Value object, JSVM_Value key, bool* result); 1982 1983 /** 1984 * @brief This API attempts to delete the key own property from object. 1985 * 1986 * @param env: The environment that the API is invoked under. 1987 * @param object: The object to query. 1988 * @param key: The name of the property to delete. 1989 * @param result: Whether the property deletion succeeded or not. result 1990 * can optionally be ignored by passing NULL. 1991 * @return Returns JSVM_OK if the API succeeded. 1992 * @since 11 1993 */ 1994 JSVM_EXTERN JSVM_Status OH_JSVM_DeleteProperty(JSVM_Env env, JSVM_Value object, JSVM_Value key, bool* result); 1995 1996 /** 1997 * @brief This API checks if the Object passed in has the named own property. 1998 * key must be a string or a symbol, or an error will be thrown. JSVM-API will 1999 * not perform any conversion between data types. 2000 * 2001 * @param env: The environment that the API is invoked under. 2002 * @param object: The object to query. 2003 * @param key: The name of the own property whose existence to check. 2004 * @param result: Whether the own property exists on the object or not. 2005 * @return Returns JSVM_OK if the API succeeded. 2006 * @since 11 2007 */ 2008 JSVM_EXTERN JSVM_Status OH_JSVM_HasOwnProperty(JSVM_Env env, JSVM_Value object, JSVM_Value key, bool* result); 2009 2010 /** 2011 * @brief This method is equivalent to calling OH_JSVM_SetProperty with 2012 * a JSVM_Value created from the string passed in as utf8Name. 2013 * 2014 * @param env: The environment that the API is invoked under. 2015 * @param object: The object on which to set the property. 2016 * @param utf8Name: The name of the property to set. 2017 * @param value: The property value. 2018 * @return Returns JSVM_OK if the API succeeded. 2019 * @since 11 2020 */ 2021 JSVM_EXTERN JSVM_Status OH_JSVM_SetNamedProperty(JSVM_Env env, 2022 JSVM_Value object, 2023 const char* utf8name, 2024 JSVM_Value value); 2025 2026 /** 2027 * @brief This method is equivalent to calling OH_JSVM_SetProperty with 2028 * a JSVM_Value created from the string passed in as utf8Name. 2029 * 2030 * @param env: The environment that the API is invoked under. 2031 * @param object: The object from which to retrieve the property. 2032 * @param utf8Name: The name of the property to get. 2033 * @param result: The value of the property. 2034 * @return Returns JSVM_OK if the API succeeded. 2035 * @since 11 2036 */ 2037 JSVM_EXTERN JSVM_Status OH_JSVM_GetNamedProperty(JSVM_Env env, 2038 JSVM_Value object, 2039 const char* utf8name, 2040 JSVM_Value* result); 2041 2042 /** 2043 * @brief This method is equivalent to calling OH_JSVM_SetProperty with 2044 * a JSVM_Value created from the string passed in as utf8Name. 2045 * 2046 * @param env: The environment that the API is invoked under. 2047 * @param object: The object to query. 2048 * @param utf8Name: The name of the property whose existence to check. 2049 * @param result: Whether the property exists on the object or not. 2050 * @return Returns JSVM_OK if the API succeeded. 2051 * @since 11 2052 */ 2053 JSVM_EXTERN JSVM_Status OH_JSVM_HasNamedProperty(JSVM_Env env, JSVM_Value object, const char* utf8name, bool* result); 2054 2055 /** 2056 * @brief This API sets an element on the Object passed in. 2057 * 2058 * @param env: The environment that the API is invoked under. 2059 * @param object: The object from which to set the properties. 2060 * @param index: The index of the property to set. 2061 * @param value: The property value. 2062 * @return Returns JSVM_OK if the API succeeded. 2063 * @since 11 2064 */ 2065 JSVM_EXTERN JSVM_Status OH_JSVM_SetElement(JSVM_Env env, JSVM_Value object, uint32_t index, JSVM_Value value); 2066 2067 /** 2068 * @brief This API gets the element at the requested index. 2069 * 2070 * @param env: The environment that the API is invoked under. 2071 * @param object: The object from which to retrieve the property. 2072 * @param index: The index of the property to get. 2073 * @param result: The value of the property. 2074 * @return Returns JSVM_OK if the API succeeded. 2075 * @since 11 2076 */ 2077 JSVM_EXTERN JSVM_Status OH_JSVM_GetElement(JSVM_Env env, JSVM_Value object, uint32_t index, JSVM_Value* result); 2078 2079 /** 2080 * @brief This API returns if the Object passed in has an element 2081 * at the requested index. 2082 * 2083 * @param env: The environment that the API is invoked under. 2084 * @param object: The object to query. 2085 * @param index: The index of the property whose existence to check. 2086 * @param result: Whether the property exists on the object or not. 2087 * @return Returns JSVM_OK if the API succeeded. 2088 * @since 11 2089 */ 2090 JSVM_EXTERN JSVM_Status OH_JSVM_HasElement(JSVM_Env env, JSVM_Value object, uint32_t index, bool* result); 2091 2092 /** 2093 * @brief This API attempts to delete the specified index from object. 2094 * 2095 * @param env: The environment that the API is invoked under. 2096 * @param object: The object to query. 2097 * @param index: The index of the property to delete. 2098 * @param result: Whether the element deletion succeeded or not. result 2099 * can optionally be ignored by passing NULL. 2100 * @return Returns JSVM_OK if the API succeeded. 2101 * @since 11 2102 */ 2103 JSVM_EXTERN JSVM_Status OH_JSVM_DeleteElement(JSVM_Env env, JSVM_Value object, uint32_t index, bool* result); 2104 2105 /** 2106 * @brief This method allows the efficient definition of multiple properties 2107 * on a given object. The properties are defined using property descriptors. 2108 * Given an array of such property descriptors, this API will set the properties 2109 * on the object one at a time, as defined by DefineOwnProperty(). 2110 * 2111 * @param env: The environment that the API is invoked under. 2112 * @param object: The object from which to retrieve the properties. 2113 * @param propertyCount: The number of elements in the properties array. 2114 * @param properties: The array of property descriptors. 2115 * @return Returns JSVM_OK if the API succeeded. 2116 * @since 11 2117 */ 2118 JSVM_EXTERN JSVM_Status OH_JSVM_DefineProperties(JSVM_Env env, 2119 JSVM_Value object, 2120 size_t propertyCount, 2121 const JSVM_PropertyDescriptor* properties); 2122 2123 /** 2124 * @brief This method freezes a given object. This prevents new properties 2125 * from being added to it, existing properties from being removed, prevents 2126 * changing the enumerability, configurability, or writability of existing 2127 * properties, and prevents the values of existing properties from being changed. 2128 * It also prevents the object's prototype from being changed. 2129 * 2130 * @param env: The environment that the API is invoked under. 2131 * @param object: The object to freeze. 2132 * @return Returns JSVM_OK if the API succeeded. 2133 * @since 11 2134 */ 2135 JSVM_EXTERN JSVM_Status OH_JSVM_ObjectFreeze(JSVM_Env env, JSVM_Value object); 2136 2137 /** 2138 * @brief This method seals a given object. This prevents new properties 2139 * from being added to it, as well as marking all existing properties as non-configurable. 2140 * 2141 * @param env: The environment that the API is invoked under. 2142 * @param object: The object to seal. 2143 * @return Returns JSVM_OK if the API succeeded. 2144 * @since 11 2145 */ 2146 JSVM_EXTERN JSVM_Status OH_JSVM_ObjectSeal(JSVM_Env env, JSVM_Value object); 2147 2148 /** 2149 * @brief This method allows a JavaScript function object to be called from 2150 * a native add-on. This is the primary mechanism of calling back from the 2151 * add-on's native code into JavaScript. 2152 * 2153 * @param env: The environment that the API is invoked under. 2154 * @param recv: The this value passed to the called function. 2155 * @param func: JSVM_Value representing the JavaScript function to be invoked. 2156 * @param argc: The count of elements in the argv array. 2157 * @param argv: Array of JSVM_values representing JavaScript values passed in as arguments to the function. 2158 * @param result: JSVM_Value representing the JavaScript object returned. 2159 * @return Returns JSVM_OK if the API succeeded. 2160 * @since 11 2161 */ 2162 JSVM_EXTERN JSVM_Status OH_JSVM_CallFunction(JSVM_Env env, 2163 JSVM_Value recv, 2164 JSVM_Value func, 2165 size_t argc, 2166 const JSVM_Value* argv, 2167 JSVM_Value* result); 2168 2169 /** 2170 * @brief This API allows an add-on author to create a function object in native 2171 * code. This is the primary mechanism to allow calling into the add-on's native 2172 * code from JavaScript.The newly created function is not automatically visible 2173 * from script after this call. Instead, a property must be explicitly set on any 2174 * object that is visible to JavaScript, in order for the function to be accessible 2175 * from script. 2176 * 2177 * @param env: The environment that the API is invoked under. 2178 * @param utf8Name: Optional name of the function encoded as UTF8. This is visible 2179 * within JavaScript as the new function object's name property. 2180 * @param length: The length of the utf8name in bytes, or JSVM_AUTO_LENGTH if it 2181 * is null-terminated. 2182 * @param cb: The native function which should be called when this function 2183 * object is invoked and data. JSVM_Callback provides more details. 2184 * @param result: JSVM_Value representing the JavaScript function object for the newly 2185 * created function. 2186 * @return Returns JSVM_OK if the API succeeded. 2187 * @since 11 2188 */ 2189 JSVM_EXTERN JSVM_Status OH_JSVM_CreateFunction(JSVM_Env env, 2190 const char* utf8name, 2191 size_t length, 2192 JSVM_Callback cb, 2193 JSVM_Value* result); 2194 2195 /** 2196 * @brief This method is used within a callback function to retrieve details about 2197 * the call like the arguments and the this pointer from a given callback info. 2198 * 2199 * @param env: The environment that the API is invoked under. 2200 * @param cbinfo: The callback info passed into the callback function. 2201 * @param argc: Specifies the length of the provided argv array and receives the 2202 * actual count of arguments. argc can optionally be ignored by passing NULL. 2203 * @param argv: C array of JSVM_values to which the arguments will be copied. If 2204 * there are more arguments than the provided count, only the requested number of 2205 * arguments are copied. If there are fewer arguments provided than claimed, the 2206 * rest of argv is filled with JSVM_Value values that represent undefined. argv 2207 * can optionally be ignored by passing NULL. 2208 * @param thisArg: Receives the JavaScript this argument for the call. thisArg 2209 * can optionally be ignored by passing NULL. 2210 * @param data: Receives the data pointer for the callback. data can optionally 2211 * be ignored by passing NULL. 2212 * @return Returns JSVM_OK if the API succeeded. 2213 * @since 11 2214 */ 2215 JSVM_EXTERN JSVM_Status OH_JSVM_GetCbInfo(JSVM_Env env, 2216 JSVM_CallbackInfo cbinfo, 2217 size_t* argc, 2218 JSVM_Value* argv, 2219 JSVM_Value* thisArg, 2220 void** data); 2221 2222 /** 2223 * @brief This API returns the new.target of the constructor call. If the 2224 * current callback is not a constructor call, the result is NULL. 2225 * 2226 * @param env: The environment that the API is invoked under. 2227 * @param cbinfo: The callback info passed into the callback function. 2228 * @param result: The new.target of the constructor call. 2229 * @return Returns JSVM_OK if the API succeeded. 2230 * @since 11 2231 */ 2232 JSVM_EXTERN JSVM_Status OH_JSVM_GetNewTarget(JSVM_Env env, JSVM_CallbackInfo cbinfo, JSVM_Value* result); 2233 2234 /** 2235 * @brief his method is used to instantiate a new JavaScript value using 2236 * a given JSVM_Value that represents the constructor for the object. 2237 * 2238 * @param env: The environment that the API is invoked under. 2239 * @param constructor: JSVM_Value representing the JavaScript function to be invoked as a constructor. 2240 * @param argc: The count of elements in the argv array. 2241 * @param argv: Array of JavaScript values as JSVM_Value representing the arguments to 2242 * the constructor. If argc is zero this parameter may be omitted by passing in NULL. 2243 * @param result: JSVM_Value representing the JavaScript object returned, which 2244 * in this case is the constructed object. 2245 * @return Returns JSVM_OK if the API succeeded. 2246 * @since 11 2247 */ 2248 JSVM_EXTERN JSVM_Status OH_JSVM_NewInstance(JSVM_Env env, 2249 JSVM_Value constructor, 2250 size_t argc, 2251 const JSVM_Value* argv, 2252 JSVM_Value* result); 2253 2254 /** 2255 * @brief When wrapping a C++ class, the C++ constructor callback passed via constructor 2256 * should be a static method on the class that calls the actual class constructor, then 2257 * wraps the new C++ instance in a JavaScript object, and returns the wrapper object. 2258 * 2259 * @param env: The environment that the API is invoked under. 2260 * @param utf8name: Name of the JavaScript constructor function. For clarity, it is 2261 * recommended to use the C++ class name when wrapping a C++ class. 2262 * @param length: The length of the utf8name in bytes, or JSVM_AUTO_LENGTH if it 2263 * is null-terminated. 2264 * @param constructor: Struct include callback function that handles constructing instances of the class. 2265 * When wrapping a C++ class, this method must be a static member with the JSVM_Callback.callback 2266 * signature. A C++ class constructor cannot be used. 2267 * Include Optional data to be passed to the constructor callback as the data 2268 * property of the callback info. JSVM_Callback provides more details. 2269 * @param propertyCount: Number of items in the properties array argument. 2270 * @param properties: Array of property descriptors describing static and instance data 2271 * properties, accessors, and methods on the class See JSVM_PropertyDescriptor. 2272 * @param result: A JSVM_Value representing the constructor function for the class. 2273 * @return Returns JSVM_OK if the API succeeded. 2274 * @since 11 2275 */ 2276 JSVM_EXTERN JSVM_Status OH_JSVM_DefineClass(JSVM_Env env, 2277 const char* utf8name, 2278 size_t length, 2279 JSVM_Callback constructor, 2280 size_t propertyCount, 2281 const JSVM_PropertyDescriptor* properties, 2282 JSVM_Value* result); 2283 2284 /** 2285 * @brief Wraps a native instance in a JavaScript object. The native instance can 2286 * be retrieved later using OH_JSVM_Unwrap(). 2287 * 2288 * @param env: The environment that the API is invoked under. 2289 * @param jsObject: The JavaScript object that will be the wrapper for the native object. 2290 * @param nativeObject: The native instance that will be wrapped in the JavaScript object. 2291 * @param finalizeCb: Optional native callback that can be used to free the native instance 2292 * when the JavaScript object has been garbage-collected. 2293 * @param finalizeHint: Optional contextual hint that is passed to the finalize callback. 2294 * properties, accessors, and methods on the class See JSVM_PropertyDescriptor. 2295 * @param result: Optional reference to the wrapped object. 2296 * @return Returns JSVM_OK if the API succeeded. 2297 * @since 11 2298 */ 2299 JSVM_EXTERN JSVM_Status OH_JSVM_Wrap(JSVM_Env env, 2300 JSVM_Value jsObject, 2301 void* nativeObject, 2302 JSVM_Finalize finalizeCb, 2303 void* finalizeHint, 2304 JSVM_Ref* result); 2305 2306 /** 2307 * @brief When JavaScript code invokes a method or property accessor on the class, the corresponding 2308 * JSVM_Callback is invoked. If the callback is for an instance method or accessor, then the this 2309 * argument to the callback is the wrapper object; the wrapped C++ instance that is the target of 2310 * the call can be obtained then by calling OH_JSVM_Unwrap() on the wrapper object. 2311 * 2312 * @param env: The environment that the API is invoked under. 2313 * @param jsObject: The object associated with the native instance. 2314 * @param result: Pointer to the wrapped native instance. 2315 * @return Returns JSVM_OK if the API succeeded. 2316 * @since 11 2317 */ 2318 JSVM_EXTERN JSVM_Status OH_JSVM_Unwrap(JSVM_Env env, JSVM_Value jsObject, void** result); 2319 2320 /** 2321 * @brief Retrieves a native instance that was previously wrapped in the JavaScript object jsObject 2322 * using OH_JSVM_Wrap() and removes the wrapping. If a finalize callback was associated with the wrapping, 2323 * it will no longer be called when the JavaScript object becomes garbage-collected. 2324 * 2325 * @param env: The environment that the API is invoked under. 2326 * @param jsObject: The object associated with the native instance. 2327 * @param result: Pointer to the wrapped native instance. 2328 * @return Returns JSVM_OK if the API succeeded. 2329 * @since 11 2330 */ 2331 JSVM_EXTERN JSVM_Status OH_JSVM_RemoveWrap(JSVM_Env env, JSVM_Value jsObject, void** result); 2332 2333 /** 2334 * @brief Associates the value of the typeTag pointer with the JavaScript object or external. 2335 * OH_JSVM_CheckObjectTypeTag() can then be used to compare the tag that was attached to the 2336 * object with one owned by the addon to ensure that the object has the right type. 2337 * If the object already has an associated type tag, this API will return JSVM_INVALID_ARG. 2338 * 2339 * @param env: The environment that the API is invoked under. 2340 * @param value: The JavaScript object or external to be marked. 2341 * @param typeTag: The tag with which the object is to be marked. 2342 * @return Returns JSVM_OK if the API succeeded. 2343 * @since 11 2344 */ 2345 JSVM_EXTERN JSVM_Status OH_JSVM_TypeTagObject(JSVM_Env env, JSVM_Value value, const JSVM_TypeTag* typeTag); 2346 2347 /** 2348 * @brief Compares the pointer given as typeTag with any that can be found on js object. 2349 * If no tag is found on js object or, if a tag is found but it does not match typeTag, 2350 * then result is set to false. If a tag is found and it matches typeTag, then result is set to true. 2351 * 2352 * @param env: The environment that the API is invoked under. 2353 * @param value: The JavaScript object or external whose type tag to examine. 2354 * @param typeTag: The tag with which to compare any tag found on the object. 2355 * @param result: Whether the type tag given matched the type tag on the object. false is also returned 2356 * if no type tag was found on the object. 2357 * @return Returns JSVM_OK if the API succeeded. 2358 * @since 11 2359 */ 2360 JSVM_EXTERN JSVM_Status OH_JSVM_CheckObjectTypeTag(JSVM_Env env, 2361 JSVM_Value value, 2362 const JSVM_TypeTag* typeTag, 2363 bool* result); 2364 2365 /** 2366 * @brief This API can be called multiple times on a single JavaScript object. 2367 * 2368 * @param env: The environment that the API is invoked under. 2369 * @param jsObject: The JavaScript object to which the native data will be attached. 2370 * @param finalizeData: Optional data to be passed to finalizeCb. 2371 * @param finalizeCb: Native callback that will be used to free the native data when the 2372 * JavaScript object has been garbage-collected. JSVM_Finalize provides more details. 2373 * @param finalizeHint: Optional contextual hint that is passed to the finalize callback. 2374 * @param result: Optional reference to the JavaScript object. 2375 * @return Returns JSVM_OK if the API succeeded. 2376 * @since 11 2377 */ 2378 JSVM_EXTERN JSVM_Status OH_JSVM_AddFinalizer(JSVM_Env env, 2379 JSVM_Value jsObject, 2380 void* finalizeData, 2381 JSVM_Finalize finalizeCb, 2382 void* finalizeHint, 2383 JSVM_Ref* result); 2384 2385 /** 2386 * @brief This API returns the highest JSVM-API version supported by the JSVM runtime. 2387 * 2388 * JSVM-API is planned to be additive such that newer releases of JSVM may support additional 2389 * API functions. In order to allow an addon to use a newer function when running with versions 2390 * of JSVM that support it, while providing fallback behavior when running with JSVM 2391 * versions that don't support it. 2392 * @param env: The environment that the API is invoked under. 2393 * @param result: The highest version of JSVM-API supported. 2394 * @return Returns JSVM_OK if the API succeeded. 2395 * @since 11 2396 */ 2397 JSVM_EXTERN JSVM_Status OH_JSVM_GetVersion(JSVM_Env env, uint32_t* result); 2398 2399 /** 2400 * @brief Return information of the VM. 2401 * 2402 * @param result: The information of the VM. 2403 * @return Returns JSVM_OK if the API succeeded. 2404 * @since 11 2405 */ 2406 JSVM_EXTERN JSVM_Status OH_JSVM_GetVMInfo(JSVM_VMInfo* result); 2407 2408 /** 2409 * @brief This function gives V8 an indication of the amount of externally 2410 * allocated memory that is kept alive by JavaScript objects (i.e. a JavaScript 2411 * object that points to its own memory allocated by a native addon). Registering 2412 * externally allocated memory will trigger global garbage collections more often 2413 * than it would otherwise. 2414 * 2415 * @param env: The environment that the API is invoked under. 2416 * @param changeInBytes: The change in externally allocated memory that is kept 2417 * alive by JavaScript objects. 2418 * @param result: The adjusted value 2419 * @return Returns JSVM_OK if the API succeeded. 2420 * @since 11 2421 */ 2422 JSVM_EXTERN JSVM_Status OH_JSVM_AdjustExternalMemory(JSVM_Env env, int64_t changeInBytes, int64_t* result); 2423 2424 /** 2425 * @brief This function notifies the VM that the system is running low on memory 2426 * and optionally triggers a garbage collection. 2427 * 2428 * @param env: The environment that the API is invoked under. 2429 * @param level: The memory pressure level set to the current VM. 2430 * @return Returns JSVM_OK if the API succeeded. 2431 * @since 11 2432 */ 2433 JSVM_EXTERN JSVM_Status OH_JSVM_MemoryPressureNotification(JSVM_Env env, JSVM_MemoryPressureLevel level); 2434 2435 /** 2436 * @brief This API creates a deferred object and a JavaScript promise. 2437 * 2438 * @param env: The environment that the API is invoked under. 2439 * @param deferred: A newly created deferred object which can later be 2440 * passed to OH_JSVM_ResolveDeferred() or OH_JSVM_RejectDeferred() to resolve 2441 * resp. reject the associated promise. 2442 * @param promise: The JavaScript promise associated with the deferred object. 2443 * @return Returns JSVM_OK if the API succeeded. 2444 * @since 11 2445 */ 2446 JSVM_EXTERN JSVM_Status OH_JSVM_CreatePromise(JSVM_Env env, JSVM_Deferred* deferred, JSVM_Value* promise); 2447 2448 /** 2449 * @brief This API resolves a JavaScript promise by way of the deferred object with 2450 * which it is associated. Thus, it can only be used to resolve JavaScript promises 2451 * for which the corresponding deferred object is available. This effectively means 2452 * that the promise must have been created using OH_JSVM_CreatePromise() and the deferred 2453 * object returned from that call must have been retained in order to be passed to this API. 2454 * 2455 * @param env: The environment that the API is invoked under. 2456 * @param deferred: The deferred object whose associated promise to resolve. 2457 * @param resolution: The value with which to resolve the promise. 2458 * @return Returns JSVM_OK if the API succeeded. 2459 * @since 11 2460 */ 2461 JSVM_EXTERN JSVM_Status OH_JSVM_ResolveDeferred(JSVM_Env env, JSVM_Deferred deferred, JSVM_Value resolution); 2462 2463 /** 2464 * @brief This API rejects a JavaScript promise by way of the deferred object with 2465 * which it is associated. Thus, it can only be used to reject JavaScript promises 2466 * for which the corresponding deferred object is available. This effectively means 2467 * that the promise must have been created using OH_JSVM_CreatePromise() and the deferred 2468 * object returned from that call must have been retained in order to be passed to this API. 2469 * 2470 * @param env: The environment that the API is invoked under. 2471 * @param deferred: The deferred object whose associated promise to resolve. 2472 * @param rejection: The value with which to reject the promise. 2473 * @return Returns JSVM_OK if the API succeeded. 2474 * @since 11 2475 */ 2476 JSVM_EXTERN JSVM_Status OH_JSVM_RejectDeferred(JSVM_Env env, JSVM_Deferred deferred, JSVM_Value rejection); 2477 2478 /** 2479 * @brief This API return indicating whether promise is a native promise object. 2480 * @param env: The environment that the API is invoked under. 2481 * @param value: The value to examine 2482 * @param isPromise: Flag indicating whether promise is a native promise object 2483 * @return Returns JSVM_OK if the API succeeded. 2484 * @since 11 2485 */ 2486 JSVM_EXTERN JSVM_Status OH_JSVM_IsPromise(JSVM_Env env, JSVM_Value value, bool* isPromise); 2487 2488 /** 2489 * @brief This API register a resolution/rejection handler with a promise. 2490 * @param env The environment that the API is invoked under. 2491 * @param promise The promise to be handled. 2492 * @param onFulfilled The function to be invoked if promise is resolved. 2493 * @param onRejected The function to be invoked if promise is rejected. 2494 * @param result Another promise returned from promise then/catch method. 2495 * @return Returns JSVM functions result code. 2496 * {@link JSVM_OK } if the API succeeded. \n 2497 * {@link JSVM_INVALID_ARG } if the arguments are invalid. \n 2498 * {@link JSVM_INVALID_TYPE } if the arguments are invalid Javascript type. \n 2499 * {@link JSVM_PENDING_EXCEPTION} if an exception occurs. \n 2500 * {@link JSVM_GENERIC_FAILURE} if the API failed. \n 2501 * 2502 * @since 16 2503 */ 2504 JSVM_EXTERN JSVM_Status OH_JSVM_PromiseRegisterHandler(JSVM_Env env, 2505 JSVM_Value promise, 2506 JSVM_Value onFulfilled, 2507 JSVM_Value onRejected, 2508 JSVM_Value* result); 2509 2510 /** 2511 * @brief This API parses a JSON string and returns it as value if successful. 2512 * @param env: The environment that the API is invoked under. 2513 * @param jsonString: The string to parse. 2514 * @param result: The parse value if successful. 2515 * @return Returns JSVM_OK if the API succeeded. 2516 * @since 11 2517 */ 2518 JSVM_EXTERN JSVM_Status OH_JSVM_JsonParse(JSVM_Env env, JSVM_Value jsonString, JSVM_Value* result); 2519 2520 /** 2521 * @brief This API stringifies the object and returns it as string if successful. 2522 * @param env: The environment that the API is invoked under. 2523 * @param jsonObject: The object to stringify. 2524 * @param result: The string if successfully stringified. 2525 * @return Returns JSVM_OK if the API succeeded. 2526 * @since 11 2527 */ 2528 JSVM_EXTERN JSVM_Status OH_JSVM_JsonStringify(JSVM_Env env, JSVM_Value jsonObject, JSVM_Value* result); 2529 2530 /** 2531 * @brief This API create the startup snapshot of the VM. 2532 * @param vm: The environment that the API is invoked under. 2533 * @param contextCount: The object to stringify. 2534 * @param contexts: The array of contexts to add to the snapshot. 2535 * @param blobData: The snapshot data. 2536 * @param blobSize: The size of snapshot data. 2537 * @return Returns JSVM_OK if the API succeeded. 2538 * @since 11 2539 */ 2540 JSVM_EXTERN JSVM_Status OH_JSVM_CreateSnapshot(JSVM_VM vm, 2541 size_t contextCount, 2542 const JSVM_Env* contexts, 2543 const char** blobData, 2544 size_t* blobSize); 2545 2546 /** 2547 * @brief This function returns a set of statistics data of the heap of the VM. 2548 * 2549 * @param vm: The VM whose heap statistics are returned. 2550 * @param result: The heap statistics data. 2551 * @return Returns JSVM_OK if the API succeeded. 2552 * @since 12 2553 */ 2554 JSVM_EXTERN JSVM_Status OH_JSVM_GetHeapStatistics(JSVM_VM vm, JSVM_HeapStatistics* result); 2555 2556 /** 2557 * @brief This function creates and starts a CPU profiler. 2558 * 2559 * @param vm: The VM to start CPU profiler for. 2560 * @param result: The pointer to the CPU profiler. 2561 * @return Returns JSVM_OK if the API succeeded. 2562 * @since 12 2563 */ 2564 JSVM_EXTERN JSVM_Status OH_JSVM_StartCpuProfiler(JSVM_VM vm, JSVM_CpuProfiler* result); 2565 2566 /** 2567 * @brief This function stops the CPU profiler and output to the stream. 2568 * 2569 * @param vm: THe VM to start CPU profiler for. 2570 * @param profiler: The CPU profiler to stop. 2571 * @param stream: The output stream callback for receiving the data. 2572 * @param streamData: Optional data to be passed to the stream callback. 2573 * @return Returns JSVM_OK if the API succeeded. 2574 * @since 12 2575 */ 2576 JSVM_EXTERN JSVM_Status OH_JSVM_StopCpuProfiler(JSVM_VM vm, 2577 JSVM_CpuProfiler profiler, 2578 JSVM_OutputStream stream, 2579 void* streamData); 2580 2581 /** 2582 * @brief This funciton takes the current heap snapshot and output to the stream. 2583 * 2584 * @param vm: The VM whose heap snapshot is taken. 2585 * @param stream: The output stream callback for receiving the data. 2586 * @param streamData: Optional data to be passed to the stream callback. 2587 * @return Returns JSVM_OK if the API succeeded. 2588 * @since 12 2589 */ 2590 JSVM_EXTERN JSVM_Status OH_JSVM_TakeHeapSnapshot(JSVM_VM vm, JSVM_OutputStream stream, void* streamData); 2591 2592 /** 2593 * @brief This functiong activates insepctor on host and port. 2594 * 2595 * @param env: The environment that the API is invoked under. 2596 * @param host: The host to listen to for inspector connections. 2597 * @param port: The port to listen to for inspector connections. 2598 * @return Returns JSVM_OK if the API succeeded. 2599 * @since 12 2600 */ 2601 JSVM_EXTERN JSVM_Status OH_JSVM_OpenInspector(JSVM_Env env, const char* host, uint16_t port); 2602 2603 /** 2604 * @brief This function attempts to close all remaining inspector connections. 2605 * 2606 * @param env: The environment that the API is invoked under. 2607 * @return Returns JSVM_OK if the API succeeded. 2608 * @since 12 2609 */ 2610 JSVM_EXTERN JSVM_Status OH_JSVM_CloseInspector(JSVM_Env env); 2611 2612 /** 2613 * @brief This function will block until a client (existing or connected later) 2614 * has sent Runtime.runIfWaitingForDebugger command. 2615 * 2616 * @param env: The environment that the API is invoked under. 2617 * @param breakNextLine: Whether break on the next line of JavaScript code. 2618 * @return Returns JSVM_OK if the API succeeded. 2619 * @since 12 2620 */ 2621 JSVM_EXTERN JSVM_Status OH_JSVM_WaitForDebugger(JSVM_Env env, bool breakNextLine); 2622 2623 /** 2624 * @brief When packaging C++classes, the C++constructor callback passed through the constructor 2625 * triggers the corresponding callback function when getter, setter, call, and other 2626 * behaviors occur on the instance object, handles the user's custom behavior, and then wraps 2627 * the new C++instance in a JavaScript object and returns the wrapper object. 2628 * 2629 * @param env: The environment that the API is invoked under. 2630 * @param utf8name: Name of the JavaScript constructor function. For clarity, it is 2631 * recommended to use the C++ class name when wrapping a C++ class. 2632 * @param length: The length of the utf8name in bytes, or JSVM_AUTO_LENGTH if it 2633 * is null-terminated. 2634 * @param constructor: Struct include callback function that handles constructing instances of the class. 2635 * When wrapping a C++ class, this method must be a static member with the JSVM_Callback.callback 2636 * signature. A C++ class constructor cannot be used. 2637 * Include Optional data to be passed to the constructor callback as the data 2638 * property of the callback info. JSVM_Callback provides more details. 2639 * @param propertyCount: Number of items in the properties array argument. 2640 * @param properties: Array of property descriptors describing static and instance data 2641 * properties, accessors, and methods on the class See JSVM_PropertyDescriptor. 2642 * @param propertyHandlerCfg: The instance object triggers the corresponding callback function. 2643 * @param callAsFunctionCallback: Calling an instance object as a function will trigger this callback. 2644 * @param result: A JSVM_Value representing the constructor function for the class. 2645 * @return Returns JSVM_OK if the API succeeded. 2646 * @since 12 2647 */ 2648 JSVM_EXTERN JSVM_Status OH_JSVM_DefineClassWithPropertyHandler(JSVM_Env env, 2649 const char* utf8name, 2650 size_t length, 2651 JSVM_Callback constructor, 2652 size_t propertyCount, 2653 const JSVM_PropertyDescriptor* properties, 2654 JSVM_PropertyHandlerCfg propertyHandlerCfg, 2655 JSVM_Callback callAsFunctionCallback, 2656 JSVM_Value* result); 2657 2658 /** 2659 * @brief Determines whether the current thread holds the lock for the specified environment. 2660 * Only threads that hold locks can use the environment. 2661 * 2662 * @param env: The environment that the API is invoked under. 2663 * @param isLocked: Flag indicating whether the current thread holds the lock for the specified environment. 2664 * @return Returns JSVM_OK if the API succeeded. 2665 * @since 12 2666 */ 2667 JSVM_EXTERN JSVM_Status OH_JSVM_IsLocked(JSVM_Env env, bool* isLocked); 2668 2669 /** 2670 * @brief Acquire the lock for the specified environment. Only threads that hold locks can use the environment. 2671 * 2672 * @param env: The environment that the API is invoked under. 2673 * @return Returns JSVM_OK if the API succeeded. 2674 * @since 12 2675 */ 2676 JSVM_EXTERN JSVM_Status OH_JSVM_AcquireLock(JSVM_Env env); 2677 2678 /** 2679 * @brief Release the lock for the specified environment. Only threads that hold locks can use the environment. 2680 * 2681 * @param env: The environment that the API is invoked under. 2682 * @return Returns JSVM_OK if the API succeeded. 2683 * @since 12 2684 */ 2685 JSVM_EXTERN JSVM_Status OH_JSVM_ReleaseLock(JSVM_Env env); 2686 2687 /** 2688 * @brief Starts the running of the task queue inside the VM. 2689 * This task queue can be executed by an external event loop. 2690 * 2691 * @param env: The VM instance on which to start the task queue. 2692 * @param result: Whether the task queue was successfully started. 2693 * @return Returns JSVM_OK if the API succeeded. 2694 * @since 12 2695 */ 2696 JSVM_EXTERN JSVM_Status OH_JSVM_PumpMessageLoop(JSVM_VM vm, bool* result); 2697 2698 /** 2699 * @brief Check to see if there are any microtasks waiting in the queue, and if there are, execute them. 2700 * 2701 * @param env: The VM instance on which to check microtasks. 2702 * @return Returns JSVM_OK if the API succeeded. 2703 * @since 12 2704 */ 2705 JSVM_EXTERN JSVM_Status OH_JSVM_PerformMicrotaskCheckpoint(JSVM_VM vm); 2706 2707 /** 2708 * @brief This API checks if the value passed in is callable. 2709 * 2710 * @param env: The VM instance on which to check microtasks. 2711 * @param value: The JavaScript value to check. 2712 * @param isCallable: Whether the given value is callable. 2713 * @return Returns JSVM_OK if the API succeeded. 2714 * @since 12 2715 */ 2716 JSVM_EXTERN JSVM_Status OH_JSVM_IsCallable(JSVM_Env env, JSVM_Value value, bool* isCallable); 2717 2718 /** 2719 * @brief This API checks if the value passed in is undefined. 2720 * This equals to `value === undefined` in JS. 2721 * 2722 * @param env: The VM instance on which to check microtasks. 2723 * @param value: The JavaScript value to check. 2724 * @param isUndefined: Whether the given value is Undefined. 2725 * @return Only returns JSVM_OK, because this API will not trigger any exception. 2726 * @since 12 2727 */ 2728 JSVM_EXTERN JSVM_Status OH_JSVM_IsUndefined(JSVM_Env env, JSVM_Value value, bool* isUndefined); 2729 2730 /** 2731 * @brief This API checks if the value passed in is a null object. 2732 * This equals to `value === null` in JS. 2733 * 2734 * @param env: The VM instance on which to check microtasks. 2735 * @param value: The JavaScript value to check. 2736 * @param isNull: Whether the given value is Null. 2737 * @return Only returns JSVM_OK, because this API will not trigger any exception. 2738 * @since 12 2739 */ 2740 JSVM_EXTERN JSVM_Status OH_JSVM_IsNull(JSVM_Env env, JSVM_Value value, bool* isNull); 2741 2742 /** 2743 * @brief This API checks if the value passed in is either a null or an undefined object. 2744 * This is equivalent to `value == null` in JS. 2745 * 2746 * @param env: The VM instance on which to check microtasks. 2747 * @param value: The JavaScript value to check. 2748 * @param isNullOrUndefined: Whether the given value is Null or Undefined. 2749 * @return Only returns JSVM_OK, because this API will not trigger any exception. 2750 * @since 12 2751 */ 2752 JSVM_EXTERN JSVM_Status OH_JSVM_IsNullOrUndefined(JSVM_Env env, JSVM_Value value, bool* isNullOrUndefined); 2753 2754 /** 2755 * @brief This API checks if the value passed in is a boolean. 2756 * This equals to `typeof value === 'boolean'` in JS. 2757 * 2758 * @param env: The VM instance on which to check microtasks. 2759 * @param value: The JavaScript value to check. 2760 * @param isBoolean: Whether the given value is Boolean. 2761 * @return Only returns JSVM_OK, because this API will not trigger any exception. 2762 * @since 12 2763 */ 2764 JSVM_EXTERN JSVM_Status OH_JSVM_IsBoolean(JSVM_Env env, JSVM_Value value, bool* isBoolean); 2765 2766 /** 2767 * @brief This API checks if the value passed in is a number. 2768 * This equals to `typeof value === 'number'` in JS. 2769 * 2770 * @param env: The VM instance on which to check microtasks. 2771 * @param value: The JavaScript value to check. 2772 * @param isNumber: Whether the given value is Number. 2773 * @return Only returns JSVM_OK, because this API will not trigger any exception. 2774 * @since 12 2775 */ 2776 JSVM_EXTERN JSVM_Status OH_JSVM_IsNumber(JSVM_Env env, JSVM_Value value, bool* isNumber); 2777 2778 /** 2779 * @brief This API checks if the value passed in is a string. 2780 * This equals to `typeof value === 'string'` in JS. 2781 * 2782 * @param env: The VM instance on which to check microtasks. 2783 * @param value: The JavaScript value to check. 2784 * @param isString: Whether the given value is String. 2785 * @return Only returns JSVM_OK, because this API will not trigger any exception. 2786 * @since 12 2787 */ 2788 JSVM_EXTERN JSVM_Status OH_JSVM_IsString(JSVM_Env env, JSVM_Value value, bool* isString); 2789 2790 /** 2791 * @brief This API checks if the value passed in is a symbol. 2792 * This equals to `typeof value === 'symbol'` in JS. 2793 * 2794 * @param env: The VM instance on which to check microtasks. 2795 * @param value: The JavaScript value to check. 2796 * @param isSymbol: Whether the given value is Symbol. 2797 * @return Only returns JSVM_OK, because this API will not trigger any exception. 2798 * @since 12 2799 */ 2800 JSVM_EXTERN JSVM_Status OH_JSVM_IsSymbol(JSVM_Env env, JSVM_Value value, bool* isSymbol); 2801 2802 /** 2803 * @brief This API checks if the value passed in is a function. 2804 * This equals to `typeof value === 'function'` in JS. 2805 * 2806 * @param env: The VM instance on which to check microtasks. 2807 * @param value: The JavaScript value to check. 2808 * @param isFunction: Whether the given value is Function. 2809 * @return Only returns JSVM_OK, because this API will not trigger any exception. 2810 * @since 12 2811 */ 2812 JSVM_EXTERN JSVM_Status OH_JSVM_IsFunction(JSVM_Env env, JSVM_Value value, bool* isFunction); 2813 2814 /** 2815 * @brief This API checks if the value passed in is an object. 2816 * 2817 * @param env: The VM instance on which to check microtasks. 2818 * @param value: The JavaScript value to check. 2819 * @param isObject: Whether the given value is Object. 2820 * @return Only returns JSVM_OK, because this API will not trigger any exception. 2821 * @since 12 2822 */ 2823 JSVM_EXTERN JSVM_Status OH_JSVM_IsObject(JSVM_Env env, JSVM_Value value, bool* isObject); 2824 2825 /** 2826 * @brief This API checks if the value passed in is a bigInt. 2827 * This equals to `typeof value === 'bigint'` in JS. 2828 * 2829 * @param env: The VM instance on which to check microtasks. 2830 * @param value: The JavaScript value to check. 2831 * @param isBigInt: Whether the given value is BigInt. 2832 * @return Only returns JSVM_OK, because this API will not trigger any exception. 2833 * @since 12 2834 */ 2835 JSVM_EXTERN JSVM_Status OH_JSVM_IsBigInt(JSVM_Env env, JSVM_Value value, bool* isBigInt); 2836 2837 /** 2838 * @brief This API checks if the value passed in is a constructor. 2839 * 2840 * @param env: The environment that the API is invoked under. 2841 * @param value: The JavaScript value to check. 2842 * @param isConstructor: Whether the given value is Constructor. 2843 * @return Returns JSVM_OK if the API succeeded. Returns JSVM_INVALID_ARG if the API failed. 2844 * @since 12 2845 */ 2846 JSVM_EXTERN JSVM_Status OH_JSVM_IsConstructor(JSVM_Env env, JSVM_Value value, bool* isConstructor); 2847 2848 /** 2849 * @brief This API returns the JavaScript value of the regular expression 2850 * corresponding to the input. 2851 * The interface may throw an exception. 2852 * 2853 * @param env: The environment that the API is invoked under. 2854 * @param value: The JavaScript string to convert to a regular expression. 2855 * @param flags: Regular expression flag bits. 2856 * @param result: A JSVM_Value representing a JavaScript RegExp. 2857 * @return Only returns JSVM function's result code. 2858 * {@link JSVM_OK } If the API succeeded.\n 2859 * {@link JSVM_INVALID_ARG } If the input parameter is invalid.\n 2860 * {@link JSVM_STRING_EXPECTED } If the value of 'value' is not a string.\n 2861 * {@link JSVM_GENERIC_FAILURE } If create RegExp failed.\n 2862 * {@link JSVM_PENDING_EXCEPTION } If the API throws an exception during runtime.\n 2863 * @since 12 2864 */ 2865 JSVM_EXTERN JSVM_Status OH_JSVM_CreateRegExp(JSVM_Env env, 2866 JSVM_Value value, 2867 JSVM_RegExpFlags flags, 2868 JSVM_Value* result); 2869 2870 /** 2871 * @brief This API returns a JSVM-API value corresponding to a JavaScript Map type. 2872 * 2873 * @param env: The environment that the API is invoked under. 2874 * @param result: A JSVM_Value representing a JavaScript Map. 2875 * @return Returns JSVM_OK if the API succeeded. Returns JSVM_INVALID_ARG if the API failed. 2876 * @since 12 2877 */ 2878 JSVM_EXTERN JSVM_Status OH_JSVM_CreateMap(JSVM_Env env, JSVM_Value* result); 2879 2880 /** 2881 * @brief This API checks if the value passed in is a Map. 2882 * 2883 * @param env: The environment that the API is invoked under. 2884 * @param value: The JavaScript value to check. 2885 * @param isMap: Whether the given value is Map. 2886 * @return Returns JSVM_OK if the API succeeded. Returns JSVM_INVALID_ARG if the API failed. 2887 * @since 12 2888 */ 2889 JSVM_EXTERN JSVM_Status OH_JSVM_IsMap(JSVM_Env env, JSVM_Value value, bool* isMap); 2890 2891 /** 2892 * @brief This API returns a JSVM-API value corresponding to a JavaScript Set type. 2893 * 2894 * @param env: The environment that the API is invoked under. 2895 * @param result: A JSVM_Value representing a JavaScript Set. 2896 * @return Returns JSVM_OK if the API succeeded. 2897 * @since 12 2898 */ 2899 JSVM_EXTERN JSVM_Status OH_JSVM_CreateSet(JSVM_Env env, JSVM_Value* result); 2900 2901 /** 2902 * @brief This API checks if the value passed in is a Set. 2903 * 2904 * @param env: The environment that the API is invoked under. 2905 * @param value: The JavaScript value to check. 2906 * @param isSet: Whether the given value is Set. 2907 * @return Returns JSVM_OK if the API succeeded. 2908 * @since 12 2909 */ 2910 JSVM_EXTERN JSVM_Status OH_JSVM_IsSet(JSVM_Env env, JSVM_Value value, bool* isSet); 2911 2912 /** 2913 * @brief This API returns the Object prototype. 2914 * 2915 * @param env: The environment that the API is invoked under. 2916 * @param object: JSVM_Value representing JavaScript Object whose prototype to return. 2917 * @param result: JSVM_Value representing prototype of the given object. 2918 * @return Returns JSVM_OK if the API succeeded. 2919 * @since 12 2920 */ 2921 JSVM_EXTERN JSVM_Status OH_JSVM_ObjectGetPrototypeOf(JSVM_Env env, JSVM_Value object, JSVM_Value* result); 2922 2923 /** 2924 * @brief This API set the prototype on the Object passed in. 2925 * 2926 * @param env: The environment that the API is invoked under. 2927 * @param object: The object on which to set the prototype. 2928 * @param prototype: The prototype value. 2929 * @return Returns JSVM_OK if the API succeeded. 2930 * @since 12 2931 */ 2932 JSVM_EXTERN JSVM_Status OH_JSVM_ObjectSetPrototypeOf(JSVM_Env env, JSVM_Value object, JSVM_Value prototype); 2933 2934 /** 2935 * @brief This API implements the abstract operation `ToBigInt()`. 2936 * 2937 * @param env: The environment that the API is invoked under. 2938 * @param value: The JavaScript value to coerce. 2939 * @param result: JSVM_Value representing the coerced JavaScript BigInt. 2940 * @return Returns JSVM_OK if the API succeeded. Returns JSVM_BIGINT_EXPECTED if the 2941 * JavaScript value fails to coerce. 2942 * @since 12 2943 */ 2944 JSVM_EXTERN JSVM_Status OH_JSVM_CoerceToBigInt(JSVM_Env env, JSVM_Value value, JSVM_Value* result); 2945 2946 /** 2947 * @brief This API checks if the value passed in is a JavaScript RegExp object. 2948 * 2949 * @param env: The environment that the API is invoked under. 2950 * @param value: The JavaScript value to check. 2951 * @param result: Whether the given value is RegExp. 2952 * @return Returns JSVM_OK if the API succeeded. 2953 * @since 12 2954 */ 2955 JSVM_EXTERN JSVM_Status OH_JSVM_IsRegExp(JSVM_Env env, JSVM_Value value, bool* result); 2956 2957 /** 2958 * @brief Creates a function with a given script as its body. 2959 * 2960 * @param env: The environment that the API is invoked under. 2961 * @param funcName: A string containing the function's name. Pass NULL to create an anonymous function. 2962 * @param length: The length of the funcName in bytes, or JSVM_AUTO_LENGTH if it 2963 * is null-terminated. 2964 * @param argc: The count of elements in the argv array. 2965 * @param argv: Array of JSVM_Values representing JavaScript strings passed in as arguments to the function. 2966 * @param script: A JavaScript string containing the script to use as the function's body. 2967 * @param result: JSVM_Value representing the JavaScript function object for the newly 2968 * created function. 2969 * @return Returns JSVM_OK if the API succeeded. Returns JSVM_GENERIC_FAILURE if the input script fails to 2970 * be compiled. 2971 * @since 12 2972 */ 2973 JSVM_EXTERN JSVM_Status OH_JSVM_CreateFunctionWithScript(JSVM_Env env, 2974 const char* funcName, 2975 size_t length, 2976 size_t argc, 2977 const JSVM_Value* argv, 2978 JSVM_Value script, 2979 JSVM_Value* result); 2980 2981 /** 2982 * @brief This function keep persistently save a JSVM_Script and extend its lifecycle 2983 * beyond the current scope. 2984 * 2985 * @param env: The environment that the API is invoked under. 2986 * @param script: A JavaScript string containing the script to be retained. 2987 * @return Returns JSVM functions result code 2988 * {@link JSVM_OK } if the API succeeded. \n 2989 * {@link JSVM_INVALID_ARG } if the script is empty or already retained. \n 2990 * @since 12 2991 */ 2992 JSVM_EXTERN JSVM_Status OH_JSVM_RetainScript(JSVM_Env env, JSVM_Script script); 2993 2994 /** 2995 * @brief This function release the script retained by OH_JSVM_RetainScript 2996 * 2997 * @param env: The environment that the API is invoked under. 2998 * @param script: A JavaScript string containing the script to be retained. 2999 * @return Returns JSVM functions result code 3000 * {@link JSVM_OK } if the API succeeded. \n 3001 * {@link JSVM_INVALID_ARG } if the script is empty or not retained. \n 3002 * @since 12 3003 */ 3004 JSVM_EXTERN JSVM_Status OH_JSVM_ReleaseScript(JSVM_Env env, JSVM_Script script); 3005 3006 /** 3007 * @brief This function activates insepctor with pid and alias it. 3008 * 3009 * @param env: The environment that the API is invoked under. 3010 * @param pid: A process id to identify the inspector connection. 3011 * @param name: An alias for the inspector that under a specific pid. 3012 * default name is jsvm if a nullptr is passed in. 3013 * @return Returns JSVM funtions result code. 3014 * Returns {@link JSVM_OK } if the function executed successfully.\n 3015 * Returns {@link JSVM_PENDING_EXCEPTION } if an exception occurs.\n 3016 * @since 12 3017 */ 3018 JSVM_EXTERN JSVM_Status OH_JSVM_OpenInspectorWithName(JSVM_Env env, int pid, const char* name); 3019 3020 /** 3021 * @brief Compile WebAssembly bytecode into a WebAssembly module. 3022 * If WebAssembly cache provided, deserialization will be performed. 3023 * 3024 * @param env: The environment that the API is invoked under. 3025 * @param wasmBytecode: WebAssembly bytecode. 3026 * @param wasmBytecodeLength: WebAssembly bytecode length in byte. 3027 * @param cacheData: Optional WebAssembly cache. 3028 * @param cacheDataLength: Optional WebAssembly cache length in byte. 3029 * @param cacheRejected: Output parameter representing whether the provided cacheData is rejected. 3030 * @param wasmModule: Output parameter representing compiled WebAssembly module. 3031 * @return Returns JSVM funtions result code. 3032 * Returns {@link JSVM_OK } if the function executed successfully.\n 3033 * Returns {@link JSVM_INVALID_ARG } if any of env, wasmBytecode is NULL, or data length is invalid.\n 3034 * Returns {@link JSVM_GENERIC_FAILURE } if compile failed.\n 3035 * Returns {@link JSVM_PENDING_EXCEPTION } if an exception occurs.\n 3036 * 3037 * @since 12 3038 */ 3039 JSVM_EXTERN JSVM_Status OH_JSVM_CompileWasmModule(JSVM_Env env, 3040 const uint8_t* wasmBytecode, 3041 size_t wasmBytecodeLength, 3042 const uint8_t* cacheData, 3043 size_t cacheDataLength, 3044 bool* cacheRejected, 3045 JSVM_Value* wasmModule); 3046 3047 /** 3048 * @brief Compile the function with the specified index in the WebAssembly module 3049 * into the specified optimization level. 3050 * 3051 * @param env: The environment that the API is invoked under. 3052 * @param wasmModule: The WebAssembly module to which the function to compiled belongs. 3053 * @param functionIndex: The index of the function to be compiled, should never be out of range. 3054 * @param optLevel: Optimization level the function will be compiled with. 3055 * @return Returns JSVM funtions result code. 3056 * Returns {@link JSVM_OK } if the function executed successfully.\n 3057 * Returns {@link JSVM_INVALID_ARG } if env is NULL, or wasmModule is NULL or is not a WebAssembly module.\n 3058 * Returns {@link JSVM_GENERIC_FAILURE } if functionIndex out of range or compile failed.\n 3059 * Returns {@link JSVM_PENDING_EXCEPTION } if an exception occurs.\n 3060 * 3061 * @since 12 3062 */ 3063 JSVM_EXTERN JSVM_Status OH_JSVM_CompileWasmFunction(JSVM_Env env, 3064 JSVM_Value wasmModule, 3065 uint32_t functionIndex, 3066 JSVM_WasmOptLevel optLevel); 3067 3068 /** 3069 * @brief Check whether the given JSVM_Value is a WebAssembly module. 3070 * 3071 * @param env: The environment that the API is invoked under. 3072 * @param value: The JavaScript value to check. 3073 * @param result: Whether the given value is a WebAssembly module. 3074 * @return Returns JSVM funtions result code. 3075 * Returns {@link JSVM_OK } if the function executed successfully.\n 3076 * Returns {@link JSVM_INVALID_ARG } if any of the input arguments is NULL.\n 3077 * 3078 * @since 12 3079 */ 3080 JSVM_EXTERN JSVM_Status OH_JSVM_IsWasmModuleObject(JSVM_Env env, JSVM_Value value, bool* result); 3081 3082 /** 3083 * @brief Create cache for compiled WebAssembly module. 3084 * 3085 * @param env: The environment that the API is invoked under. 3086 * @param wasmModule: The compiled WebAssembly module. 3087 * @param data: Output parameter representing generated WebAssembly module cache. 3088 * @param length: Output parameter representing byte length of generated WebAssembly module cache. 3089 * @return Returns JSVM funtions result code. 3090 * Returns {@link JSVM_OK } if the function executed successfully.\n 3091 * Returns {@link JSVM_INVALID_ARG } if any of the input arguments is NULL.\n 3092 * Returns {@link JSVM_GENERIC_FAILURE } if create wasm cache failed.\n 3093 * 3094 * @since 12 3095 */ 3096 JSVM_EXTERN JSVM_Status OH_JSVM_CreateWasmCache(JSVM_Env env, 3097 JSVM_Value wasmModule, 3098 const uint8_t** data, 3099 size_t* length); 3100 3101 /** 3102 * @brief Release cache data with specified cache type. 3103 * 3104 * @param env: The environment that the API is invoked under. 3105 * @param cacheData: The cache data to be released, double free is undefined behaviors. 3106 * @param cacheType: The type of cache data. 3107 * @return Returns JSVM funtions result code. 3108 * Returns {@link JSVM_OK } if the function executed successfully.\n 3109 * Returns {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL or cacheType is illegal.\n 3110 * 3111 * @since 12 3112 */ 3113 JSVM_EXTERN JSVM_Status OH_JSVM_ReleaseCache(JSVM_Env env, const uint8_t* cacheData, JSVM_CacheType cacheType); 3114 3115 /** 3116 * @brief Trace start with specified categories for all JSVM VM.(Non-thread-safe) 3117 * 3118 * @param count The count of trace categories. 3119 * @param categories Select internal trace events for tracing by categories. 3120 * @param tag User-defined tag of trace data. 3121 * @param eventsCount Number of trace events. 3122 * @return Returns JSVM funtions result code. 3123 * {@link JSVM_OK } if the function executed successfully.\n 3124 * {@link JSVM_INVALID_ARG } if categories or count is illegal.\n 3125 * 3126 * @since 16 3127 */ 3128 JSVM_EXTERN JSVM_Status OH_JSVM_TraceStart(size_t count, 3129 const JSVM_TraceCategory* categories, 3130 const char* tag, 3131 size_t eventsCount); 3132 3133 /** 3134 * @brief Trace stop for specified categories for all JSVM VM.(Non-thread-safe) 3135 * 3136 * @param stream The output stream callback for receiving the data. 3137 * @param streamData Data passed to the stream callback. 3138 * @return Returns JSVM funtions result code. 3139 * {@link JSVM_OK } if the function executed successfully.\n 3140 * {@link JSVM_INVALID_ARG } if stream or streamData is NULL\n 3141 * 3142 * @since 16 3143 */ 3144 JSVM_EXTERN JSVM_Status OH_JSVM_TraceStop(JSVM_OutputStream stream, void* streamData); 3145 3146 /** 3147 * @brief When wrapping a C++ class, the C++ constructor callback passed via constructor 3148 * should be a static method on the class that calls the actual class constructor, then 3149 * wraps the new C++ instance in a JavaScript object according to the different Options 3150 * passed in, and returns the wrapper object. 3151 * 3152 * @param env The environment that the API is invoked under. 3153 * @param utf8name Name of the JavaScript constructor function. For clarity, it is 3154 * recommended to use the C++ class name when wrapping a C++ class. 3155 * @param length The length of the utf8name in bytes, or JSVM_AUTO_LENGTH if it 3156 * is null-terminated. 3157 * @param constructor Struct include callback function that handles constructing instances of the class. 3158 * When wrapping a C++ class, this method must be a static member with the JSVM_Callback.callback 3159 * signature. A C++ class constructor cannot be used. 3160 * Include Optional data to be passed to the constructor callback as the data 3161 * property of the callback info. JSVM_Callback provides more details. 3162 * @param propertyCount Number of items in the properties array argument. 3163 * @param properties Array of property descriptors describing static and instance data 3164 * properties, accessors, and methods on the class See JSVM_PropertyDescriptor. 3165 * @param parentClass The parent-class of the currently defined class. 3166 * @param optionCount Number of items in an option array argument. 3167 * @param options DefineClass options to be passed. 3168 * @param result A JSVM_Value representing the constructor function for the class. 3169 * @return Returns JSVM functions result code. 3170 * {@link JSVM_OK } if the function executed successfully. \n 3171 * {@link JSVM_INVALID_ARG } if any of the pointer arguments is NULL. \n 3172 * {@link JSVM_GENERIC_FAILURE} if the input utf8name | constructor | properties is invalid. \n 3173 * @since 16 3174 */ 3175 JSVM_EXTERN JSVM_Status OH_JSVM_DefineClassWithOptions(JSVM_Env env, 3176 const char* utf8name, 3177 size_t length, 3178 JSVM_Callback constructor, 3179 size_t propertyCount, 3180 const JSVM_PropertyDescriptor* properties, 3181 JSVM_Value parentClass, 3182 size_t optionCount, 3183 JSVM_DefineClassOptions options[], 3184 JSVM_Value* result); 3185 3186 // clang-format on 3187 EXTERN_C_END 3188 3189 /** @} */ 3190 #endif /* ARK_RUNTIME_JSVM_JSVM_H */ 3191