koffi 2.3.4 → 2.3.6-beta.1
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 +25 -2
- package/doc/changelog.md +4 -0
- package/doc/index.rst +1 -2
- package/doc/types.md +3 -3
- package/package.json +5 -5
- package/src/cnoke/cnoke.js +40 -834
- package/src/cnoke/package.json +1 -0
- package/src/cnoke/src/builder.js +447 -0
- package/src/cnoke/src/index.js +20 -0
- package/src/cnoke/src/tools.js +401 -0
- package/src/core/libcc/libcc.cc +2 -2
- package/src/koffi/build/2.3.6-beta.1/koffi_darwin_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_darwin_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_freebsd_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_freebsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_freebsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_linux_arm32hf/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_linux_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_linux_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_linux_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_openbsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_openbsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_win32_arm64/koffi.exp +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_win32_arm64/koffi.lib +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_win32_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_win32_arm64/koffi.pdb +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_win32_ia32/koffi.exp +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_win32_ia32/koffi.lib +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_win32_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_win32_ia32/koffi.pdb +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_win32_x64/koffi.exp +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_win32_x64/koffi.lib +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_win32_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.1/koffi_win32_x64/koffi.pdb +0 -0
- package/src/koffi/src/abi_arm32.cc +43 -14
- package/src/koffi/src/abi_arm64.cc +95 -21
- package/src/koffi/src/abi_riscv64.cc +125 -64
- package/src/koffi/src/abi_x64_sysv.cc +38 -20
- package/src/koffi/src/abi_x64_win.cc +11 -5
- package/src/koffi/src/abi_x86.cc +14 -7
- package/src/koffi/src/call.cc +114 -44
- package/src/koffi/src/call.hh +6 -4
- package/src/koffi/src/ffi.cc +172 -147
- package/src/koffi/src/ffi.hh +18 -10
- package/src/koffi/src/index.d.ts +28 -7
- package/src/koffi/src/index.js +23 -4
- package/src/koffi/src/util.cc +261 -69
- package/src/koffi/src/util.hh +34 -8
- package/vendor/node-addon-api/CHANGELOG.md +122 -9
- package/vendor/node-addon-api/CONTRIBUTING.md +10 -10
- package/vendor/node-addon-api/README.md +36 -12
- package/vendor/node-addon-api/benchmark/function_args.cc +95 -62
- package/vendor/node-addon-api/benchmark/function_args.js +6 -6
- package/vendor/node-addon-api/benchmark/index.js +1 -1
- package/vendor/node-addon-api/benchmark/property_descriptor.cc +27 -34
- package/vendor/node-addon-api/benchmark/property_descriptor.js +5 -4
- package/vendor/node-addon-api/doc/async_operations.md +1 -1
- package/vendor/node-addon-api/doc/async_worker_variants.md +23 -2
- package/vendor/node-addon-api/doc/cmake-js.md +1 -1
- package/vendor/node-addon-api/doc/error_handling.md +3 -3
- package/vendor/node-addon-api/doc/external.md +7 -0
- package/vendor/node-addon-api/doc/handle_scope.md +14 -0
- package/vendor/node-addon-api/doc/hierarchy.md +1 -1
- package/vendor/node-addon-api/doc/object.md +27 -0
- package/vendor/node-addon-api/index.js +3 -3
- package/vendor/node-addon-api/napi-inl.deprecated.h +121 -127
- package/vendor/node-addon-api/napi-inl.h +1178 -1144
- package/vendor/node-addon-api/napi.h +2786 -2675
- package/vendor/node-addon-api/package.json +42 -1
- package/vendor/node-addon-api/test/addon.cc +8 -6
- package/vendor/node-addon-api/test/addon_build/index.js +9 -9
- package/vendor/node-addon-api/test/addon_build/tpl/addon.cc +2 -1
- package/vendor/node-addon-api/test/addon_build/tpl/index.js +4 -4
- package/vendor/node-addon-api/test/addon_data.cc +12 -13
- package/vendor/node-addon-api/test/array_buffer.js +3 -2
- package/vendor/node-addon-api/test/async_progress_queue_worker.cc +13 -3
- package/vendor/node-addon-api/test/async_progress_queue_worker.js +5 -5
- package/vendor/node-addon-api/test/async_progress_worker.cc +65 -9
- package/vendor/node-addon-api/test/async_progress_worker.js +14 -9
- package/vendor/node-addon-api/test/async_worker.cc +236 -3
- package/vendor/node-addon-api/test/async_worker.js +122 -37
- package/vendor/node-addon-api/test/async_worker_nocallback.js +9 -3
- package/vendor/node-addon-api/test/async_worker_persistent.js +2 -2
- package/vendor/node-addon-api/test/basic_types/array.js +3 -4
- package/vendor/node-addon-api/test/basic_types/boolean.cc +4 -2
- package/vendor/node-addon-api/test/basic_types/boolean.js +1 -2
- package/vendor/node-addon-api/test/basic_types/number.cc +12 -6
- package/vendor/node-addon-api/test/basic_types/number.js +19 -18
- package/vendor/node-addon-api/test/basic_types/value.cc +52 -1
- package/vendor/node-addon-api/test/basic_types/value.js +44 -21
- package/vendor/node-addon-api/test/bigint.cc +2 -1
- package/vendor/node-addon-api/test/binding.cc +11 -5
- package/vendor/node-addon-api/test/binding.gyp +3 -1
- package/vendor/node-addon-api/test/buffer.cc +46 -38
- package/vendor/node-addon-api/test/buffer.js +12 -12
- package/vendor/node-addon-api/test/callbackInfo.cc +27 -0
- package/vendor/node-addon-api/test/callbackInfo.js +9 -0
- package/vendor/node-addon-api/test/callbackscope.cc +19 -2
- package/vendor/node-addon-api/test/callbackscope.js +20 -20
- package/vendor/node-addon-api/test/common/index.js +37 -4
- package/vendor/node-addon-api/test/dataview/dataview.js +5 -5
- package/vendor/node-addon-api/test/dataview/dataview_read_write.js +14 -12
- package/vendor/node-addon-api/test/date.cc +2 -1
- package/vendor/node-addon-api/test/date.js +2 -2
- package/vendor/node-addon-api/test/env_cleanup.cc +12 -0
- package/vendor/node-addon-api/test/env_cleanup.js +38 -39
- package/vendor/node-addon-api/test/error.cc +6 -5
- package/vendor/node-addon-api/test/error_terminating_environment.js +64 -60
- package/vendor/node-addon-api/test/external.cc +36 -32
- package/vendor/node-addon-api/test/external.js +43 -46
- package/vendor/node-addon-api/test/function.cc +58 -44
- package/vendor/node-addon-api/test/function.js +4 -0
- package/vendor/node-addon-api/test/function_reference.cc +15 -13
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.js +50 -53
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.js +33 -34
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.js +38 -40
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.js +47 -49
- package/vendor/node-addon-api/test/handlescope.cc +29 -3
- package/vendor/node-addon-api/test/handlescope.js +5 -3
- package/vendor/node-addon-api/test/index.js +1 -5
- package/vendor/node-addon-api/test/maybe/check.cc +49 -3
- package/vendor/node-addon-api/test/maybe/index.js +19 -7
- package/vendor/node-addon-api/test/memory_management.cc +9 -8
- package/vendor/node-addon-api/test/memory_management.js +2 -2
- package/vendor/node-addon-api/test/movable_callbacks.js +2 -2
- package/vendor/node-addon-api/test/name.js +3 -3
- package/vendor/node-addon-api/test/napi_child.js +2 -2
- package/vendor/node-addon-api/test/object/delete_property.js +7 -7
- package/vendor/node-addon-api/test/object/finalizer.cc +13 -12
- package/vendor/node-addon-api/test/object/finalizer.js +2 -2
- package/vendor/node-addon-api/test/object/get_property.js +6 -6
- package/vendor/node-addon-api/test/object/has_own_property.js +3 -3
- package/vendor/node-addon-api/test/object/has_property.js +4 -4
- package/vendor/node-addon-api/test/object/object.cc +191 -111
- package/vendor/node-addon-api/test/object/object.js +53 -52
- package/vendor/node-addon-api/test/object/object_deprecated.cc +24 -20
- package/vendor/node-addon-api/test/object/object_deprecated.js +3 -8
- package/vendor/node-addon-api/test/object/object_freeze_seal.js +54 -54
- package/vendor/node-addon-api/test/object/object_type_tag.cc +39 -0
- package/vendor/node-addon-api/test/object/object_type_tag.js +55 -0
- package/vendor/node-addon-api/test/object/subscript_operator.js +2 -2
- package/vendor/node-addon-api/test/object_reference.js +100 -100
- package/vendor/node-addon-api/test/objectwrap.cc +41 -34
- package/vendor/node-addon-api/test/objectwrap.js +23 -19
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.cc +5 -5
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.js +1 -1
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.cc +7 -7
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.js +1 -1
- package/vendor/node-addon-api/test/objectwrap_removewrap.js +24 -32
- package/vendor/node-addon-api/test/objectwrap_worker_thread.js +5 -4
- package/vendor/node-addon-api/test/promise.cc +7 -0
- package/vendor/node-addon-api/test/promise.js +3 -1
- package/vendor/node-addon-api/test/reference.cc +1 -1
- package/vendor/node-addon-api/test/reference.js +2 -2
- package/vendor/node-addon-api/test/run_script.cc +1 -1
- package/vendor/node-addon-api/test/symbol.js +59 -66
- package/vendor/node-addon-api/test/testUtil.js +6 -6
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.cc +64 -29
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.js +71 -34
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.cc +111 -19
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.js +2 -1
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.cc +36 -26
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.js +5 -5
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.cc +3 -2
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.js +1 -1
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.cc +47 -32
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.js +3 -3
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.cc +22 -9
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.js +76 -31
- package/vendor/node-addon-api/test/thunking_manual.cc +61 -74
- package/vendor/node-addon-api/test/thunking_manual.js +6 -7
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.cc +20 -20
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.js +19 -19
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc +57 -5
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +2 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js +5 -5
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc +5 -1
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js +4 -3
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.js +3 -3
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc +14 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js +76 -31
- package/vendor/node-addon-api/test/typedarray-bigint.js +2 -2
- package/vendor/node-addon-api/test/typedarray.cc +263 -70
- package/vendor/node-addon-api/test/typedarray.js +44 -10
- package/vendor/node-addon-api/test/version_management.cc +16 -15
- package/vendor/node-addon-api/test/version_management.js +18 -20
- package/vendor/node-addon-api/tools/check-napi.js +13 -14
- package/vendor/node-addon-api/tools/conversion.js +161 -169
- package/vendor/node-addon-api/tools/eslint-format.js +9 -1
- package/vendor/node-addon-api/unit-test/README.md +4 -4
- package/src/koffi/build/2.3.4/koffi_darwin_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_darwin_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_freebsd_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_freebsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_freebsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_linux_arm32hf.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_linux_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_linux_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_linux_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_openbsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_openbsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_win32_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_win32_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.4/koffi_win32_x64.tar.gz +0 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
/* eslint-disable no-lone-blocks */
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
const assert = require('assert');
|
|
4
5
|
|
|
5
6
|
module.exports = require('../common').runTest(test);
|
|
6
7
|
|
|
7
|
-
function test(binding) {
|
|
8
|
+
function test (binding) {
|
|
8
9
|
const MIN_INT32 = -2147483648;
|
|
9
10
|
const MAX_INT32 = 2147483647;
|
|
10
11
|
const MIN_UINT32 = 0;
|
|
@@ -16,9 +17,9 @@ function test(binding) {
|
|
|
16
17
|
const MIN_DOUBLE = binding.basic_types_number.minDouble();
|
|
17
18
|
const MAX_DOUBLE = binding.basic_types_number.maxDouble();
|
|
18
19
|
|
|
19
|
-
function randomRangeTestForInteger(min, max, converter) {
|
|
20
|
-
for (let i = min; i < max; i+= Math.floor(Math.random() * max / 100)) {
|
|
21
|
-
|
|
20
|
+
function randomRangeTestForInteger (min, max, converter) {
|
|
21
|
+
for (let i = min; i < max; i += Math.floor(Math.random() * max / 100)) {
|
|
22
|
+
assert.strictEqual(i, converter(i));
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -96,19 +97,19 @@ function test(binding) {
|
|
|
96
97
|
|
|
97
98
|
// Construction test
|
|
98
99
|
{
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
assert.strictEqual(binding.basic_types_number.createEmptyNumber(), true);
|
|
101
|
+
randomRangeTestForInteger(MIN_INT32, MAX_INT32, binding.basic_types_number.createNumberFromExistingValue);
|
|
102
|
+
assert.strictEqual(MIN_INT32, binding.basic_types_number.createNumberFromExistingValue(MIN_INT32));
|
|
103
|
+
assert.strictEqual(MAX_INT32, binding.basic_types_number.createNumberFromExistingValue(MAX_INT32));
|
|
104
|
+
randomRangeTestForInteger(MIN_UINT32, MAX_UINT32, binding.basic_types_number.createNumberFromExistingValue);
|
|
105
|
+
assert.strictEqual(MIN_UINT32, binding.basic_types_number.createNumberFromExistingValue(MIN_UINT32));
|
|
106
|
+
assert.strictEqual(MAX_UINT32, binding.basic_types_number.createNumberFromExistingValue(MAX_UINT32));
|
|
107
|
+
randomRangeTestForInteger(MIN_INT64, MAX_INT64, binding.basic_types_number.createNumberFromExistingValue);
|
|
108
|
+
assert.strictEqual(MIN_INT64, binding.basic_types_number.createNumberFromExistingValue(MIN_INT64));
|
|
109
|
+
assert.strictEqual(MAX_INT64, binding.basic_types_number.createNumberFromExistingValue(MAX_INT64));
|
|
110
|
+
assert.strictEqual(MIN_FLOAT, binding.basic_types_number.createNumberFromExistingValue(MIN_FLOAT));
|
|
111
|
+
assert.strictEqual(MAX_FLOAT, binding.basic_types_number.createNumberFromExistingValue(MAX_FLOAT));
|
|
112
|
+
assert.strictEqual(MIN_DOUBLE, binding.basic_types_number.createNumberFromExistingValue(MIN_DOUBLE));
|
|
113
|
+
assert.strictEqual(MAX_DOUBLE, binding.basic_types_number.createNumberFromExistingValue(MAX_DOUBLE));
|
|
113
114
|
}
|
|
114
115
|
}
|
|
@@ -12,7 +12,44 @@ Value CreateExternal(const CallbackInfo& info) {
|
|
|
12
12
|
return External<int>::New(info.Env(), &testData);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
}
|
|
15
|
+
} // end anonymous namespace
|
|
16
|
+
|
|
17
|
+
static Value StrictlyEquals(const CallbackInfo& info) {
|
|
18
|
+
bool strictlyEquals = info[0].StrictEquals(info[1]);
|
|
19
|
+
return Boolean::New(info.Env(), strictlyEquals);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// tests the '==' overload
|
|
23
|
+
static Value StrictEqualsOverload(const CallbackInfo& info) {
|
|
24
|
+
bool strictlyEquals = info[0] == info[1];
|
|
25
|
+
return Boolean::New(info.Env(), strictlyEquals);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// tests the '!=' overload
|
|
29
|
+
static Value StrictlyNotEqualsOverload(const CallbackInfo& info) {
|
|
30
|
+
bool strictlyEquals = info[0] != info[1];
|
|
31
|
+
return Boolean::New(info.Env(), strictlyEquals);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static Value ValueReturnsCorrectEnv(const CallbackInfo& info) {
|
|
35
|
+
Value testValue = CreateExternal(info);
|
|
36
|
+
return Boolean::New(info.Env(), testValue.Env() == info.Env());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static Value EmptyValueReturnNullPtrOnCast(const CallbackInfo& info) {
|
|
40
|
+
Value emptyValue;
|
|
41
|
+
bool isNullPtr = static_cast<napi_value>(emptyValue) == nullptr;
|
|
42
|
+
return Boolean::New(info.Env(), isNullPtr);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static Value NonEmptyValueReturnValOnCast(const CallbackInfo& info) {
|
|
46
|
+
Value boolValue = Value::From(info.Env(), true);
|
|
47
|
+
return Boolean::New(info.Env(), static_cast<napi_value>(boolValue));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static Value CreateNonEmptyValue(const CallbackInfo& info) {
|
|
51
|
+
return Napi::Value(info.Env(), String::New(info.Env(), "non_empty_val"));
|
|
52
|
+
}
|
|
16
53
|
|
|
17
54
|
static Value IsEmpty(const CallbackInfo& info) {
|
|
18
55
|
Value value;
|
|
@@ -114,6 +151,20 @@ Object InitBasicTypesValue(Env env) {
|
|
|
114
151
|
exports["toString"] = Function::New(env, ToString);
|
|
115
152
|
exports["toObject"] = Function::New(env, ToObject);
|
|
116
153
|
|
|
154
|
+
exports["strictlyEquals"] = Function::New(env, StrictlyEquals);
|
|
155
|
+
exports["strictlyEqualsOverload"] = Function::New(env, StrictEqualsOverload);
|
|
156
|
+
exports["strictlyNotEqualsOverload"] =
|
|
157
|
+
Function::New(env, StrictlyNotEqualsOverload);
|
|
158
|
+
|
|
159
|
+
exports["assertValueReturnsCorrectEnv"] =
|
|
160
|
+
Function::New(env, ValueReturnsCorrectEnv);
|
|
161
|
+
|
|
162
|
+
exports["assertEmptyValReturnNullPtrOnCast"] =
|
|
163
|
+
Function::New(env, EmptyValueReturnNullPtrOnCast);
|
|
164
|
+
exports["assertNonEmptyReturnValOnCast"] =
|
|
165
|
+
Function::New(env, NonEmptyValueReturnValOnCast);
|
|
166
|
+
|
|
167
|
+
exports["createNonEmptyValue"] = Function::New(env, CreateNonEmptyValue);
|
|
117
168
|
exports["createExternal"] = Function::New(env, CreateExternal);
|
|
118
169
|
|
|
119
170
|
return exports;
|
|
@@ -4,33 +4,27 @@ const assert = require('assert');
|
|
|
4
4
|
|
|
5
5
|
module.exports = require('../common').runTest(test);
|
|
6
6
|
|
|
7
|
-
function test(binding) {
|
|
7
|
+
function test (binding) {
|
|
8
8
|
const externalValue = binding.basic_types_value.createExternal();
|
|
9
9
|
|
|
10
|
-
function isObject(value) {
|
|
10
|
+
function isObject (value) {
|
|
11
11
|
return (typeof value === 'object' && value !== externalValue) ||
|
|
12
12
|
(typeof value === 'function');
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function detailedTypeOf(value) {
|
|
15
|
+
function detailedTypeOf (value) {
|
|
16
16
|
const type = typeof value;
|
|
17
|
-
if (type !== 'object')
|
|
18
|
-
return type;
|
|
17
|
+
if (type !== 'object') { return type; }
|
|
19
18
|
|
|
20
|
-
if (value === null)
|
|
21
|
-
return 'null';
|
|
19
|
+
if (value === null) { return 'null'; }
|
|
22
20
|
|
|
23
|
-
if (Array.isArray(value))
|
|
24
|
-
return 'array';
|
|
21
|
+
if (Array.isArray(value)) { return 'array'; }
|
|
25
22
|
|
|
26
|
-
if (value === externalValue)
|
|
27
|
-
return 'external';
|
|
23
|
+
if (value === externalValue) { return 'external'; }
|
|
28
24
|
|
|
29
|
-
if (!value.constructor)
|
|
30
|
-
return type;
|
|
25
|
+
if (!value.constructor) { return type; }
|
|
31
26
|
|
|
32
|
-
if (value instanceof ArrayBuffer)
|
|
33
|
-
return 'arraybuffer';
|
|
27
|
+
if (value instanceof ArrayBuffer) { return 'arraybuffer'; }
|
|
34
28
|
|
|
35
29
|
if (ArrayBuffer.isView(value)) {
|
|
36
30
|
if (value instanceof DataView) {
|
|
@@ -40,13 +34,12 @@ function test(binding) {
|
|
|
40
34
|
}
|
|
41
35
|
}
|
|
42
36
|
|
|
43
|
-
if (value instanceof Promise)
|
|
44
|
-
return 'promise';
|
|
37
|
+
if (value instanceof Promise) { return 'promise'; }
|
|
45
38
|
|
|
46
39
|
return 'object';
|
|
47
40
|
}
|
|
48
41
|
|
|
49
|
-
function typeCheckerTest(typeChecker, expectedType) {
|
|
42
|
+
function typeCheckerTest (typeChecker, expectedType) {
|
|
50
43
|
const testValueList = [
|
|
51
44
|
undefined,
|
|
52
45
|
null,
|
|
@@ -58,7 +51,7 @@ function test(binding) {
|
|
|
58
51
|
new ArrayBuffer(10),
|
|
59
52
|
new Int32Array(new ArrayBuffer(12)),
|
|
60
53
|
{},
|
|
61
|
-
function() {},
|
|
54
|
+
function () {},
|
|
62
55
|
new Promise((resolve, reject) => {}),
|
|
63
56
|
new DataView(new ArrayBuffer(12)),
|
|
64
57
|
externalValue
|
|
@@ -73,7 +66,7 @@ function test(binding) {
|
|
|
73
66
|
});
|
|
74
67
|
}
|
|
75
68
|
|
|
76
|
-
function typeConverterTest(typeConverter, expectedType) {
|
|
69
|
+
function typeConverterTest (typeConverter, expectedType) {
|
|
77
70
|
const testValueList = [
|
|
78
71
|
true,
|
|
79
72
|
false,
|
|
@@ -84,7 +77,7 @@ function test(binding) {
|
|
|
84
77
|
new ArrayBuffer(10),
|
|
85
78
|
new Int32Array(new ArrayBuffer(12)),
|
|
86
79
|
{},
|
|
87
|
-
function() {},
|
|
80
|
+
function () {},
|
|
88
81
|
new Promise((resolve, reject) => {})
|
|
89
82
|
];
|
|
90
83
|
|
|
@@ -100,8 +93,38 @@ function test(binding) {
|
|
|
100
93
|
});
|
|
101
94
|
}
|
|
102
95
|
|
|
96
|
+
function assertValueStrictlyEqual (value) {
|
|
97
|
+
const newValue = value.createNonEmptyValue();
|
|
98
|
+
assert(value.strictlyEquals(newValue, newValue));
|
|
99
|
+
assert(value.strictlyEqualsOverload(newValue, newValue));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function assertValueStrictlyNonEqual (value) {
|
|
103
|
+
const valueA = value.createNonEmptyValue();
|
|
104
|
+
const valueB = value.createExternal();
|
|
105
|
+
assert(value.strictlyNotEqualsOverload(valueA, valueB));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function assertValueReturnsCorrectEnv (value) {
|
|
109
|
+
assert(value.assertValueReturnsCorrectEnv());
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function assertEmptyValueNullPtrOnCast (value) {
|
|
113
|
+
assert(value.assertEmptyValReturnNullPtrOnCast());
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function assertNonEmptyReturnValOnCast (value) {
|
|
117
|
+
assert(value.assertNonEmptyReturnValOnCast());
|
|
118
|
+
}
|
|
119
|
+
|
|
103
120
|
const value = binding.basic_types_value;
|
|
104
121
|
|
|
122
|
+
assertValueStrictlyEqual(value);
|
|
123
|
+
assertValueStrictlyNonEqual(value);
|
|
124
|
+
assertValueReturnsCorrectEnv(value);
|
|
125
|
+
assertEmptyValueNullPtrOnCast(value);
|
|
126
|
+
assertNonEmptyReturnValOnCast(value);
|
|
127
|
+
|
|
105
128
|
typeCheckerTest(value.isUndefined, 'undefined');
|
|
106
129
|
typeCheckerTest(value.isNull, 'null');
|
|
107
130
|
typeCheckerTest(value.isBoolean, 'boolean');
|
|
@@ -59,7 +59,8 @@ Value TestWords(const CallbackInfo& info) {
|
|
|
59
59
|
big.ToWords(&sign_bit, &word_count, words);
|
|
60
60
|
|
|
61
61
|
if (word_count != expected_word_count) {
|
|
62
|
-
Error::New(info.Env(), "word count did not match")
|
|
62
|
+
Error::New(info.Env(), "word count did not match")
|
|
63
|
+
.ThrowAsJavaScriptException();
|
|
63
64
|
return BigInt();
|
|
64
65
|
}
|
|
65
66
|
|
|
@@ -28,6 +28,7 @@ Object InitCallbackScope(Env env);
|
|
|
28
28
|
#if (NAPI_VERSION > 4)
|
|
29
29
|
Object InitDate(Env env);
|
|
30
30
|
#endif
|
|
31
|
+
Object InitCallbackInfo(Env env);
|
|
31
32
|
Object InitDataView(Env env);
|
|
32
33
|
Object InitDataViewReadWrite(Env env);
|
|
33
34
|
Object InitEnvCleanup(Env env);
|
|
@@ -43,7 +44,7 @@ Object InitName(Env env);
|
|
|
43
44
|
Object InitObject(Env env);
|
|
44
45
|
#ifndef NODE_ADDON_API_DISABLE_DEPRECATED
|
|
45
46
|
Object InitObjectDeprecated(Env env);
|
|
46
|
-
#endif
|
|
47
|
+
#endif // !NODE_ADDON_API_DISABLE_DEPRECATED
|
|
47
48
|
Object InitPromise(Env env);
|
|
48
49
|
Object InitRunScript(Env env);
|
|
49
50
|
#if (NAPI_VERSION > 3)
|
|
@@ -74,6 +75,7 @@ Object InitVersionManagement(Env env);
|
|
|
74
75
|
Object InitThunkingManual(Env env);
|
|
75
76
|
#if (NAPI_VERSION > 7)
|
|
76
77
|
Object InitObjectFreezeSeal(Env env);
|
|
78
|
+
Object InitObjectTypeTag(Env env);
|
|
77
79
|
#endif
|
|
78
80
|
|
|
79
81
|
#if defined(NODE_ADDON_API_ENABLE_MAYBE)
|
|
@@ -108,6 +110,7 @@ Object Init(Env env, Object exports) {
|
|
|
108
110
|
#if (NAPI_VERSION > 2)
|
|
109
111
|
exports.Set("callbackscope", InitCallbackScope(env));
|
|
110
112
|
#endif
|
|
113
|
+
exports.Set("callbackInfo", InitCallbackInfo(env));
|
|
111
114
|
exports.Set("dataview", InitDataView(env));
|
|
112
115
|
exports.Set("dataview_read_write", InitDataView(env));
|
|
113
116
|
exports.Set("dataview_read_write", InitDataViewReadWrite(env));
|
|
@@ -126,13 +129,14 @@ Object Init(Env env, Object exports) {
|
|
|
126
129
|
exports.Set("object", InitObject(env));
|
|
127
130
|
#ifndef NODE_ADDON_API_DISABLE_DEPRECATED
|
|
128
131
|
exports.Set("object_deprecated", InitObjectDeprecated(env));
|
|
129
|
-
#endif
|
|
132
|
+
#endif // !NODE_ADDON_API_DISABLE_DEPRECATED
|
|
130
133
|
exports.Set("promise", InitPromise(env));
|
|
131
134
|
exports.Set("run_script", InitRunScript(env));
|
|
132
135
|
exports.Set("symbol", InitSymbol(env));
|
|
133
136
|
#if (NAPI_VERSION > 3)
|
|
134
137
|
exports.Set("threadsafe_function_ctx", InitThreadSafeFunctionCtx(env));
|
|
135
|
-
exports.Set("threadsafe_function_existing_tsfn",
|
|
138
|
+
exports.Set("threadsafe_function_existing_tsfn",
|
|
139
|
+
InitThreadSafeFunctionExistingTsfn(env));
|
|
136
140
|
exports.Set("threadsafe_function_ptr", InitThreadSafeFunctionPtr(env));
|
|
137
141
|
exports.Set("threadsafe_function_sum", InitThreadSafeFunctionSum(env));
|
|
138
142
|
exports.Set("threadsafe_function_unref", InitThreadSafeFunctionUnref(env));
|
|
@@ -152,16 +156,18 @@ Object Init(Env env, Object exports) {
|
|
|
152
156
|
exports.Set("typedarray", InitTypedArray(env));
|
|
153
157
|
exports.Set("objectwrap", InitObjectWrap(env));
|
|
154
158
|
exports.Set("objectwrapConstructorException",
|
|
155
|
-
|
|
159
|
+
InitObjectWrapConstructorException(env));
|
|
156
160
|
exports.Set("objectwrap_function", InitObjectWrapFunction(env));
|
|
157
161
|
exports.Set("objectwrap_removewrap", InitObjectWrapRemoveWrap(env));
|
|
158
|
-
exports.Set("objectwrap_multiple_inheritance",
|
|
162
|
+
exports.Set("objectwrap_multiple_inheritance",
|
|
163
|
+
InitObjectWrapMultipleInheritance(env));
|
|
159
164
|
exports.Set("objectreference", InitObjectReference(env));
|
|
160
165
|
exports.Set("reference", InitReference(env));
|
|
161
166
|
exports.Set("version_management", InitVersionManagement(env));
|
|
162
167
|
exports.Set("thunking_manual", InitThunkingManual(env));
|
|
163
168
|
#if (NAPI_VERSION > 7)
|
|
164
169
|
exports.Set("object_freeze_seal", InitObjectFreezeSeal(env));
|
|
170
|
+
exports.Set("object_type_tag", InitObjectTypeTag(env));
|
|
165
171
|
#endif
|
|
166
172
|
|
|
167
173
|
#if defined(NODE_ADDON_API_ENABLE_MAYBE)
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
'basic_types/number.cc',
|
|
18
18
|
'basic_types/value.cc',
|
|
19
19
|
'bigint.cc',
|
|
20
|
+
'callbackInfo.cc',
|
|
20
21
|
'date.cc',
|
|
21
22
|
'binding.cc',
|
|
22
23
|
'buffer.cc',
|
|
@@ -46,11 +47,12 @@
|
|
|
46
47
|
'object/has_property.cc',
|
|
47
48
|
'object/object.cc',
|
|
48
49
|
'object/object_freeze_seal.cc',
|
|
50
|
+
'object/object_type_tag.cc',
|
|
49
51
|
'object/set_property.cc',
|
|
50
52
|
'object/subscript_operator.cc',
|
|
51
53
|
'promise.cc',
|
|
52
54
|
'run_script.cc',
|
|
53
|
-
|
|
55
|
+
'symbol.cc',
|
|
54
56
|
'threadsafe_function/threadsafe_function_ctx.cc',
|
|
55
57
|
'threadsafe_function/threadsafe_function_existing_tsfn.cc',
|
|
56
58
|
'threadsafe_function/threadsafe_function_ptr.cc',
|
|
@@ -29,7 +29,8 @@ Value CreateBuffer(const CallbackInfo& info) {
|
|
|
29
29
|
Buffer<uint16_t> buffer = Buffer<uint16_t>::New(info.Env(), testLength);
|
|
30
30
|
|
|
31
31
|
if (buffer.Length() != testLength) {
|
|
32
|
-
Error::New(info.Env(), "Incorrect buffer length.")
|
|
32
|
+
Error::New(info.Env(), "Incorrect buffer length.")
|
|
33
|
+
.ThrowAsJavaScriptException();
|
|
33
34
|
return Value();
|
|
34
35
|
}
|
|
35
36
|
|
|
@@ -40,18 +41,18 @@ Value CreateBuffer(const CallbackInfo& info) {
|
|
|
40
41
|
Value CreateExternalBuffer(const CallbackInfo& info) {
|
|
41
42
|
finalizeCount = 0;
|
|
42
43
|
|
|
43
|
-
Buffer<uint16_t> buffer =
|
|
44
|
-
|
|
45
|
-
testData,
|
|
46
|
-
testLength);
|
|
44
|
+
Buffer<uint16_t> buffer =
|
|
45
|
+
Buffer<uint16_t>::New(info.Env(), testData, testLength);
|
|
47
46
|
|
|
48
47
|
if (buffer.Length() != testLength) {
|
|
49
|
-
Error::New(info.Env(), "Incorrect buffer length.")
|
|
48
|
+
Error::New(info.Env(), "Incorrect buffer length.")
|
|
49
|
+
.ThrowAsJavaScriptException();
|
|
50
50
|
return Value();
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
if (buffer.Data() != testData) {
|
|
54
|
-
Error::New(info.Env(), "Incorrect buffer data.")
|
|
54
|
+
Error::New(info.Env(), "Incorrect buffer data.")
|
|
55
|
+
.ThrowAsJavaScriptException();
|
|
55
56
|
return Value();
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -65,21 +66,20 @@ Value CreateExternalBufferWithFinalize(const CallbackInfo& info) {
|
|
|
65
66
|
uint16_t* data = new uint16_t[testLength];
|
|
66
67
|
|
|
67
68
|
Buffer<uint16_t> buffer = Buffer<uint16_t>::New(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
delete[] finalizeData;
|
|
73
|
-
finalizeCount++;
|
|
74
|
-
});
|
|
69
|
+
info.Env(), data, testLength, [](Env /*env*/, uint16_t* finalizeData) {
|
|
70
|
+
delete[] finalizeData;
|
|
71
|
+
finalizeCount++;
|
|
72
|
+
});
|
|
75
73
|
|
|
76
74
|
if (buffer.Length() != testLength) {
|
|
77
|
-
Error::New(info.Env(), "Incorrect buffer length.")
|
|
75
|
+
Error::New(info.Env(), "Incorrect buffer length.")
|
|
76
|
+
.ThrowAsJavaScriptException();
|
|
78
77
|
return Value();
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
if (buffer.Data() != data) {
|
|
82
|
-
Error::New(info.Env(), "Incorrect buffer data.")
|
|
81
|
+
Error::New(info.Env(), "Incorrect buffer data.")
|
|
82
|
+
.ThrowAsJavaScriptException();
|
|
83
83
|
return Value();
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -94,22 +94,24 @@ Value CreateExternalBufferWithFinalizeHint(const CallbackInfo& info) {
|
|
|
94
94
|
|
|
95
95
|
char* hint = nullptr;
|
|
96
96
|
Buffer<uint16_t> buffer = Buffer<uint16_t>::New(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
info.Env(),
|
|
98
|
+
data,
|
|
99
|
+
testLength,
|
|
100
|
+
[](Env /*env*/, uint16_t* finalizeData, char* /*finalizeHint*/) {
|
|
101
|
+
delete[] finalizeData;
|
|
102
|
+
finalizeCount++;
|
|
103
|
+
},
|
|
104
|
+
hint);
|
|
105
105
|
|
|
106
106
|
if (buffer.Length() != testLength) {
|
|
107
|
-
Error::New(info.Env(), "Incorrect buffer length.")
|
|
107
|
+
Error::New(info.Env(), "Incorrect buffer length.")
|
|
108
|
+
.ThrowAsJavaScriptException();
|
|
108
109
|
return Value();
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
if (buffer.Data() != data) {
|
|
112
|
-
Error::New(info.Env(), "Incorrect buffer data.")
|
|
113
|
+
Error::New(info.Env(), "Incorrect buffer data.")
|
|
114
|
+
.ThrowAsJavaScriptException();
|
|
113
115
|
return Value();
|
|
114
116
|
}
|
|
115
117
|
|
|
@@ -120,21 +122,24 @@ Value CreateExternalBufferWithFinalizeHint(const CallbackInfo& info) {
|
|
|
120
122
|
Value CreateBufferCopy(const CallbackInfo& info) {
|
|
121
123
|
InitData(testData, testLength);
|
|
122
124
|
|
|
123
|
-
Buffer<uint16_t> buffer =
|
|
124
|
-
|
|
125
|
+
Buffer<uint16_t> buffer =
|
|
126
|
+
Buffer<uint16_t>::Copy(info.Env(), testData, testLength);
|
|
125
127
|
|
|
126
128
|
if (buffer.Length() != testLength) {
|
|
127
|
-
Error::New(info.Env(), "Incorrect buffer length.")
|
|
129
|
+
Error::New(info.Env(), "Incorrect buffer length.")
|
|
130
|
+
.ThrowAsJavaScriptException();
|
|
128
131
|
return Value();
|
|
129
132
|
}
|
|
130
133
|
|
|
131
134
|
if (buffer.Data() == testData) {
|
|
132
|
-
Error::New(info.Env(), "Copy should have different memory.")
|
|
135
|
+
Error::New(info.Env(), "Copy should have different memory.")
|
|
136
|
+
.ThrowAsJavaScriptException();
|
|
133
137
|
return Value();
|
|
134
138
|
}
|
|
135
139
|
|
|
136
140
|
if (!VerifyData(buffer.Data(), buffer.Length())) {
|
|
137
|
-
Error::New(info.Env(), "Copy data is incorrect.")
|
|
141
|
+
Error::New(info.Env(), "Copy data is incorrect.")
|
|
142
|
+
.ThrowAsJavaScriptException();
|
|
138
143
|
return Value();
|
|
139
144
|
}
|
|
140
145
|
|
|
@@ -143,28 +148,31 @@ Value CreateBufferCopy(const CallbackInfo& info) {
|
|
|
143
148
|
|
|
144
149
|
void CheckBuffer(const CallbackInfo& info) {
|
|
145
150
|
if (!info[0].IsBuffer()) {
|
|
146
|
-
Error::New(info.Env(), "A buffer was expected.")
|
|
151
|
+
Error::New(info.Env(), "A buffer was expected.")
|
|
152
|
+
.ThrowAsJavaScriptException();
|
|
147
153
|
return;
|
|
148
154
|
}
|
|
149
155
|
|
|
150
156
|
Buffer<uint16_t> buffer = info[0].As<Buffer<uint16_t>>();
|
|
151
157
|
|
|
152
158
|
if (buffer.Length() != testLength) {
|
|
153
|
-
Error::New(info.Env(), "Incorrect buffer length.")
|
|
159
|
+
Error::New(info.Env(), "Incorrect buffer length.")
|
|
160
|
+
.ThrowAsJavaScriptException();
|
|
154
161
|
return;
|
|
155
162
|
}
|
|
156
163
|
|
|
157
164
|
if (!VerifyData(buffer.Data(), testLength)) {
|
|
158
|
-
Error::New(info.Env(), "Incorrect buffer data.")
|
|
165
|
+
Error::New(info.Env(), "Incorrect buffer data.")
|
|
166
|
+
.ThrowAsJavaScriptException();
|
|
159
167
|
return;
|
|
160
168
|
}
|
|
161
169
|
}
|
|
162
170
|
|
|
163
171
|
Value GetFinalizeCount(const CallbackInfo& info) {
|
|
164
|
-
|
|
172
|
+
return Number::New(info.Env(), finalizeCount);
|
|
165
173
|
}
|
|
166
174
|
|
|
167
|
-
}
|
|
175
|
+
} // end anonymous namespace
|
|
168
176
|
|
|
169
177
|
Object InitBuffer(Env env) {
|
|
170
178
|
Object exports = Object::New(env);
|
|
@@ -172,9 +180,9 @@ Object InitBuffer(Env env) {
|
|
|
172
180
|
exports["createBuffer"] = Function::New(env, CreateBuffer);
|
|
173
181
|
exports["createExternalBuffer"] = Function::New(env, CreateExternalBuffer);
|
|
174
182
|
exports["createExternalBufferWithFinalize"] =
|
|
175
|
-
|
|
183
|
+
Function::New(env, CreateExternalBufferWithFinalize);
|
|
176
184
|
exports["createExternalBufferWithFinalizeHint"] =
|
|
177
|
-
|
|
185
|
+
Function::New(env, CreateExternalBufferWithFinalizeHint);
|
|
178
186
|
exports["createBufferCopy"] = Function::New(env, CreateBufferCopy);
|
|
179
187
|
exports["checkBuffer"] = Function::New(env, CheckBuffer);
|
|
180
188
|
exports["getFinalizeCount"] = Function::New(env, GetFinalizeCount);
|
|
@@ -6,7 +6,7 @@ const safeBuffer = require('safe-buffer');
|
|
|
6
6
|
|
|
7
7
|
module.exports = require('./common').runTest(test);
|
|
8
8
|
|
|
9
|
-
function test(binding) {
|
|
9
|
+
function test (binding) {
|
|
10
10
|
return testUtil.runGCTests([
|
|
11
11
|
'Internal Buffer',
|
|
12
12
|
() => {
|
|
@@ -34,8 +34,8 @@ function test(binding) {
|
|
|
34
34
|
assert.strictEqual(0, binding.buffer.getFinalizeCount());
|
|
35
35
|
},
|
|
36
36
|
() => {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
global.gc();
|
|
38
|
+
assert.strictEqual(0, binding.buffer.getFinalizeCount());
|
|
39
39
|
},
|
|
40
40
|
|
|
41
41
|
'External Buffer with finalizer',
|
|
@@ -46,24 +46,24 @@ function test(binding) {
|
|
|
46
46
|
assert.strictEqual(0, binding.buffer.getFinalizeCount());
|
|
47
47
|
},
|
|
48
48
|
() => {
|
|
49
|
-
|
|
49
|
+
global.gc();
|
|
50
50
|
},
|
|
51
51
|
() => {
|
|
52
|
-
|
|
52
|
+
assert.strictEqual(1, binding.buffer.getFinalizeCount());
|
|
53
53
|
},
|
|
54
54
|
|
|
55
55
|
'External Buffer with finalizer hint',
|
|
56
56
|
() => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
const test = binding.buffer.createExternalBufferWithFinalizeHint();
|
|
58
|
+
binding.buffer.checkBuffer(test);
|
|
59
|
+
assert.ok(test instanceof Buffer);
|
|
60
|
+
assert.strictEqual(0, binding.buffer.getFinalizeCount());
|
|
61
61
|
},
|
|
62
62
|
() => {
|
|
63
|
-
|
|
63
|
+
global.gc();
|
|
64
64
|
},
|
|
65
65
|
() => {
|
|
66
|
-
|
|
67
|
-
}
|
|
66
|
+
assert.strictEqual(1, binding.buffer.getFinalizeCount());
|
|
67
|
+
}
|
|
68
68
|
]);
|
|
69
69
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#include <assert.h>
|
|
2
|
+
#include "napi.h"
|
|
3
|
+
using namespace Napi;
|
|
4
|
+
|
|
5
|
+
struct TestCBInfoSetData {
|
|
6
|
+
static void Test(napi_env env, napi_callback_info info) {
|
|
7
|
+
Napi::CallbackInfo cbInfo(env, info);
|
|
8
|
+
int valuePointer = 1220202;
|
|
9
|
+
cbInfo.SetData(&valuePointer);
|
|
10
|
+
|
|
11
|
+
int* placeHolder = static_cast<int*>(cbInfo.Data());
|
|
12
|
+
assert(*(placeHolder) == valuePointer);
|
|
13
|
+
assert(placeHolder == &valuePointer);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
void TestCallbackInfoSetData(const Napi::CallbackInfo& info) {
|
|
18
|
+
napi_callback_info cb_info = static_cast<napi_callback_info>(info);
|
|
19
|
+
TestCBInfoSetData::Test(info.Env(), cb_info);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Object InitCallbackInfo(Env env) {
|
|
23
|
+
Object exports = Object::New(env);
|
|
24
|
+
|
|
25
|
+
exports["testCbSetData"] = Function::New(env, TestCallbackInfoSetData);
|
|
26
|
+
return exports;
|
|
27
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
#include "assert.h"
|
|
1
2
|
#include "napi.h"
|
|
2
|
-
|
|
3
3
|
using namespace Napi;
|
|
4
4
|
|
|
5
5
|
#if (NAPI_VERSION > 2)
|
|
6
|
+
|
|
6
7
|
namespace {
|
|
7
8
|
|
|
8
9
|
static void RunInCallbackScope(const CallbackInfo& info) {
|
|
@@ -12,11 +13,27 @@ static void RunInCallbackScope(const CallbackInfo& info) {
|
|
|
12
13
|
callback.Call({});
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
static void RunInCallbackScopeFromExisting(const CallbackInfo& info) {
|
|
17
|
+
Function callback = info[0].As<Function>();
|
|
18
|
+
Env env = info.Env();
|
|
19
|
+
|
|
20
|
+
AsyncContext ctx(env, "existing_callback_scope_test");
|
|
21
|
+
napi_callback_scope scope;
|
|
22
|
+
napi_open_callback_scope(env, Object::New(env), ctx, &scope);
|
|
23
|
+
|
|
24
|
+
CallbackScope existingScope(env, scope);
|
|
25
|
+
assert(existingScope.Env() == env);
|
|
26
|
+
|
|
27
|
+
callback.Call({});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
} // namespace
|
|
16
31
|
|
|
17
32
|
Object InitCallbackScope(Env env) {
|
|
18
33
|
Object exports = Object::New(env);
|
|
19
34
|
exports["runInCallbackScope"] = Function::New(env, RunInCallbackScope);
|
|
35
|
+
exports["runInPreExistingCbScope"] =
|
|
36
|
+
Function::New(env, RunInCallbackScopeFromExisting);
|
|
20
37
|
return exports;
|
|
21
38
|
}
|
|
22
39
|
#endif
|