koffi 1.1.0-beta.1 → 1.1.0-beta.4
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 +4 -0
- package/README.md +20 -11
- package/build/qemu/1.1.0-beta.4/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.4/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.4/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.4/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.4/koffi_linux_arm.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.4/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.4/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.4/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.4/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.4/koffi_win32_x64.tar.gz +0 -0
- package/package.json +1 -1
- package/qemu/qemu.js +1 -0
- package/src/abi_arm32.cc +27 -45
- package/src/abi_arm64.cc +58 -132
- package/src/abi_x64_sysv.cc +24 -7
- package/src/abi_x64_win.cc +3 -0
- package/src/abi_x86.cc +3 -0
- package/src/call.cc +540 -33
- package/src/call.hh +5 -3
- package/src/ffi.cc +129 -4
- package/src/ffi.hh +5 -1
- package/src/parser.cc +7 -2
- package/src/util.cc +72 -0
- package/src/util.hh +2 -0
- package/test/misc.c +14 -8
- 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/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/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 +123 -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 +411 -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 +588 -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/package.json +415 -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 +36 -0
- package/vendor/node-addon-api/test/async_context.js +122 -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 +173 -0
- package/vendor/node-addon-api/test/binding.gyp +124 -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 +114 -0
- package/vendor/node-addon-api/test/common/test_helper.h +71 -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 +95 -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 +324 -0
- package/vendor/node-addon-api/test/function.js +133 -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 +159 -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 +350 -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 +45 -0
- package/vendor/node-addon-api/test/object/set_property.js +30 -0
- package/vendor/node-addon-api/test/object/subscript_operator.cc +58 -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_function.cc +45 -0
- package/vendor/node-addon-api/test/objectwrap_function.js +22 -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/unit-test/README.md +28 -0
- package/vendor/node-addon-api/unit-test/binding-file-template.js +39 -0
- package/vendor/node-addon-api/unit-test/binding.gyp +72 -0
- package/vendor/node-addon-api/unit-test/exceptions.js +32 -0
- package/vendor/node-addon-api/unit-test/generate-binding-cc.js +61 -0
- package/vendor/node-addon-api/unit-test/injectTestParams.js +101 -0
- package/vendor/node-addon-api/unit-test/listOfTestModules.js +88 -0
- package/vendor/node-addon-api/unit-test/matchModules.js +65 -0
- package/vendor/node-addon-api/unit-test/setup.js +13 -0
- package/vendor/node-addon-api/unit-test/spawnTask.js +26 -0
- package/vendor/node-addon-api/unit-test/test.js +30 -0
- package/build/qemu/1.1.0-beta.1/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_linux_arm.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_win32_x64.tar.gz +0 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
|
|
5
|
+
module.exports = require('../common').runTest(test);
|
|
6
|
+
|
|
7
|
+
function test(binding) {
|
|
8
|
+
function assertPropertyIs(obj, key, attribute) {
|
|
9
|
+
const propDesc = Object.getOwnPropertyDescriptor(obj, key);
|
|
10
|
+
assert.ok(propDesc);
|
|
11
|
+
assert.ok(propDesc[attribute]);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function assertPropertyIsNot(obj, key, attribute) {
|
|
15
|
+
const propDesc = Object.getOwnPropertyDescriptor(obj, key);
|
|
16
|
+
assert.ok(propDesc);
|
|
17
|
+
assert.ok(!propDesc[attribute]);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function testDefineProperties(nameType) {
|
|
21
|
+
const obj = {};
|
|
22
|
+
binding.object.defineProperties(obj, nameType);
|
|
23
|
+
|
|
24
|
+
// accessors
|
|
25
|
+
assertPropertyIsNot(obj, 'readonlyAccessor', 'enumerable');
|
|
26
|
+
assertPropertyIsNot(obj, 'readonlyAccessor', 'configurable');
|
|
27
|
+
assert.strictEqual(obj.readonlyAccessor, true);
|
|
28
|
+
|
|
29
|
+
assertPropertyIsNot(obj, 'readonlyAccessorWithUserData', 'enumerable');
|
|
30
|
+
assertPropertyIsNot(obj, 'readonlyAccessorWithUserData', 'configurable');
|
|
31
|
+
assert.strictEqual(obj.readonlyAccessorWithUserData, 1234, nameType);
|
|
32
|
+
|
|
33
|
+
assertPropertyIsNot(obj, 'readwriteAccessor', 'enumerable');
|
|
34
|
+
assertPropertyIsNot(obj, 'readwriteAccessor', 'configurable');
|
|
35
|
+
obj.readwriteAccessor = false;
|
|
36
|
+
assert.strictEqual(obj.readwriteAccessor, false);
|
|
37
|
+
obj.readwriteAccessor = true;
|
|
38
|
+
assert.strictEqual(obj.readwriteAccessor, true);
|
|
39
|
+
|
|
40
|
+
assertPropertyIsNot(obj, 'readwriteAccessorWithUserData', 'enumerable');
|
|
41
|
+
assertPropertyIsNot(obj, 'readwriteAccessorWithUserData', 'configurable');
|
|
42
|
+
obj.readwriteAccessorWithUserData = 2;
|
|
43
|
+
assert.strictEqual(obj.readwriteAccessorWithUserData, 2);
|
|
44
|
+
obj.readwriteAccessorWithUserData = -14;
|
|
45
|
+
assert.strictEqual(obj.readwriteAccessorWithUserData, -14);
|
|
46
|
+
|
|
47
|
+
// templated accessors
|
|
48
|
+
assertPropertyIsNot(obj, 'readonlyAccessorT', 'enumerable');
|
|
49
|
+
assertPropertyIsNot(obj, 'readonlyAccessorT', 'configurable');
|
|
50
|
+
assert.strictEqual(obj.readonlyAccessorT, true);
|
|
51
|
+
|
|
52
|
+
assertPropertyIsNot(obj, 'readonlyAccessorWithUserDataT', 'enumerable');
|
|
53
|
+
assertPropertyIsNot(obj, 'readonlyAccessorWithUserDataT', 'configurable');
|
|
54
|
+
assert.strictEqual(obj.readonlyAccessorWithUserDataT, -14, nameType);
|
|
55
|
+
|
|
56
|
+
assertPropertyIsNot(obj, 'readwriteAccessorT', 'enumerable');
|
|
57
|
+
assertPropertyIsNot(obj, 'readwriteAccessorT', 'configurable');
|
|
58
|
+
obj.readwriteAccessorT = false;
|
|
59
|
+
assert.strictEqual(obj.readwriteAccessorT, false);
|
|
60
|
+
obj.readwriteAccessorT = true;
|
|
61
|
+
assert.strictEqual(obj.readwriteAccessorT, true);
|
|
62
|
+
|
|
63
|
+
assertPropertyIsNot(obj, 'readwriteAccessorWithUserDataT', 'enumerable');
|
|
64
|
+
assertPropertyIsNot(obj, 'readwriteAccessorWithUserDataT', 'configurable');
|
|
65
|
+
obj.readwriteAccessorWithUserDataT = 2;
|
|
66
|
+
assert.strictEqual(obj.readwriteAccessorWithUserDataT, 2);
|
|
67
|
+
obj.readwriteAccessorWithUserDataT = -14;
|
|
68
|
+
assert.strictEqual(obj.readwriteAccessorWithUserDataT, -14);
|
|
69
|
+
|
|
70
|
+
// values
|
|
71
|
+
assertPropertyIsNot(obj, 'readonlyValue', 'writable');
|
|
72
|
+
assertPropertyIsNot(obj, 'readonlyValue', 'enumerable');
|
|
73
|
+
assertPropertyIsNot(obj, 'readonlyValue', 'configurable');
|
|
74
|
+
assert.strictEqual(obj.readonlyValue, true);
|
|
75
|
+
|
|
76
|
+
assertPropertyIs(obj, 'readwriteValue', 'writable');
|
|
77
|
+
assertPropertyIsNot(obj, 'readwriteValue', 'enumerable');
|
|
78
|
+
assertPropertyIsNot(obj, 'readwriteValue', 'configurable');
|
|
79
|
+
obj.readwriteValue = false;
|
|
80
|
+
assert.strictEqual(obj.readwriteValue, false);
|
|
81
|
+
obj.readwriteValue = true;
|
|
82
|
+
assert.strictEqual(obj.readwriteValue, true);
|
|
83
|
+
|
|
84
|
+
assertPropertyIsNot(obj, 'enumerableValue', 'writable');
|
|
85
|
+
assertPropertyIs(obj, 'enumerableValue', 'enumerable');
|
|
86
|
+
assertPropertyIsNot(obj, 'enumerableValue', 'configurable');
|
|
87
|
+
|
|
88
|
+
assertPropertyIsNot(obj, 'configurableValue', 'writable');
|
|
89
|
+
assertPropertyIsNot(obj, 'configurableValue', 'enumerable');
|
|
90
|
+
assertPropertyIs(obj, 'configurableValue', 'configurable');
|
|
91
|
+
|
|
92
|
+
// functions
|
|
93
|
+
assertPropertyIsNot(obj, 'function', 'writable');
|
|
94
|
+
assertPropertyIsNot(obj, 'function', 'enumerable');
|
|
95
|
+
assertPropertyIsNot(obj, 'function', 'configurable');
|
|
96
|
+
assert.strictEqual(obj.function(), true);
|
|
97
|
+
assert.strictEqual(obj.functionWithUserData(), obj.readonlyAccessorWithUserDataT);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
testDefineProperties('literal');
|
|
101
|
+
testDefineProperties('string');
|
|
102
|
+
testDefineProperties('value');
|
|
103
|
+
|
|
104
|
+
{
|
|
105
|
+
assert.strictEqual(binding.object.emptyConstructor(true), true);
|
|
106
|
+
assert.strictEqual(binding.object.emptyConstructor(false), false);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
{
|
|
110
|
+
const expected = { 'one': 1, 'two': 2, 'three': 3 };
|
|
111
|
+
const actual = binding.object.constructorFromObject(expected);
|
|
112
|
+
assert.deepStrictEqual(actual, expected);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
{
|
|
116
|
+
const obj = {};
|
|
117
|
+
const testSym = Symbol();
|
|
118
|
+
binding.object.defineValueProperty(obj, testSym, 1);
|
|
119
|
+
assert.strictEqual(obj[testSym], 1);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
{
|
|
123
|
+
const testSym = Symbol();
|
|
124
|
+
const obj = { 'one': 1, 'two': 2, 'three': 3, [testSym]: 4 };
|
|
125
|
+
var arr = binding.object.GetPropertyNames(obj);
|
|
126
|
+
assert.deepStrictEqual(arr, ['one', 'two', 'three']);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
{
|
|
130
|
+
const magicObject = binding.object.createObjectUsingMagic();
|
|
131
|
+
assert.deepStrictEqual(magicObject, {
|
|
132
|
+
0: 0,
|
|
133
|
+
42: 120,
|
|
134
|
+
cp_false: false,
|
|
135
|
+
cp_true: true,
|
|
136
|
+
s_true: true,
|
|
137
|
+
s_false: false,
|
|
138
|
+
'0.0f': 0,
|
|
139
|
+
'0.0': 0,
|
|
140
|
+
'-1': -1,
|
|
141
|
+
foo2: 'foo',
|
|
142
|
+
foo4: 'foo',
|
|
143
|
+
foo5: 'foo',
|
|
144
|
+
foo6: 'foo',
|
|
145
|
+
foo7: 'foo',
|
|
146
|
+
circular: magicObject,
|
|
147
|
+
circular2: magicObject
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
{
|
|
152
|
+
function Ctor() {};
|
|
153
|
+
|
|
154
|
+
assert.strictEqual(binding.object.instanceOf(new Ctor(), Ctor), true);
|
|
155
|
+
assert.strictEqual(binding.object.instanceOf(new Ctor(), Object), true);
|
|
156
|
+
assert.strictEqual(binding.object.instanceOf({}, Ctor), false);
|
|
157
|
+
assert.strictEqual(binding.object.instanceOf(null, Ctor), false);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if ('sum' in binding.object) {
|
|
161
|
+
{
|
|
162
|
+
const obj = {
|
|
163
|
+
'-forbid': -0x4B1D,
|
|
164
|
+
'-feedcode': -0xFEEDC0DE,
|
|
165
|
+
'+office': +0x0FF1CE,
|
|
166
|
+
'+forbid': +0x4B1D,
|
|
167
|
+
'+deadbeef': +0xDEADBEEF,
|
|
168
|
+
'+feedcode': +0xFEEDC0DE,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
let sum = 0;
|
|
172
|
+
for (const key in obj) {
|
|
173
|
+
sum += obj[key];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
assert.strictEqual(binding.object.sum(obj), sum);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
{
|
|
180
|
+
const obj = new Proxy({
|
|
181
|
+
'-forbid': -0x4B1D,
|
|
182
|
+
'-feedcode': -0xFEEDC0DE,
|
|
183
|
+
'+office': +0x0FF1CE,
|
|
184
|
+
'+forbid': +0x4B1D,
|
|
185
|
+
'+deadbeef': +0xDEADBEEF,
|
|
186
|
+
'+feedcode': +0xFEEDC0DE,
|
|
187
|
+
}, {
|
|
188
|
+
getOwnPropertyDescriptor(target, p) {
|
|
189
|
+
throw new Error("getOwnPropertyDescriptor error");
|
|
190
|
+
},
|
|
191
|
+
ownKeys(target) {
|
|
192
|
+
throw new Error("ownKeys error");
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
assert.throws(() => {
|
|
197
|
+
binding.object.sum(obj);
|
|
198
|
+
}, /ownKeys error/);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if ('increment' in binding.object) {
|
|
203
|
+
const obj = {
|
|
204
|
+
'a': 0,
|
|
205
|
+
'b': 1,
|
|
206
|
+
'c': 2,
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
binding.object.increment(obj);
|
|
210
|
+
|
|
211
|
+
assert.deepStrictEqual(obj, {
|
|
212
|
+
'a': 1,
|
|
213
|
+
'b': 2,
|
|
214
|
+
'c': 3,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#include "napi.h"
|
|
2
|
+
|
|
3
|
+
using namespace Napi;
|
|
4
|
+
|
|
5
|
+
static bool testValue = true;
|
|
6
|
+
|
|
7
|
+
namespace {
|
|
8
|
+
|
|
9
|
+
Value TestGetter(const CallbackInfo& info) {
|
|
10
|
+
return Boolean::New(info.Env(), testValue);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
void TestSetter(const CallbackInfo& info) {
|
|
14
|
+
testValue = info[0].As<Boolean>();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Value TestFunction(const CallbackInfo& info) {
|
|
18
|
+
return Boolean::New(info.Env(), true);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
void DefineProperties(const CallbackInfo& info) {
|
|
22
|
+
Object obj = info[0].As<Object>();
|
|
23
|
+
String nameType = info[1].As<String>();
|
|
24
|
+
Env env = info.Env();
|
|
25
|
+
|
|
26
|
+
if (nameType.Utf8Value() == "literal") {
|
|
27
|
+
obj.DefineProperties({
|
|
28
|
+
PropertyDescriptor::Accessor("readonlyAccessor", TestGetter),
|
|
29
|
+
PropertyDescriptor::Accessor("readwriteAccessor", TestGetter, TestSetter),
|
|
30
|
+
PropertyDescriptor::Function("function", TestFunction),
|
|
31
|
+
});
|
|
32
|
+
} else if (nameType.Utf8Value() == "string") {
|
|
33
|
+
// VS2013 has lifetime issues when passing temporary objects into the constructor of another
|
|
34
|
+
// object. It generates code to destruct the object as soon as the constructor call returns.
|
|
35
|
+
// Since this isn't a common case for using std::string objects, I'm refactoring the test to
|
|
36
|
+
// work around the issue.
|
|
37
|
+
std::string str1("readonlyAccessor");
|
|
38
|
+
std::string str2("readwriteAccessor");
|
|
39
|
+
std::string str7("function");
|
|
40
|
+
|
|
41
|
+
obj.DefineProperties({
|
|
42
|
+
PropertyDescriptor::Accessor(str1, TestGetter),
|
|
43
|
+
PropertyDescriptor::Accessor(str2, TestGetter, TestSetter),
|
|
44
|
+
PropertyDescriptor::Function(str7, TestFunction),
|
|
45
|
+
});
|
|
46
|
+
} else if (nameType.Utf8Value() == "value") {
|
|
47
|
+
obj.DefineProperties({
|
|
48
|
+
PropertyDescriptor::Accessor(
|
|
49
|
+
Napi::String::New(env, "readonlyAccessor"), TestGetter),
|
|
50
|
+
PropertyDescriptor::Accessor(
|
|
51
|
+
Napi::String::New(env, "readwriteAccessor"), TestGetter, TestSetter),
|
|
52
|
+
PropertyDescriptor::Function(
|
|
53
|
+
Napi::String::New(env, "function"), TestFunction),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
} // end of anonymous namespace
|
|
59
|
+
|
|
60
|
+
Object InitObjectDeprecated(Env env) {
|
|
61
|
+
Object exports = Object::New(env);
|
|
62
|
+
|
|
63
|
+
exports["defineProperties"] = Function::New(env, DefineProperties);
|
|
64
|
+
|
|
65
|
+
return exports;
|
|
66
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
|
|
5
|
+
module.exports = require('../common').runTest(test);
|
|
6
|
+
|
|
7
|
+
function test(binding) {
|
|
8
|
+
if (!('object_deprecated' in binding)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
function assertPropertyIs(obj, key, attribute) {
|
|
12
|
+
const propDesc = Object.getOwnPropertyDescriptor(obj, key);
|
|
13
|
+
assert.ok(propDesc);
|
|
14
|
+
assert.ok(propDesc[attribute]);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function assertPropertyIsNot(obj, key, attribute) {
|
|
18
|
+
const propDesc = Object.getOwnPropertyDescriptor(obj, key);
|
|
19
|
+
assert.ok(propDesc);
|
|
20
|
+
assert.ok(!propDesc[attribute]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function testDefineProperties(nameType) {
|
|
24
|
+
const obj = {};
|
|
25
|
+
binding.object.defineProperties(obj, nameType);
|
|
26
|
+
|
|
27
|
+
assertPropertyIsNot(obj, 'readonlyAccessor', 'enumerable');
|
|
28
|
+
assertPropertyIsNot(obj, 'readonlyAccessor', 'configurable');
|
|
29
|
+
assert.strictEqual(obj.readonlyAccessor, true);
|
|
30
|
+
|
|
31
|
+
assertPropertyIsNot(obj, 'readwriteAccessor', 'enumerable');
|
|
32
|
+
assertPropertyIsNot(obj, 'readwriteAccessor', 'configurable');
|
|
33
|
+
obj.readwriteAccessor = false;
|
|
34
|
+
assert.strictEqual(obj.readwriteAccessor, false);
|
|
35
|
+
obj.readwriteAccessor = true;
|
|
36
|
+
assert.strictEqual(obj.readwriteAccessor, true);
|
|
37
|
+
|
|
38
|
+
assertPropertyIsNot(obj, 'function', 'writable');
|
|
39
|
+
assertPropertyIsNot(obj, 'function', 'enumerable');
|
|
40
|
+
assertPropertyIsNot(obj, 'function', 'configurable');
|
|
41
|
+
assert.strictEqual(obj.function(), true);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
testDefineProperties('literal');
|
|
45
|
+
testDefineProperties('string');
|
|
46
|
+
testDefineProperties('value');
|
|
47
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#include "napi.h"
|
|
2
|
+
#include "test_helper.h"
|
|
3
|
+
|
|
4
|
+
#if (NAPI_VERSION > 7)
|
|
5
|
+
|
|
6
|
+
using namespace Napi;
|
|
7
|
+
|
|
8
|
+
Value Freeze(const CallbackInfo& info) {
|
|
9
|
+
Object obj = info[0].As<Object>();
|
|
10
|
+
return Boolean::New(info.Env(), MaybeUnwrapOr(obj.Freeze(), false));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
Value Seal(const CallbackInfo& info) {
|
|
14
|
+
Object obj = info[0].As<Object>();
|
|
15
|
+
return Boolean::New(info.Env(), MaybeUnwrapOr(obj.Seal(), false));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Object InitObjectFreezeSeal(Env env) {
|
|
19
|
+
Object exports = Object::New(env);
|
|
20
|
+
exports["freeze"] = Function::New(env, Freeze);
|
|
21
|
+
exports["seal"] = Function::New(env, Seal);
|
|
22
|
+
return exports;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#endif
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
|
|
5
|
+
module.exports = require('../common').runTest(test);
|
|
6
|
+
|
|
7
|
+
function test(binding) {
|
|
8
|
+
{
|
|
9
|
+
const obj = { x: 'a', y: 'b', z: 'c' };
|
|
10
|
+
assert.strictEqual(binding.object_freeze_seal.freeze(obj), true);
|
|
11
|
+
assert.strictEqual(Object.isFrozen(obj), true);
|
|
12
|
+
assert.throws(() => {
|
|
13
|
+
obj.x = 10;
|
|
14
|
+
}, /Cannot assign to read only property 'x' of object '#<Object>/);
|
|
15
|
+
assert.throws(() => {
|
|
16
|
+
obj.w = 15;
|
|
17
|
+
}, /Cannot add property w, object is not extensible/);
|
|
18
|
+
assert.throws(() => {
|
|
19
|
+
delete obj.x;
|
|
20
|
+
}, /Cannot delete property 'x' of #<Object>/);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
{
|
|
24
|
+
const obj = new Proxy({ x: 'a', y: 'b', z: 'c' }, {
|
|
25
|
+
preventExtensions() {
|
|
26
|
+
throw new Error('foo');
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
assert.throws(() => {
|
|
31
|
+
binding.object_freeze_seal.freeze(obj);
|
|
32
|
+
}, /foo/);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
{
|
|
36
|
+
const obj = { x: 'a', y: 'b', z: 'c' };
|
|
37
|
+
assert.strictEqual(binding.object_freeze_seal.seal(obj), true);
|
|
38
|
+
assert.strictEqual(Object.isSealed(obj), true);
|
|
39
|
+
assert.throws(() => {
|
|
40
|
+
obj.w = 'd';
|
|
41
|
+
}, /Cannot add property w, object is not extensible/);
|
|
42
|
+
assert.throws(() => {
|
|
43
|
+
delete obj.x;
|
|
44
|
+
}, /Cannot delete property 'x' of #<Object>/);
|
|
45
|
+
// Sealed objects allow updating existing properties,
|
|
46
|
+
// so this should not throw.
|
|
47
|
+
obj.x = 'd';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
{
|
|
51
|
+
const obj = new Proxy({ x: 'a', y: 'b', z: 'c' }, {
|
|
52
|
+
preventExtensions() {
|
|
53
|
+
throw new Error('foo');
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
assert.throws(() => {
|
|
58
|
+
binding.object_freeze_seal.seal(obj);
|
|
59
|
+
}, /foo/);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#include "napi.h"
|
|
2
|
+
#include "test_helper.h"
|
|
3
|
+
|
|
4
|
+
using namespace Napi;
|
|
5
|
+
|
|
6
|
+
Value SetPropertyWithNapiValue(const CallbackInfo& info) {
|
|
7
|
+
Object obj = info[0].As<Object>();
|
|
8
|
+
Name key = info[1].As<Name>();
|
|
9
|
+
Value value = info[2];
|
|
10
|
+
return Boolean::New(
|
|
11
|
+
info.Env(),
|
|
12
|
+
MaybeUnwrapOr(obj.Set(static_cast<napi_value>(key), value), false));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Value SetPropertyWithNapiWrapperValue(const CallbackInfo& info) {
|
|
16
|
+
Object obj = info[0].As<Object>();
|
|
17
|
+
Name key = info[1].As<Name>();
|
|
18
|
+
Value value = info[2];
|
|
19
|
+
return Boolean::New(info.Env(), MaybeUnwrapOr(obj.Set(key, value), false));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Value SetPropertyWithUint32(const CallbackInfo& info) {
|
|
23
|
+
Object obj = info[0].As<Object>();
|
|
24
|
+
Number key = info[1].As<Number>();
|
|
25
|
+
Value value = info[2];
|
|
26
|
+
return Boolean::New(info.Env(),
|
|
27
|
+
MaybeUnwrapOr(obj.Set(key.Uint32Value(), value), false));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Value SetPropertyWithCStyleString(const CallbackInfo& info) {
|
|
31
|
+
Object obj = info[0].As<Object>();
|
|
32
|
+
String jsKey = info[1].As<String>();
|
|
33
|
+
Value value = info[2];
|
|
34
|
+
return Boolean::New(
|
|
35
|
+
info.Env(),
|
|
36
|
+
MaybeUnwrapOr(obj.Set(jsKey.Utf8Value().c_str(), value), false));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Value SetPropertyWithCppStyleString(const CallbackInfo& info) {
|
|
40
|
+
Object obj = info[0].As<Object>();
|
|
41
|
+
String jsKey = info[1].As<String>();
|
|
42
|
+
Value value = info[2];
|
|
43
|
+
return Boolean::New(info.Env(),
|
|
44
|
+
MaybeUnwrapOr(obj.Set(jsKey.Utf8Value(), value), false));
|
|
45
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
|
|
5
|
+
module.exports = require('../common').runTest(test);
|
|
6
|
+
|
|
7
|
+
function test (binding) {
|
|
8
|
+
function testSetProperty (nativeSetProperty, key = 'test') {
|
|
9
|
+
const obj = {};
|
|
10
|
+
assert.strictEqual(nativeSetProperty(obj, key, 1), true);
|
|
11
|
+
assert.strictEqual(obj[key], 1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function testShouldThrowErrorIfKeyIsInvalid (nativeSetProperty) {
|
|
15
|
+
assert.throws(() => {
|
|
16
|
+
nativeSetProperty(undefined, 'test', 1);
|
|
17
|
+
}, /Cannot convert undefined or null to object/);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
testSetProperty(binding.object.setPropertyWithNapiValue);
|
|
21
|
+
testSetProperty(binding.object.setPropertyWithNapiWrapperValue);
|
|
22
|
+
testSetProperty(binding.object.setPropertyWithCStyleString);
|
|
23
|
+
testSetProperty(binding.object.setPropertyWithCppStyleString);
|
|
24
|
+
testSetProperty(binding.object.setPropertyWithUint32, 12);
|
|
25
|
+
|
|
26
|
+
testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithNapiValue);
|
|
27
|
+
testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithNapiWrapperValue);
|
|
28
|
+
testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithCStyleString);
|
|
29
|
+
testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithCppStyleString);
|
|
30
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#include "napi.h"
|
|
2
|
+
#include "test_helper.h"
|
|
3
|
+
|
|
4
|
+
using namespace Napi;
|
|
5
|
+
|
|
6
|
+
Value SubscriptGetWithCStyleString(const CallbackInfo& info) {
|
|
7
|
+
String jsKey = info[1].As<String>();
|
|
8
|
+
|
|
9
|
+
// make sure const case compiles
|
|
10
|
+
const Object obj2 = info[0].As<Object>();
|
|
11
|
+
MaybeUnwrap(obj2[jsKey.Utf8Value().c_str()]).As<Boolean>();
|
|
12
|
+
|
|
13
|
+
Object obj = info[0].As<Object>();
|
|
14
|
+
return obj[jsKey.Utf8Value().c_str()];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Value SubscriptGetWithCppStyleString(const CallbackInfo& info) {
|
|
18
|
+
String jsKey = info[1].As<String>();
|
|
19
|
+
|
|
20
|
+
// make sure const case compiles
|
|
21
|
+
const Object obj2 = info[0].As<Object>();
|
|
22
|
+
MaybeUnwrap(obj2[jsKey.Utf8Value()]).As<Boolean>();
|
|
23
|
+
|
|
24
|
+
Object obj = info[0].As<Object>();
|
|
25
|
+
return obj[jsKey.Utf8Value()];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Value SubscriptGetAtIndex(const CallbackInfo& info) {
|
|
29
|
+
uint32_t index = info[1].As<Napi::Number>();
|
|
30
|
+
|
|
31
|
+
// make sure const case compiles
|
|
32
|
+
const Object obj2 = info[0].As<Object>();
|
|
33
|
+
MaybeUnwrap(obj2[index]).As<Boolean>();
|
|
34
|
+
|
|
35
|
+
Object obj = info[0].As<Object>();
|
|
36
|
+
return obj[index];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void SubscriptSetWithCStyleString(const CallbackInfo& info) {
|
|
40
|
+
Object obj = info[0].As<Object>();
|
|
41
|
+
String jsKey = info[1].As<String>();
|
|
42
|
+
Value value = info[2];
|
|
43
|
+
obj[jsKey.Utf8Value().c_str()] = value;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void SubscriptSetWithCppStyleString(const CallbackInfo& info) {
|
|
47
|
+
Object obj = info[0].As<Object>();
|
|
48
|
+
String jsKey = info[1].As<String>();
|
|
49
|
+
Value value = info[2];
|
|
50
|
+
obj[jsKey.Utf8Value()] = value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void SubscriptSetAtIndex(const CallbackInfo& info) {
|
|
54
|
+
Object obj = info[0].As<Object>();
|
|
55
|
+
uint32_t index = info[1].As<Napi::Number>();
|
|
56
|
+
Value value = info[2];
|
|
57
|
+
obj[index] = value;
|
|
58
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
|
|
5
|
+
module.exports = require('../common').runTest(test);
|
|
6
|
+
|
|
7
|
+
function test(binding) {
|
|
8
|
+
function testProperty(obj, key, value, nativeGetProperty, nativeSetProperty) {
|
|
9
|
+
nativeSetProperty(obj, key, value);
|
|
10
|
+
assert.strictEqual(nativeGetProperty(obj, key), value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
testProperty({}, 'key', 'value', binding.object.subscriptGetWithCStyleString, binding.object.subscriptSetWithCStyleString);
|
|
14
|
+
testProperty({ key: 'override me' }, 'key', 'value', binding.object.subscriptGetWithCppStyleString, binding.object.subscriptSetWithCppStyleString);
|
|
15
|
+
testProperty({}, 0, 'value', binding.object.subscriptGetAtIndex, binding.object.subscriptSetAtIndex);
|
|
16
|
+
testProperty({ key: 'override me' }, 0, 'value', binding.object.subscriptGetAtIndex, binding.object.subscriptSetAtIndex);
|
|
17
|
+
}
|