koffi 0.9.0 → 0.9.3
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/CMakeLists.txt +2 -36
- package/package.json +8 -4
- package/vendor/dragonbox/CMakeLists.txt +123 -0
- package/vendor/dragonbox/LICENSE-Apache2-LLVM +218 -0
- package/vendor/dragonbox/LICENSE-Boost +23 -0
- package/vendor/dragonbox/README.md +277 -0
- package/vendor/dragonbox/cmake/dragonboxConfig.cmake +1 -0
- package/vendor/dragonbox/include/dragonbox/dragonbox.h +2670 -0
- package/vendor/dragonbox/include/dragonbox/dragonbox_to_chars.h +108 -0
- package/vendor/dragonbox/other_files/Dragonbox.pdf +0 -0
- package/vendor/dragonbox/other_files/Dragonbox_old.pdf +0 -0
- package/vendor/dragonbox/other_files/milo_benchmark.png +0 -0
- package/vendor/dragonbox/other_files/unknown_win64_vc2019.html +540 -0
- package/vendor/dragonbox/other_files/unknown_win64_vc2019_randomdigit_time.png +0 -0
- package/vendor/dragonbox/source/dragonbox_to_chars.cpp +303 -0
- package/vendor/dragonbox/subproject/3rdparty/grisu_exact/CMakeLists.txt +24 -0
- package/vendor/dragonbox/subproject/3rdparty/grisu_exact/fp_to_chars.cpp +238 -0
- package/vendor/dragonbox/subproject/3rdparty/grisu_exact/fp_to_chars.h +95 -0
- package/vendor/dragonbox/subproject/3rdparty/grisu_exact/grisu_exact.h +2666 -0
- package/vendor/dragonbox/subproject/3rdparty/ryu/CMakeLists.txt +16 -0
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/common.h +114 -0
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s.c +509 -0
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s_full_table.h +367 -0
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s_intrinsics.h +357 -0
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/digit_table.h +35 -0
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s.c +345 -0
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s_full_table.h +55 -0
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s_intrinsics.h +128 -0
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/ryu.h +46 -0
- package/vendor/dragonbox/subproject/3rdparty/schubfach/CMakeLists.txt +22 -0
- package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_32.cc +699 -0
- package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_32.h +31 -0
- package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_64.cc +1354 -0
- package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_64.h +31 -0
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/example_shaded_plots.m +68 -0
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/license.txt +25 -0
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_distribution.m +92 -0
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_distribution_prctile.m +121 -0
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_histogram_shaded.m +99 -0
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_shaded.m +93 -0
- package/vendor/dragonbox/subproject/benchmark/CMakeLists.txt +65 -0
- package/vendor/dragonbox/subproject/benchmark/include/benchmark.h +40 -0
- package/vendor/dragonbox/subproject/benchmark/matlab/plot_benchmarks.m +22 -0
- package/vendor/dragonbox/subproject/benchmark/matlab/plot_digit_benchmark.m +78 -0
- package/vendor/dragonbox/subproject/benchmark/matlab/plot_uniform_benchmark.m +95 -0
- package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary32_clang.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary32_msvc.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary64_clang.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary64_msvc.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary32_clang.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary32_msvc.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary64_clang.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary64_msvc.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/source/benchmark.cpp +238 -0
- package/vendor/dragonbox/subproject/benchmark/source/dragonbox.cpp +30 -0
- package/vendor/dragonbox/subproject/benchmark/source/grisu_exact.cpp +36 -0
- package/vendor/dragonbox/subproject/benchmark/source/ryu.cpp +27 -0
- package/vendor/dragonbox/subproject/benchmark/source/schubfach.cpp +31 -0
- package/vendor/dragonbox/subproject/common/CMakeLists.txt +42 -0
- package/vendor/dragonbox/subproject/common/include/best_rational_approx.h +97 -0
- package/vendor/dragonbox/subproject/common/include/big_uint.h +218 -0
- package/vendor/dragonbox/subproject/common/include/continued_fractions.h +174 -0
- package/vendor/dragonbox/subproject/common/include/good_rational_approx.h +267 -0
- package/vendor/dragonbox/subproject/common/include/random_float.h +182 -0
- package/vendor/dragonbox/subproject/common/include/rational_continued_fractions.h +57 -0
- package/vendor/dragonbox/subproject/common/source/big_uint.cpp +602 -0
- package/vendor/dragonbox/subproject/meta/CMakeLists.txt +41 -0
- package/vendor/dragonbox/subproject/meta/results/binary32_generated_cache.txt +82 -0
- package/vendor/dragonbox/subproject/meta/results/binary64_compressed_cache_error_table.txt +10 -0
- package/vendor/dragonbox/subproject/meta/results/binary64_generated_cache.txt +623 -0
- package/vendor/dragonbox/subproject/meta/source/generate_cache.cpp +126 -0
- package/vendor/dragonbox/subproject/meta/source/live_test.cpp +81 -0
- package/vendor/dragonbox/subproject/meta/source/perf_test.cpp +104 -0
- package/vendor/dragonbox/subproject/meta/source/sandbox.cpp +20 -0
- package/vendor/dragonbox/subproject/test/CMakeLists.txt +70 -0
- package/vendor/dragonbox/subproject/test/results/binary32.csv +255 -0
- package/vendor/dragonbox/subproject/test/results/binary64.csv +2047 -0
- package/vendor/dragonbox/subproject/test/results/plot_required_bits.m +18 -0
- package/vendor/dragonbox/subproject/test/source/test_all_shorter_interval_cases.cpp +88 -0
- package/vendor/dragonbox/subproject/test/source/uniform_random_test.cpp +95 -0
- package/vendor/dragonbox/subproject/test/source/verify_cache_precision.cpp +338 -0
- package/vendor/dragonbox/subproject/test/source/verify_compressed_cache.cpp +154 -0
- package/vendor/dragonbox/subproject/test/source/verify_fast_multiplication.cpp +168 -0
- package/vendor/dragonbox/subproject/test/source/verify_log_computation.cpp +251 -0
- package/vendor/dragonbox/subproject/test/source/verify_magic_division.cpp +113 -0
- package/vendor/libcc/libcc.cc +7651 -0
- package/vendor/libcc/libcc.hh +4312 -0
- package/vendor/node-addon-api/CHANGELOG.md +859 -0
- package/vendor/node-addon-api/CODE_OF_CONDUCT.md +4 -0
- package/vendor/node-addon-api/CONTRIBUTING.md +93 -0
- package/vendor/node-addon-api/LICENSE.md +13 -0
- package/vendor/node-addon-api/README.md +293 -0
- package/vendor/node-addon-api/appveyor.yml +37 -0
- package/vendor/node-addon-api/benchmark/README.md +47 -0
- package/vendor/node-addon-api/benchmark/binding.gyp +25 -0
- package/vendor/node-addon-api/benchmark/function_args.cc +217 -0
- package/vendor/node-addon-api/benchmark/function_args.js +60 -0
- package/vendor/node-addon-api/benchmark/index.js +34 -0
- package/vendor/node-addon-api/benchmark/property_descriptor.cc +91 -0
- package/vendor/node-addon-api/benchmark/property_descriptor.js +37 -0
- package/vendor/node-addon-api/common.gypi +21 -0
- package/vendor/node-addon-api/doc/addon.md +163 -0
- package/vendor/node-addon-api/doc/array.md +81 -0
- package/vendor/node-addon-api/doc/array_buffer.md +155 -0
- package/vendor/node-addon-api/doc/async_context.md +86 -0
- package/vendor/node-addon-api/doc/async_operations.md +31 -0
- package/vendor/node-addon-api/doc/async_worker.md +427 -0
- package/vendor/node-addon-api/doc/async_worker_variants.md +557 -0
- package/vendor/node-addon-api/doc/bigint.md +97 -0
- package/vendor/node-addon-api/doc/boolean.md +68 -0
- package/vendor/node-addon-api/doc/buffer.md +150 -0
- package/vendor/node-addon-api/doc/callback_scope.md +54 -0
- package/vendor/node-addon-api/doc/callbackinfo.md +97 -0
- package/vendor/node-addon-api/doc/checker-tool.md +32 -0
- package/vendor/node-addon-api/doc/class_property_descriptor.md +115 -0
- package/vendor/node-addon-api/doc/cmake-js.md +68 -0
- package/vendor/node-addon-api/doc/conversion-tool.md +28 -0
- package/vendor/node-addon-api/doc/creating_a_release.md +62 -0
- package/vendor/node-addon-api/doc/dataview.md +248 -0
- package/vendor/node-addon-api/doc/date.md +68 -0
- package/vendor/node-addon-api/doc/env.md +196 -0
- package/vendor/node-addon-api/doc/error.md +120 -0
- package/vendor/node-addon-api/doc/error_handling.md +254 -0
- package/vendor/node-addon-api/doc/escapable_handle_scope.md +80 -0
- package/vendor/node-addon-api/doc/external.md +63 -0
- package/vendor/node-addon-api/doc/function.md +402 -0
- package/vendor/node-addon-api/doc/function_reference.md +238 -0
- package/vendor/node-addon-api/doc/generator.md +13 -0
- package/vendor/node-addon-api/doc/handle_scope.md +63 -0
- package/vendor/node-addon-api/doc/hierarchy.md +91 -0
- package/vendor/node-addon-api/doc/instance_wrap.md +408 -0
- package/vendor/node-addon-api/doc/maybe.md +76 -0
- package/vendor/node-addon-api/doc/memory_management.md +27 -0
- package/vendor/node-addon-api/doc/name.md +29 -0
- package/vendor/node-addon-api/doc/node-gyp.md +82 -0
- package/vendor/node-addon-api/doc/number.md +163 -0
- package/vendor/node-addon-api/doc/object.md +432 -0
- package/vendor/node-addon-api/doc/object_lifetime_management.md +83 -0
- package/vendor/node-addon-api/doc/object_reference.md +117 -0
- package/vendor/node-addon-api/doc/object_wrap.md +561 -0
- package/vendor/node-addon-api/doc/prebuild_tools.md +16 -0
- package/vendor/node-addon-api/doc/promises.md +79 -0
- package/vendor/node-addon-api/doc/property_descriptor.md +286 -0
- package/vendor/node-addon-api/doc/propertylvalue.md +50 -0
- package/vendor/node-addon-api/doc/range_error.md +59 -0
- package/vendor/node-addon-api/doc/reference.md +113 -0
- package/vendor/node-addon-api/doc/setup.md +110 -0
- package/vendor/node-addon-api/doc/string.md +93 -0
- package/vendor/node-addon-api/doc/symbol.md +61 -0
- package/vendor/node-addon-api/doc/threadsafe.md +121 -0
- package/vendor/node-addon-api/doc/threadsafe_function.md +290 -0
- package/vendor/node-addon-api/doc/type_error.md +59 -0
- package/vendor/node-addon-api/doc/typed_array.md +78 -0
- package/vendor/node-addon-api/doc/typed_array_of.md +137 -0
- package/vendor/node-addon-api/doc/typed_threadsafe_function.md +306 -0
- package/vendor/node-addon-api/doc/value.md +340 -0
- package/vendor/node-addon-api/doc/version_management.md +43 -0
- package/vendor/node-addon-api/except.gypi +25 -0
- package/vendor/node-addon-api/index.js +11 -0
- package/vendor/node-addon-api/napi-inl.deprecated.h +192 -0
- package/vendor/node-addon-api/napi-inl.h +6209 -0
- package/vendor/node-addon-api/napi.h +2983 -0
- package/vendor/node-addon-api/node_api.gyp +9 -0
- package/vendor/node-addon-api/noexcept.gypi +26 -0
- package/vendor/node-addon-api/nothing.c +0 -0
- package/vendor/node-addon-api/package-support.json +21 -0
- package/vendor/node-addon-api/package.json +399 -0
- package/vendor/node-addon-api/test/README.md +91 -0
- package/vendor/node-addon-api/test/addon.cc +36 -0
- package/vendor/node-addon-api/test/addon.js +11 -0
- package/vendor/node-addon-api/test/addon_build/index.js +49 -0
- package/vendor/node-addon-api/test/addon_build/tpl/addon.cc +17 -0
- package/vendor/node-addon-api/test/addon_build/tpl/binding.gyp +62 -0
- package/vendor/node-addon-api/test/addon_build/tpl/index.js +9 -0
- package/vendor/node-addon-api/test/addon_build/tpl/package.json +11 -0
- package/vendor/node-addon-api/test/addon_data.cc +99 -0
- package/vendor/node-addon-api/test/addon_data.js +46 -0
- package/vendor/node-addon-api/test/array_buffer.cc +243 -0
- package/vendor/node-addon-api/test/array_buffer.js +69 -0
- package/vendor/node-addon-api/test/async_context.cc +21 -0
- package/vendor/node-addon-api/test/async_context.js +86 -0
- package/vendor/node-addon-api/test/async_progress_queue_worker.cc +83 -0
- package/vendor/node-addon-api/test/async_progress_queue_worker.js +46 -0
- package/vendor/node-addon-api/test/async_progress_worker.cc +134 -0
- package/vendor/node-addon-api/test/async_progress_worker.js +61 -0
- package/vendor/node-addon-api/test/async_worker.cc +106 -0
- package/vendor/node-addon-api/test/async_worker.js +179 -0
- package/vendor/node-addon-api/test/async_worker_nocallback.js +13 -0
- package/vendor/node-addon-api/test/async_worker_persistent.cc +63 -0
- package/vendor/node-addon-api/test/async_worker_persistent.js +24 -0
- package/vendor/node-addon-api/test/basic_types/array.cc +40 -0
- package/vendor/node-addon-api/test/basic_types/array.js +35 -0
- package/vendor/node-addon-api/test/basic_types/boolean.cc +38 -0
- package/vendor/node-addon-api/test/basic_types/boolean.js +35 -0
- package/vendor/node-addon-api/test/basic_types/number.cc +99 -0
- package/vendor/node-addon-api/test/basic_types/number.js +114 -0
- package/vendor/node-addon-api/test/basic_types/value.cc +120 -0
- package/vendor/node-addon-api/test/basic_types/value.js +133 -0
- package/vendor/node-addon-api/test/bigint.cc +91 -0
- package/vendor/node-addon-api/test/bigint.js +53 -0
- package/vendor/node-addon-api/test/binding-swallowexcept.cc +12 -0
- package/vendor/node-addon-api/test/binding.cc +171 -0
- package/vendor/node-addon-api/test/binding.gyp +117 -0
- package/vendor/node-addon-api/test/buffer.cc +183 -0
- package/vendor/node-addon-api/test/buffer.js +69 -0
- package/vendor/node-addon-api/test/callbackscope.cc +22 -0
- package/vendor/node-addon-api/test/callbackscope.js +49 -0
- package/vendor/node-addon-api/test/common/index.js +113 -0
- package/vendor/node-addon-api/test/common/test_helper.h +61 -0
- package/vendor/node-addon-api/test/dataview/dataview.cc +48 -0
- package/vendor/node-addon-api/test/dataview/dataview.js +35 -0
- package/vendor/node-addon-api/test/dataview/dataview_read_write.cc +115 -0
- package/vendor/node-addon-api/test/dataview/dataview_read_write.js +90 -0
- package/vendor/node-addon-api/test/date.cc +44 -0
- package/vendor/node-addon-api/test/date.js +18 -0
- package/vendor/node-addon-api/test/env_cleanup.cc +88 -0
- package/vendor/node-addon-api/test/env_cleanup.js +56 -0
- package/vendor/node-addon-api/test/error.cc +287 -0
- package/vendor/node-addon-api/test/error.js +81 -0
- package/vendor/node-addon-api/test/error_handling_for_primitives.cc +13 -0
- package/vendor/node-addon-api/test/error_handling_for_primitives.js +29 -0
- package/vendor/node-addon-api/test/error_terminating_environment.js +94 -0
- package/vendor/node-addon-api/test/external.cc +81 -0
- package/vendor/node-addon-api/test/external.js +88 -0
- package/vendor/node-addon-api/test/function.cc +295 -0
- package/vendor/node-addon-api/test/function.js +121 -0
- package/vendor/node-addon-api/test/function_reference.cc +202 -0
- package/vendor/node-addon-api/test/function_reference.js +157 -0
- package/vendor/node-addon-api/test/globalObject/global_object.cc +61 -0
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.cc +31 -0
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.js +61 -0
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.cc +40 -0
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.js +57 -0
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.cc +28 -0
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.js +48 -0
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.cc +31 -0
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.js +58 -0
- package/vendor/node-addon-api/test/handlescope.cc +60 -0
- package/vendor/node-addon-api/test/handlescope.js +14 -0
- package/vendor/node-addon-api/test/index.js +136 -0
- package/vendor/node-addon-api/test/maybe/check.cc +23 -0
- package/vendor/node-addon-api/test/maybe/index.js +38 -0
- package/vendor/node-addon-api/test/memory_management.cc +17 -0
- package/vendor/node-addon-api/test/memory_management.js +9 -0
- package/vendor/node-addon-api/test/movable_callbacks.cc +23 -0
- package/vendor/node-addon-api/test/movable_callbacks.js +21 -0
- package/vendor/node-addon-api/test/name.cc +108 -0
- package/vendor/node-addon-api/test/name.js +59 -0
- package/vendor/node-addon-api/test/napi_child.js +14 -0
- package/vendor/node-addon-api/test/object/delete_property.cc +38 -0
- package/vendor/node-addon-api/test/object/delete_property.js +41 -0
- package/vendor/node-addon-api/test/object/finalizer.cc +29 -0
- package/vendor/node-addon-api/test/object/finalizer.js +28 -0
- package/vendor/node-addon-api/test/object/get_property.cc +34 -0
- package/vendor/node-addon-api/test/object/get_property.js +40 -0
- package/vendor/node-addon-api/test/object/has_own_property.cc +34 -0
- package/vendor/node-addon-api/test/object/has_own_property.js +34 -0
- package/vendor/node-addon-api/test/object/has_property.cc +38 -0
- package/vendor/node-addon-api/test/object/has_property.js +37 -0
- package/vendor/node-addon-api/test/object/object.cc +348 -0
- package/vendor/node-addon-api/test/object/object.js +217 -0
- package/vendor/node-addon-api/test/object/object_deprecated.cc +66 -0
- package/vendor/node-addon-api/test/object/object_deprecated.js +47 -0
- package/vendor/node-addon-api/test/object/object_freeze_seal.cc +25 -0
- package/vendor/node-addon-api/test/object/object_freeze_seal.js +61 -0
- package/vendor/node-addon-api/test/object/set_property.cc +37 -0
- package/vendor/node-addon-api/test/object/set_property.js +29 -0
- package/vendor/node-addon-api/test/object/subscript_operator.cc +42 -0
- package/vendor/node-addon-api/test/object/subscript_operator.js +17 -0
- package/vendor/node-addon-api/test/object_reference.cc +219 -0
- package/vendor/node-addon-api/test/object_reference.js +259 -0
- package/vendor/node-addon-api/test/objectwrap.cc +268 -0
- package/vendor/node-addon-api/test/objectwrap.js +284 -0
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.cc +26 -0
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.js +18 -0
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.cc +30 -0
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.js +13 -0
- package/vendor/node-addon-api/test/objectwrap_removewrap.cc +45 -0
- package/vendor/node-addon-api/test/objectwrap_removewrap.js +40 -0
- package/vendor/node-addon-api/test/objectwrap_worker_thread.js +19 -0
- package/vendor/node-addon-api/test/promise.cc +29 -0
- package/vendor/node-addon-api/test/promise.js +18 -0
- package/vendor/node-addon-api/test/reference.cc +24 -0
- package/vendor/node-addon-api/test/reference.js +14 -0
- package/vendor/node-addon-api/test/run_script.cc +56 -0
- package/vendor/node-addon-api/test/run_script.js +45 -0
- package/vendor/node-addon-api/test/symbol.cc +79 -0
- package/vendor/node-addon-api/test/symbol.js +73 -0
- package/vendor/node-addon-api/test/testUtil.js +54 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.cc +195 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.js +188 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.cc +63 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.js +12 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.cc +115 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.js +14 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.cc +26 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.js +7 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.cc +225 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.js +59 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.cc +42 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.js +53 -0
- package/vendor/node-addon-api/test/thunking_manual.cc +140 -0
- package/vendor/node-addon-api/test/thunking_manual.js +17 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.cc +215 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.js +188 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc +68 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +12 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc +127 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js +14 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc +28 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js +7 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc +237 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.js +59 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc +53 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js +53 -0
- package/vendor/node-addon-api/test/typedarray-bigint.js +58 -0
- package/vendor/node-addon-api/test/typedarray.cc +216 -0
- package/vendor/node-addon-api/test/typedarray.js +69 -0
- package/vendor/node-addon-api/test/version_management.cc +27 -0
- package/vendor/node-addon-api/test/version_management.js +31 -0
- package/vendor/node-addon-api/tools/README.md +73 -0
- package/vendor/node-addon-api/tools/check-napi.js +100 -0
- package/vendor/node-addon-api/tools/clang-format.js +68 -0
- package/vendor/node-addon-api/tools/conversion.js +309 -0
- package/vendor/node-addon-api/tools/eslint-format.js +71 -0
- package/build/ALL_BUILD.vcxproj +0 -190
- package/build/ALL_BUILD.vcxproj.filters +0 -8
- package/build/CMakeCache.txt +0 -429
- package/build/CMakeFiles/3.23.0-rc1/CMakeASMCompiler.cmake +0 -20
- package/build/CMakeFiles/3.23.0-rc1/CMakeASM_MASMCompiler.cmake +0 -20
- package/build/CMakeFiles/3.23.0-rc1/CMakeCCompiler.cmake +0 -72
- package/build/CMakeFiles/3.23.0-rc1/CMakeCXXCompiler.cmake +0 -83
- package/build/CMakeFiles/3.23.0-rc1/CMakeDetermineCompilerABI_C.bin +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CMakeDetermineCompilerABI_CXX.bin +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CMakeRCCompiler.cmake +0 -6
- package/build/CMakeFiles/3.23.0-rc1/CMakeSystem.cmake +0 -15
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdC/CMakeCCompilerId.c +0 -828
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdC/CompilerIdC.exe +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdC/CompilerIdC.vcxproj +0 -71
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdC/Debug/CMakeCCompilerId.obj +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdC/Debug/CompilerIdC.exe.recipe +0 -11
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdC/Debug/CompilerIdC.tlog/CL.command.1.tlog +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdC/Debug/CompilerIdC.tlog/CL.read.1.tlog +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdC/Debug/CompilerIdC.tlog/CL.write.1.tlog +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdC/Debug/CompilerIdC.tlog/CompilerIdC.lastbuildstate +0 -2
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdC/Debug/CompilerIdC.tlog/link.command.1.tlog +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdC/Debug/CompilerIdC.tlog/link.read.1.tlog +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdC/Debug/CompilerIdC.tlog/link.write.1.tlog +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdCXX/CMakeCXXCompilerId.cpp +0 -816
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdCXX/CompilerIdCXX.exe +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdCXX/CompilerIdCXX.vcxproj +0 -71
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdCXX/Debug/CMakeCXXCompilerId.obj +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdCXX/Debug/CompilerIdCXX.exe.recipe +0 -11
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdCXX/Debug/CompilerIdCXX.tlog/CL.command.1.tlog +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdCXX/Debug/CompilerIdCXX.tlog/CL.read.1.tlog +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdCXX/Debug/CompilerIdCXX.tlog/CL.write.1.tlog +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdCXX/Debug/CompilerIdCXX.tlog/CompilerIdCXX.lastbuildstate +0 -2
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdCXX/Debug/CompilerIdCXX.tlog/link.command.1.tlog +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdCXX/Debug/CompilerIdCXX.tlog/link.read.1.tlog +0 -0
- package/build/CMakeFiles/3.23.0-rc1/CompilerIdCXX/Debug/CompilerIdCXX.tlog/link.write.1.tlog +0 -0
- package/build/CMakeFiles/3.23.0-rc1/VCTargetsPath.txt +0 -1
- package/build/CMakeFiles/3.23.0-rc1/VCTargetsPath.vcxproj +0 -31
- package/build/CMakeFiles/3.23.0-rc1/x64/Debug/VCTargetsPath.recipe +0 -11
- package/build/CMakeFiles/3.23.0-rc1/x64/Debug/VCTargetsPath.tlog/VCTargetsPath.lastbuildstate +0 -2
- package/build/CMakeFiles/41bcd16856091d4a38fd1f71fbe2f202/generate.stamp.rule +0 -1
- package/build/CMakeFiles/CMakeError.log +0 -108
- package/build/CMakeFiles/CMakeOutput.log +0 -413
- package/build/CMakeFiles/TargetDirectories.txt +0 -4
- package/build/CMakeFiles/cmake.check_cache +0 -1
- package/build/CMakeFiles/generate.stamp +0 -1
- package/build/CMakeFiles/generate.stamp.depend +0 -28
- package/build/CMakeFiles/generate.stamp.list +0 -1
- package/build/Raylib.dir/Release/Raylib.dll.recipe +0 -14
- package/build/Raylib.dir/Release/Raylib.tlog/CL.command.1.tlog +0 -0
- package/build/Raylib.dir/Release/Raylib.tlog/CL.read.1.tlog +0 -0
- package/build/Raylib.dir/Release/Raylib.tlog/CL.write.1.tlog +0 -0
- package/build/Raylib.dir/Release/Raylib.tlog/CustomBuild.command.1.tlog +0 -10
- package/build/Raylib.dir/Release/Raylib.tlog/CustomBuild.read.1.tlog +0 -27
- package/build/Raylib.dir/Release/Raylib.tlog/CustomBuild.write.1.tlog +0 -2
- package/build/Raylib.dir/Release/Raylib.tlog/Raylib.lastbuildstate +0 -2
- package/build/Raylib.dir/Release/Raylib.tlog/Raylib.write.1u.tlog +0 -0
- package/build/Raylib.dir/Release/Raylib.tlog/link.command.1.tlog +0 -0
- package/build/Raylib.dir/Release/Raylib.tlog/link.read.1.tlog +0 -0
- package/build/Raylib.dir/Release/Raylib.tlog/link.write.1.tlog +0 -0
- package/build/Raylib.dir/Release/raudio.obj +0 -0
- package/build/Raylib.dir/Release/rcore.obj +0 -0
- package/build/Raylib.dir/Release/rglfw.obj +0 -0
- package/build/Raylib.dir/Release/rmodels.obj +0 -0
- package/build/Raylib.dir/Release/rshapes.obj +0 -0
- package/build/Raylib.dir/Release/rtext.obj +0 -0
- package/build/Raylib.dir/Release/rtextures.obj +0 -0
- package/build/Raylib.dir/Release/utils.obj +0 -0
- package/build/Raylib.vcxproj +0 -358
- package/build/Raylib.vcxproj.filters +0 -37
- package/build/Release/Raylib.dll +0 -0
- package/build/Release/Raylib.exp +0 -0
- package/build/Release/Raylib.lib +0 -0
- package/build/Release/koffi.exp +0 -0
- package/build/Release/koffi.lib +0 -0
- package/build/Release/koffi.node +0 -0
- package/build/ZERO_CHECK.vcxproj +0 -176
- package/build/ZERO_CHECK.vcxproj.filters +0 -13
- package/build/cmake_install.cmake +0 -44
- package/build/koffi.dir/Release/call_arm64.obj +0 -0
- package/build/koffi.dir/Release/call_x64_sysv.obj +0 -0
- package/build/koffi.dir/Release/call_x64_win.obj +0 -0
- package/build/koffi.dir/Release/call_x64_win_fwd.obj +0 -0
- package/build/koffi.dir/Release/call_x86.obj +0 -0
- package/build/koffi.dir/Release/ffi.obj +0 -0
- package/build/koffi.dir/Release/koffi.node.recipe +0 -14
- package/build/koffi.dir/Release/koffi.tlog/CL.command.1.tlog +0 -0
- package/build/koffi.dir/Release/koffi.tlog/CL.read.1.tlog +0 -0
- package/build/koffi.dir/Release/koffi.tlog/CL.write.1.tlog +0 -0
- package/build/koffi.dir/Release/koffi.tlog/CustomBuild.command.1.tlog +0 -10
- package/build/koffi.dir/Release/koffi.tlog/CustomBuild.read.1.tlog +0 -27
- package/build/koffi.dir/Release/koffi.tlog/CustomBuild.write.1.tlog +0 -2
- package/build/koffi.dir/Release/koffi.tlog/Masm.read.1u.tlog +0 -0
- package/build/koffi.dir/Release/koffi.tlog/Masm.write.1u.tlog +0 -0
- package/build/koffi.dir/Release/koffi.tlog/koffi.lastbuildstate +0 -2
- package/build/koffi.dir/Release/koffi.tlog/koffi.write.1u.tlog +0 -0
- package/build/koffi.dir/Release/koffi.tlog/link.command.1.tlog +0 -0
- package/build/koffi.dir/Release/koffi.tlog/link.read.1.tlog +0 -0
- package/build/koffi.dir/Release/koffi.tlog/link.write.1.tlog +0 -0
- package/build/koffi.dir/Release/libcc.obj +0 -0
- package/build/koffi.dir/Release/util.obj +0 -0
- package/build/koffi.dir/Release/win_delay_load_hook.obj +0 -0
- package/build/koffi.sln +0 -67
- package/build/koffi.vcxproj +0 -363
- package/build/koffi.vcxproj.filters +0 -40
- package/build/x64/Release/ALL_BUILD/ALL_BUILD.recipe +0 -20
- package/build/x64/Release/ALL_BUILD/ALL_BUILD.tlog/ALL_BUILD.lastbuildstate +0 -2
- package/build/x64/Release/ALL_BUILD/ALL_BUILD.tlog/CustomBuild.command.1.tlog +0 -10
- package/build/x64/Release/ALL_BUILD/ALL_BUILD.tlog/CustomBuild.read.1.tlog +0 -27
- package/build/x64/Release/ALL_BUILD/ALL_BUILD.tlog/CustomBuild.write.1.tlog +0 -2
- package/build/x64/Release/ZERO_CHECK/ZERO_CHECK.recipe +0 -11
- package/build/x64/Release/ZERO_CHECK/ZERO_CHECK.tlog/CustomBuild.command.1.tlog +0 -10
- package/build/x64/Release/ZERO_CHECK/ZERO_CHECK.tlog/CustomBuild.read.1.tlog +0 -28
- package/build/x64/Release/ZERO_CHECK/ZERO_CHECK.tlog/CustomBuild.write.1.tlog +0 -2
- package/build/x64/Release/ZERO_CHECK/ZERO_CHECK.tlog/ZERO_CHECK.lastbuildstate +0 -2
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* ThreadSafeFunction Tests: Thread Id Sums
|
|
7
|
+
*
|
|
8
|
+
* Every native C++ function that utilizes the TSFN will call the registered
|
|
9
|
+
* callback with the thread id. Passing Array.prototype.push with a bound array
|
|
10
|
+
* will push the thread id to the array. Therefore, starting `N` threads, we
|
|
11
|
+
* will expect the sum of all elements in the array to be `(N-1) * (N) / 2` (as
|
|
12
|
+
* thread IDs are 0-based)
|
|
13
|
+
*
|
|
14
|
+
* We check different methods of passing a ThreadSafeFunction around multiple
|
|
15
|
+
* threads:
|
|
16
|
+
* - `testWithTSFN`: The main thread creates the TSFN. Then, it creates
|
|
17
|
+
* threads, passing the TSFN at thread construction. The number of threads is
|
|
18
|
+
* static (known at TSFN creation).
|
|
19
|
+
* - `testDelayedTSFN`: The main thread creates threads, passing a promise to a
|
|
20
|
+
* TSFN at construction. Then, it creates the TSFN, and resolves each
|
|
21
|
+
* threads' promise. The number of threads is static.
|
|
22
|
+
* - `testAcquire`: The native binding returns a function to start a new. A
|
|
23
|
+
* call to this function will return `false` once `N` calls have been made.
|
|
24
|
+
* Each thread will acquire its own use of the TSFN, call it, and then
|
|
25
|
+
* release.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const THREAD_COUNT = 5;
|
|
29
|
+
const EXPECTED_SUM = (THREAD_COUNT - 1) * (THREAD_COUNT) / 2;
|
|
30
|
+
|
|
31
|
+
module.exports = require('../common').runTest(test);
|
|
32
|
+
|
|
33
|
+
/** @param {number[]} N */
|
|
34
|
+
const sum = (N) => N.reduce((sum, n) => sum + n, 0);
|
|
35
|
+
|
|
36
|
+
function test(binding) {
|
|
37
|
+
async function check(bindingFunction) {
|
|
38
|
+
const calls = [];
|
|
39
|
+
const result = await bindingFunction(THREAD_COUNT, Array.prototype.push.bind(calls));
|
|
40
|
+
assert.ok(result);
|
|
41
|
+
assert.equal(sum(calls), EXPECTED_SUM);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function checkAcquire() {
|
|
45
|
+
const calls = [];
|
|
46
|
+
const { promise, createThread, stopThreads } = binding.typed_threadsafe_function_sum.testAcquire(Array.prototype.push.bind(calls));
|
|
47
|
+
for (let i = 0; i < THREAD_COUNT; i++) {
|
|
48
|
+
createThread();
|
|
49
|
+
}
|
|
50
|
+
stopThreads();
|
|
51
|
+
const result = await promise;
|
|
52
|
+
assert.ok(result);
|
|
53
|
+
assert.equal(sum(calls), EXPECTED_SUM);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return check(binding.typed_threadsafe_function_sum.testDelayedTSFN)
|
|
57
|
+
.then(() => check(binding.typed_threadsafe_function_sum.testWithTSFN))
|
|
58
|
+
.then(() => checkAcquire());
|
|
59
|
+
}
|
package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#include "napi.h"
|
|
2
|
+
#include "test_helper.h"
|
|
3
|
+
|
|
4
|
+
#if (NAPI_VERSION > 3)
|
|
5
|
+
|
|
6
|
+
using namespace Napi;
|
|
7
|
+
|
|
8
|
+
namespace {
|
|
9
|
+
|
|
10
|
+
using TSFN = TypedThreadSafeFunction<>;
|
|
11
|
+
using ContextType = std::nullptr_t;
|
|
12
|
+
using FinalizerDataType = void;
|
|
13
|
+
static Value TestUnref(const CallbackInfo& info) {
|
|
14
|
+
Napi::Env env = info.Env();
|
|
15
|
+
Object global = env.Global();
|
|
16
|
+
Object resource = info[0].As<Object>();
|
|
17
|
+
Function cb = info[1].As<Function>();
|
|
18
|
+
Function setTimeout = MaybeUnwrap(global.Get("setTimeout")).As<Function>();
|
|
19
|
+
TSFN* tsfn = new TSFN;
|
|
20
|
+
|
|
21
|
+
*tsfn = TSFN::New(
|
|
22
|
+
info.Env(),
|
|
23
|
+
cb,
|
|
24
|
+
resource,
|
|
25
|
+
"Test",
|
|
26
|
+
1,
|
|
27
|
+
1,
|
|
28
|
+
nullptr,
|
|
29
|
+
[tsfn](Napi::Env /* env */, FinalizerDataType*, ContextType*) {
|
|
30
|
+
delete tsfn;
|
|
31
|
+
},
|
|
32
|
+
static_cast<FinalizerDataType*>(nullptr));
|
|
33
|
+
|
|
34
|
+
tsfn->BlockingCall();
|
|
35
|
+
|
|
36
|
+
setTimeout.Call(
|
|
37
|
+
global,
|
|
38
|
+
{Function::New(
|
|
39
|
+
env, [tsfn](const CallbackInfo& info) { tsfn->Unref(info.Env()); }),
|
|
40
|
+
Number::New(env, 100)});
|
|
41
|
+
|
|
42
|
+
return info.Env().Undefined();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
} // namespace
|
|
46
|
+
|
|
47
|
+
Object InitTypedThreadSafeFunctionUnref(Env env) {
|
|
48
|
+
Object exports = Object::New(env);
|
|
49
|
+
exports["testUnref"] = Function::New(env, TestUnref);
|
|
50
|
+
return exports;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#endif
|
package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
|
|
5
|
+
const isMainProcess = process.argv[1] != __filename;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* In order to test that the event loop exits even with an active TSFN, we need
|
|
9
|
+
* to spawn a new process for the test.
|
|
10
|
+
* - Main process: spawns new node instance, executing this script
|
|
11
|
+
* - Child process: creates TSFN. Native module Unref's via setTimeout after some time but does NOT call Release.
|
|
12
|
+
*
|
|
13
|
+
* Main process should expect child process to exit.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
if (isMainProcess) {
|
|
17
|
+
module.exports = require('../common').runTestWithBindingPath(test);
|
|
18
|
+
} else {
|
|
19
|
+
test(process.argv[2]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function test(bindingFile) {
|
|
23
|
+
if (isMainProcess) {
|
|
24
|
+
// Main process
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const child = require('../napi_child').spawn(process.argv[0], [
|
|
27
|
+
'--expose-gc', __filename, bindingFile
|
|
28
|
+
], { stdio: 'inherit' });
|
|
29
|
+
|
|
30
|
+
let timeout = setTimeout( function() {
|
|
31
|
+
child.kill();
|
|
32
|
+
timeout = 0;
|
|
33
|
+
reject(new Error("Expected child to die"));
|
|
34
|
+
}, 5000);
|
|
35
|
+
|
|
36
|
+
child.on("error", (err) => {
|
|
37
|
+
clearTimeout(timeout);
|
|
38
|
+
timeout = 0;
|
|
39
|
+
reject(new Error(err));
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
child.on("close", (code) => {
|
|
43
|
+
if (timeout) clearTimeout(timeout);
|
|
44
|
+
assert.strictEqual(code, 0, "Expected return value 0");
|
|
45
|
+
resolve();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
} else {
|
|
49
|
+
// Child process
|
|
50
|
+
const binding = require(bindingFile);
|
|
51
|
+
binding.typed_threadsafe_function_unref.testUnref({}, () => { });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
|
|
5
|
+
module.exports = require('./common').runTest(test);
|
|
6
|
+
|
|
7
|
+
function test(binding) {
|
|
8
|
+
[
|
|
9
|
+
['bigint64', BigInt64Array],
|
|
10
|
+
['biguint64', BigUint64Array],
|
|
11
|
+
].forEach(([type, Constructor]) => {
|
|
12
|
+
try {
|
|
13
|
+
const length = 4;
|
|
14
|
+
const t = binding.typedarray.createTypedArray(type, length);
|
|
15
|
+
assert.ok(t instanceof Constructor);
|
|
16
|
+
assert.strictEqual(binding.typedarray.getTypedArrayType(t), type);
|
|
17
|
+
assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length);
|
|
18
|
+
|
|
19
|
+
t[3] = 11n;
|
|
20
|
+
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11n);
|
|
21
|
+
binding.typedarray.setTypedArrayElement(t, 3, 22n);
|
|
22
|
+
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 22n);
|
|
23
|
+
assert.strictEqual(t[3], 22n);
|
|
24
|
+
|
|
25
|
+
const b = binding.typedarray.getTypedArrayBuffer(t);
|
|
26
|
+
assert.ok(b instanceof ArrayBuffer);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.log(type, Constructor);
|
|
29
|
+
throw e;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const length = 4;
|
|
34
|
+
const offset = 8;
|
|
35
|
+
const b = new ArrayBuffer(offset + 64 * 4);
|
|
36
|
+
|
|
37
|
+
const t = binding.typedarray.createTypedArray(type, length, b, offset);
|
|
38
|
+
assert.ok(t instanceof Constructor);
|
|
39
|
+
assert.strictEqual(binding.typedarray.getTypedArrayType(t), type);
|
|
40
|
+
assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length);
|
|
41
|
+
|
|
42
|
+
t[3] = 11n;
|
|
43
|
+
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11n);
|
|
44
|
+
binding.typedarray.setTypedArrayElement(t, 3, 22n);
|
|
45
|
+
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 22n);
|
|
46
|
+
assert.strictEqual(t[3], 22n);
|
|
47
|
+
|
|
48
|
+
assert.strictEqual(binding.typedarray.getTypedArrayBuffer(t), b);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.log(type, Constructor);
|
|
51
|
+
throw e;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
assert.throws(() => {
|
|
56
|
+
binding.typedarray.createInvalidTypedArray();
|
|
57
|
+
}, /Invalid (pointer passed as )?argument/);
|
|
58
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
#include "napi.h"
|
|
2
|
+
|
|
3
|
+
using namespace Napi;
|
|
4
|
+
|
|
5
|
+
#if defined(NAPI_HAS_CONSTEXPR)
|
|
6
|
+
#define NAPI_TYPEDARRAY_NEW(className, env, length, type) className::New(env, length)
|
|
7
|
+
#define NAPI_TYPEDARRAY_NEW_BUFFER(className, env, length, buffer, bufferOffset, type) \
|
|
8
|
+
className::New(env, length, buffer, bufferOffset)
|
|
9
|
+
#else
|
|
10
|
+
#define NAPI_TYPEDARRAY_NEW(className, env, length, type) className::New(env, length, type)
|
|
11
|
+
#define NAPI_TYPEDARRAY_NEW_BUFFER(className, env, length, buffer, bufferOffset, type) \
|
|
12
|
+
className::New(env, length, buffer, bufferOffset, type)
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
namespace {
|
|
16
|
+
|
|
17
|
+
Value CreateTypedArray(const CallbackInfo& info) {
|
|
18
|
+
std::string arrayType = info[0].As<String>();
|
|
19
|
+
size_t length = info[1].As<Number>().Uint32Value();
|
|
20
|
+
ArrayBuffer buffer = info[2].As<ArrayBuffer>();
|
|
21
|
+
size_t bufferOffset = info[3].IsUndefined() ? 0 : info[3].As<Number>().Uint32Value();
|
|
22
|
+
|
|
23
|
+
if (arrayType == "int8") {
|
|
24
|
+
return buffer.IsUndefined() ?
|
|
25
|
+
NAPI_TYPEDARRAY_NEW(Int8Array, info.Env(), length, napi_int8_array) :
|
|
26
|
+
NAPI_TYPEDARRAY_NEW_BUFFER(Int8Array, info.Env(), length, buffer, bufferOffset,
|
|
27
|
+
napi_int8_array);
|
|
28
|
+
} else if (arrayType == "uint8") {
|
|
29
|
+
return buffer.IsUndefined() ?
|
|
30
|
+
NAPI_TYPEDARRAY_NEW(Uint8Array, info.Env(), length, napi_uint8_array) :
|
|
31
|
+
NAPI_TYPEDARRAY_NEW_BUFFER(Uint8Array, info.Env(), length, buffer, bufferOffset,
|
|
32
|
+
napi_uint8_array);
|
|
33
|
+
} else if (arrayType == "uint8_clamped") {
|
|
34
|
+
return buffer.IsUndefined() ?
|
|
35
|
+
Uint8Array::New(info.Env(), length, napi_uint8_clamped_array) :
|
|
36
|
+
Uint8Array::New(info.Env(), length, buffer, bufferOffset, napi_uint8_clamped_array);
|
|
37
|
+
} else if (arrayType == "int16") {
|
|
38
|
+
return buffer.IsUndefined() ?
|
|
39
|
+
NAPI_TYPEDARRAY_NEW(Int16Array, info.Env(), length, napi_int16_array) :
|
|
40
|
+
NAPI_TYPEDARRAY_NEW_BUFFER(Int16Array, info.Env(), length, buffer, bufferOffset,
|
|
41
|
+
napi_int16_array);
|
|
42
|
+
} else if (arrayType == "uint16") {
|
|
43
|
+
return buffer.IsUndefined() ?
|
|
44
|
+
NAPI_TYPEDARRAY_NEW(Uint16Array, info.Env(), length, napi_uint16_array) :
|
|
45
|
+
NAPI_TYPEDARRAY_NEW_BUFFER(Uint16Array, info.Env(), length, buffer, bufferOffset,
|
|
46
|
+
napi_uint16_array);
|
|
47
|
+
} else if (arrayType == "int32") {
|
|
48
|
+
return buffer.IsUndefined() ?
|
|
49
|
+
NAPI_TYPEDARRAY_NEW(Int32Array, info.Env(), length, napi_int32_array) :
|
|
50
|
+
NAPI_TYPEDARRAY_NEW_BUFFER(Int32Array, info.Env(), length, buffer, bufferOffset,
|
|
51
|
+
napi_int32_array);
|
|
52
|
+
} else if (arrayType == "uint32") {
|
|
53
|
+
return buffer.IsUndefined() ?
|
|
54
|
+
NAPI_TYPEDARRAY_NEW(Uint32Array, info.Env(), length, napi_uint32_array) :
|
|
55
|
+
NAPI_TYPEDARRAY_NEW_BUFFER(Uint32Array, info.Env(), length, buffer, bufferOffset,
|
|
56
|
+
napi_uint32_array);
|
|
57
|
+
} else if (arrayType == "float32") {
|
|
58
|
+
return buffer.IsUndefined() ?
|
|
59
|
+
NAPI_TYPEDARRAY_NEW(Float32Array, info.Env(), length, napi_float32_array) :
|
|
60
|
+
NAPI_TYPEDARRAY_NEW_BUFFER(Float32Array, info.Env(), length, buffer, bufferOffset,
|
|
61
|
+
napi_float32_array);
|
|
62
|
+
} else if (arrayType == "float64") {
|
|
63
|
+
return buffer.IsUndefined() ?
|
|
64
|
+
NAPI_TYPEDARRAY_NEW(Float64Array, info.Env(), length, napi_float64_array) :
|
|
65
|
+
NAPI_TYPEDARRAY_NEW_BUFFER(Float64Array, info.Env(), length, buffer, bufferOffset,
|
|
66
|
+
napi_float64_array);
|
|
67
|
+
#if (NAPI_VERSION > 5)
|
|
68
|
+
} else if (arrayType == "bigint64") {
|
|
69
|
+
return buffer.IsUndefined() ?
|
|
70
|
+
NAPI_TYPEDARRAY_NEW(BigInt64Array, info.Env(), length, napi_bigint64_array) :
|
|
71
|
+
NAPI_TYPEDARRAY_NEW_BUFFER(BigInt64Array, info.Env(), length, buffer, bufferOffset,
|
|
72
|
+
napi_bigint64_array);
|
|
73
|
+
} else if (arrayType == "biguint64") {
|
|
74
|
+
return buffer.IsUndefined() ?
|
|
75
|
+
NAPI_TYPEDARRAY_NEW(BigUint64Array, info.Env(), length, napi_biguint64_array) :
|
|
76
|
+
NAPI_TYPEDARRAY_NEW_BUFFER(BigUint64Array, info.Env(), length, buffer, bufferOffset,
|
|
77
|
+
napi_biguint64_array);
|
|
78
|
+
#endif
|
|
79
|
+
} else {
|
|
80
|
+
Error::New(info.Env(), "Invalid typed-array type.").ThrowAsJavaScriptException();
|
|
81
|
+
return Value();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Value CreateInvalidTypedArray(const CallbackInfo& info) {
|
|
86
|
+
return NAPI_TYPEDARRAY_NEW_BUFFER(Int8Array, info.Env(), 1, ArrayBuffer(), 0, napi_int8_array);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
Value GetTypedArrayType(const CallbackInfo& info) {
|
|
90
|
+
TypedArray array = info[0].As<TypedArray>();
|
|
91
|
+
switch (array.TypedArrayType()) {
|
|
92
|
+
case napi_int8_array: return String::New(info.Env(), "int8");
|
|
93
|
+
case napi_uint8_array: return String::New(info.Env(), "uint8");
|
|
94
|
+
case napi_uint8_clamped_array: return String::New(info.Env(), "uint8_clamped");
|
|
95
|
+
case napi_int16_array: return String::New(info.Env(), "int16");
|
|
96
|
+
case napi_uint16_array: return String::New(info.Env(), "uint16");
|
|
97
|
+
case napi_int32_array: return String::New(info.Env(), "int32");
|
|
98
|
+
case napi_uint32_array: return String::New(info.Env(), "uint32");
|
|
99
|
+
case napi_float32_array: return String::New(info.Env(), "float32");
|
|
100
|
+
case napi_float64_array: return String::New(info.Env(), "float64");
|
|
101
|
+
#if (NAPI_VERSION > 5)
|
|
102
|
+
case napi_bigint64_array: return String::New(info.Env(), "bigint64");
|
|
103
|
+
case napi_biguint64_array: return String::New(info.Env(), "biguint64");
|
|
104
|
+
#endif
|
|
105
|
+
default: return String::New(info.Env(), "invalid");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
Value GetTypedArrayLength(const CallbackInfo& info) {
|
|
110
|
+
TypedArray array = info[0].As<TypedArray>();
|
|
111
|
+
return Number::New(info.Env(), static_cast<double>(array.ElementLength()));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
Value GetTypedArrayBuffer(const CallbackInfo& info) {
|
|
115
|
+
TypedArray array = info[0].As<TypedArray>();
|
|
116
|
+
return array.ArrayBuffer();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
Value GetTypedArrayElement(const CallbackInfo& info) {
|
|
120
|
+
TypedArray array = info[0].As<TypedArray>();
|
|
121
|
+
size_t index = info[1].As<Number>().Uint32Value();
|
|
122
|
+
switch (array.TypedArrayType()) {
|
|
123
|
+
case napi_int8_array:
|
|
124
|
+
return Number::New(info.Env(), array.As<Int8Array>()[index]);
|
|
125
|
+
case napi_uint8_array:
|
|
126
|
+
return Number::New(info.Env(), array.As<Uint8Array>()[index]);
|
|
127
|
+
case napi_uint8_clamped_array:
|
|
128
|
+
return Number::New(info.Env(), array.As<Uint8Array>()[index]);
|
|
129
|
+
case napi_int16_array:
|
|
130
|
+
return Number::New(info.Env(), array.As<Int16Array>()[index]);
|
|
131
|
+
case napi_uint16_array:
|
|
132
|
+
return Number::New(info.Env(), array.As<Uint16Array>()[index]);
|
|
133
|
+
case napi_int32_array:
|
|
134
|
+
return Number::New(info.Env(), array.As<Int32Array>()[index]);
|
|
135
|
+
case napi_uint32_array:
|
|
136
|
+
return Number::New(info.Env(), array.As<Uint32Array>()[index]);
|
|
137
|
+
case napi_float32_array:
|
|
138
|
+
return Number::New(info.Env(), array.As<Float32Array>()[index]);
|
|
139
|
+
case napi_float64_array:
|
|
140
|
+
return Number::New(info.Env(), array.As<Float64Array>()[index]);
|
|
141
|
+
#if (NAPI_VERSION > 5)
|
|
142
|
+
case napi_bigint64_array:
|
|
143
|
+
return BigInt::New(info.Env(), array.As<BigInt64Array>()[index]);
|
|
144
|
+
case napi_biguint64_array:
|
|
145
|
+
return BigInt::New(info.Env(), array.As<BigUint64Array>()[index]);
|
|
146
|
+
#endif
|
|
147
|
+
default:
|
|
148
|
+
Error::New(info.Env(), "Invalid typed-array type.").ThrowAsJavaScriptException();
|
|
149
|
+
return Value();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
void SetTypedArrayElement(const CallbackInfo& info) {
|
|
154
|
+
TypedArray array = info[0].As<TypedArray>();
|
|
155
|
+
size_t index = info[1].As<Number>().Uint32Value();
|
|
156
|
+
Number value = info[2].As<Number>();
|
|
157
|
+
switch (array.TypedArrayType()) {
|
|
158
|
+
case napi_int8_array:
|
|
159
|
+
array.As<Int8Array>()[index] = static_cast<int8_t>(value.Int32Value());
|
|
160
|
+
break;
|
|
161
|
+
case napi_uint8_array:
|
|
162
|
+
array.As<Uint8Array>()[index] = static_cast<uint8_t>(value.Uint32Value());
|
|
163
|
+
break;
|
|
164
|
+
case napi_uint8_clamped_array:
|
|
165
|
+
array.As<Uint8Array>()[index] = static_cast<uint8_t>(value.Uint32Value());
|
|
166
|
+
break;
|
|
167
|
+
case napi_int16_array:
|
|
168
|
+
array.As<Int16Array>()[index] = static_cast<int16_t>(value.Int32Value());
|
|
169
|
+
break;
|
|
170
|
+
case napi_uint16_array:
|
|
171
|
+
array.As<Uint16Array>()[index] = static_cast<uint16_t>(value.Uint32Value());
|
|
172
|
+
break;
|
|
173
|
+
case napi_int32_array:
|
|
174
|
+
array.As<Int32Array>()[index] = value.Int32Value();
|
|
175
|
+
break;
|
|
176
|
+
case napi_uint32_array:
|
|
177
|
+
array.As<Uint32Array>()[index] = value.Uint32Value();
|
|
178
|
+
break;
|
|
179
|
+
case napi_float32_array:
|
|
180
|
+
array.As<Float32Array>()[index] = value.FloatValue();
|
|
181
|
+
break;
|
|
182
|
+
case napi_float64_array:
|
|
183
|
+
array.As<Float64Array>()[index] = value.DoubleValue();
|
|
184
|
+
break;
|
|
185
|
+
#if (NAPI_VERSION > 5)
|
|
186
|
+
case napi_bigint64_array: {
|
|
187
|
+
bool lossless;
|
|
188
|
+
array.As<BigInt64Array>()[index] = value.As<BigInt>().Int64Value(&lossless);
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case napi_biguint64_array: {
|
|
192
|
+
bool lossless;
|
|
193
|
+
array.As<BigUint64Array>()[index] = value.As<BigInt>().Uint64Value(&lossless);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
#endif
|
|
197
|
+
default:
|
|
198
|
+
Error::New(info.Env(), "Invalid typed-array type.").ThrowAsJavaScriptException();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
} // end anonymous namespace
|
|
203
|
+
|
|
204
|
+
Object InitTypedArray(Env env) {
|
|
205
|
+
Object exports = Object::New(env);
|
|
206
|
+
|
|
207
|
+
exports["createTypedArray"] = Function::New(env, CreateTypedArray);
|
|
208
|
+
exports["createInvalidTypedArray"] = Function::New(env, CreateInvalidTypedArray);
|
|
209
|
+
exports["getTypedArrayType"] = Function::New(env, GetTypedArrayType);
|
|
210
|
+
exports["getTypedArrayLength"] = Function::New(env, GetTypedArrayLength);
|
|
211
|
+
exports["getTypedArrayBuffer"] = Function::New(env, GetTypedArrayBuffer);
|
|
212
|
+
exports["getTypedArrayElement"] = Function::New(env, GetTypedArrayElement);
|
|
213
|
+
exports["setTypedArrayElement"] = Function::New(env, SetTypedArrayElement);
|
|
214
|
+
|
|
215
|
+
return exports;
|
|
216
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
|
|
5
|
+
module.exports = require('./common').runTest(test);
|
|
6
|
+
|
|
7
|
+
function test(binding) {
|
|
8
|
+
const testData = [
|
|
9
|
+
[ 'int8', Int8Array ],
|
|
10
|
+
[ 'uint8', Uint8Array ],
|
|
11
|
+
[ 'uint8_clamped', Uint8ClampedArray ],
|
|
12
|
+
[ 'int16', Int16Array ],
|
|
13
|
+
[ 'uint16', Uint16Array ],
|
|
14
|
+
[ 'int32', Int32Array ],
|
|
15
|
+
[ 'uint32', Uint32Array ],
|
|
16
|
+
[ 'float32', Float32Array ],
|
|
17
|
+
[ 'float64', Float64Array ],
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
testData.forEach(data => {
|
|
21
|
+
try {
|
|
22
|
+
const length = 4;
|
|
23
|
+
const t = binding.typedarray.createTypedArray(data[0], length);
|
|
24
|
+
assert.ok(t instanceof data[1]);
|
|
25
|
+
assert.strictEqual(binding.typedarray.getTypedArrayType(t), data[0]);
|
|
26
|
+
assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length);
|
|
27
|
+
|
|
28
|
+
t[3] = 11;
|
|
29
|
+
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11);
|
|
30
|
+
binding.typedarray.setTypedArrayElement(t, 3, 22);
|
|
31
|
+
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 22);
|
|
32
|
+
assert.strictEqual(t[3], 22);
|
|
33
|
+
|
|
34
|
+
const b = binding.typedarray.getTypedArrayBuffer(t);
|
|
35
|
+
assert.ok(b instanceof ArrayBuffer);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
console.log(data);
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
testData.forEach(data => {
|
|
43
|
+
try {
|
|
44
|
+
const length = 4;
|
|
45
|
+
const offset = 8;
|
|
46
|
+
const b = new ArrayBuffer(offset + 64 * 4);
|
|
47
|
+
|
|
48
|
+
const t = binding.typedarray.createTypedArray(data[0], length, b, offset);
|
|
49
|
+
assert.ok(t instanceof data[1]);
|
|
50
|
+
assert.strictEqual(binding.typedarray.getTypedArrayType(t), data[0]);
|
|
51
|
+
assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length);
|
|
52
|
+
|
|
53
|
+
t[3] = 11;
|
|
54
|
+
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11);
|
|
55
|
+
binding.typedarray.setTypedArrayElement(t, 3, 22);
|
|
56
|
+
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 22);
|
|
57
|
+
assert.strictEqual(t[3], 22);
|
|
58
|
+
|
|
59
|
+
assert.strictEqual(binding.typedarray.getTypedArrayBuffer(t), b);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.log(data);
|
|
62
|
+
throw e;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
assert.throws(() => {
|
|
67
|
+
binding.typedarray.createInvalidTypedArray();
|
|
68
|
+
}, /Invalid (pointer passed as )?argument/);
|
|
69
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#include "napi.h"
|
|
2
|
+
|
|
3
|
+
using namespace Napi;
|
|
4
|
+
|
|
5
|
+
Value getNapiVersion(const CallbackInfo& info) {
|
|
6
|
+
Napi::Env env = info.Env();
|
|
7
|
+
uint32_t napi_version = VersionManagement::GetNapiVersion(env);
|
|
8
|
+
return Number::New(env, napi_version);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
Value getNodeVersion(const CallbackInfo& info) {
|
|
12
|
+
Napi::Env env = info.Env();
|
|
13
|
+
const napi_node_version* node_version = VersionManagement::GetNodeVersion(env);
|
|
14
|
+
Object version = Object::New(env);
|
|
15
|
+
version.Set("major", Number::New(env, node_version->major));
|
|
16
|
+
version.Set("minor", Number::New(env, node_version->minor));
|
|
17
|
+
version.Set("patch", Number::New(env, node_version->patch));
|
|
18
|
+
version.Set("release", String::New(env, node_version->release));
|
|
19
|
+
return version;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Object InitVersionManagement(Env env) {
|
|
23
|
+
Object exports = Object::New(env);
|
|
24
|
+
exports["getNapiVersion"] = Function::New(env, getNapiVersion);
|
|
25
|
+
exports["getNodeVersion"] = Function::New(env, getNodeVersion);
|
|
26
|
+
return exports;
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
|
|
5
|
+
module.exports = require('./common').runTest(test);
|
|
6
|
+
|
|
7
|
+
function parseVersion() {
|
|
8
|
+
const expected = {};
|
|
9
|
+
expected.napi = parseInt(process.versions.napi);
|
|
10
|
+
expected.release = process.release.name;
|
|
11
|
+
const nodeVersion = process.versions.node.split('.');
|
|
12
|
+
expected.major = parseInt(nodeVersion[0]);
|
|
13
|
+
expected.minor = parseInt(nodeVersion[1]);
|
|
14
|
+
expected.patch = parseInt(nodeVersion[2]);
|
|
15
|
+
return expected;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function test(binding) {
|
|
19
|
+
|
|
20
|
+
const expected = parseVersion();
|
|
21
|
+
|
|
22
|
+
const napiVersion = binding.version_management.getNapiVersion();
|
|
23
|
+
assert.strictEqual(napiVersion, expected.napi);
|
|
24
|
+
|
|
25
|
+
const nodeVersion = binding.version_management.getNodeVersion();
|
|
26
|
+
assert.strictEqual(nodeVersion.major, expected.major);
|
|
27
|
+
assert.strictEqual(nodeVersion.minor, expected.minor);
|
|
28
|
+
assert.strictEqual(nodeVersion.patch, expected.patch);
|
|
29
|
+
assert.strictEqual(nodeVersion.release, expected.release);
|
|
30
|
+
|
|
31
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Tools
|
|
2
|
+
|
|
3
|
+
## clang-format
|
|
4
|
+
|
|
5
|
+
The clang-format checking tools is designed to check changed lines of code compared to given git-refs.
|
|
6
|
+
|
|
7
|
+
## Migration Script
|
|
8
|
+
|
|
9
|
+
The migration tool is designed to reduce repetitive work in the migration process. However, the script is not aiming to convert every thing for you. There are usually some small fixes and major reconstruction required.
|
|
10
|
+
|
|
11
|
+
### How To Use
|
|
12
|
+
|
|
13
|
+
To run the conversion script, first make sure you have the latest `node-addon-api` in your `node_modules` directory.
|
|
14
|
+
```
|
|
15
|
+
npm install node-addon-api
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Then run the script passing your project directory
|
|
19
|
+
```
|
|
20
|
+
node ./node_modules/node-addon-api/tools/conversion.js ./
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
After finish, recompile and debug things that are missed by the script.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Quick Fixes
|
|
27
|
+
Here is the list of things that can be fixed easily.
|
|
28
|
+
1. Change your methods' return value to void if it doesn't return value to JavaScript.
|
|
29
|
+
2. Use `.` to access attribute or to invoke member function in Napi::Object instead of `->`.
|
|
30
|
+
3. `Napi::New(env, value);` to `Napi::[Type]::New(env, value);
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Major Reconstructions
|
|
34
|
+
The implementation of `Napi::ObjectWrap` is significantly different from NAN's. `Napi::ObjectWrap` takes a pointer to the wrapped object and creates a reference to the wrapped object inside ObjectWrap constructor. `Napi::ObjectWrap` also associates wrapped object's instance methods to Javascript module instead of static methods like NAN.
|
|
35
|
+
|
|
36
|
+
So if you use Nan::ObjectWrap in your module, you will need to execute the following steps.
|
|
37
|
+
|
|
38
|
+
1. Convert your [ClassName]::New function to a constructor function that takes a `Napi::CallbackInfo`. Declare it as
|
|
39
|
+
```
|
|
40
|
+
[ClassName](const Napi::CallbackInfo& info);
|
|
41
|
+
```
|
|
42
|
+
and define it as
|
|
43
|
+
```
|
|
44
|
+
[ClassName]::[ClassName](const Napi::CallbackInfo& info) : Napi::ObjectWrap<[ClassName]>(info){
|
|
45
|
+
...
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
This way, the `Napi::ObjectWrap` constructor will be invoked after the object has been instantiated and `Napi::ObjectWrap` can use the `this` pointer to create a reference to the wrapped object.
|
|
49
|
+
|
|
50
|
+
2. Move your original constructor code into the new constructor. Delete your original constructor.
|
|
51
|
+
3. In your class initialization function, associate native methods in the following way.
|
|
52
|
+
```
|
|
53
|
+
Napi::FunctionReference constructor;
|
|
54
|
+
|
|
55
|
+
void [ClassName]::Init(Napi::Env env, Napi::Object exports, Napi::Object module) {
|
|
56
|
+
Napi::HandleScope scope(env);
|
|
57
|
+
Napi::Function ctor = DefineClass(env, "Canvas", {
|
|
58
|
+
InstanceMethod<&[ClassName]::Func1>("Func1"),
|
|
59
|
+
InstanceMethod<&[ClassName]::Func2>("Func2"),
|
|
60
|
+
InstanceAccessor<&[ClassName]::ValueGetter>("Value"),
|
|
61
|
+
StaticMethod<&[ClassName]::StaticMethod>("MethodName"),
|
|
62
|
+
InstanceValue("Value", Napi::[Type]::New(env, value)),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
constructor = Napi::Persistent(ctor);
|
|
66
|
+
constructor .SuppressDestruct();
|
|
67
|
+
exports.Set("[ClassName]", ctor);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
4. In function where you need to Unwrap the ObjectWrap in NAN like `[ClassName]* native = Nan::ObjectWrap::Unwrap<[ClassName]>(info.This());`, use `this` pointer directly as the unwrapped object as each ObjectWrap instance is associated with a unique object instance.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
If you still find issues after following this guide, please leave us an issue describing your problem and we will try to resolve it.
|