harmony 鸿蒙Node-API

2022-08-09 浏览 (1114)

Node-API

Introduction

Node-API (NAPI) provides APIs to encapsulate JavaScript (JS) capabilities as a native plug-in. It is independent of the underlying JS and is maintained as part of Node.js.

Supported Capabilities

NAPI eliminates the differences between underlying JS engines and provides a set of stable interfaces.

The OpenHarmony N-API component optimizes the Node-API interface implementation and provides connection to underlying engines such as ArkJS. Currently, some interfaces in the Node-API standard library are supported.

Symbols Exported from the N-API Component Standard Library

TypeSymbolDescription
FUNCnapi_module_registerRegisters the NAPI native module.
FUNCnapi_get_last_error_infoObtains the napi_extended_error_info structure, which contains the latest error information.
FUNCnapi_throwThrows a JS value.
FUNCnapi_throw_errorThrows a JS Error with text information.
FUNCnapi_throw_type_errorThrows a JS TypeError with text information.
FUNCnapi_throw_range_errorThrows a JS RangeError with text information.
FUNCnapi_is_errorChecks whether napi_value indicates an error object.
FUNCnapi_create_errorCreates a JS Error with text information.
FUNCnapi_create_type_errorCreates a JS TypeError with text information.
FUNCnapi_create_range_errorCreates a JS RangeError with text information.
FUNCnapi_get_and_clear_last_exceptionObtains and clears the latest exception.
FUNCnapi_is_exception_pendingChecks whether an exception occurs.
FUNCnapi_fatal_errorRaises a fatal error to terminate the process immediately.
FUNCnapi_open_handle_scopeCreates a context environment.
FUNCnapi_close_handle_scopeCloses the context environment. After the context environment is closed, all references declared in it are closed.
FUNCnapi_open_escapable_handle_scopeCreates an escapable handle scope from which the declared values can be returned to the parent scope.
FUNCnapi_close_escapable_handle_scopeCloses the escapable handle scope passed in.
FUNCnapi_escape_handlePromotes the handle to the input JS object so that it is valid for the lifespan of its parent scope.
FUNCnapi_create_referenceCreates a reference for an Object to extend its lifespan. The caller needs to manage the reference lifespan.
FUNCnapi_delete_referenceDeletes the reference passed in.
FUNCnapi_reference_refIncrements the reference count for the reference passed in and returns the count.
FUNCnapi_reference_unrefDecrements the reference count for the reference passed in and returns the count.
FUNCnapi_get_reference_valueObtains the JS Object associated with the reference.
FUNCnapi_create_arrayCreates a JS Array.
FUNCnapi_create_array_with_lengthCreates a JS Array of the specified length.
FUNCnapi_create_arraybufferCreates a JS ArrayBuffer of the specified size.
FUNCnapi_create_externalAllocates a JS value with external data.
FUNCnapi_create_external_arraybufferAllocates a JS ArrayBuffer with external data.
FUNCnapi_create_objectCreates a default JS Object.
FUNCnapi_create_symbolCreate a JS Symbol.
FUNCnapi_create_typedarrayCreates a JS TypeArray from an existing ArrayBuffer.
FUNCnapi_create_dataviewCreates a JS DataView from an existing ArrayBuffer.
FUNCnapi_create_int32Creates a JS Number from C int32_t data.
FUNCnapi_create_uint32Creates a JS Number from C uint32_t data.
FUNCnapi_create_int64Creates a JS Number from C int64_t data.
FUNCnapi_create_doubleCreates a JS Number from C double data.
FUNCnapi_create_string_latin1Creates a JS String from an ISO-8859-1-encoded C string.
FUNCnapi_create_string_utf8Creates a JS String from a UTF8-encoded C string.
FUNCnapi_create_string_utf16Creates a JS String from a UTF16-encoded C string.
FUNCnapi_get_array_lengthObtains the length of an array.
FUNCnapi_get_arraybuffer_infoObtains the underlying data buffer of the ArrayBuffer and its length.
FUNCnapi_get_prototypeObtains the prototype of the specified JS Object.
FUNCnapi_get_typedarray_infoObtains properties of the specified TypedArray.
FUNCnapi_get_dataview_infoObtains properties of the specified DataView.
FUNCnapi_get_value_boolObtains the C Boolean equivalent of the given JS Boolean.
FUNCnapi_get_value_doubleObtains the C double equivalent of the given JS Number.
FUNCnapi_get_value_externalObtains the external data pointer previously passed through napi_create_external().
FUNCnapi_get_value_int32Obtains the C int32 equivalent of the given JS Number.
FUNCnapi_get_value_int64Obtains the C int64 equivalent of the given JS Number.
FUNCnapi_get_value_string_latin1Obtains the ISO-8859-1-encoded string corresponding to the given JS value.
FUNCnapi_get_value_string_utf8Obtains the UTF8-encoded string corresponding to the given JS value.
FUNCnapi_get_value_string_utf16Obtains the UTF16-encoded string corresponding to the given JS value.
FUNCnapi_get_value_uint32Obtains the C uint32 equivalent of the given JS Number.
FUNCnapi_get_booleanObtains the JS Boolean object based on the given C Boolean value.
FUNCnapi_get_globalObtains the global object.
FUNCnapi_get_nullObtains the null object.
FUNCnapi_get_undefinedObtains the undefined object.
FUNCnapi_coerce_to_boolForcibly converts the given JS value to a JS Boolean value.
FUNCnapi_coerce_to_numberForcibly converts the given JS value to a JS number.
FUNCnapi_coerce_to_objectForcibly converts the given JS value to a JS object.
FUNCnapi_coerce_to_stringForcibly converts the given JS value to a JS string.
FUNCnapi_typeofObtains the JS type of the given JS value.
FUNCnapi_instanceofChecks whether the given object is an instance of the specified constructor.
FUNCnapi_is_arrayChecks whether the given JS value is an array.
FUNCnapi_is_arraybufferChecks whether the given JS value is a ArrayBuffer.
FUNCnapi_is_typedarrayChecks whether the given JS value is a TypedArray.
FUNCnapi_is_dataviewChecks whether the given JS value is a DataView.
FUNCnapi_is_dateChecks whether the given JS value is a JS Date object.
FUNCnapi_strict_equalsChecks whether two JS values are strictly equal.
FUNCnapi_get_property_namesObtains the names of the enumerable properties of Object in an array of strings.
FUNCnapi_set_propertySets a property for the given Object.
FUNCnapi_get_propertyObtains the requested property of the given Object.
FUNCnapi_has_propertyChecks whether the given Object has the specified property.
FUNCnapi_delete_propertyDeletes the key property from the given Object.
FUNCnapi_has_own_propertyChecks whether the given Object has the own property named key.
FUNCnapi_set_named_propertySets a property with the specified name for the given Object.
FUNCnapi_get_named_propertyObtains the property with the specified name in the given Object.
FUNCnapi_has_named_propertyChecks whether the given Object has the property with the specified name.
FUNCnapi_set_elementSets an element at the specified index of the given Object.
FUNCnapi_get_elementObtains the element at the specified index of the given Object.
FUNCnapi_has_elementObtains the element if the given Object has an element at the specified index.
FUNCnapi_delete_elementDeletes the element at the specified index of the given Object.
FUNCnapi_define_propertiesDefines multiple properties for the given Object.
FUNCnapi_type_tag_objectAssociates the value of the tag pointer with Object.
FUNCnapi_check_object_type_tagChecks whether a tag pointer is associated with the JS Object.
FUNCnapi_call_functionCalls a JS function in a native method, that is, native call JS.
FUNCnapi_create_functionCreates a native method for JS to call.
FUNCnapi_get_cb_infoObtains detailed information about the call, such as the parameters and this pointer, from the given callback info.
FUNCnapi_get_new_targetObtains the new.target of the constructor call.
FUNCnapi_new_instanceCreates an instance based on the given constructor.
FUNCnapi_define_classDefines a JS class corresponding to the C++ class.
FUNCnapi_wrapWraps a native instance in a JS object.
FUNCnapi_unwrapObtains the native instance that was previously wrapped in a JS object.
FUNCnapi_remove_wrapObtains the native instance that was previously wrapped in a JS object and removes the wrapping.
FUNCnapi_create_async_workCreates a work object that executes logic asynchronously.
FUNCnapi_delete_async_workReleases an asynchronous work object.
FUNCnapi_queue_async_workAdds an asynchronous work object to the queue so that it can be scheduled for execution.
FUNCnapi_cancel_async_workCancels the queued asynchronous work if it has not been started.
FUNCnapi_get_node_versionObtains the current Node-API version.
FUNCnapi_get_versionObtains the latest Node-API version supported when the Node.js runtime.
FUNCnapi_create_promiseCreates a deferred object and a JS promise.
FUNCnapi_resolve_deferredResolves a deferred object that is associated with a JS promise.
FUNCnapi_reject_deferredRejects a deferred object that is associated with a JS promise.
FUNCnapi_is_promiseChecks whether the given JS value is a promise object.
FUNCnapi_get_uv_event_loopObtains the current libuv loop instance.
FUNCnapi_create_threadsafe_functionCreates a thread-safe function.
FUNCnapi_get_threadsafe_function_contextObtains the context of a thread-safe function.
FUNCnapi_call_threadsafe_functionCalls a thread-safe function.
FUNCnapi_acquire_threadsafe_functionIndicates that a thread starts to use a thread-safe function.
FUNCnapi_release_threadsafe_functionIndicates that a thread releases a thread-safe function.
FUNCnapi_ref_threadsafe_functionIndicates that the event loop running on the main thread should not exit until the thread-safe function is destroyed.
FUNCnapi_unref_threadsafe_functionIndicates that the event loop running on the main thread may exit before the thread-safe function is destroyed.
FUNCnapi_create_dateCreates a JS Date from C double data.
FUNCnapi_get_date_valueObtains the C double equivalent of the given JS Date.
FUNCnapi_create_bigint_int64Creates a JS BigInt from C int64 data.
FUNCnapi_create_bigint_uint64Creates a JS BigInt from C uint64 data.
FUNCnapi_create_bigint_wordsCreates a single JS BigInt from a C uint64 array.
FUNCnapi_get_value_bigint_int64Obtains the C int64 equivalent of the given JS BigInt.
FUNCnapi_get_value_bigint_uint64Obtains the C uint64 equivalent of the given JS BigInt.
FUNCnapi_get_value_bigint_wordsObtains information from the given JS BigInt, including the sign bit, 64-bit little-endian array, and number of elements in the array.
FUNCnapi_create_bufferCreates a JS Buffer instance of the specified size.
FUNCnapi_create_buffer_copyCreates a JS Buffer instance of the specified size, and initializes it with data copied from the passed-in buffer.
FUNCnapi_create_external_bufferCreates a JS Buffer instance of the specified size, and initializes it with the given data. The Buffer instance created can include extra.
FUNCnapi_get_buffer_infoObtains the underlying data of Buffer and its length.
FUNCnapi_is_bufferChecks whether the given JS value is a Buffer object.
FUNCnapi_object_freezeFreezes the given object.
FUNCnapi_object_sealSeals the given object.
FUNCnapi_get_all_property_namesObtains an array containing the names of all the available properties of this object.
FUNCnapi_detach_arraybufferDetaches the underlying data of the given ArrayBuffer.
FUNCnapi_is_detached_arraybufferChecks whether the given ArrayBuffer has been detached.

Extended Symbols of the N-API Component

TypeSymbolDescription
FUNCnapi_queue_async_work_with_qosAdds asynchronously working objects to the queue and schedules them based on the QoS priority.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙1.0.0 (2022/03/09)

harmony 鸿蒙1.0.0 (2022/03/09)

harmony 鸿蒙OpenHarmony Docker镜像

harmony 鸿蒙OpenHarmony Docker Image

harmony 鸿蒙Legal Notices

harmony 鸿蒙OpenHarmony Project

harmony 鸿蒙IDL Specifications and User Guide (for System Applications Only)

harmony 鸿蒙Application Development

harmony 鸿蒙OAID Service

harmony 鸿蒙AI

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/5a27a9efa5e04a5c9f5fec6dba18bb60