koffi 2.16.0-beta.2 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +59 -0
- package/build/koffi/darwin_arm64/koffi.node +0 -0
- package/build/koffi/darwin_x64/koffi.node +0 -0
- package/build/koffi/freebsd_arm64/koffi.node +0 -0
- package/build/koffi/freebsd_ia32/koffi.node +0 -0
- package/build/koffi/freebsd_x64/koffi.node +0 -0
- package/build/koffi/linux_arm64/koffi.node +0 -0
- package/build/koffi/linux_armhf/koffi.node +0 -0
- package/build/koffi/linux_ia32/koffi.node +0 -0
- package/build/koffi/linux_loong64/koffi.node +0 -0
- package/build/koffi/linux_riscv64d/koffi.node +0 -0
- package/build/koffi/linux_x64/koffi.node +0 -0
- package/build/koffi/musl_arm64/koffi.node +0 -0
- package/build/koffi/musl_x64/koffi.node +0 -0
- package/build/koffi/openbsd_ia32/koffi.node +0 -0
- package/build/koffi/openbsd_x64/koffi.node +0 -0
- package/build/koffi/win32_arm64/koffi.exp +0 -0
- package/build/koffi/win32_arm64/koffi.lib +0 -0
- package/build/koffi/win32_arm64/koffi.node +0 -0
- package/build/koffi/win32_ia32/koffi.exp +0 -0
- package/build/koffi/win32_ia32/koffi.lib +0 -0
- package/build/koffi/win32_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.exp +0 -0
- package/build/koffi/win32_x64/koffi.lib +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/index.d.ts +9 -11
- package/index.js +6 -9
- package/indirect.js +6 -9
- package/lib/native/base/base.cc +1 -6
- package/package.json +3 -3
- package/src/cnoke/assets/FindCNoke.cmake +27 -16
- package/src/cnoke/assets/toolchains.json +126 -0
- package/src/cnoke/cnoke.js +27 -33
- package/src/cnoke/src/builder.js +124 -63
- package/src/cnoke/src/tools.js +1 -5
- package/src/koffi/CMakeLists.txt +32 -21
- package/src/koffi/src/{abi/arm32.cc → abi_arm32.cc} +235 -238
- package/src/koffi/src/{abi/arm32_asm.S → abi_arm32_asm.S} +19 -15
- package/src/koffi/src/{abi/arm64.cc → abi_arm64.cc} +253 -274
- package/src/koffi/src/{abi/arm64_asm.S → abi_arm64_asm.S} +16 -10
- package/src/koffi/src/{abi/arm64_asm.asm → abi_arm64_asm.asm} +17 -10
- package/src/koffi/src/{abi/loong64_asm.S → abi_loong64_asm.S} +16 -10
- package/src/koffi/src/{abi/riscv64.cc → abi_riscv64.cc} +233 -236
- package/src/koffi/src/{abi/riscv64_asm.S → abi_riscv64_asm.S} +16 -10
- package/src/koffi/src/{abi/x64_sysv.cc → abi_x64_sysv.cc} +208 -212
- package/src/koffi/src/{abi/x64_sysv_asm.S → abi_x64_sysv_asm.S} +17 -10
- package/src/koffi/src/{abi/x64_win.cc → abi_x64_win.cc} +175 -206
- package/src/koffi/src/{abi/x64_win_asm.S → abi_x64_win_asm.S} +49 -27
- package/src/koffi/src/{abi/x64_win_asm.asm → abi_x64_win_asm.asm} +54 -27
- package/src/koffi/src/{abi/x86.cc → abi_x86.cc} +187 -226
- package/src/koffi/src/{abi/x86_asm.S → abi_x86_asm.S} +36 -21
- package/src/koffi/src/{abi/x86_asm.asm → abi_x86_asm.asm} +31 -16
- package/src/koffi/src/call.cc +473 -287
- package/src/koffi/src/call.hh +15 -18
- package/src/koffi/src/ffi.cc +167 -183
- package/src/koffi/src/ffi.hh +59 -13
- package/src/koffi/src/init.js +1 -0
- package/src/koffi/src/util.cc +113 -159
- package/src/koffi/src/util.hh +23 -74
- package/src/koffi/src/win32.cc +13 -0
- package/src/koffi/src/win32.hh +7 -0
- package/src/koffi/tools/write_trampolines.js +77 -0
- package/doc/README.md +0 -27
- package/doc/assets.ini +0 -24
- package/doc/build.sh +0 -9
- package/doc/develop.sh +0 -15
- package/doc/pages/404.md +0 -17
- package/doc/pages.ini +0 -86
- package/doc/static/highlight.js +0 -8
- package/doc/static/koffi.css +0 -11
- package/doc/static/koffi.png +0 -0
- package/doc/static/logo.webp +0 -0
- package/doc/static/perf_linux.png +0 -0
- package/doc/static/perf_windows.png +0 -0
- package/doc/static/print.css +0 -10
- package/doc/templates/code.html +0 -48
- package/doc/templates/page.html +0 -47
- package/src/koffi/cmake/raylib.cmake +0 -85
- package/src/koffi/cmake/sqlite3.cmake +0 -9
- package/src/koffi/examples/electron-builder/README.md +0 -11
- package/src/koffi/examples/electron-builder/package.json +0 -21
- package/src/koffi/examples/electron-builder/src/app.js +0 -20
- package/src/koffi/examples/electron-builder/src/index.html +0 -143
- package/src/koffi/examples/electron-builder/src/preload.js +0 -5
- package/src/koffi/examples/electron-forge/README.md +0 -25
- package/src/koffi/examples/electron-forge/forge.config.js +0 -63
- package/src/koffi/examples/electron-forge/package.json +0 -39
- package/src/koffi/examples/electron-forge/src/index.css +0 -7
- package/src/koffi/examples/electron-forge/src/index.html +0 -143
- package/src/koffi/examples/electron-forge/src/main.js +0 -52
- package/src/koffi/examples/electron-forge/src/preload.js +0 -5
- package/src/koffi/examples/electron-forge/src/renderer.js +0 -31
- package/src/koffi/examples/electron-forge/webpack.main.config.js +0 -11
- package/src/koffi/examples/electron-forge/webpack.renderer.config.js +0 -13
- package/src/koffi/examples/electron-forge/webpack.rules.js +0 -35
- package/src/koffi/examples/node-esbuild/README.md +0 -19
- package/src/koffi/examples/node-esbuild/index.js +0 -2
- package/src/koffi/examples/node-esbuild/package.json +0 -16
- package/src/koffi/examples/nwjs/README.md +0 -20
- package/src/koffi/examples/nwjs/package.json +0 -11
- package/src/koffi/examples/nwjs/src/index.html +0 -145
- package/src/koffi/examples/nwjs/src/package.json +0 -10
- package/src/koffi/examples/yao-pkg/README.md +0 -17
- package/src/koffi/examples/yao-pkg/index.js +0 -2
- package/src/koffi/examples/yao-pkg/package.json +0 -22
- package/src/koffi/src/primitives.inc +0 -39
- package/src/koffi/src/trampolines/armasm.inc +0 -32771
- package/src/koffi/src/trampolines/gnu.inc +0 -24577
- package/src/koffi/src/trampolines/masm32.inc +0 -32769
- package/src/koffi/src/trampolines/masm64.inc +0 -32769
- package/src/koffi/src/trampolines/prototypes.inc +0 -16388
- package/vendor/node-addon-api/CHANGELOG.md +0 -1272
- package/vendor/node-addon-api/CODE_OF_CONDUCT.md +0 -4
- package/vendor/node-addon-api/CONTRIBUTING.md +0 -203
- package/vendor/node-addon-api/appveyor.yml +0 -37
- package/vendor/node-addon-api/benchmark/README.md +0 -47
- package/vendor/node-addon-api/benchmark/binding.gyp +0 -25
- package/vendor/node-addon-api/benchmark/function_args.cc +0 -250
- package/vendor/node-addon-api/benchmark/function_args.js +0 -60
- package/vendor/node-addon-api/benchmark/index.js +0 -34
- package/vendor/node-addon-api/benchmark/property_descriptor.cc +0 -84
- package/vendor/node-addon-api/benchmark/property_descriptor.js +0 -38
- package/vendor/node-addon-api/common.gypi +0 -21
- package/vendor/node-addon-api/doc/README.md +0 -145
- package/vendor/node-addon-api/doc/addon.md +0 -163
- package/vendor/node-addon-api/doc/array.md +0 -81
- package/vendor/node-addon-api/doc/array_buffer.md +0 -165
- package/vendor/node-addon-api/doc/async_context.md +0 -86
- package/vendor/node-addon-api/doc/async_operations.md +0 -31
- package/vendor/node-addon-api/doc/async_worker.md +0 -428
- package/vendor/node-addon-api/doc/async_worker_variants.md +0 -578
- package/vendor/node-addon-api/doc/basic_env.md +0 -200
- package/vendor/node-addon-api/doc/bigint.md +0 -97
- package/vendor/node-addon-api/doc/boolean.md +0 -68
- package/vendor/node-addon-api/doc/buffer.md +0 -245
- package/vendor/node-addon-api/doc/callback_scope.md +0 -54
- package/vendor/node-addon-api/doc/callbackinfo.md +0 -97
- package/vendor/node-addon-api/doc/checker-tool.md +0 -32
- package/vendor/node-addon-api/doc/class_property_descriptor.md +0 -123
- package/vendor/node-addon-api/doc/cmake-js.md +0 -87
- package/vendor/node-addon-api/doc/contributing/creating_a_release.md +0 -95
- package/vendor/node-addon-api/doc/conversion-tool.md +0 -28
- package/vendor/node-addon-api/doc/dataview.md +0 -248
- package/vendor/node-addon-api/doc/date.md +0 -68
- package/vendor/node-addon-api/doc/env.md +0 -87
- package/vendor/node-addon-api/doc/error.md +0 -120
- package/vendor/node-addon-api/doc/error_handling.md +0 -266
- package/vendor/node-addon-api/doc/escapable_handle_scope.md +0 -80
- package/vendor/node-addon-api/doc/external.md +0 -79
- package/vendor/node-addon-api/doc/external_buffer.md +0 -18
- package/vendor/node-addon-api/doc/finalization.md +0 -153
- package/vendor/node-addon-api/doc/function.md +0 -402
- package/vendor/node-addon-api/doc/function_reference.md +0 -238
- package/vendor/node-addon-api/doc/generator.md +0 -13
- package/vendor/node-addon-api/doc/handle_scope.md +0 -77
- package/vendor/node-addon-api/doc/hierarchy.md +0 -95
- package/vendor/node-addon-api/doc/instance_wrap.md +0 -408
- package/vendor/node-addon-api/doc/maybe.md +0 -76
- package/vendor/node-addon-api/doc/memory_management.md +0 -27
- package/vendor/node-addon-api/doc/name.md +0 -29
- package/vendor/node-addon-api/doc/node-gyp.md +0 -82
- package/vendor/node-addon-api/doc/number.md +0 -163
- package/vendor/node-addon-api/doc/object.md +0 -411
- package/vendor/node-addon-api/doc/object_lifetime_management.md +0 -83
- package/vendor/node-addon-api/doc/object_reference.md +0 -117
- package/vendor/node-addon-api/doc/object_wrap.md +0 -604
- package/vendor/node-addon-api/doc/prebuild_tools.md +0 -16
- package/vendor/node-addon-api/doc/promises.md +0 -130
- package/vendor/node-addon-api/doc/property_descriptor.md +0 -286
- package/vendor/node-addon-api/doc/propertylvalue.md +0 -50
- package/vendor/node-addon-api/doc/range_error.md +0 -59
- package/vendor/node-addon-api/doc/reference.md +0 -113
- package/vendor/node-addon-api/doc/setup.md +0 -115
- package/vendor/node-addon-api/doc/string.md +0 -93
- package/vendor/node-addon-api/doc/symbol.md +0 -61
- package/vendor/node-addon-api/doc/syntax_error.md +0 -66
- package/vendor/node-addon-api/doc/threadsafe.md +0 -121
- package/vendor/node-addon-api/doc/threadsafe_function.md +0 -290
- package/vendor/node-addon-api/doc/type_error.md +0 -59
- package/vendor/node-addon-api/doc/type_taggable.md +0 -40
- package/vendor/node-addon-api/doc/typed_array.md +0 -78
- package/vendor/node-addon-api/doc/typed_array_of.md +0 -137
- package/vendor/node-addon-api/doc/typed_threadsafe_function.md +0 -306
- package/vendor/node-addon-api/doc/value.md +0 -368
- package/vendor/node-addon-api/doc/version_management.md +0 -43
- package/vendor/node-addon-api/eslint.config.js +0 -5
- package/vendor/node-addon-api/except.gypi +0 -25
- package/vendor/node-addon-api/index.js +0 -14
- package/vendor/node-addon-api/node_addon_api.gyp +0 -42
- package/vendor/node-addon-api/node_api.gyp +0 -9
- package/vendor/node-addon-api/noexcept.gypi +0 -26
- package/vendor/node-addon-api/nothing.c +0 -0
- package/vendor/node-addon-api/package-support.json +0 -21
- package/vendor/node-addon-api/package.json +0 -480
- package/vendor/node-addon-api/release-please-config.json +0 -15
- package/vendor/node-addon-api/test/README.md +0 -91
- package/vendor/node-addon-api/test/addon.cc +0 -44
- package/vendor/node-addon-api/test/addon.js +0 -7
- package/vendor/node-addon-api/test/addon_build/index.js +0 -49
- package/vendor/node-addon-api/test/addon_build/tpl/addon.cc +0 -18
- package/vendor/node-addon-api/test/addon_build/tpl/binding.gyp +0 -63
- package/vendor/node-addon-api/test/addon_build/tpl/index.js +0 -9
- package/vendor/node-addon-api/test/addon_build/tpl/package.json +0 -11
- package/vendor/node-addon-api/test/addon_data.cc +0 -98
- package/vendor/node-addon-api/test/addon_data.js +0 -24
- package/vendor/node-addon-api/test/array_buffer.cc +0 -243
- package/vendor/node-addon-api/test/array_buffer.js +0 -70
- package/vendor/node-addon-api/test/async_context.cc +0 -36
- package/vendor/node-addon-api/test/async_context.js +0 -122
- package/vendor/node-addon-api/test/async_progress_queue_worker.cc +0 -248
- package/vendor/node-addon-api/test/async_progress_queue_worker.js +0 -180
- package/vendor/node-addon-api/test/async_progress_worker.cc +0 -357
- package/vendor/node-addon-api/test/async_progress_worker.js +0 -200
- package/vendor/node-addon-api/test/async_worker.cc +0 -341
- package/vendor/node-addon-api/test/async_worker.js +0 -264
- package/vendor/node-addon-api/test/async_worker_nocallback.js +0 -19
- package/vendor/node-addon-api/test/async_worker_persistent.cc +0 -63
- package/vendor/node-addon-api/test/async_worker_persistent.js +0 -24
- package/vendor/node-addon-api/test/basic_types/array.cc +0 -40
- package/vendor/node-addon-api/test/basic_types/array.js +0 -34
- package/vendor/node-addon-api/test/basic_types/boolean.cc +0 -40
- package/vendor/node-addon-api/test/basic_types/boolean.js +0 -34
- package/vendor/node-addon-api/test/basic_types/number.cc +0 -105
- package/vendor/node-addon-api/test/basic_types/number.js +0 -115
- package/vendor/node-addon-api/test/basic_types/value.cc +0 -177
- package/vendor/node-addon-api/test/basic_types/value.js +0 -173
- package/vendor/node-addon-api/test/bigint.cc +0 -91
- package/vendor/node-addon-api/test/bigint.js +0 -53
- package/vendor/node-addon-api/test/binding-swallowexcept.cc +0 -12
- package/vendor/node-addon-api/test/binding.cc +0 -200
- package/vendor/node-addon-api/test/binding.gyp +0 -160
- package/vendor/node-addon-api/test/buffer.cc +0 -185
- package/vendor/node-addon-api/test/buffer.h +0 -26
- package/vendor/node-addon-api/test/buffer.js +0 -150
- package/vendor/node-addon-api/test/buffer_new_or_copy-inl.h +0 -68
- package/vendor/node-addon-api/test/buffer_no_external.cc +0 -24
- package/vendor/node-addon-api/test/callbackInfo.cc +0 -27
- package/vendor/node-addon-api/test/callbackInfo.js +0 -9
- package/vendor/node-addon-api/test/callbackscope.cc +0 -39
- package/vendor/node-addon-api/test/callbackscope.js +0 -49
- package/vendor/node-addon-api/test/child_processes/addon.js +0 -11
- package/vendor/node-addon-api/test/child_processes/addon_data.js +0 -24
- package/vendor/node-addon-api/test/child_processes/objectwrap_function.js +0 -22
- package/vendor/node-addon-api/test/child_processes/threadsafe_function_exception.js +0 -33
- package/vendor/node-addon-api/test/child_processes/typed_threadsafe_function_exception.js +0 -19
- package/vendor/node-addon-api/test/common/index.js +0 -246
- package/vendor/node-addon-api/test/common/test_helper.h +0 -71
- package/vendor/node-addon-api/test/dataview/dataview.cc +0 -48
- package/vendor/node-addon-api/test/dataview/dataview.js +0 -35
- package/vendor/node-addon-api/test/dataview/dataview_read_write.cc +0 -115
- package/vendor/node-addon-api/test/dataview/dataview_read_write.js +0 -92
- package/vendor/node-addon-api/test/date.cc +0 -45
- package/vendor/node-addon-api/test/date.js +0 -18
- package/vendor/node-addon-api/test/env_cleanup.cc +0 -100
- package/vendor/node-addon-api/test/env_cleanup.js +0 -55
- package/vendor/node-addon-api/test/env_misc.cc +0 -25
- package/vendor/node-addon-api/test/env_misc.js +0 -12
- package/vendor/node-addon-api/test/error.cc +0 -436
- package/vendor/node-addon-api/test/error.js +0 -111
- package/vendor/node-addon-api/test/error_handling_for_primitives.cc +0 -13
- package/vendor/node-addon-api/test/error_handling_for_primitives.js +0 -29
- package/vendor/node-addon-api/test/error_terminating_environment.js +0 -99
- package/vendor/node-addon-api/test/except_all.cc +0 -22
- package/vendor/node-addon-api/test/except_all.js +0 -14
- package/vendor/node-addon-api/test/exports.js +0 -19
- package/vendor/node-addon-api/test/external.cc +0 -85
- package/vendor/node-addon-api/test/external.js +0 -85
- package/vendor/node-addon-api/test/finalizer_order.cc +0 -152
- package/vendor/node-addon-api/test/finalizer_order.js +0 -98
- package/vendor/node-addon-api/test/function.cc +0 -338
- package/vendor/node-addon-api/test/function.js +0 -137
- package/vendor/node-addon-api/test/function_reference.cc +0 -204
- package/vendor/node-addon-api/test/function_reference.js +0 -157
- package/vendor/node-addon-api/test/globalObject/global_object.cc +0 -61
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.cc +0 -31
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.js +0 -58
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.cc +0 -40
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.js +0 -56
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.cc +0 -28
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.js +0 -46
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.cc +0 -31
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.js +0 -56
- package/vendor/node-addon-api/test/handlescope.cc +0 -86
- package/vendor/node-addon-api/test/handlescope.js +0 -16
- package/vendor/node-addon-api/test/index.js +0 -160
- package/vendor/node-addon-api/test/maybe/check.cc +0 -69
- package/vendor/node-addon-api/test/maybe/index.js +0 -50
- package/vendor/node-addon-api/test/memory_management.cc +0 -18
- package/vendor/node-addon-api/test/memory_management.js +0 -9
- package/vendor/node-addon-api/test/movable_callbacks.cc +0 -23
- package/vendor/node-addon-api/test/movable_callbacks.js +0 -21
- package/vendor/node-addon-api/test/name.cc +0 -110
- package/vendor/node-addon-api/test/name.js +0 -59
- package/vendor/node-addon-api/test/napi_child.js +0 -14
- package/vendor/node-addon-api/test/object/delete_property.cc +0 -38
- package/vendor/node-addon-api/test/object/delete_property.js +0 -41
- package/vendor/node-addon-api/test/object/finalizer.cc +0 -30
- package/vendor/node-addon-api/test/object/finalizer.js +0 -28
- package/vendor/node-addon-api/test/object/get_property.cc +0 -34
- package/vendor/node-addon-api/test/object/get_property.js +0 -40
- package/vendor/node-addon-api/test/object/has_own_property.cc +0 -34
- package/vendor/node-addon-api/test/object/has_own_property.js +0 -34
- package/vendor/node-addon-api/test/object/has_property.cc +0 -38
- package/vendor/node-addon-api/test/object/has_property.js +0 -37
- package/vendor/node-addon-api/test/object/object.cc +0 -430
- package/vendor/node-addon-api/test/object/object.js +0 -218
- package/vendor/node-addon-api/test/object/object_deprecated.cc +0 -70
- package/vendor/node-addon-api/test/object/object_deprecated.js +0 -42
- package/vendor/node-addon-api/test/object/object_freeze_seal.cc +0 -25
- package/vendor/node-addon-api/test/object/object_freeze_seal.js +0 -61
- package/vendor/node-addon-api/test/object/set_property.cc +0 -45
- package/vendor/node-addon-api/test/object/set_property.js +0 -30
- package/vendor/node-addon-api/test/object/subscript_operator.cc +0 -58
- package/vendor/node-addon-api/test/object/subscript_operator.js +0 -17
- package/vendor/node-addon-api/test/object_reference.cc +0 -417
- package/vendor/node-addon-api/test/object_reference.js +0 -262
- package/vendor/node-addon-api/test/objectwrap.cc +0 -295
- package/vendor/node-addon-api/test/objectwrap.js +0 -309
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.cc +0 -26
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.js +0 -18
- package/vendor/node-addon-api/test/objectwrap_function.cc +0 -43
- package/vendor/node-addon-api/test/objectwrap_function.js +0 -6
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.cc +0 -30
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.js +0 -13
- package/vendor/node-addon-api/test/objectwrap_removewrap.cc +0 -45
- package/vendor/node-addon-api/test/objectwrap_removewrap.js +0 -32
- package/vendor/node-addon-api/test/objectwrap_worker_thread.js +0 -20
- package/vendor/node-addon-api/test/promise.cc +0 -111
- package/vendor/node-addon-api/test/promise.js +0 -43
- package/vendor/node-addon-api/test/reference.cc +0 -78
- package/vendor/node-addon-api/test/reference.js +0 -20
- package/vendor/node-addon-api/test/require_basic_finalizers/index.js +0 -38
- package/vendor/node-addon-api/test/require_basic_finalizers/tpl/addon.cc +0 -12
- package/vendor/node-addon-api/test/require_basic_finalizers/tpl/binding.gyp +0 -48
- package/vendor/node-addon-api/test/require_basic_finalizers/tpl/index.js +0 -3
- package/vendor/node-addon-api/test/require_basic_finalizers/tpl/package.json +0 -11
- package/vendor/node-addon-api/test/run_script.cc +0 -56
- package/vendor/node-addon-api/test/run_script.js +0 -45
- package/vendor/node-addon-api/test/symbol.cc +0 -79
- package/vendor/node-addon-api/test/symbol.js +0 -66
- package/vendor/node-addon-api/test/testUtil.js +0 -54
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.cc +0 -230
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.js +0 -225
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.cc +0 -155
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.js +0 -13
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_exception.cc +0 -50
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_exception.js +0 -20
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.cc +0 -125
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.js +0 -14
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.cc +0 -27
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.js +0 -7
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.cc +0 -240
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.js +0 -59
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.cc +0 -55
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.js +0 -98
- package/vendor/node-addon-api/test/thunking_manual.cc +0 -127
- package/vendor/node-addon-api/test/thunking_manual.js +0 -16
- package/vendor/node-addon-api/test/type_taggable.cc +0 -66
- package/vendor/node-addon-api/test/type_taggable.js +0 -59
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.cc +0 -215
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.js +0 -188
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc +0 -120
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +0 -14
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_exception.cc +0 -39
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_exception.js +0 -13
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc +0 -127
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js +0 -14
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc +0 -32
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js +0 -8
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc +0 -237
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.js +0 -59
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc +0 -67
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js +0 -98
- package/vendor/node-addon-api/test/typedarray-bigint.js +0 -58
- package/vendor/node-addon-api/test/typedarray.cc +0 -413
- package/vendor/node-addon-api/test/typedarray.js +0 -103
- package/vendor/node-addon-api/test/value_type_cast.cc +0 -60
- package/vendor/node-addon-api/test/value_type_cast.js +0 -106
- package/vendor/node-addon-api/test/version_management.cc +0 -28
- package/vendor/node-addon-api/test/version_management.js +0 -29
- package/vendor/node-addon-api/tools/README.md +0 -73
- package/vendor/node-addon-api/tools/check-napi.js +0 -99
- package/vendor/node-addon-api/tools/clang-format.js +0 -71
- package/vendor/node-addon-api/tools/conversion.js +0 -301
- package/vendor/node-addon-api/unit-test/README.md +0 -28
- package/vendor/node-addon-api/unit-test/binding-file-template.js +0 -39
- package/vendor/node-addon-api/unit-test/binding.gyp +0 -72
- package/vendor/node-addon-api/unit-test/exceptions.js +0 -32
- package/vendor/node-addon-api/unit-test/generate-binding-cc.js +0 -61
- package/vendor/node-addon-api/unit-test/injectTestParams.js +0 -101
- package/vendor/node-addon-api/unit-test/listOfTestModules.js +0 -88
- package/vendor/node-addon-api/unit-test/matchModules.js +0 -65
- package/vendor/node-addon-api/unit-test/setup.js +0 -13
- package/vendor/node-addon-api/unit-test/spawnTask.js +0 -26
- package/vendor/node-addon-api/unit-test/test.js +0 -30
- package/vendor/node-api-headers/CHANGELOG.md +0 -130
- package/vendor/node-api-headers/CODE_OF_CONDUCT.md +0 -4
- package/vendor/node-api-headers/CONTRIBUTING.md +0 -32
- package/vendor/node-api-headers/CREATING_A_RELEASE.md +0 -68
- package/vendor/node-api-headers/index.js +0 -17
- package/vendor/node-api-headers/lib/clang-utils.js +0 -50
- package/vendor/node-api-headers/lib/parse-utils.js +0 -92
- package/vendor/node-api-headers/package.json +0 -59
- package/vendor/node-api-headers/release-please-config.json +0 -12
- package/vendor/node-api-headers/scripts/update-headers.js +0 -246
- package/vendor/node-api-headers/scripts/write-symbols.js +0 -154
- package/vendor/node-api-headers/scripts/write-win32-def.js +0 -52
- package/vendor/node-api-headers/symbols.js +0 -257
- package/vendor/node-api-headers/test/parse-utils.js +0 -21
- /package/doc/{pages/benchmarks.md → benchmarks.md} +0 -0
- /package/doc/{pages/callbacks.md → callbacks.md} +0 -0
- /package/doc/{pages/contribute.md → contribute.md} +0 -0
- /package/doc/{pages/functions.md → functions.md} +0 -0
- /package/doc/{pages/index.md → index.md} +0 -0
- /package/doc/{pages/input.md → input.md} +0 -0
- /package/doc/{pages/migration.md → migration.md} +0 -0
- /package/doc/{pages/misc.md → misc.md} +0 -0
- /package/doc/{pages/output.md → output.md} +0 -0
- /package/doc/{pages/packaging.md → packaging.md} +0 -0
- /package/doc/{pages/platforms.md → platforms.md} +0 -0
- /package/doc/{pages/pointers.md → pointers.md} +0 -0
- /package/doc/{pages/start.md → start.md} +0 -0
- /package/doc/{pages/unions.md → unions.md} +0 -0
- /package/doc/{pages/variables.md → variables.md} +0 -0
- /package/src/koffi/src/{abi/loong64.cc → abi_loong64.cc} +0 -0
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
# Error handling
|
|
2
|
-
|
|
3
|
-
Error handling represents one of the most important considerations when
|
|
4
|
-
implementing a Node.js native add-on. When an error occurs in your C++ code you
|
|
5
|
-
have to handle and dispatch it correctly. **node-addon-api** uses return values and
|
|
6
|
-
JavaScript exceptions for error handling. You can choose return values or
|
|
7
|
-
exception handling based on the mechanism that works best for your add-on.
|
|
8
|
-
|
|
9
|
-
The `Napi::Error` is a persistent reference (for more info see: [`Napi::ObjectReference`](object_reference.md))
|
|
10
|
-
to a JavaScript error object. Use of this class depends on whether C++
|
|
11
|
-
exceptions are enabled at compile time.
|
|
12
|
-
|
|
13
|
-
If C++ exceptions are enabled (for more info see: [Setup](setup.md)), then the
|
|
14
|
-
`Napi::Error` class extends `std::exception` and enables integrated
|
|
15
|
-
error-handling for C++ exceptions and JavaScript exceptions.
|
|
16
|
-
|
|
17
|
-
Note, that due to limitations of the Node-API, if one attempts to cast the error object wrapping a primitive inside a C++ addon, the wrapped object
|
|
18
|
-
will be received instead. (With property `4bda9e7e-4913-4dbc-95de-891cbf66598e-errorVal` containing the primitive value thrown)
|
|
19
|
-
|
|
20
|
-
The following sections explain the approach for each case:
|
|
21
|
-
|
|
22
|
-
- [Handling Errors With C++ Exceptions](#exceptions)
|
|
23
|
-
- [Handling Errors With Maybe Type and C++ Exceptions Disabled](#noexceptions-maybe)
|
|
24
|
-
- [Handling Errors Without C++ Exceptions](#noexceptions)
|
|
25
|
-
|
|
26
|
-
<a name="exceptions"></a>
|
|
27
|
-
|
|
28
|
-
In most cases when an error occurs, the addon should do whatever cleanup is possible
|
|
29
|
-
and then return to JavaScript so that the error can be propagated. In less frequent
|
|
30
|
-
cases the addon may be able to recover from the error, clear the error and then
|
|
31
|
-
continue.
|
|
32
|
-
|
|
33
|
-
## Handling Errors With C++ Exceptions
|
|
34
|
-
|
|
35
|
-
When C++ exceptions are enabled try/catch can be used to catch exceptions thrown
|
|
36
|
-
from calls to JavaScript and then they can either be handled or rethrown before
|
|
37
|
-
returning from a native method.
|
|
38
|
-
|
|
39
|
-
If a node-addon-api call fails without executing any JavaScript code (for example due to
|
|
40
|
-
an invalid argument), then node-addon-api automatically converts and throws
|
|
41
|
-
the error as a C++ exception of type `Napi::Error`.
|
|
42
|
-
|
|
43
|
-
If a JavaScript function called by C++ code via node-addon-api throws a JavaScript
|
|
44
|
-
exception, then node-addon-api automatically converts and throws it as a C++
|
|
45
|
-
exception of type `Napi::Error` on return from the JavaScript code to the native
|
|
46
|
-
method.
|
|
47
|
-
|
|
48
|
-
If a C++ exception of type `Napi::Error` escapes from a Node-API C++ callback, then
|
|
49
|
-
the Node-API wrapper automatically converts and throws it as a JavaScript exception.
|
|
50
|
-
|
|
51
|
-
If other types of C++ exceptions are thrown, node-addon-api will either abort
|
|
52
|
-
the process or wrap the exception in an `Napi::Error` in order to throw it as a
|
|
53
|
-
JavaScript exception. This behavior is determined by which node-gyp dependency
|
|
54
|
-
used:
|
|
55
|
-
|
|
56
|
-
- When using the `node_addon_api_except` dependency, only `Napi::Error` objects
|
|
57
|
-
will be handled.
|
|
58
|
-
- When using the `node_addon_api_except_all` dependency, all exceptions will be
|
|
59
|
-
handled. For exceptions derived from `std::exception`, an `Napi::Error` will be
|
|
60
|
-
created with the message of the exception's `what()` member function. For all
|
|
61
|
-
other exceptions, an `Napi::Error` will be created with a generic error message.
|
|
62
|
-
|
|
63
|
-
On return from a native method, node-addon-api will automatically convert a pending
|
|
64
|
-
`Napi::Error` C++ exception to a JavaScript exception.
|
|
65
|
-
|
|
66
|
-
When C++ exceptions are enabled try/catch can be used to catch exceptions thrown
|
|
67
|
-
from calls to JavaScript and then they can either be handled or rethrown before
|
|
68
|
-
returning from a native method.
|
|
69
|
-
|
|
70
|
-
## Examples with C++ exceptions enabled
|
|
71
|
-
|
|
72
|
-
### Throwing a C++ exception
|
|
73
|
-
|
|
74
|
-
```cpp
|
|
75
|
-
Env env = ...
|
|
76
|
-
throw Napi::Error::New(env, "Example exception");
|
|
77
|
-
// other C++ statements
|
|
78
|
-
// ...
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
The statements following the throw statement will not be executed. The exception
|
|
82
|
-
will bubble up as a C++ exception of type `Napi::Error`, until it is either caught
|
|
83
|
-
while still in C++, or else automatically propagated as a JavaScript exception
|
|
84
|
-
when returning to JavaScript.
|
|
85
|
-
|
|
86
|
-
### Propagating a Node-API C++ exception
|
|
87
|
-
|
|
88
|
-
```cpp
|
|
89
|
-
Napi::Function jsFunctionThatThrows = someValue.As<Napi::Function>();
|
|
90
|
-
Napi::Value result = jsFunctionThatThrows({ arg1, arg2 });
|
|
91
|
-
// other C++ statements
|
|
92
|
-
// ...
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
The C++ statements following the call to the JavaScript function will not be
|
|
96
|
-
executed. The exception will bubble up as a C++ exception of type `Napi::Error`,
|
|
97
|
-
until it is either caught while still in C++, or else automatically propagated as
|
|
98
|
-
a JavaScript exception when returning to JavaScript.
|
|
99
|
-
|
|
100
|
-
### Handling a Node-API C++ exception
|
|
101
|
-
|
|
102
|
-
```cpp
|
|
103
|
-
Napi::Function jsFunctionThatThrows = someValue.As<Napi::Function>();
|
|
104
|
-
Napi::Value result;
|
|
105
|
-
try {
|
|
106
|
-
result = jsFunctionThatThrows({ arg1, arg2 });
|
|
107
|
-
} catch (const Error& e) {
|
|
108
|
-
cerr << "Caught JavaScript exception: " + e.what();
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
Since the exception was caught here, it will not be propagated as a JavaScript
|
|
113
|
-
exception.
|
|
114
|
-
|
|
115
|
-
<a name="noexceptions-maybe"></a>
|
|
116
|
-
|
|
117
|
-
## Handling Errors With Maybe Type and C++ Exceptions Disabled
|
|
118
|
-
|
|
119
|
-
If C++ exceptions are disabled (for more info see: [Setup](setup.md)), then the
|
|
120
|
-
`Napi::Error` class does not extend `std::exception`. This means that any calls to
|
|
121
|
-
node-addon-api functions do not throw a C++ exceptions. Instead, these node-api
|
|
122
|
-
functions that call into JavaScript are returning with `Maybe` boxed values.
|
|
123
|
-
In that case, the calling side should convert the `Maybe` boxed values with
|
|
124
|
-
checks to ensure that the call did succeed and therefore no exception is pending.
|
|
125
|
-
If the check fails, that is to say, the returning value is _empty_, the calling
|
|
126
|
-
side should determine what to do with `env.GetAndClearPendingException()` before
|
|
127
|
-
attempting to call another node-api (for more info see: [Env](env.md)).
|
|
128
|
-
|
|
129
|
-
The conversion from the `Maybe` boxed value to the actual return value is
|
|
130
|
-
enforced by compilers so that the exceptions must be properly handled before
|
|
131
|
-
continuing.
|
|
132
|
-
|
|
133
|
-
## Examples with Maybe Type and C++ exceptions disabled
|
|
134
|
-
|
|
135
|
-
### Throwing a JS exception
|
|
136
|
-
|
|
137
|
-
```cpp
|
|
138
|
-
Napi::Env env = ...
|
|
139
|
-
Napi::Error::New(env, "Example exception").ThrowAsJavaScriptException();
|
|
140
|
-
return;
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
After throwing a JavaScript exception, the code should generally return
|
|
144
|
-
immediately from the native callback, after performing any necessary cleanup.
|
|
145
|
-
|
|
146
|
-
### Propagating a Node-API JS exception
|
|
147
|
-
|
|
148
|
-
```cpp
|
|
149
|
-
Napi::Env env = ...
|
|
150
|
-
Napi::Function jsFunctionThatThrows = someValue.As<Napi::Function>();
|
|
151
|
-
Maybe<Napi::Value> maybeResult = jsFunctionThatThrows({ arg1, arg2 });
|
|
152
|
-
Napi::Value result;
|
|
153
|
-
if (!maybeResult.To(&result)) {
|
|
154
|
-
// The Maybe is empty, calling into js failed, cleaning up...
|
|
155
|
-
// It is recommended to return an empty Maybe if the procedure failed.
|
|
156
|
-
return result;
|
|
157
|
-
}
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
If `maybeResult.To(&result)` returns false a JavaScript exception is pending.
|
|
161
|
-
To let the exception propagate, the code should generally return immediately
|
|
162
|
-
from the native callback, after performing any necessary cleanup.
|
|
163
|
-
|
|
164
|
-
### Handling a Node-API JS exception
|
|
165
|
-
|
|
166
|
-
```cpp
|
|
167
|
-
Napi::Env env = ...
|
|
168
|
-
Napi::Function jsFunctionThatThrows = someValue.As<Napi::Function>();
|
|
169
|
-
Maybe<Napi::Value> maybeResult = jsFunctionThatThrows({ arg1, arg2 });
|
|
170
|
-
if (maybeResult.IsNothing()) {
|
|
171
|
-
Napi::Error e = env.GetAndClearPendingException();
|
|
172
|
-
cerr << "Caught JavaScript exception: " + e.Message();
|
|
173
|
-
}
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
Since the exception was cleared here, it will not be propagated as a JavaScript
|
|
177
|
-
exception after the native callback returns.
|
|
178
|
-
|
|
179
|
-
<a name="noexceptions"></a>
|
|
180
|
-
|
|
181
|
-
## Handling Errors Without C++ Exceptions
|
|
182
|
-
|
|
183
|
-
If C++ exceptions are disabled (for more info see: [Setup](setup.md)), then the
|
|
184
|
-
`Napi::Error` class does not extend `std::exception`. This means that any calls to
|
|
185
|
-
node-addon-api function do not throw a C++ exceptions. Instead, it raises
|
|
186
|
-
_pending_ JavaScript exceptions and returns an _empty_ `Napi::Value`.
|
|
187
|
-
The calling code should check `env.IsExceptionPending()` before attempting to use a
|
|
188
|
-
returned value, and may use methods on the `Napi::Env` class
|
|
189
|
-
to check for, get, and clear a pending JavaScript exception (for more info see: [Env](env.md)).
|
|
190
|
-
If the pending exception is not cleared, it will be thrown when the native code
|
|
191
|
-
returns to JavaScript.
|
|
192
|
-
|
|
193
|
-
## Examples with C++ exceptions disabled
|
|
194
|
-
|
|
195
|
-
### Throwing a JS exception
|
|
196
|
-
|
|
197
|
-
```cpp
|
|
198
|
-
Napi::Env env = ...
|
|
199
|
-
Napi::Error::New(env, "Example exception").ThrowAsJavaScriptException();
|
|
200
|
-
return;
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
After throwing a JavaScript exception, the code should generally return
|
|
204
|
-
immediately from the native callback, after performing any necessary cleanup.
|
|
205
|
-
|
|
206
|
-
### Propagating a Node-API JS exception
|
|
207
|
-
|
|
208
|
-
```cpp
|
|
209
|
-
Napi::Env env = ...
|
|
210
|
-
Napi::Function jsFunctionThatThrows = someValue.As<Napi::Function>();
|
|
211
|
-
Napi::Value result = jsFunctionThatThrows({ arg1, arg2 });
|
|
212
|
-
if (env.IsExceptionPending()) {
|
|
213
|
-
Error e = env.GetAndClearPendingException();
|
|
214
|
-
return e.Value();
|
|
215
|
-
}
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
If env.IsExceptionPending() returns true a JavaScript exception is pending. To
|
|
219
|
-
let the exception propagate, the code should generally return immediately from
|
|
220
|
-
the native callback, after performing any necessary cleanup.
|
|
221
|
-
|
|
222
|
-
### Handling a Node-API JS exception
|
|
223
|
-
|
|
224
|
-
```cpp
|
|
225
|
-
Napi::Env env = ...
|
|
226
|
-
Napi::Function jsFunctionThatThrows = someValue.As<Napi::Function>();
|
|
227
|
-
Napi::Value result = jsFunctionThatThrows({ arg1, arg2 });
|
|
228
|
-
if (env.IsExceptionPending()) {
|
|
229
|
-
Napi::Error e = env.GetAndClearPendingException();
|
|
230
|
-
cerr << "Caught JavaScript exception: " + e.Message();
|
|
231
|
-
}
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
Since the exception was cleared here, it will not be propagated as a JavaScript
|
|
235
|
-
exception after the native callback returns.
|
|
236
|
-
|
|
237
|
-
## Calling Node-API directly from a **node-addon-api** addon
|
|
238
|
-
|
|
239
|
-
**node-addon-api** provides macros for throwing errors in response to non-OK
|
|
240
|
-
`napi_status` results when calling [Node-API](https://nodejs.org/docs/latest/api/n-api.html)
|
|
241
|
-
functions from within a native addon. These macros are defined differently
|
|
242
|
-
depending on whether C++ exceptions are enabled or not, but are available for
|
|
243
|
-
use in either case.
|
|
244
|
-
|
|
245
|
-
### `NAPI_THROW(e, ...)`
|
|
246
|
-
|
|
247
|
-
This macro accepts a `Napi::Error`, throws it, and returns the value given as
|
|
248
|
-
the last parameter. If C++ exceptions are enabled (by defining
|
|
249
|
-
`NAPI_CPP_EXCEPTIONS` during the build), the return value will be ignored.
|
|
250
|
-
|
|
251
|
-
### `NAPI_THROW_IF_FAILED(env, status, ...)`
|
|
252
|
-
|
|
253
|
-
This macro accepts a `Napi::Env` and a `napi_status`. It constructs an error
|
|
254
|
-
from the `napi_status`, throws it, and returns the value given as the last
|
|
255
|
-
parameter. If C++ exceptions are enabled (by defining `NAPI_CPP_EXCEPTIONS`
|
|
256
|
-
during the build), the return value will be ignored.
|
|
257
|
-
|
|
258
|
-
### `NAPI_THROW_IF_FAILED_VOID(env, status)`
|
|
259
|
-
|
|
260
|
-
This macro accepts a `Napi::Env` and a `napi_status`. It constructs an error
|
|
261
|
-
from the `napi_status`, throws it, and returns.
|
|
262
|
-
|
|
263
|
-
### `NAPI_FATAL_IF_FAILED(status, location, message)`
|
|
264
|
-
|
|
265
|
-
This macro accepts a `napi_status`, a C string indicating the location where the
|
|
266
|
-
error occurred, and a second C string for the message to display.
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# EscapableHandleScope
|
|
2
|
-
|
|
3
|
-
The `Napi::EscapableHandleScope` class is used to manage the lifetime of object handles
|
|
4
|
-
which are created through the use of node-addon-api. These handles
|
|
5
|
-
keep an object alive in the heap in order to ensure that the objects
|
|
6
|
-
are not collected by the garbage collector while native code is using them.
|
|
7
|
-
A handle may be created when any new node-addon-api Value or one
|
|
8
|
-
of its subclasses is created or returned.
|
|
9
|
-
|
|
10
|
-
The `Napi::EscapableHandleScope` is a special type of `Napi::HandleScope`
|
|
11
|
-
which allows a single handle to be "promoted" to an outer scope.
|
|
12
|
-
|
|
13
|
-
For more details refer to the section titled
|
|
14
|
-
[Object lifetime management](object_lifetime_management.md).
|
|
15
|
-
|
|
16
|
-
## Methods
|
|
17
|
-
|
|
18
|
-
### Constructor
|
|
19
|
-
|
|
20
|
-
Creates a new escapable handle scope.
|
|
21
|
-
|
|
22
|
-
```cpp
|
|
23
|
-
Napi::EscapableHandleScope Napi::EscapableHandleScope::New(Napi::Env env);
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
- `[in] Env`: The environment in which to construct the `Napi::EscapableHandleScope` object.
|
|
27
|
-
|
|
28
|
-
Returns a new `Napi::EscapableHandleScope`
|
|
29
|
-
|
|
30
|
-
### Constructor
|
|
31
|
-
|
|
32
|
-
Creates a new escapable handle scope.
|
|
33
|
-
|
|
34
|
-
```cpp
|
|
35
|
-
Napi::EscapableHandleScope Napi::EscapableHandleScope::New(napi_env env, napi_handle_scope scope);
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
- `[in] env`: `napi_env` in which the scope passed in was created.
|
|
39
|
-
- `[in] scope`: pre-existing `napi_handle_scope`.
|
|
40
|
-
|
|
41
|
-
Returns a new `Napi::EscapableHandleScope` instance which wraps the
|
|
42
|
-
`napi_escapable_handle_scope` handle passed in. This can be used
|
|
43
|
-
to mix usage of the C Node-API and node-addon-api.
|
|
44
|
-
|
|
45
|
-
```cpp
|
|
46
|
-
operator Napi::EscapableHandleScope::napi_escapable_handle_scope() const
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Returns the Node-API `napi_escapable_handle_scope` wrapped by the `Napi::EscapableHandleScope` object.
|
|
50
|
-
This can be used to mix usage of the C Node-API and node-addon-api by allowing
|
|
51
|
-
the class to be used be converted to a `napi_escapable_handle_scope`.
|
|
52
|
-
|
|
53
|
-
### Destructor
|
|
54
|
-
```cpp
|
|
55
|
-
Napi::EscapableHandleScope::~EscapableHandleScope();
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
Deletes the `Napi::EscapableHandleScope` instance and allows any objects/handles created
|
|
59
|
-
in the scope to be collected by the garbage collector. There is no
|
|
60
|
-
guarantee as to when the garbage collector will do this.
|
|
61
|
-
|
|
62
|
-
### Escape
|
|
63
|
-
|
|
64
|
-
```cpp
|
|
65
|
-
napi::Value Napi::EscapableHandleScope::Escape(napi_value escapee);
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
- `[in] escapee`: `Napi::Value` or `napi_env` to promote to the outer scope
|
|
69
|
-
|
|
70
|
-
Returns `Napi::Value` which can be used in the outer scope. This method can
|
|
71
|
-
be called at most once on a given `Napi::EscapableHandleScope`. If it is called
|
|
72
|
-
more than once an exception will be thrown.
|
|
73
|
-
|
|
74
|
-
### Env
|
|
75
|
-
|
|
76
|
-
```cpp
|
|
77
|
-
Napi::Env Napi::EscapableHandleScope::Env() const;
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
Returns the `Napi::Env` associated with the `Napi::EscapableHandleScope`.
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# External (template)
|
|
2
|
-
|
|
3
|
-
Class `Napi::External<T>` inherits from class [`Napi::TypeTaggable`][].
|
|
4
|
-
|
|
5
|
-
The `Napi::External` template class implements the ability to create a `Napi::Value` object with arbitrary C++ data. It is the user's responsibility to manage the memory for the arbitrary C++ data.
|
|
6
|
-
|
|
7
|
-
`Napi::External` objects can be created with an optional Finalizer function and
|
|
8
|
-
optional Hint value. The `Finalizer` function, if specified, is called when your
|
|
9
|
-
`Napi::External` object is released by Node's garbage collector. It gives your
|
|
10
|
-
code the opportunity to free any dynamically created data. If you specify a Hint
|
|
11
|
-
value, it is passed to your `Finalizer` function. See [Finalization][] for more details.
|
|
12
|
-
|
|
13
|
-
Note that `Napi::Value::IsExternal()` will return `true` for any external value.
|
|
14
|
-
It does not differentiate between the templated parameter `T` in
|
|
15
|
-
`Napi::External<T>`. It is up to the addon to ensure an `Napi::External<T>`
|
|
16
|
-
object holds the correct `T` when retrieving the data via
|
|
17
|
-
`Napi::External<T>::Data()`. One method to ensure an object is of a specific
|
|
18
|
-
type is through [type tags](./object.md#TypeTag).
|
|
19
|
-
|
|
20
|
-
## Methods
|
|
21
|
-
|
|
22
|
-
### New
|
|
23
|
-
|
|
24
|
-
```cpp
|
|
25
|
-
template <typename T>
|
|
26
|
-
static Napi::External Napi::External::New(napi_env env, T* data);
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
- `[in] env`: The `napi_env` environment in which to construct the `Napi::External` object.
|
|
30
|
-
- `[in] data`: The arbitrary C++ data to be held by the `Napi::External` object.
|
|
31
|
-
|
|
32
|
-
Returns the created `Napi::External<T>` object.
|
|
33
|
-
|
|
34
|
-
### New
|
|
35
|
-
|
|
36
|
-
```cpp
|
|
37
|
-
template <typename T>
|
|
38
|
-
static Napi::External Napi::External::New(napi_env env,
|
|
39
|
-
T* data,
|
|
40
|
-
Finalizer finalizeCallback);
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
- `[in] env`: The `napi_env` environment in which to construct the `Napi::External` object.
|
|
44
|
-
- `[in] data`: The arbitrary C++ data to be held by the `Napi::External` object.
|
|
45
|
-
- `[in] finalizeCallback`: The function called when the engine destroys the
|
|
46
|
-
`Napi::External` object, implementing `operator()(Napi::BasicEnv, T*)`. See
|
|
47
|
-
[Finalization][] for more details.
|
|
48
|
-
|
|
49
|
-
Returns the created `Napi::External<T>` object.
|
|
50
|
-
|
|
51
|
-
### New
|
|
52
|
-
|
|
53
|
-
```cpp
|
|
54
|
-
template <typename T>
|
|
55
|
-
static Napi::External Napi::External::New(napi_env env,
|
|
56
|
-
T* data,
|
|
57
|
-
Finalizer finalizeCallback,
|
|
58
|
-
Hint* finalizeHint);
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
- `[in] env`: The `napi_env` environment in which to construct the `Napi::External` object.
|
|
62
|
-
- `[in] data`: The arbitrary C++ data to be held by the `Napi::External` object.
|
|
63
|
-
- `[in] finalizeCallback`: The function called when the engine destroys the
|
|
64
|
-
`Napi::External` object, implementing `operator()(Napi::BasicEnv, T*, Hint*)`.
|
|
65
|
-
See [Finalization][] for more details.
|
|
66
|
-
- `[in] finalizeHint`: The hint value passed to the `finalizeCallback` function.
|
|
67
|
-
|
|
68
|
-
Returns the created `Napi::External<T>` object.
|
|
69
|
-
|
|
70
|
-
### Data
|
|
71
|
-
|
|
72
|
-
```cpp
|
|
73
|
-
T* Napi::External::Data() const;
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
Returns a pointer to the arbitrary C++ data held by the `Napi::External` object.
|
|
77
|
-
|
|
78
|
-
[Finalization]: ./finalization.md
|
|
79
|
-
[`Napi::TypeTaggable`]: ./type_taggable.md
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# External Buffer
|
|
2
|
-
|
|
3
|
-
**Some runtimes other than Node.js have dropped support for external buffers**.
|
|
4
|
-
On runtimes other than Node.js, node-api methods may return
|
|
5
|
-
`napi_no_external_buffers_allowed` to indicate that external
|
|
6
|
-
buffers are not supported. One such runtime is Electron as
|
|
7
|
-
described in this issue
|
|
8
|
-
[electron/issues/35801](https://github.com/electron/electron/issues/35801).
|
|
9
|
-
|
|
10
|
-
In order to maintain broadest compatibility with all runtimes,
|
|
11
|
-
you may define `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` in your addon before
|
|
12
|
-
includes for the node-api and node-addon-api headers. Doing so will hide the
|
|
13
|
-
functions that create external buffers. This will ensure a compilation error
|
|
14
|
-
occurs if you accidentally use one of these methods.
|
|
15
|
-
|
|
16
|
-
In node-addon-api, the `Napi::Buffer::NewOrCopy` provides a convenient way to
|
|
17
|
-
create an external buffer, or allocate a new buffer and copy the data when the
|
|
18
|
-
external buffer is not supported.
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
# Finalization
|
|
2
|
-
|
|
3
|
-
Various node-addon-api methods accept a templated `Finalizer finalizeCallback`
|
|
4
|
-
parameter. This parameter represents a native callback function that runs in
|
|
5
|
-
response to a garbage collection event. A finalizer is considered a _basic_
|
|
6
|
-
finalizer if the callback only utilizes a certain subset of APIs, which may
|
|
7
|
-
provide more efficient memory management, optimizations, improved execution, or
|
|
8
|
-
other benefits.
|
|
9
|
-
|
|
10
|
-
In general, it is best to use basic finalizers whenever possible (eg. when
|
|
11
|
-
access to JavaScript is _not_ needed). The
|
|
12
|
-
`NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS` preprocessor directive can be defined
|
|
13
|
-
to ensure that all finalizers are basic.
|
|
14
|
-
|
|
15
|
-
## Finalizers
|
|
16
|
-
|
|
17
|
-
The callback takes `Napi::Env` as its first argument:
|
|
18
|
-
|
|
19
|
-
### Example
|
|
20
|
-
|
|
21
|
-
```cpp
|
|
22
|
-
Napi::External<int>::New(Env(), new int(1), [](Napi::Env env, int* data) {
|
|
23
|
-
env.RunScript("console.log('Finalizer called')");
|
|
24
|
-
delete data;
|
|
25
|
-
});
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Basic Finalizers
|
|
29
|
-
|
|
30
|
-
Use of basic finalizers may allow the engine to perform optimizations when
|
|
31
|
-
scheduling or executing the callback. For example, V8 does not allow access to
|
|
32
|
-
the engine heap during garbage collection. Restricting finalizers from accessing
|
|
33
|
-
the engine heap allows the callback to execute during garbage collection,
|
|
34
|
-
providing a chance to free native memory eagerly.
|
|
35
|
-
|
|
36
|
-
In general, APIs that access engine heap are not allowed in basic finalizers.
|
|
37
|
-
|
|
38
|
-
The callback takes `Napi::BasicEnv` as its first argument:
|
|
39
|
-
|
|
40
|
-
### Example
|
|
41
|
-
|
|
42
|
-
```cpp
|
|
43
|
-
Napi::ArrayBuffer::New(
|
|
44
|
-
Env(), data, length, [](Napi::BasicEnv /*env*/, void* finalizeData) {
|
|
45
|
-
delete[] static_cast<uint8_t*>(finalizeData);
|
|
46
|
-
});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Scheduling Finalizers
|
|
50
|
-
|
|
51
|
-
In addition to passing finalizers to `Napi::External`s and other Node-API
|
|
52
|
-
constructs, `Napi::BasicEnv::PostFinalize(Napi::BasicEnv, Finalizer)` can be
|
|
53
|
-
used to schedule a callback to run outside of the garbage collector
|
|
54
|
-
finalization. Since the associated native memory may already be freed by the
|
|
55
|
-
basic finalizer, any additional data may be passed eg. via the finalizer's
|
|
56
|
-
parameters (`T data*`, `Hint hint*`) or via lambda capture. This allows for
|
|
57
|
-
freeing native data in a basic finalizer, while executing any JavaScript code in
|
|
58
|
-
an additional finalizer.
|
|
59
|
-
|
|
60
|
-
### Example
|
|
61
|
-
|
|
62
|
-
```cpp
|
|
63
|
-
// Native Add-on
|
|
64
|
-
|
|
65
|
-
#include <iostream>
|
|
66
|
-
#include <memory>
|
|
67
|
-
#include "napi.h"
|
|
68
|
-
|
|
69
|
-
using namespace Napi;
|
|
70
|
-
|
|
71
|
-
// A structure representing some data that uses a "large" amount of memory.
|
|
72
|
-
class LargeData {
|
|
73
|
-
public:
|
|
74
|
-
LargeData() : id(instances++) {}
|
|
75
|
-
size_t id;
|
|
76
|
-
|
|
77
|
-
static size_t instances;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
size_t LargeData::instances = 0;
|
|
81
|
-
|
|
82
|
-
// Basic finalizer to free `LargeData`. Takes ownership of the pointer and
|
|
83
|
-
// frees its memory after use.
|
|
84
|
-
void MyBasicFinalizer(Napi::BasicEnv env, LargeData* data) {
|
|
85
|
-
std::unique_ptr<LargeData> instance(data);
|
|
86
|
-
std::cout << "Basic finalizer for instance " << instance->id
|
|
87
|
-
<< " called\n";
|
|
88
|
-
|
|
89
|
-
// Register a finalizer. Since the instance will be deleted by
|
|
90
|
-
// the time this callback executes, pass the instance's `id` via lambda copy
|
|
91
|
-
// capture and _not_ a reference capture that accesses `this`.
|
|
92
|
-
env.PostFinalizer([instanceId = instance->id](Napi::Env env) {
|
|
93
|
-
env.RunScript("console.log('Finalizer for instance " +
|
|
94
|
-
std::to_string(instanceId) + " called');");
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// Free the `LargeData` held in `data` once `instance` goes out of scope.
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
Value CreateExternal(const CallbackInfo& info) {
|
|
101
|
-
// Create a new instance of LargeData.
|
|
102
|
-
auto instance = std::make_unique<LargeData>();
|
|
103
|
-
|
|
104
|
-
// Wrap the instance in an External object, registering a basic
|
|
105
|
-
// finalizer that will delete the instance to free the "large" amount of
|
|
106
|
-
// memory.
|
|
107
|
-
return External<LargeData>::New(info.Env(), instance.release(), MyBasicFinalizer);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
Object Init(Napi::Env env, Object exports) {
|
|
111
|
-
exports["createExternal"] = Function::New(env, CreateExternal);
|
|
112
|
-
return exports;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
NODE_API_MODULE(addon, Init)
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
```js
|
|
119
|
-
// JavaScript
|
|
120
|
-
|
|
121
|
-
const { createExternal } = require('./addon.node');
|
|
122
|
-
|
|
123
|
-
for (let i = 0; i < 5; i++) {
|
|
124
|
-
const ext = createExternal();
|
|
125
|
-
// ... do something with `ext` ..
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
console.log('Loop complete');
|
|
129
|
-
await new Promise(resolve => setImmediate(resolve));
|
|
130
|
-
console.log('Next event loop cycle');
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
Possible output:
|
|
134
|
-
|
|
135
|
-
```
|
|
136
|
-
Basic finalizer for instance 0 called
|
|
137
|
-
Basic finalizer for instance 1 called
|
|
138
|
-
Basic finalizer for instance 2 called
|
|
139
|
-
Basic finalizer for instance 3 called
|
|
140
|
-
Basic finalizer for instance 4 called
|
|
141
|
-
Loop complete
|
|
142
|
-
Finalizer for instance 3 called
|
|
143
|
-
Finalizer for instance 4 called
|
|
144
|
-
Finalizer for instance 1 called
|
|
145
|
-
Finalizer for instance 2 called
|
|
146
|
-
Finalizer for instance 0 called
|
|
147
|
-
Next event loop cycle
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
If the garbage collector runs during the loop, the basic finalizers execute and
|
|
151
|
-
display their logging message synchronously during the loop execution. The
|
|
152
|
-
additional finalizers execute at some later point after the garbage collection
|
|
153
|
-
cycle.
|