Node-API支持的Node-API接口(二)

一、扩展能力

接口功能说明
napi_queue_async_work_with_qos将异步工作对象加到队列,由底层根据传入的qos优先级去调度执行。
napi_run_script_path运行指定abc文件。
napi_load_module将abc文件作为模块加载,返回模块的命名空间。
napi_load_module_with_info将abc文件作为模块加载,返回模块的命名空间, 可在新创建的ArkTs基础运行时环境中使用。
napi_create_object_with_properties使用给定的napi_property_descriptor创建js Object。descriptor的键名必须为 string,且不可转为number。
napi_create_object_with_named_properties使用给定的napi_value和键名创建js Object。键名必须为 string,且不可转为number。
napi_coerce_to_native_binding_object强制将js Object和Native对象绑定。
napi_run_event_loop触发底层的事件循环。
napi_stop_event_loop停止底层的事件循环。
napi_serialize将ArkTS对象转换为native数据。
napi_deserialize将native数据转为ArkTS对象。
napi_delete_serialization_data删除序列化数据。
napi_call_threadsafe_function_with_priority将指定优先级和入队方式的任务投递到ArkTS线程。
napi_is_sendable判断给定JS value是否是Sendable的。
napi_define_sendable_class创建一个sendable类。
napi_create_sendable_object_with_properties使用给定的napi_property_descriptor创建一个sendable对象。
napi_create_sendable_array创建一个sendable数组。
napi_create_sendable_array_with_length创建一个指定长度的sendable数组。
napi_create_sendable_arraybuffer创建一个sendable ArrayBuffer。
napi_create_sendable_typedarray创建一个sendable TypedArray。
napi_wrap_sendable包裹一个native实例到ArkTS对象中。
napi_wrap_sendable_with_size包裹一个native实例到ArkTS对象中并指定大小。
napi_unwrap_sendable获取ArkTS对象包裹的native实例。
napi_remove_wrap_sendable移除并获取ArkTS对象包裹的native实例。

1、napi_queue_async_work_with_qos 

napi_status napi_queue_async_work_with_qos(napi_env env,
                                           napi_async_work work,
                                           napi_qos_t qos);

2、napi_run_script_path

napi_status napi_run_script_path(napi_env env,
                                 const char* abcPath,
                                 napi_value* result);

3、napi_load_module

napi_status napi_load_module(napi_env env,
                             const char* path,
                             napi_value* result);

4、napi_create_object_with_properties

napi_status napi_create_object_with_properties(napi_env env,
                                               napi_value* result,
                                               size_t property_count,
                                               const napi_property_descriptor* properties);

5、napi_create_object_with_named_properties

napi_status napi_create_object_with_named_properties(napi_env env,
                                                     napi_value* result,
                                                     size_t property_count,
                                                     const char** keys,
                                                     const napi_value* values);

6、napi_coerce_to_native_binding_object

napi_status napi_coerce_to_native_binding_object(napi_env env,
                                                 napi_value js_object,
                                                 napi_native_binding_detach_callback detach_cb,
                                                 napi_native_binding_attach_callback attach_cb,
                                                 void* native_object,
                                                 void* hint);

7、napi_run_event_loop

napi_status napi_run_event_loop(napi_env env, napi_event_mode mode);

8、napi_stop_event_loop

napi_status napi_stop_event_loop(napi_env env);

9、napi_serialize

napi_status napi_serialize(napi_env env,
                           napi_value object,
                           napi_value transfer_list,
                           napi_value clone_list,
                           void** result);

10、napi_deserialize

napi_status napi_deserialize(napi_env env, void* buffer, napi_value* object);

11、napi_delete_serialization_data

napi_status napi_delete_serialization_data(napi_env env, void* buffer);

12、napi_call_threadsafe_function_with_priority

napi_status napi_call_threadsafe_function_with_priority(napi_threadsafe_function func,
                                                        void *data,
                                                        napi_task_priority priority,
                                                        bool isTail);

13、napi_is_sendable

napi_status napi_is_sendable(napi_env env, napi_value value, bool* result);

14、napi_define_sendable_class

napi_status napi_define_sendable_class(napi_env env,
                                       const char* utf8name,
                                       size_t length,
                                       napi_callback constructor,
                                       void* data,
                                       size_t property_count,
                                       const napi_property_descriptor* properties,
                                       napi_value parent,
                                       napi_value* result);

15、napi_create_sendable_object_with_properties

napi_status napi_create_sendable_object_with_properties(napi_env env,
                                                        size_t property_count,
                                                        const napi_property_descriptor* properties,
                                                        napi_value* result);

16、napi_create_sendable_array

napi_status napi_create_sendable_array(napi_env env, napi_value* result);

17、napi_create_sendable_array_with_length

napi_status napi_create_sendable_array_with_length(napi_env env, size_t length, napi_value* result);

18、napi_create_sendable_arraybuffer

napi_status napi_create_sendable_arraybuffer(napi_env env, size_t byte_length, void** data, napi_value* result);

19、napi_create_sendable_typedarray

napi_status napi_create_sendable_typedarray(napi_env env,
                                            napi_typedarray_type type,
                                            size_t length,
                                            napi_value arraybuffer,
                                            size_t byte_offset,
                                            napi_value* result);

20、napi_wrap_sendable

napi_status napi_wrap_sendable(napi_env env,
                               napi_value js_object,
                               void* native_object,
                               napi_finalize finalize_cb,
                               void* finalize_hint);

21、napi_wrap_sendable_with_size

napi_status napi_wrap_sendable_with_size(napi_env env,
                                         napi_value js_object,
                                         void* native_object,
                                         napi_finalize finalize_cb,
                                         void* finalize_hint,
                                         size_t native_binding_size);

22、napi_unwrap_sendable

napi_status napi_unwrap_sendable(napi_env env, napi_value js_object, void** result);

23、napi_remove_wrap_sendable

napi_status napi_remove_wrap_sendable(napi_env env, napi_value js_object, void** result);

二、环境生命周期

接口功能说明
napi_set_instance_data绑定与当前运行的环境相关联的数据项。
napi_get_instance_data检索与当前运行的环境相关联的数据项。

三、对象生命周期管理

接口功能说明
napi_add_env_cleanup_hook注册环境清理钩子函数。
napi_remove_env_cleanup_hook取消环境清理钩子函数。
napi_add_async_cleanup_hook注册清理异步钩子函数。
napi_remove_async_cleanup_hook取消清理异步钩子函数。

四、ArkTs基础运行时环境

接口功能说明
napi_create_ark_runtime创建基础运行时环境
napi_destroy_ark_runtime销毁基础运行时环境

五、其他实用工具

接口功能说明
node_api_get_module_file_name用于获取加载项加载位置的绝对路径。

 

  • 15
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值