harmony 鸿蒙jsvm.h

  • 2025-06-12
  • 浏览 (4)

jsvm.h

Overview

Provides JSVM-API API definitions.

The APIs are used to provide independent, standard, and complete JavaScript engine capabilities, including managing the engine lifecycle, compiling and running JS code, implementing JS/C++ cross-language invoking, and taking snapshots.

Library: libjsvm.so

System capability: SystemCapability.ArkCompiler.JSVM

Since: 11

Related module: JSVM

Summary

Macros

Name Description
JSVM_VERSION_EXPERIMENTAL   2147483647
JSVM_VERSION   8
JSVM_EXTERN   attribute((visibility(“default”)))
JSVM_AUTO_LENGTH   SIZE_MAX Automatic length.
EXTERN_C_START
EXTERN_C_END

Functions

Name Description
EXTERN_C_START JSVM_EXTERN JSVM_Status OH_JSVM_Init (const JSVM_InitOptions *options) Initializes a JavaScript VM.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateVM (const JSVM_CreateVMOptions *options, JSVM_VM *result) Creates a VM instance.
JSVM_EXTERN JSVM_Status OH_JSVM_DestroyVM (JSVM_VM vm) Destroys a VM instance.
JSVM_EXTERN JSVM_Status OH_JSVM_OpenVMScope (JSVM_VM vm, JSVM_VMScope *result) Opens a new VM scope for a VM instance.
JSVM_EXTERN JSVM_Status OH_JSVM_CloseVMScope (JSVM_VM vm, JSVM_VMScope scope) Closes the VM scope of a VM instance.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateEnv (JSVM_VM vm, size_t propertyCount, const JSVM_PropertyDescriptor *properties, JSVM_Env *result) Creates a new environment based on the optional properties of the new context.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateEnvFromSnapshot (JSVM_VM vm, size_t index, JSVM_Env *result) Creates a new environment based on the startup snapshot of the VM.
JSVM_EXTERN JSVM_Status OH_JSVM_DestroyEnv (JSVM_Env env) Destroys the environment.
JSVM_EXTERN JSVM_Status OH_JSVM_OpenEnvScope (JSVM_Env env, JSVM_EnvScope *result) Opens a new environment scope.
JSVM_EXTERN JSVM_Status OH_JSVM_CloseEnvScope (JSVM_Env env, JSVM_EnvScope scope) Closes an environment scope.
JSVM_EXTERN JSVM_Status OH_JSVM_GetVM (JSVM_Env env, JSVM_VM *result) Gets a VM instance.
JSVM_EXTERN JSVM_Status OH_JSVM_CompileScript (JSVM_Env env, JSVM_Value script, const uint8_t *cachedData, size_t cacheDataLength, bool eagerCompile, bool *cacheRejected, JSVM_Script *result) Compiles a string of JavaScript code and returns the compiled script.
JSVM_EXTERN JSVM_Status OH_JSVM_CompileScriptWithOrigin (JSVM_Env env, JSVM_Value script, const uint8_t *cachedData, size_t cacheDataLength, bool eagerCompile, bool *cacheRejected, JSVM_ScriptOrigin *origin, JSVM_Script *result) Compiles a string of JavaScript code that contains source map information and returns the compiled script.
JSVM_EXTERN JSVM_Status OH_JSVM_CompileScriptWithOptions (JSVM_Env env, JSVM_Value script, size_t optionCount, JSVM_CompileOptions options[], JSVM_Value *result) Compiles a string of JavaScript code and returns the compiled script.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateCodeCache (JSVM_Env env, JSVM_Script script, const uint8_t **data, size_t *length) Creates a code cache for the compiled script.
JSVM_EXTERN JSVM_Status OH_JSVM_RunScript (JSVM_Env env, JSVM_Script script, JSVM_Value *result) Runs a string of JavaScript code and returns its result, including the following precautions: Unlike eval, this function does not allow the script to access the current lexical scope, and therefore does not allow the script to access the module scope. This means that pseudo-global variables such as require will be unavailable. The script can access the global scope. The functions and variable declarations in the script will be added to the global object. Variable declarations using let and const are globally visible, but are not added to the global object. The value of this is global in the script.
JSVM_EXTERN JSVM_Status OH_JSVM_SetInstanceData (JSVM_Env env, void *data, JSVM_Finalize finalizeCb, void *finalizeHint) Sets instance data so that it is associated with the currently running JSVM environment. You can use OH_JSVM_GetInstanceData() to get data later. Any existing data set by a previous call to OH_JSVM_SetInstanceData() will be overwritten. If finalizeCb was previously provided, it will not be called.
JSVM_EXTERN JSVM_Status OH_JSVM_GetInstanceData (JSVM_Env env, void **data) Gets instance data that has been set by OH_JSVM_SetInstanceData(). If no associated data is set, this function is called successfully and data is set to NULL.
JSVM_EXTERN JSVM_Status OH_JSVM_GetLastErrorInfo (JSVM_Env env, const JSVM_ExtendedErrorInfo **result) Gets the JSVM_ExtendedErrorInfo struct that contains information about the last error that occurred. The content of JSVM_ExtendedErrorInfo returned is valid only before the JSVM-API function is called for the same environment. This includes a call to OH_JSVM_IsExceptionPending, so you may often need to copy information for later use. The pointer returned in error_message points to a statically defined string, so if you copy it from the error_message field (which will be overwritten) before calling another JSVM-API function, you can safely use the pointer.
JSVM_EXTERN JSVM_Status OH_JSVM_Throw (JSVM_Env env, JSVM_Value error) Throws the provided JavaScript value.
JSVM_EXTERN JSVM_Status OH_JSVM_ThrowError (JSVM_Env env, const char *code, const char *msg) Throws a JavaScript Error with the provided text.
JSVM_EXTERN JSVM_Status OH_JSVM_ThrowTypeError (JSVM_Env env, const char *code, const char *msg) Throws a JavaScript TypeError with the provided text.
JSVM_EXTERN JSVM_Status OH_JSVM_ThrowRangeError (JSVM_Env env, const char *code, const char *msg) Throws a JavaScript RangeError with the provided text.
JSVM_EXTERN JSVM_Status OH_JSVM_ThrowSyntaxError (JSVM_Env env, const char *code, const char *msg) Throws a JavaScript SyntaxError with the provided text.
JSVM_EXTERN JSVM_Status OH_JSVM_IsError (JSVM_Env env, JSVM_Value value, bool *result) Checks whether the given JSVM_Value indicates an error.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateError (JSVM_Env env, JSVM_Value code, JSVM_Value msg, JSVM_Value *result) Creates a JavaScript Error with the provided text.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateTypeError (JSVM_Env env, JSVM_Value code, JSVM_Value msg, JSVM_Value *result) Creates a JavaScript TypeError with the provided text.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateRangeError (JSVM_Env env, JSVM_Value code, JSVM_Value msg, JSVM_Value *result) Creates a JavaScript RangeError with the provided text.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateSyntaxError (JSVM_Env env, JSVM_Value code, JSVM_Value msg, JSVM_Value *result) Creates a JavaScript SyntaxError with the provided text.
JSVM_EXTERN JSVM_Status OH_JSVM_GetAndClearLastException (JSVM_Env env, JSVM_Value *result) Gets and clears the last exception. If pending occurs, a JavaScript exception is returned. Otherwise, NULL is returned.
JSVM_EXTERN JSVM_Status OH_JSVM_IsExceptionPending (JSVM_Env env, bool *result) Checks whether the last exception is caused by pending. If yes, true is returned. Otherwise, false is returned.
JSVM_EXTERN JSVM_Status OH_JSVM_OpenHandleScope (JSVM_Env env, JSVM_HandleScope *result) Opens a new scope.
JSVM_EXTERN JSVM_Status OH_JSVM_CloseHandleScope (JSVM_Env env, JSVM_HandleScope scope) Closes the scope. Scopes must be closed in the reverse order of opening scopes.
JSVM_EXTERN JSVM_Status OH_JSVM_OpenEscapableHandleScope (JSVM_Env env, JSVM_EscapableHandleScope *result) Opens a new scope from which an object can be escalated to an external scope.
JSVM_EXTERN JSVM_Status OH_JSVM_CloseEscapableHandleScope (JSVM_Env env, JSVM_EscapableHandleScope scope) Closes the scope. Scopes must be closed in the reverse order of opening scopes. This JSVM_API can be called even if there is a suspended JavaScript exception.
JSVM_EXTERN JSVM_Status OH_JSVM_EscapeHandle (JSVM_Env env, JSVM_EscapableHandleScope scope, JSVM_Value escapee, JSVM_Value *result) Escalates the handle to a JavaScript object so that it is valid through the lifecycle of the external scope. Each scope can be called only once. If it is called for multiple times, an error is returned.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateReference (JSVM_Env env, JSVM_Value value, uint32_t initialRefcount, JSVM_Ref *result) Creates a new reference with the specified reference count for the passed-in value.
JSVM_EXTERN JSVM_Status OH_JSVM_DeleteReference (JSVM_Env env, JSVM_Ref ref) Deletes the passed-in reference.
JSVM_EXTERN JSVM_Status OH_JSVM_ReferenceRef (JSVM_Env env, JSVM_Ref ref, uint32_t *result) Increases the reference count and returns the new reference count.
JSVM_EXTERN JSVM_Status OH_JSVM_ReferenceUnref (JSVM_Env env, JSVM_Ref ref, uint32_t *result) Decreases the reference count and returns the new reference count.
JSVM_EXTERN JSVM_Status OH_JSVM_GetReferenceValue (JSVM_Env env, JSVM_Ref ref, JSVM_Value *result) Gets the JSVM_Value returned by the JSVM-API , indicating the JavaScript value associated with JSVM_Ref. Otherwise, the result is NULL.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateArray (JSVM_Env env, JSVM_Value *result) Returns the JSVM-API value corresponding to the JavaScript Array type.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateArrayWithLength (JSVM_Env env, size_t length, JSVM_Value *result) Returns the JSVM-API value corresponding to the JavaScript Array type. The length attribute of the array is set to the passed-in length parameter. However, there is no guarantee that the underlying buffer is pre-allocated by the VM when the array is created. This behavior is left to the underlying VM implementation.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateArraybuffer (JSVM_Env env, size_t byteLength, void **data, JSVM_Value *result) Returns the JSVM-API value corresponding to the JavaScript ArrayBuffer type. ArrayBuffer is used to represent a fixed-length binary data buffer. It is usually used as the backup buffer of the TypedArray object. The allocated ArrayBuffer has an underlying byte buffer whose size is determined by the length argument. The underlying buffer can be returned to and operated by the caller. This buffer can only be written directly from the native code. To write data from JavaScript to this buffer, you need to create a TypedArray or DataView object.
JSVM_Status JSVM_CDECL OH_JSVM_AllocateArrayBufferBackingStoreData (size_t byteLength, JSVM_InitializedFlag initialized, void **data) Allocates the BackingStore memory for the array buffer.
JSVM_Status JSVM_CDECL OH_JSVM_FreeArrayBufferBackingStoreData (void *data) Frees the BackingStore memory allocated by OH_JSVM_AllocateArrayBufferBackingStoreData.
JSVM_Status JSVM_CDECL OH_JSVM_CreateArrayBufferFromBackingStoreData (JSVM_Env env, void *data, size_t backingStoreSize, size_t offset, size_t arrayBufferSize, JSVM_Value *result) Creates an array buffer on the allocated BackingStore memory.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateDate (JSVM_Env env, double time, JSVM_Value *result) Allocates a JavaScript Date object. This API does not process leap seconds. This is because ECMAScript complies with the POSIX time specifications and ignores leap seconds.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateExternal (JSVM_Env env, void *data, JSVM_Finalize finalizeCb, void *finalizeHint, JSVM_Value *result) Allocates a JavaScript value with external data. This is used to pass external data through JavaScript code. You can use OH_JSVM_GetValueExternal to retrieve the value from the native code. This API adds a JSVM_Finalize callback, which is called when the newly created JavaScript object is garbage collected. The created value is not an object, so it does not support additional attributes. It is considered as a unique value type: Calling OH_JSVM_Typeof() with an external value generates JSVM_EXTERNAL.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateObject (JSVM_Env env, JSVM_Value *result) Allocates a default JavaScript object. This function is equivalent to executing new Object() in JavaScript.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateSymbol (JSVM_Env env, JSVM_Value description, JSVM_Value *result) Creates a JavaScript symbol value from a UTF8-encoded C string.
JSVM_EXTERN JSVM_Status OH_JSVM_SymbolFor (JSVM_Env env, const char *utf8description, size_t length, JSVM_Value *result) Searches the global registry for an existing symbol with the given description. If the symbol already exists, it is returned. Otherwise, a new symbol is created in the registry.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateTypedarray (JSVM_Env env, JSVM_TypedarrayType type, size_t length, JSVM_Value arraybuffer, size_t byteOffset, JSVM_Value *result) Creates a JavaScript TypedArray object based on an existing ArrayBuffer object. The TypedArray object provides an array-like view on the underlying data buffer, where each element has the same underlying binary scalar data type. The requirement is as follows: (length* Element size) + byteOffset ≤ Size of the passed-in array (in bytes). Otherwise, a RangeError is thrown.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateDataview (JSVM_Env env, size_t length, JSVM_Value arraybuffer, size_t byteOffset, JSVM_Value *result) Creates a JavaScript DataView object based on an existing ArrayBuffer object. The DataView object provides an array-like view on the underlying data buffer, where elements can have different sizes and types. The requirement is as follows: length in binary + byteOffset ≤ Size of the passed-in array (in bytes). Otherwise, a RangeError is thrown.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateInt32 (JSVM_Env env, int32_t value, JSVM_Value *result) Creates a JavaScript number object from a C int32_t object.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateUint32 (JSVM_Env env, uint32_t value, JSVM_Value *result) Creates a JavaScript number object from a C uint32_t object.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateInt64 (JSVM_Env env, int64_t value, JSVM_Value *result) Creates a JavaScript number object from a C int64_t object.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateDouble (JSVM_Env env, double value, JSVM_Value *result) Creates a JavaScript number object from a C double object.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateBigintInt64 (JSVM_Env env, int64_t value, JSVM_Value *result) Creates a JavaScript BigInt object from a C int64_t object.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateBigintUint64 (JSVM_Env env, uint64_t value, JSVM_Value *result) Creates a JavaScript BigInt object from a C uint64_t object.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateBigintWords (JSVM_Env env, int signBit, size_t wordCount, const uint64_t *words, JSVM_Value *result) Creates a JavaScript BigInt value from a group of C uint64_t words.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateStringLatin1 (JSVM_Env env, const char *str, size_t length, JSVM_Value *result) Creates a JavaScript string from a C string encoded using ISO-8859-1. Copies a native string.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateStringUtf16 (JSVM_Env env, const char16_t *str, size_t length, JSVM_Value *result) Creates a JavaScript string from a C string encoded using UTF16-LE. Copies a native string.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateStringUtf8 (JSVM_Env env, const char *str, size_t length, JSVM_Value *result) Creates a JavaScript string from a C string encoded using UTF8. Copies a native string.
JSVM_EXTERN JSVM_Status OH_JSVM_GetArrayLength (JSVM_Env env, JSVM_Value value, uint32_t *result) Gets the length of an array.
JSVM_EXTERN JSVM_Status OH_JSVM_GetArraybufferInfo (JSVM_Env env, JSVM_Value arraybuffer, void **data, size_t *byteLength) Gets the underlying data buffer of the ArrayBuffer and its length.
JSVM_EXTERN JSVM_Status OH_JSVM_GetPrototype (JSVM_Env env, JSVM_Value object, JSVM_Value *result) Gets the prototype of an object.
JSVM_EXTERN JSVM_Status OH_JSVM_GetTypedarrayInfo (JSVM_Env env, JSVM_Value typedarray, JSVM_TypedarrayType *type, size_t *length, void **data, JSVM_Value *arraybuffer, size_t *byteOffset) Gets the properties of a typed array. If any property is not required, its output parameter can be NULL.
JSVM_EXTERN JSVM_Status OH_JSVM_GetDataviewInfo (JSVM_Env env, JSVM_Value dataview, size_t *bytelength, void **data, JSVM_Value *arraybuffer, size_t *byteOffset) Gets the proprieties of a DataView. If any property is not required, its output parameter can be set to NULL.
JSVM_EXTERN JSVM_Status OH_JSVM_GetDateValue (JSVM_Env env, JSVM_Value value, double *result) Gets the C double-precision primitive equivalent of a given JavaScript date. If this API is successfully called, JSVM_OK is returned. If a JSVM_Value of a non-JavaScript date type is passed in, JSVM_DATA_EXPECTED is returned.
JSVM_EXTERN JSVM_Status OH_JSVM_GetValueBool (JSVM_Env env, JSVM_Value value, bool *result) Gets the C Boolean primitive equivalent of a given JavaScript Boolean.
JSVM_EXTERN JSVM_Status OH_JSVM_GetValueDouble (JSVM_Env env, JSVM_Value value, double *result) Gets the C double-precision primitive equivalent of a given JavaScript number.
JSVM_EXTERN JSVM_Status OH_JSVM_GetValueBigintInt64 (JSVM_Env env, JSVM_Value value, int64_t *result, bool *lossless) Gets the C int64_t primitive equivalent of a given JavaScript BigInt. If necessary, it truncates the value and sets lossless to false.
JSVM_EXTERN JSVM_Status OH_JSVM_GetValueBigintUint64 (JSVM_Env env, JSVM_Value value, uint64_t *result, bool *lossless) Gets the C uint64_t primitive equivalent of a given JavaScript BigInt. If necessary, it truncates the value and sets lossless to false.
JSVM_EXTERN JSVM_Status OH_JSVM_GetValueBigintWords (JSVM_Env env, JSVM_Value value, int *signBit, size_t *wordCount, uint64_t *words) Gets the sign bit, 64-bit little-endian array, and number of elements in the array from a BigInt value. Both signBit and words can be set to NULL. In this case, only wordCount is obtained.
JSVM_EXTERN JSVM_Status OH_JSVM_GetValueExternal (JSVM_Env env, JSVM_Value value, void **result) Gets the external data pointer previously passed to OH_JSVM_CreateExternal().
JSVM_EXTERN JSVM_Status OH_JSVM_GetValueInt32 (JSVM_Env env, JSVM_Value value, int32_t *result) Gets the C int32 primitive equivalent of a given JavaScript number.
JSVM_EXTERN JSVM_Status OH_JSVM_GetValueInt64 (JSVM_Env env, JSVM_Value value, int64_t *result) Gets the C int64 primitive equivalent of a given JavaScript number.
JSVM_EXTERN JSVM_Status OH_JSVM_GetValueStringLatin1 (JSVM_Env env, JSVM_Value value, char *buf, size_t bufsize, size_t *result) Gets an ISO-8859-1 encoded string corresponding to the passed-in value.
JSVM_EXTERN JSVM_Status OH_JSVM_GetValueStringUtf8 (JSVM_Env env, JSVM_Value value, char *buf, size_t bufsize, size_t *result) Gets a UTF8-encoded string corresponding to the passed-in value.
JSVM_EXTERN JSVM_Status OH_JSVM_GetValueStringUtf16 (JSVM_Env env, JSVM_Value value, char16_t *buf, size_t bufsize, size_t *result) Gets a UTF16-encoded string based on the passed-in value.
JSVM_EXTERN JSVM_Status OH_JSVM_GetValueUint32 (JSVM_Env env, JSVM_Value value, uint32_t *result) Gets a C uint_32 primitive equivalent of a given JavaScript number.
JSVM_EXTERN JSVM_Status OH_JSVM_GetBoolean (JSVM_Env env, bool value, JSVM_Value *result) Gets a JavaScript singleton object that is used to represent the given Boolean value.
JSVM_EXTERN JSVM_Status OH_JSVM_GetGlobal (JSVM_Env env, JSVM_Value *result) Gets the global object.
JSVM_EXTERN JSVM_Status OH_JSVM_GetNull (JSVM_Env env, JSVM_Value *result) Gets the null object.
JSVM_EXTERN JSVM_Status OH_JSVM_GetUndefined (JSVM_Env env, JSVM_Value *result) Gets the undefined object.
JSVM_EXTERN JSVM_Status OH_JSVM_CoerceToBool (JSVM_Env env, JSVM_Value value, JSVM_Value *result) Implements the abstract operation ToBoolean().
JSVM_EXTERN JSVM_Status OH_JSVM_CoerceToNumber (JSVM_Env env, JSVM_Value value, JSVM_Value *result) Implements the abstract operation ToNumber(). If the passed-in value is an object, the function may run JavaScript code.
JSVM_EXTERN JSVM_Status OH_JSVM_CoerceToObject (JSVM_Env env, JSVM_Value value, JSVM_Value *result) Implements the abstract operation ToObject().
JSVM_EXTERN JSVM_Status OH_JSVM_CoerceToString (JSVM_Env env, JSVM_Value value, JSVM_Value *result) Implements the abstract operation ToString(). If the passed-in value is an object, the function may run JavaScript code.
JSVM_EXTERN JSVM_Status OH_JSVM_Typeof (JSVM_Env env, JSVM_Value value, JSVM_ValueType *result) Provides behavior similar to calling the typeof operator on a defined object. The difference is that this function supports the detection of external values; it detects null as a separate type, while ECMAScript typeof is used to detect objects. If the value type is invalid, an error is returned.
JSVM_EXTERN JSVM_Status OH_JSVM_Instanceof (JSVM_Env env, JSVM_Value object, JSVM_Value constructor, bool *result) Provides behavior similar to calling the instanceof operator on an object.
JSVM_EXTERN JSVM_Status OH_JSVM_IsArray (JSVM_Env env, JSVM_Value value, bool *result) Provides behavior similar to calling IsArray on an object.
JSVM_EXTERN JSVM_Status OH_JSVM_IsArraybuffer (JSVM_Env env, JSVM_Value value, bool *result) Checks whether the passed-in object is ArrayBuffer.
JSVM_EXTERN JSVM_Status OH_JSVM_IsDate (JSVM_Env env, JSVM_Value value, bool *isDate) Checks whether the passed-in object is a date.
JSVM_EXTERN JSVM_Status OH_JSVM_IsTypedarray (JSVM_Env env, JSVM_Value value, bool *result) Checks whether the passed-in object is a typed array.
JSVM_EXTERN JSVM_Status OH_JSVM_IsDataview (JSVM_Env env, JSVM_Value value, bool *result) Checks whether the passed-in object is a DataView.
JSVM_EXTERN JSVM_Status OH_JSVM_StrictEquals (JSVM_Env env, JSVM_Value lhs, JSVM_Value rhs, bool *result) Provides behavior similar to calling the strict equality algorithm.
JSVM_EXTERN JSVM_Status OH_JSVM_Equals (JSVM_Env env, JSVM_Value lhs, JSVM_Value rhs, bool *result) Provides behavior similar to calling the loose equality algorithm. Regardless of the JavaScript value type, true is returned as long as the values are equal.
JSVM_EXTERN JSVM_Status OH_JSVM_DetachArraybuffer (JSVM_Env env, JSVM_Value arraybuffer) Provides behavior similar to calling the ArrayBuffer detach operation.
JSVM_EXTERN JSVM_Status OH_JSVM_IsDetachedArraybuffer (JSVM_Env env, JSVM_Value value, bool *result) Provides behavior similar to calling the ArrayBuffer IsDetachedBuffer operation.
JSVM_EXTERN JSVM_Status OH_JSVM_GetPropertyNames (JSVM_Env env, JSVM_Value object, JSVM_Value *result) Gets the names of enumerable properties of an object as an array of characters. The properties of the object whose key is a symbol are not included.
JSVM_EXTERN JSVM_Status OH_JSVM_GetAllPropertyNames (JSVM_Env env, JSVM_Value object, JSVM_KeyCollectionMode keyMode, JSVM_KeyFilter keyFilter, JSVM_KeyConversion keyConversion, JSVM_Value *result) Gets an array containing the names of the available properties of this object.
JSVM_EXTERN JSVM_Status OH_JSVM_SetProperty (JSVM_Env env, JSVM_Value object, JSVM_Value key, JSVM_Value value) Sets a property for the passed-in object.
JSVM_EXTERN JSVM_Status OH_JSVM_GetProperty (JSVM_Env env, JSVM_Value object, JSVM_Value key, JSVM_Value *result) Gets the requested property from the passed-in object.
JSVM_EXTERN JSVM_Status OH_JSVM_HasProperty (JSVM_Env env, JSVM_Value object, JSVM_Value key, bool *result) Checks whether the passed-in object has the property with the specified name.
JSVM_EXTERN JSVM_Status OH_JSVM_DeleteProperty (JSVM_Env env, JSVM_Value object, JSVM_Value key, bool *result) Deletes the property of the key from the object.
JSVM_EXTERN JSVM_Status OH_JSVM_HasOwnProperty (JSVM_Env env, JSVM_Value object, JSVM_Value key, bool *result) Checks whether the passed-in object has its own property. The key must be a string or symbol. Otherwise, an error is thrown. The JSVM-API does not perform any conversion between data types.
JSVM_EXTERN JSVM_Status OH_JSVM_SetNamedProperty (JSVM_Env env, JSVM_Value object, const char *utf8name, JSVM_Value value) This method is equivalent to calling OH_JSVM_SetProperty, where the JSVM_Value is created using the character string passed through utf8Name.
JSVM_EXTERN JSVM_Status OH_JSVM_GetNamedProperty (JSVM_Env env, JSVM_Value object, const char *utf8name, JSVM_Value *result) This method is equivalent to calling OH_JSVM_GetProperty, where the JSVM_Value is created using the character string passed through utf8Name.
JSVM_EXTERN JSVM_Status OH_JSVM_HasNamedProperty (JSVM_Env env, JSVM_Value object, const char *utf8name, bool *result) This method is equivalent to calling OH_JSVM_HasProperty, where the JSVM_Value is created using the character string passed through utf8Name.
JSVM_EXTERN JSVM_Status OH_JSVM_SetElement (JSVM_Env env, JSVM_Value object, uint32_t index, JSVM_Value value) Sets an element on the passed-in object.
JSVM_EXTERN JSVM_Status OH_JSVM_GetElement (JSVM_Env env, JSVM_Value object, uint32_t index, JSVM_Value *result) Gets the element at the requested index.
JSVM_EXTERN JSVM_Status OH_JSVM_HasElement (JSVM_Env env, JSVM_Value object, uint32_t index, bool *result) Checks whether an object has an element at the specified index. If yes, the JSVM-API returns true.
JSVM_EXTERN JSVM_Status OH_JSVM_DeleteElement (JSVM_Env env, JSVM_Value object, uint32_t index, bool *result) Deletes the element at the specified index from an object.
JSVM_EXTERN JSVM_Status OH_JSVM_DefineProperties (JSVM_Env env, JSVM_Value object, size_t propertyCount, const JSVM_PropertyDescriptor *properties) Defines properties on a given object by using property descriptors. Through an array of property descriptors, this API sets the properties in the array in turn for the object.
JSVM_EXTERN JSVM_Status OH_JSVM_ObjectFreeze (JSVM_Env env, JSVM_Value object) Freezes the given object. This prevents additions or deletions of properties, enumerability, configurability, or writeability change of properties, or value change of properties. It also prevents prototype change of an object.
JSVM_EXTERN JSVM_Status OH_JSVM_ObjectSeal (JSVM_Env env, JSVM_Value object) Seals a specified object. This prevents additions of properties and marks existing properties non-configurable.
JSVM_EXTERN JSVM_Status OH_JSVM_CallFunction (JSVM_Env env, JSVM_Value recv, JSVM_Value func, size_t argc, const JSVM_Value *argv, JSVM_Value *result) Supports calling JavaScript function objects from native code, which is the main mechanism for JavaScript to call back from native code.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateFunction (JSVM_Env env, const char *utf8name, size_t length, JSVM_Callback cb, JSVM_Value *result) Supports creating function objects in native code, which is the main mechanism for JavaScript to call native code. After this call, the newly created function is no longer automatically visible in the script. Instead, the setting property must be displayed on any object visible to JavaScript in order to access the function from the script.
JSVM_EXTERN JSVM_Status OH_JSVM_GetCbInfo (JSVM_Env env, JSVM_CallbackInfo cbinfo, size_t *argc, JSVM_Value *argv, JSVM_Value *thisArg, void **data) Gets detailed information about the callback, such as the parameter from the given callback information and the this pointer.
JSVM_EXTERN JSVM_Status OH_JSVM_GetNewTarget (JSVM_Env env, JSVM_CallbackInfo cbinfo, JSVM_Value *result) Gets the new target called by the constructor. If the current callback is not a constructor call, the result is NULL.
JSVM_EXTERN JSVM_Status OH_JSVM_NewInstance (JSVM_Env env, JSVM_Value constructor, size_t argc, const JSVM_Value *argv, JSVM_Value *result) Instantiates a new JavaScript value by using the constructor represented by the given JSVM_Value.
JSVM_EXTERN JSVM_Status OH_JSVM_DefineClass (JSVM_Env env, const char *utf8name, size_t length, JSVM_Callback constructor, size_t propertyCount, const JSVM_PropertyDescriptor *properties, JSVM_Value *result) Defines a JavaScript class.
JSVM_EXTERN JSVM_Status OH_JSVM_Wrap (JSVM_Env env, JSVM_Value jsObject, void *nativeObject, JSVM_Finalize finalizeCb, void *finalizeHint, JSVM_Ref *result) Wraps a native instance in the JavaScript object. The native instance can be obtained using OH_JSVM_Unwrap().
JSVM_EXTERN JSVM_Status OH_JSVM_Unwrap (JSVM_Env env, JSVM_Value jsObject, void **result) When the JavaScript code calls a method of a class or property accessor, the corresponding JSVM_Callback is called. If the callback is for an instance method or accessor, the this argument of the callback is the wrapper object. Then you can obtain the C++ instance as the call target by calling OH_JSVM_Unwrap() of the wrapper object.
JSVM_EXTERN JSVM_Status OH_JSVM_RemoveWrap (JSVM_Env env, JSVM_Value jsObject, void **result) Removes the wrap of the native instance, which is previously wrapped in js_object by OH_JSVM_Wrap(). If the finalize callback is associated with wrap, it will not be called when the JavaScript object is garbage collected.
JSVM_EXTERN JSVM_Status OH_JSVM_TypeTagObject (JSVM_Env env, JSVM_Value value, const JSVM_TypeTag *typeTag) Associates the value of the typeTag pointer with a JavaScript object or an external value. You can call OH_JSVM_CheckObjectTypeTag() to check the type of the tag attached to the object, to ensure that the object type is correct. If the object already has an associated type tag, JSVM_INVALID_ARG is returned.
JSVM_EXTERN JSVM_Status OH_JSVM_CheckObjectTypeTag (JSVM_Env env, JSVM_Value value, const JSVM_TypeTag *typeTag, bool *result) Compares the typeTag with the tag on a JavaScript object or external value. If they are the same tag, result is set to true. Otherwise, result is set to false.
JSVM_EXTERN JSVM_Status OH_JSVM_AddFinalizer (JSVM_Env env, JSVM_Value jsObject, void *finalizeData, JSVM_Finalize finalizeCb, void *finalizeHint, JSVM_Ref *result) Adds the JSVM_Finalize callback to a JavaScript object. This callback is called when the JavaScript object is garbage collected. OH_JSVM_AddFinalizer can be called multiple times on a single JavaScript object.
JSVM_EXTERN JSVM_Status OH_JSVM_GetVersion (JSVM_Env env, uint32_t *result) Gets the latest JSVM-API version supported by the JSVM runtime. New JSVM-API APIs will be added to support more functions. With this API, the new functions of a certain JSVM version can be used, or callbacks are provided.
JSVM_EXTERN JSVM_Status OH_JSVM_GetVMInfo (JSVM_VMInfo *result) Gets the VM information.
JSVM_EXTERN JSVM_Status OH_JSVM_AdjustExternalMemory (JSVM_Env env, int64_t changeInBytes, int64_t *result) Notifies the underlying VM of the size of externally allocated memory that remains active due to the JavaScript object. Registering externally allocated memory triggers global garbage collection more frequently than in other ways.
JSVM_EXTERN JSVM_Status OH_JSVM_MemoryPressureNotification (JSVM_Env env, JSVM_MemoryPressureLevel level) Notifies the VM of insufficient system memory and selectively triggers garbage collection.
JSVM_EXTERN JSVM_Status OH_JSVM_CreatePromise (JSVM_Env env, JSVM_Deferred *deferred, JSVM_Value *promise) Creates a deferred object and a JavaScript promise.
JSVM_EXTERN JSVM_Status OH_JSVM_ResolveDeferred (JSVM_Env env, JSVM_Deferred deferred, JSVM_Value resolution) Resolves a JavaScript promise by using the associated deferred object. It can only be used to resolve the JavaScript promise of the corresponding available deferred object. This means that promise must be created using OH_JSVM_CreatePromise(), and the object returned from this call must be retained so that it can be passed to this API.
JSVM_EXTERN JSVM_Status OH_JSVM_RejectDeferred (JSVM_Env env, JSVM_Deferred deferred, JSVM_Value rejection) Rejects a JavaScript promise by using the associated deferred object. It can only be used to reject the JavaScript promise of the corresponding available deferred object. This means that promise must be created using OH_JSVM_CreatePromise(), and the object returned from this call must be retained so that it can be passed to this API.
JSVM_EXTERN JSVM_Status OH_JSVM_IsPromise (JSVM_Env env, JSVM_Value value, bool *isPromise) Checks whether a promise object is a native promise object.
JSVM_EXTERN JSVM_Status OH_JSVM_JsonParse (JSVM_Env env, JSVM_Value jsonString, JSVM_Value *result) Parses a JSON string and returns the parsed value.
JSVM_EXTERN JSVM_Status OH_JSVM_JsonStringify (JSVM_Env env, JSVM_Value jsonObject, JSVM_Value *result) Converts an object into a JSON string and returns the converted string.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateSnapshot (JSVM_VM vm, size_t contextCount, const JSVM_Env *contexts, const char **blobData, size_t *blobSize) Creates a VM startup snapshot.
JSVM_EXTERN JSVM_Status OH_JSVM_GetHeapStatistics (JSVM_VM vm, JSVM_HeapStatistics *result) Gets heap statistics of a VM.
JSVM_EXTERN JSVM_Status OH_JSVM_StartCpuProfiler (JSVM_VM vm, JSVM_CpuProfiler *result) Creates and starts a CPU profiler.
JSVM_EXTERN JSVM_Status OH_JSVM_StopCpuProfiler (JSVM_VM vm, JSVM_CpuProfiler profiler, JSVM_OutputStream stream, void *streamData) Stops the CPU profiler and outputs the result to a stream.
JSVM_EXTERN JSVM_Status OH_JSVM_TakeHeapSnapshot (JSVM_VM vm, JSVM_OutputStream stream, void *streamData) Takes a heap snapshot and outputs it to a stream.
JSVM_EXTERN JSVM_Status OH_JSVM_OpenInspector (JSVM_Env env, const char *host, uint16_t port) Opens an inspector on the specified host and port for debugging JavaScript code.
JSVM_EXTERN JSVM_Status OH_JSVM_CloseInspector (JSVM_Env env) Closes all remaining inspector connections.
JSVM_EXTERN JSVM_Status OH_JSVM_WaitForDebugger (JSVM_Env env, bool breakNextLine) Waits for the host to set up a socket connection with an inspector. After the connection is set up, the application continues to run. Runtime.runIfWaitingForDebugger is sent.
JSVM_EXTERN JSVM_Status OH_JSVM_DefineClassWithPropertyHandler (JSVM_Env env, const char *utf8name, size_t length, JSVM_Callback constructor, size_t propertyCount, const JSVM_PropertyDescriptor *properties, JSVM_PropertyHandlerCfg propertyHandlerCfg, JSVM_Callback callAsFunctionCallback, JSVM_Value *result) Defines a set of JavaScript class property operations including getter(), setter(), deleter(), and enumerator() with the given class name, constructor, properties, and callback handler, which are called as callbacks.
JSVM_EXTERN JSVM_Status OH_JSVM_IsUndefined (JSVM_Env env, JSVM_Value value, bool *isUndefined) Checks whether the value passed in is Undefined. This API is equivalent to executing JavaScript code value === undefined.
JSVM_EXTERN JSVM_Status OH_JSVM_IsNull (JSVM_Env env, JSVM_Value value, bool *isNull) Checks whether the value passed in is a Null object. This API is equivalent to executing JavaScript code value === null.
JSVM_EXTERN JSVM_Status OH_JSVM_IsNullOrUndefined (JSVM_Env env, JSVM_Value value, bool *isNullOrUndefined) Checks whether the value passed in is Null or Undefined. This API is equivalent to executing JavaScript code value == null.
JSVM_EXTERN JSVM_Status OH_JSVM_IsBoolean (JSVM_Env env, JSVM_Value value, bool *isBoolean) Checks whether the value passed in is a Boolean value. This API is equivalent to executing JavaScript code typeof value === ‘boolean’.
JSVM_EXTERN JSVM_Status OH_JSVM_IsNumber (JSVM_Env env, JSVM_Value value, bool *isNumber) Checks whether the value passed in is a number. This API is equivalent to executing JavaScript code typeof value === ‘number’.
JSVM_EXTERN JSVM_Status OH_JSVM_IsString (JSVM_Env env, JSVM_Value value, bool *isString) Checks whether the value passed in is a string. This API is equivalent to executing JavaScript code typeof value === ‘string’.
JSVM_EXTERN JSVM_Status OH_JSVM_IsSymbol (JSVM_Env env, JSVM_Value value, bool *isSymbol) Checks whether the value passed in is a symbol. This API is equivalent to executing JavaScript code typeof value === ‘symbol’.
JSVM_EXTERN JSVM_Status OH_JSVM_IsFunction (JSVM_Env env, JSVM_Value value, bool *isFunction) Checks whether the value passed in is a function. This API is equivalent to executing JavaScript code typeof value === ‘function’.
JSVM_EXTERN JSVM_Status OH_JSVM_IsObject (JSVM_Env env, JSVM_Value value, bool *isObject) Checks whether the value passed in is an object.
JSVM_EXTERN JSVM_Status OH_JSVM_IsBigInt (JSVM_Env env, JSVM_Value value, bool *isBigInt) Checks whether the value passed in is a BigInt. This API is equivalent to executing JS code typeof value === ‘bigint’.
JSVM_Status JSVM_CDECL OH_JSVM_CreateMap (JSVM_Env env, JSVM_Value *result) Returns the JavaScript value corresponding to the JavaScript Map type.
JSVM_Status JSVM_CDECL OH_JSVM_IsMap (JSVM_Env env, JSVM_Value value, bool *isMap) Checks whether the value passed in is a map.
JSVM_Status JSVM_CDECL OH_JSVM_IsConstructor (JSVM_Env env, JSVM_Value value, bool *isConstructor) Checks whether the value passed in is a constructor.
JSVM_Status JSVM_CDECL OH_JSVM_CreateRegExp (JSVM_Env env, JSVM_Value value, JSVM_RegExpFlags flags, JSVM_Value *result) Returns the JavaScript value of the regular expression corresponding to the input. An exception may be thrown.
JSVM_EXTERN JSVM_Status OH_JSVM_ObjectGetPrototypeOf (JSVM_Env env, JSVM_Value object, JSVM_Value *result) Gets the prototype of a JavaScript object.
JSVM_EXTERN JSVM_Status OH_JSVM_ObjectSetPrototypeOf (JSVM_Env env, JSVM_Value object, JSVM_Value prototype) Sets the prototype of a JavaScript object.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateSet (JSVM_Env env, JSVM_Value *result) Creates a JavaScript Set object.
JSVM_EXTERN JSVM_Status OH_JSVM_IsSet (JSVM_Env env, JSVM_Value value, bool *isSet) Checks whether the specified object is of the Set type.
JSVM_EXTERN JSVM_Status OH_JSVM_CoerceToBigInt (JSVM_Env env, JSVM_Value value, JSVM_Value *result) Implements the abstract operation ToBigInt().
JSVM_EXTERN JSVM_Status OH_JSVM_IsRegExp (JSVM_Env env, JSVM_Value value, bool *result) Checks whether the value passed in is a JavaScript RegExp object.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateFunctionWithScript (JSVM_Env env, const char *funcName, size_t length, size_t argc, const JSVM_Value *argv, JSVM_Value script, JSVM_Value *result) Creates a function with the given JavaScript as the function body.
JSVM_EXTERN JSVM_Status OH_JSVM_PumpMessageLoop (JSVM_VM vm, bool *result) Starts the running of the task queue in the VM. The task queue can be executed through an external event loop.
JSVM_EXTERN JSVM_Status OH_JSVM_PerformMicrotaskCheckpoint (JSVM_VM vm) Checks whether there are micro tasks waiting in the queue. If yes, execute them.
JSVM_EXTERN JSVM_Status OH_JSVM_RetainScript (JSVM_Env env, JSVM_Script script) Retains a JSVM_Script and extends its lifecycle beyond the current scope.
JSVM_EXTERN JSVM_Status OH_JSVM_ReleaseScript (JSVM_Env env, JSVM_Script script) Releases the script retained by OH_JSVM_RetainScript. The released script cannot be used again.
JSVM_EXTERN JSVM_Status OH_JSVM_OpenInspectorWithName (JSVM_Env env, int pid, const char *name) Opens an inspector with the specified name, in order to open the UNIX domain port corresponding to the PID.
JSVM_EXTERN JSVM_Status OH_JSVM_CompileWasmModule (JSVM_Env env, const uint8_t *wasmBytecode, size_t wasmBytecodeLength, const uint8_t *cacheData, size_t cacheDataLength, bool *cacheRejected, JSVM_Value *wasmModule) Compiles WebAssembly bytecode to get a WebAssembly module. If the WebAssembly cache is provided, it will be deserialized first.
JSVM_EXTERN JSVM_Status OH_JSVM_CompileWasmFunction (JSVM_Env env, JSVM_Value wasmModule, uint32_t functionIndex, JSVM_WasmOptLevel optLevel) Compiles the function with the specified index in the WebAssembly module at a specified optimization level.
JSVM_EXTERN JSVM_Status OH_JSVM_IsWasmModuleObject (JSVM_Env env, JSVM_Value value, bool *result) Checks whether the given JSVM_Value is a WebAssembly module.
JSVM_EXTERN JSVM_Status OH_JSVM_CreateWasmCache (JSVM_Env env, JSVM_Value wasmModule, const uint8_t **data, size_t *length) Creates a WebAssembly cache.
JSVM_EXTERN JSVM_Status OH_JSVM_ReleaseCache (JSVM_Env env, const uint8_t *cacheData, JSVM_CacheType cacheType) Releases the cache of a specified type.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Common Capabilities

harmony 鸿蒙_j_s_v_m

harmony 鸿蒙JSVM_CallbackStruct

harmony 鸿蒙JSVM_CreateVMOptions

harmony 鸿蒙JSVM_ExtendedErrorInfo

harmony 鸿蒙JSVM_HeapStatistics

harmony 鸿蒙JSVM_InitOptions

harmony 鸿蒙JSVM_PropertyDescriptor

harmony 鸿蒙JSVM_PropertyHandlerConfigurationStruct

harmony 鸿蒙JSVM_ScriptOrigin

0  赞