koffi 2.3.4 → 2.3.5
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 +18 -2
- package/doc/changelog.md +4 -0
- package/doc/index.rst +1 -2
- package/doc/types.md +3 -3
- package/package.json +2 -2
- package/src/core/libcc/libcc.cc +2 -2
- package/src/koffi/build/2.3.5/koffi_darwin_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_darwin_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_freebsd_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_freebsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_freebsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_linux_arm32hf.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_linux_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_linux_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_linux_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_openbsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_openbsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_win32_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_win32_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_win32_x64.tar.gz +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/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
|
@@ -4,8 +4,8 @@ const assert = require('assert');
|
|
|
4
4
|
|
|
5
5
|
module.exports = require('../common').runTest(test);
|
|
6
6
|
|
|
7
|
-
function test(binding) {
|
|
8
|
-
function testHasProperty(nativeHasProperty) {
|
|
7
|
+
function test (binding) {
|
|
8
|
+
function testHasProperty (nativeHasProperty) {
|
|
9
9
|
const obj = { one: 1 };
|
|
10
10
|
|
|
11
11
|
Object.defineProperty(obj, 'two', { value: 2 });
|
|
@@ -16,14 +16,14 @@ function test(binding) {
|
|
|
16
16
|
assert.strictEqual(nativeHasProperty(obj, 'toString'), true);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
function testShouldThrowErrorIfKeyIsInvalid(nativeHasProperty) {
|
|
19
|
+
function testShouldThrowErrorIfKeyIsInvalid (nativeHasProperty) {
|
|
20
20
|
assert.throws(() => {
|
|
21
21
|
nativeHasProperty(undefined, 'test');
|
|
22
22
|
}, /Cannot convert undefined or null to object/);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const objectWithInt32Key = { 12: 101 };
|
|
26
|
-
assert.strictEqual(binding.object.hasPropertyWithUint32(objectWithInt32Key,12),true);
|
|
26
|
+
assert.strictEqual(binding.object.hasPropertyWithUint32(objectWithInt32Key, 12), true);
|
|
27
27
|
|
|
28
28
|
testHasProperty(binding.object.hasPropertyWithNapiValue);
|
|
29
29
|
testHasProperty(binding.object.hasPropertyWithNapiWrapperValue);
|
|
@@ -56,11 +56,11 @@ struct UserDataHolder {
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
Value TestGetter(const CallbackInfo& info) {
|
|
59
|
-
|
|
59
|
+
return Boolean::New(info.Env(), testValue);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
void TestSetter(const CallbackInfo& info) {
|
|
63
|
-
|
|
63
|
+
testValue = info[0].As<Boolean>();
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
Value TestGetterWithUserData(const CallbackInfo& info) {
|
|
@@ -74,7 +74,7 @@ void TestSetterWithUserData(const CallbackInfo& info) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
Value TestFunction(const CallbackInfo& info) {
|
|
77
|
-
|
|
77
|
+
return Boolean::New(info.Env(), true);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
Value TestFunctionWithUserData(const CallbackInfo& info) {
|
|
@@ -112,36 +112,56 @@ void DefineProperties(const CallbackInfo& info) {
|
|
|
112
112
|
|
|
113
113
|
if (nameType.Utf8Value() == "literal") {
|
|
114
114
|
obj.DefineProperties({
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
115
|
+
PropertyDescriptor::Accessor(env, obj, "readonlyAccessor", TestGetter),
|
|
116
|
+
PropertyDescriptor::Accessor(
|
|
117
|
+
env, obj, "readwriteAccessor", TestGetter, TestSetter),
|
|
118
|
+
PropertyDescriptor::Accessor(env,
|
|
119
|
+
obj,
|
|
120
|
+
"readonlyAccessorWithUserData",
|
|
121
|
+
TestGetterWithUserData,
|
|
122
|
+
napi_property_attributes::napi_default,
|
|
123
|
+
reinterpret_cast<void*>(holder)),
|
|
124
|
+
PropertyDescriptor::Accessor(env,
|
|
125
|
+
obj,
|
|
126
|
+
"readwriteAccessorWithUserData",
|
|
127
|
+
TestGetterWithUserData,
|
|
128
|
+
TestSetterWithUserData,
|
|
129
|
+
napi_property_attributes::napi_default,
|
|
130
|
+
reinterpret_cast<void*>(holder)),
|
|
131
|
+
|
|
132
|
+
PropertyDescriptor::Accessor<TestGetter>("readonlyAccessorT"),
|
|
133
|
+
PropertyDescriptor::Accessor<TestGetter, TestSetter>(
|
|
134
|
+
"readwriteAccessorT"),
|
|
135
|
+
PropertyDescriptor::Accessor<TestGetterWithUserData>(
|
|
136
|
+
"readonlyAccessorWithUserDataT",
|
|
137
|
+
napi_property_attributes::napi_default,
|
|
138
|
+
reinterpret_cast<void*>(holder)),
|
|
139
|
+
PropertyDescriptor::Accessor<TestGetterWithUserData,
|
|
140
|
+
TestSetterWithUserData>(
|
|
141
|
+
"readwriteAccessorWithUserDataT",
|
|
142
|
+
napi_property_attributes::napi_default,
|
|
143
|
+
reinterpret_cast<void*>(holder)),
|
|
144
|
+
|
|
145
|
+
PropertyDescriptor::Value("readonlyValue", trueValue),
|
|
146
|
+
PropertyDescriptor::Value("readwriteValue", trueValue, napi_writable),
|
|
147
|
+
PropertyDescriptor::Value(
|
|
148
|
+
"enumerableValue", trueValue, napi_enumerable),
|
|
149
|
+
PropertyDescriptor::Value(
|
|
150
|
+
"configurableValue", trueValue, napi_configurable),
|
|
151
|
+
PropertyDescriptor::Function(env, obj, "function", TestFunction),
|
|
152
|
+
PropertyDescriptor::Function(env,
|
|
153
|
+
obj,
|
|
154
|
+
"functionWithUserData",
|
|
155
|
+
TestFunctionWithUserData,
|
|
156
|
+
napi_property_attributes::napi_default,
|
|
157
|
+
reinterpret_cast<void*>(holder)),
|
|
139
158
|
});
|
|
140
159
|
} else if (nameType.Utf8Value() == "string") {
|
|
141
|
-
// VS2013 has lifetime issues when passing temporary objects into the
|
|
142
|
-
// object. It generates code to destruct the object
|
|
143
|
-
// Since this isn't a common case
|
|
144
|
-
//
|
|
160
|
+
// VS2013 has lifetime issues when passing temporary objects into the
|
|
161
|
+
// constructor of another object. It generates code to destruct the object
|
|
162
|
+
// as soon as the constructor call returns. Since this isn't a common case
|
|
163
|
+
// for using std::string objects, I'm refactoring the test to work around
|
|
164
|
+
// the issue.
|
|
145
165
|
std::string str1("readonlyAccessor");
|
|
146
166
|
std::string str2("readwriteAccessor");
|
|
147
167
|
std::string str1a("readonlyAccessorWithUserData");
|
|
@@ -160,66 +180,105 @@ void DefineProperties(const CallbackInfo& info) {
|
|
|
160
180
|
std::string str8("functionWithUserData");
|
|
161
181
|
|
|
162
182
|
obj.DefineProperties({
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
PropertyDescriptor::Accessor(env, obj, str1, TestGetter),
|
|
184
|
+
PropertyDescriptor::Accessor(env, obj, str2, TestGetter, TestSetter),
|
|
185
|
+
PropertyDescriptor::Accessor(env,
|
|
186
|
+
obj,
|
|
187
|
+
str1a,
|
|
188
|
+
TestGetterWithUserData,
|
|
189
|
+
napi_property_attributes::napi_default,
|
|
190
|
+
reinterpret_cast<void*>(holder)),
|
|
191
|
+
PropertyDescriptor::Accessor(env,
|
|
192
|
+
obj,
|
|
193
|
+
str2a,
|
|
194
|
+
TestGetterWithUserData,
|
|
195
|
+
TestSetterWithUserData,
|
|
196
|
+
napi_property_attributes::napi_default,
|
|
197
|
+
reinterpret_cast<void*>(holder)),
|
|
198
|
+
|
|
199
|
+
PropertyDescriptor::Accessor<TestGetter>(str1t),
|
|
200
|
+
PropertyDescriptor::Accessor<TestGetter, TestSetter>(str2t),
|
|
201
|
+
PropertyDescriptor::Accessor<TestGetterWithUserData>(
|
|
202
|
+
str1at,
|
|
203
|
+
napi_property_attributes::napi_default,
|
|
204
|
+
reinterpret_cast<void*>(holder)),
|
|
205
|
+
PropertyDescriptor::Accessor<TestGetterWithUserData,
|
|
206
|
+
TestSetterWithUserData>(
|
|
207
|
+
str2at,
|
|
208
|
+
napi_property_attributes::napi_default,
|
|
209
|
+
reinterpret_cast<void*>(holder)),
|
|
210
|
+
|
|
211
|
+
PropertyDescriptor::Value(str3, trueValue),
|
|
212
|
+
PropertyDescriptor::Value(str4, trueValue, napi_writable),
|
|
213
|
+
PropertyDescriptor::Value(str5, trueValue, napi_enumerable),
|
|
214
|
+
PropertyDescriptor::Value(str6, trueValue, napi_configurable),
|
|
215
|
+
PropertyDescriptor::Function(env, obj, str7, TestFunction),
|
|
216
|
+
PropertyDescriptor::Function(env,
|
|
217
|
+
obj,
|
|
218
|
+
str8,
|
|
219
|
+
TestFunctionWithUserData,
|
|
220
|
+
napi_property_attributes::napi_default,
|
|
221
|
+
reinterpret_cast<void*>(holder)),
|
|
185
222
|
});
|
|
186
223
|
} else if (nameType.Utf8Value() == "value") {
|
|
187
224
|
obj.DefineProperties({
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
225
|
+
PropertyDescriptor::Accessor(
|
|
226
|
+
env, obj, Napi::String::New(env, "readonlyAccessor"), TestGetter),
|
|
227
|
+
PropertyDescriptor::Accessor(
|
|
228
|
+
env,
|
|
229
|
+
obj,
|
|
230
|
+
Napi::String::New(env, "readwriteAccessor"),
|
|
231
|
+
TestGetter,
|
|
232
|
+
TestSetter),
|
|
233
|
+
PropertyDescriptor::Accessor(
|
|
234
|
+
env,
|
|
235
|
+
obj,
|
|
236
|
+
Napi::String::New(env, "readonlyAccessorWithUserData"),
|
|
237
|
+
TestGetterWithUserData,
|
|
238
|
+
napi_property_attributes::napi_default,
|
|
239
|
+
reinterpret_cast<void*>(holder)),
|
|
240
|
+
PropertyDescriptor::Accessor(
|
|
241
|
+
env,
|
|
242
|
+
obj,
|
|
243
|
+
Napi::String::New(env, "readwriteAccessorWithUserData"),
|
|
244
|
+
TestGetterWithUserData,
|
|
245
|
+
TestSetterWithUserData,
|
|
246
|
+
napi_property_attributes::napi_default,
|
|
247
|
+
reinterpret_cast<void*>(holder)),
|
|
248
|
+
|
|
249
|
+
PropertyDescriptor::Accessor<TestGetter>(
|
|
250
|
+
Napi::String::New(env, "readonlyAccessorT")),
|
|
251
|
+
PropertyDescriptor::Accessor<TestGetter, TestSetter>(
|
|
252
|
+
Napi::String::New(env, "readwriteAccessorT")),
|
|
253
|
+
PropertyDescriptor::Accessor<TestGetterWithUserData>(
|
|
254
|
+
Napi::String::New(env, "readonlyAccessorWithUserDataT"),
|
|
255
|
+
napi_property_attributes::napi_default,
|
|
256
|
+
reinterpret_cast<void*>(holder)),
|
|
257
|
+
PropertyDescriptor::Accessor<TestGetterWithUserData,
|
|
258
|
+
TestSetterWithUserData>(
|
|
259
|
+
Napi::String::New(env, "readwriteAccessorWithUserDataT"),
|
|
260
|
+
napi_property_attributes::napi_default,
|
|
261
|
+
reinterpret_cast<void*>(holder)),
|
|
262
|
+
|
|
263
|
+
PropertyDescriptor::Value(Napi::String::New(env, "readonlyValue"),
|
|
264
|
+
trueValue),
|
|
265
|
+
PropertyDescriptor::Value(
|
|
266
|
+
Napi::String::New(env, "readwriteValue"), trueValue, napi_writable),
|
|
267
|
+
PropertyDescriptor::Value(Napi::String::New(env, "enumerableValue"),
|
|
268
|
+
trueValue,
|
|
269
|
+
napi_enumerable),
|
|
270
|
+
PropertyDescriptor::Value(Napi::String::New(env, "configurableValue"),
|
|
271
|
+
trueValue,
|
|
272
|
+
napi_configurable),
|
|
273
|
+
PropertyDescriptor::Function(
|
|
274
|
+
env, obj, Napi::String::New(env, "function"), TestFunction),
|
|
275
|
+
PropertyDescriptor::Function(
|
|
276
|
+
env,
|
|
277
|
+
obj,
|
|
278
|
+
Napi::String::New(env, "functionWithUserData"),
|
|
279
|
+
TestFunctionWithUserData,
|
|
280
|
+
napi_property_attributes::napi_default,
|
|
281
|
+
reinterpret_cast<void*>(holder)),
|
|
223
282
|
});
|
|
224
283
|
}
|
|
225
284
|
}
|
|
@@ -295,36 +354,57 @@ Object InitObject(Env env) {
|
|
|
295
354
|
exports["defineValueProperty"] = Function::New(env, DefineValueProperty);
|
|
296
355
|
|
|
297
356
|
exports["getPropertyWithUint32"] = Function::New(env, GetPropertyWithUint32);
|
|
298
|
-
exports["getPropertyWithNapiValue"] =
|
|
299
|
-
|
|
300
|
-
exports["
|
|
301
|
-
|
|
357
|
+
exports["getPropertyWithNapiValue"] =
|
|
358
|
+
Function::New(env, GetPropertyWithNapiValue);
|
|
359
|
+
exports["getPropertyWithNapiWrapperValue"] =
|
|
360
|
+
Function::New(env, GetPropertyWithNapiWrapperValue);
|
|
361
|
+
exports["getPropertyWithCStyleString"] =
|
|
362
|
+
Function::New(env, GetPropertyWithCStyleString);
|
|
363
|
+
exports["getPropertyWithCppStyleString"] =
|
|
364
|
+
Function::New(env, GetPropertyWithCppStyleString);
|
|
302
365
|
|
|
303
366
|
exports["setPropertyWithUint32"] = Function::New(env, SetPropertyWithUint32);
|
|
304
|
-
exports["setPropertyWithNapiValue"] =
|
|
305
|
-
|
|
306
|
-
exports["
|
|
307
|
-
|
|
367
|
+
exports["setPropertyWithNapiValue"] =
|
|
368
|
+
Function::New(env, SetPropertyWithNapiValue);
|
|
369
|
+
exports["setPropertyWithNapiWrapperValue"] =
|
|
370
|
+
Function::New(env, SetPropertyWithNapiWrapperValue);
|
|
371
|
+
exports["setPropertyWithCStyleString"] =
|
|
372
|
+
Function::New(env, SetPropertyWithCStyleString);
|
|
373
|
+
exports["setPropertyWithCppStyleString"] =
|
|
374
|
+
Function::New(env, SetPropertyWithCppStyleString);
|
|
308
375
|
|
|
309
376
|
exports["deletePropertyWithUint32"] =
|
|
310
377
|
Function::New(env, DeletePropertyWithUint32);
|
|
311
|
-
exports["deletePropertyWithNapiValue"] =
|
|
312
|
-
|
|
313
|
-
exports["
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
exports["
|
|
318
|
-
|
|
319
|
-
|
|
378
|
+
exports["deletePropertyWithNapiValue"] =
|
|
379
|
+
Function::New(env, DeletePropertyWithNapiValue);
|
|
380
|
+
exports["deletePropertyWithNapiWrapperValue"] =
|
|
381
|
+
Function::New(env, DeletePropertyWithNapiWrapperValue);
|
|
382
|
+
exports["deletePropertyWithCStyleString"] =
|
|
383
|
+
Function::New(env, DeletePropertyWithCStyleString);
|
|
384
|
+
exports["deletePropertyWithCppStyleString"] =
|
|
385
|
+
Function::New(env, DeletePropertyWithCppStyleString);
|
|
386
|
+
|
|
387
|
+
exports["hasOwnPropertyWithNapiValue"] =
|
|
388
|
+
Function::New(env, HasOwnPropertyWithNapiValue);
|
|
389
|
+
exports["hasOwnPropertyWithNapiWrapperValue"] =
|
|
390
|
+
Function::New(env, HasOwnPropertyWithNapiWrapperValue);
|
|
391
|
+
exports["hasOwnPropertyWithCStyleString"] =
|
|
392
|
+
Function::New(env, HasOwnPropertyWithCStyleString);
|
|
393
|
+
exports["hasOwnPropertyWithCppStyleString"] =
|
|
394
|
+
Function::New(env, HasOwnPropertyWithCppStyleString);
|
|
320
395
|
|
|
321
396
|
exports["hasPropertyWithUint32"] = Function::New(env, HasPropertyWithUint32);
|
|
322
|
-
exports["hasPropertyWithNapiValue"] =
|
|
323
|
-
|
|
324
|
-
exports["
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
397
|
+
exports["hasPropertyWithNapiValue"] =
|
|
398
|
+
Function::New(env, HasPropertyWithNapiValue);
|
|
399
|
+
exports["hasPropertyWithNapiWrapperValue"] =
|
|
400
|
+
Function::New(env, HasPropertyWithNapiWrapperValue);
|
|
401
|
+
exports["hasPropertyWithCStyleString"] =
|
|
402
|
+
Function::New(env, HasPropertyWithCStyleString);
|
|
403
|
+
exports["hasPropertyWithCppStyleString"] =
|
|
404
|
+
Function::New(env, HasPropertyWithCppStyleString);
|
|
405
|
+
|
|
406
|
+
exports["createObjectUsingMagic"] =
|
|
407
|
+
Function::New(env, CreateObjectUsingMagic);
|
|
328
408
|
#ifdef NAPI_CPP_EXCEPTIONS
|
|
329
409
|
exports["sum"] = Function::New(env, Sum);
|
|
330
410
|
exports["increment"] = Function::New(env, Increment);
|
|
@@ -4,20 +4,20 @@ const assert = require('assert');
|
|
|
4
4
|
|
|
5
5
|
module.exports = require('../common').runTest(test);
|
|
6
6
|
|
|
7
|
-
function test(binding) {
|
|
8
|
-
function assertPropertyIs(obj, key, attribute) {
|
|
7
|
+
function test (binding) {
|
|
8
|
+
function assertPropertyIs (obj, key, attribute) {
|
|
9
9
|
const propDesc = Object.getOwnPropertyDescriptor(obj, key);
|
|
10
10
|
assert.ok(propDesc);
|
|
11
11
|
assert.ok(propDesc[attribute]);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
function assertPropertyIsNot(obj, key, attribute) {
|
|
14
|
+
function assertPropertyIsNot (obj, key, attribute) {
|
|
15
15
|
const propDesc = Object.getOwnPropertyDescriptor(obj, key);
|
|
16
16
|
assert.ok(propDesc);
|
|
17
17
|
assert.ok(!propDesc[attribute]);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
function testDefineProperties(nameType) {
|
|
20
|
+
function testDefineProperties (nameType) {
|
|
21
21
|
const obj = {};
|
|
22
22
|
binding.object.defineProperties(obj, nameType);
|
|
23
23
|
|
|
@@ -101,28 +101,29 @@ function test(binding) {
|
|
|
101
101
|
testDefineProperties('string');
|
|
102
102
|
testDefineProperties('value');
|
|
103
103
|
|
|
104
|
+
// eslint-disable-next-line no-lone-blocks
|
|
104
105
|
{
|
|
105
106
|
assert.strictEqual(binding.object.emptyConstructor(true), true);
|
|
106
107
|
assert.strictEqual(binding.object.emptyConstructor(false), false);
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
{
|
|
110
|
-
const expected = {
|
|
111
|
+
const expected = { one: 1, two: 2, three: 3 };
|
|
111
112
|
const actual = binding.object.constructorFromObject(expected);
|
|
112
113
|
assert.deepStrictEqual(actual, expected);
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
{
|
|
116
117
|
const obj = {};
|
|
117
|
-
const testSym = Symbol();
|
|
118
|
+
const testSym = Symbol('testSym');
|
|
118
119
|
binding.object.defineValueProperty(obj, testSym, 1);
|
|
119
120
|
assert.strictEqual(obj[testSym], 1);
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
{
|
|
123
|
-
const testSym = Symbol();
|
|
124
|
-
const obj = {
|
|
125
|
-
|
|
124
|
+
const testSym = Symbol('testSym');
|
|
125
|
+
const obj = { one: 1, two: 2, three: 3, [testSym]: 4 };
|
|
126
|
+
const arr = binding.object.GetPropertyNames(obj);
|
|
126
127
|
assert.deepStrictEqual(arr, ['one', 'two', 'three']);
|
|
127
128
|
}
|
|
128
129
|
|
|
@@ -149,7 +150,7 @@ function test(binding) {
|
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
{
|
|
152
|
-
function Ctor() {}
|
|
153
|
+
function Ctor () {}
|
|
153
154
|
|
|
154
155
|
assert.strictEqual(binding.object.instanceOf(new Ctor(), Ctor), true);
|
|
155
156
|
assert.strictEqual(binding.object.instanceOf(new Ctor(), Object), true);
|
|
@@ -158,60 +159,60 @@ function test(binding) {
|
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
if ('sum' in binding.object) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
assert.strictEqual(binding.object.sum(obj), sum);
|
|
162
|
+
{
|
|
163
|
+
const obj = {
|
|
164
|
+
'-forbid': -0x4B1D,
|
|
165
|
+
'-feedcode': -0xFEEDC0DE,
|
|
166
|
+
'+office': +0x0FF1CE,
|
|
167
|
+
'+forbid': +0x4B1D,
|
|
168
|
+
'+deadbeef': +0xDEADBEEF,
|
|
169
|
+
'+feedcode': +0xFEEDC0DE
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
let sum = 0;
|
|
173
|
+
for (const key in obj) {
|
|
174
|
+
sum += obj[key];
|
|
177
175
|
}
|
|
178
176
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
177
|
+
assert.strictEqual(binding.object.sum(obj), sum);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
{
|
|
181
|
+
const obj = new Proxy({
|
|
182
|
+
'-forbid': -0x4B1D,
|
|
183
|
+
'-feedcode': -0xFEEDC0DE,
|
|
184
|
+
'+office': +0x0FF1CE,
|
|
185
|
+
'+forbid': +0x4B1D,
|
|
186
|
+
'+deadbeef': +0xDEADBEEF,
|
|
187
|
+
'+feedcode': +0xFEEDC0DE
|
|
188
|
+
}, {
|
|
189
|
+
getOwnPropertyDescriptor (target, p) {
|
|
190
|
+
throw new Error('getOwnPropertyDescriptor error');
|
|
191
|
+
},
|
|
192
|
+
ownKeys (target) {
|
|
193
|
+
throw new Error('ownKeys error');
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
assert.throws(() => {
|
|
198
|
+
binding.object.sum(obj);
|
|
199
|
+
}, /ownKeys error/);
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
if ('increment' in binding.object) {
|
|
203
204
|
const obj = {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
a: 0,
|
|
206
|
+
b: 1,
|
|
207
|
+
c: 2
|
|
207
208
|
};
|
|
208
209
|
|
|
209
210
|
binding.object.increment(obj);
|
|
210
211
|
|
|
211
212
|
assert.deepStrictEqual(obj, {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
a: 1,
|
|
214
|
+
b: 2,
|
|
215
|
+
c: 3
|
|
215
216
|
});
|
|
216
217
|
}
|
|
217
218
|
}
|
|
@@ -7,15 +7,15 @@ static bool testValue = true;
|
|
|
7
7
|
namespace {
|
|
8
8
|
|
|
9
9
|
Value TestGetter(const CallbackInfo& info) {
|
|
10
|
-
|
|
10
|
+
return Boolean::New(info.Env(), testValue);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
void TestSetter(const CallbackInfo& info) {
|
|
14
|
-
|
|
14
|
+
testValue = info[0].As<Boolean>();
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
Value TestFunction(const CallbackInfo& info) {
|
|
18
|
-
|
|
18
|
+
return Boolean::New(info.Env(), true);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
void DefineProperties(const CallbackInfo& info) {
|
|
@@ -25,37 +25,41 @@ void DefineProperties(const CallbackInfo& info) {
|
|
|
25
25
|
|
|
26
26
|
if (nameType.Utf8Value() == "literal") {
|
|
27
27
|
obj.DefineProperties({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
PropertyDescriptor::Accessor("readonlyAccessor", TestGetter),
|
|
29
|
+
PropertyDescriptor::Accessor(
|
|
30
|
+
"readwriteAccessor", TestGetter, TestSetter),
|
|
31
|
+
PropertyDescriptor::Function("function", TestFunction),
|
|
31
32
|
});
|
|
32
33
|
} else if (nameType.Utf8Value() == "string") {
|
|
33
|
-
// VS2013 has lifetime issues when passing temporary objects into the
|
|
34
|
-
// object. It generates code to destruct the object
|
|
35
|
-
// Since this isn't a common case
|
|
36
|
-
//
|
|
34
|
+
// VS2013 has lifetime issues when passing temporary objects into the
|
|
35
|
+
// constructor of another object. It generates code to destruct the object
|
|
36
|
+
// as soon as the constructor call returns. Since this isn't a common case
|
|
37
|
+
// for using std::string objects, I'm refactoring the test to work around
|
|
38
|
+
// the issue.
|
|
37
39
|
std::string str1("readonlyAccessor");
|
|
38
40
|
std::string str2("readwriteAccessor");
|
|
39
41
|
std::string str7("function");
|
|
40
42
|
|
|
41
43
|
obj.DefineProperties({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
PropertyDescriptor::Accessor(str1, TestGetter),
|
|
45
|
+
PropertyDescriptor::Accessor(str2, TestGetter, TestSetter),
|
|
46
|
+
PropertyDescriptor::Function(str7, TestFunction),
|
|
45
47
|
});
|
|
46
48
|
} else if (nameType.Utf8Value() == "value") {
|
|
47
49
|
obj.DefineProperties({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
PropertyDescriptor::Accessor(Napi::String::New(env, "readonlyAccessor"),
|
|
51
|
+
TestGetter),
|
|
52
|
+
PropertyDescriptor::Accessor(
|
|
53
|
+
Napi::String::New(env, "readwriteAccessor"),
|
|
54
|
+
TestGetter,
|
|
55
|
+
TestSetter),
|
|
56
|
+
PropertyDescriptor::Function(Napi::String::New(env, "function"),
|
|
57
|
+
TestFunction),
|
|
54
58
|
});
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
}
|
|
62
|
+
} // end of anonymous namespace
|
|
59
63
|
|
|
60
64
|
Object InitObjectDeprecated(Env env) {
|
|
61
65
|
Object exports = Object::New(env);
|