koffi 1.0.5 → 1.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -21
- package/build/qemu/1.1.0-beta.0/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_linux_arm.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_win32_x64.tar.gz +0 -0
- package/package.json +1 -1
- package/qemu/qemu.js +11 -5
- package/qemu/registry/machines.json +20 -10
- package/src/abi_arm32.cc +13 -6
- package/src/abi_arm64.cc +13 -6
- package/src/abi_x64_sysv.cc +13 -6
- package/src/abi_x64_win.cc +13 -6
- package/src/abi_x86.cc +13 -6
- package/src/call.cc +25 -26
- package/src/call.hh +27 -41
- package/src/ffi.cc +152 -17
- package/src/ffi.hh +24 -10
- package/test/misc.c +2 -2
- package/build/qemu/1.0.5/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.0.5/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.0.5/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.0.5/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.0.5/koffi_linux_arm.tar.gz +0 -0
- package/build/qemu/1.0.5/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.0.5/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.0.5/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.0.5/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.0.5/koffi_win32_x64.tar.gz +0 -0
- package/test/misc.js +0 -227
- package/vendor/node-addon-api/CODE_OF_CONDUCT.md +0 -4
- package/vendor/node-addon-api/CONTRIBUTING.md +0 -93
- package/vendor/node-addon-api/appveyor.yml +0 -37
- package/vendor/node-addon-api/benchmark/README.md +0 -47
- package/vendor/node-addon-api/benchmark/binding.gyp +0 -25
- package/vendor/node-addon-api/benchmark/function_args.cc +0 -217
- package/vendor/node-addon-api/benchmark/function_args.js +0 -60
- package/vendor/node-addon-api/benchmark/index.js +0 -34
- package/vendor/node-addon-api/benchmark/property_descriptor.cc +0 -91
- package/vendor/node-addon-api/benchmark/property_descriptor.js +0 -37
- package/vendor/node-addon-api/doc/addon.md +0 -163
- package/vendor/node-addon-api/doc/array.md +0 -81
- package/vendor/node-addon-api/doc/array_buffer.md +0 -155
- package/vendor/node-addon-api/doc/async_context.md +0 -86
- package/vendor/node-addon-api/doc/async_operations.md +0 -31
- package/vendor/node-addon-api/doc/async_worker.md +0 -427
- package/vendor/node-addon-api/doc/async_worker_variants.md +0 -557
- package/vendor/node-addon-api/doc/bigint.md +0 -97
- package/vendor/node-addon-api/doc/boolean.md +0 -68
- package/vendor/node-addon-api/doc/buffer.md +0 -150
- package/vendor/node-addon-api/doc/callback_scope.md +0 -54
- package/vendor/node-addon-api/doc/callbackinfo.md +0 -97
- package/vendor/node-addon-api/doc/checker-tool.md +0 -32
- package/vendor/node-addon-api/doc/class_property_descriptor.md +0 -123
- package/vendor/node-addon-api/doc/cmake-js.md +0 -68
- package/vendor/node-addon-api/doc/conversion-tool.md +0 -28
- package/vendor/node-addon-api/doc/creating_a_release.md +0 -62
- package/vendor/node-addon-api/doc/dataview.md +0 -248
- package/vendor/node-addon-api/doc/date.md +0 -68
- package/vendor/node-addon-api/doc/env.md +0 -196
- package/vendor/node-addon-api/doc/error.md +0 -120
- package/vendor/node-addon-api/doc/error_handling.md +0 -254
- package/vendor/node-addon-api/doc/escapable_handle_scope.md +0 -80
- package/vendor/node-addon-api/doc/external.md +0 -63
- package/vendor/node-addon-api/doc/function.md +0 -402
- package/vendor/node-addon-api/doc/function_reference.md +0 -238
- package/vendor/node-addon-api/doc/generator.md +0 -13
- package/vendor/node-addon-api/doc/handle_scope.md +0 -63
- package/vendor/node-addon-api/doc/hierarchy.md +0 -91
- package/vendor/node-addon-api/doc/instance_wrap.md +0 -408
- package/vendor/node-addon-api/doc/maybe.md +0 -76
- package/vendor/node-addon-api/doc/memory_management.md +0 -27
- package/vendor/node-addon-api/doc/name.md +0 -29
- package/vendor/node-addon-api/doc/node-gyp.md +0 -82
- package/vendor/node-addon-api/doc/number.md +0 -163
- package/vendor/node-addon-api/doc/object.md +0 -411
- package/vendor/node-addon-api/doc/object_lifetime_management.md +0 -83
- package/vendor/node-addon-api/doc/object_reference.md +0 -117
- package/vendor/node-addon-api/doc/object_wrap.md +0 -588
- package/vendor/node-addon-api/doc/prebuild_tools.md +0 -16
- package/vendor/node-addon-api/doc/promises.md +0 -79
- package/vendor/node-addon-api/doc/property_descriptor.md +0 -286
- package/vendor/node-addon-api/doc/propertylvalue.md +0 -50
- package/vendor/node-addon-api/doc/range_error.md +0 -59
- package/vendor/node-addon-api/doc/reference.md +0 -113
- package/vendor/node-addon-api/doc/setup.md +0 -110
- package/vendor/node-addon-api/doc/string.md +0 -93
- package/vendor/node-addon-api/doc/symbol.md +0 -61
- package/vendor/node-addon-api/doc/threadsafe.md +0 -121
- package/vendor/node-addon-api/doc/threadsafe_function.md +0 -290
- package/vendor/node-addon-api/doc/type_error.md +0 -59
- package/vendor/node-addon-api/doc/typed_array.md +0 -78
- package/vendor/node-addon-api/doc/typed_array_of.md +0 -137
- package/vendor/node-addon-api/doc/typed_threadsafe_function.md +0 -306
- package/vendor/node-addon-api/doc/value.md +0 -340
- package/vendor/node-addon-api/doc/version_management.md +0 -43
- package/vendor/node-addon-api/package.json +0 -415
- package/vendor/node-addon-api/test/README.md +0 -91
- package/vendor/node-addon-api/test/addon.cc +0 -36
- package/vendor/node-addon-api/test/addon.js +0 -11
- package/vendor/node-addon-api/test/addon_build/index.js +0 -49
- package/vendor/node-addon-api/test/addon_build/tpl/addon.cc +0 -17
- package/vendor/node-addon-api/test/addon_build/tpl/binding.gyp +0 -62
- package/vendor/node-addon-api/test/addon_build/tpl/index.js +0 -9
- package/vendor/node-addon-api/test/addon_build/tpl/package.json +0 -11
- package/vendor/node-addon-api/test/addon_data.cc +0 -99
- package/vendor/node-addon-api/test/addon_data.js +0 -46
- package/vendor/node-addon-api/test/array_buffer.cc +0 -243
- package/vendor/node-addon-api/test/array_buffer.js +0 -69
- package/vendor/node-addon-api/test/async_context.cc +0 -36
- package/vendor/node-addon-api/test/async_context.js +0 -122
- package/vendor/node-addon-api/test/async_progress_queue_worker.cc +0 -83
- package/vendor/node-addon-api/test/async_progress_queue_worker.js +0 -46
- package/vendor/node-addon-api/test/async_progress_worker.cc +0 -134
- package/vendor/node-addon-api/test/async_progress_worker.js +0 -61
- package/vendor/node-addon-api/test/async_worker.cc +0 -106
- package/vendor/node-addon-api/test/async_worker.js +0 -179
- package/vendor/node-addon-api/test/async_worker_nocallback.js +0 -13
- package/vendor/node-addon-api/test/async_worker_persistent.cc +0 -63
- package/vendor/node-addon-api/test/async_worker_persistent.js +0 -24
- package/vendor/node-addon-api/test/basic_types/array.cc +0 -40
- package/vendor/node-addon-api/test/basic_types/array.js +0 -35
- package/vendor/node-addon-api/test/basic_types/boolean.cc +0 -38
- package/vendor/node-addon-api/test/basic_types/boolean.js +0 -35
- package/vendor/node-addon-api/test/basic_types/number.cc +0 -99
- package/vendor/node-addon-api/test/basic_types/number.js +0 -114
- package/vendor/node-addon-api/test/basic_types/value.cc +0 -120
- package/vendor/node-addon-api/test/basic_types/value.js +0 -133
- package/vendor/node-addon-api/test/bigint.cc +0 -91
- package/vendor/node-addon-api/test/bigint.js +0 -53
- package/vendor/node-addon-api/test/binding-swallowexcept.cc +0 -12
- package/vendor/node-addon-api/test/binding.cc +0 -173
- package/vendor/node-addon-api/test/binding.gyp +0 -124
- package/vendor/node-addon-api/test/buffer.cc +0 -183
- package/vendor/node-addon-api/test/buffer.js +0 -69
- package/vendor/node-addon-api/test/callbackscope.cc +0 -22
- package/vendor/node-addon-api/test/callbackscope.js +0 -49
- package/vendor/node-addon-api/test/common/index.js +0 -114
- package/vendor/node-addon-api/test/common/test_helper.h +0 -71
- package/vendor/node-addon-api/test/dataview/dataview.cc +0 -48
- package/vendor/node-addon-api/test/dataview/dataview.js +0 -35
- package/vendor/node-addon-api/test/dataview/dataview_read_write.cc +0 -115
- package/vendor/node-addon-api/test/dataview/dataview_read_write.js +0 -90
- package/vendor/node-addon-api/test/date.cc +0 -44
- package/vendor/node-addon-api/test/date.js +0 -18
- package/vendor/node-addon-api/test/env_cleanup.cc +0 -88
- package/vendor/node-addon-api/test/env_cleanup.js +0 -56
- package/vendor/node-addon-api/test/error.cc +0 -287
- package/vendor/node-addon-api/test/error.js +0 -81
- package/vendor/node-addon-api/test/error_handling_for_primitives.cc +0 -13
- package/vendor/node-addon-api/test/error_handling_for_primitives.js +0 -29
- package/vendor/node-addon-api/test/error_terminating_environment.js +0 -95
- package/vendor/node-addon-api/test/external.cc +0 -81
- package/vendor/node-addon-api/test/external.js +0 -88
- package/vendor/node-addon-api/test/function.cc +0 -324
- package/vendor/node-addon-api/test/function.js +0 -133
- package/vendor/node-addon-api/test/function_reference.cc +0 -202
- package/vendor/node-addon-api/test/function_reference.js +0 -157
- package/vendor/node-addon-api/test/globalObject/global_object.cc +0 -61
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.cc +0 -31
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.js +0 -61
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.cc +0 -40
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.js +0 -57
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.cc +0 -28
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.js +0 -48
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.cc +0 -31
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.js +0 -58
- package/vendor/node-addon-api/test/handlescope.cc +0 -60
- package/vendor/node-addon-api/test/handlescope.js +0 -14
- package/vendor/node-addon-api/test/index.js +0 -159
- package/vendor/node-addon-api/test/maybe/check.cc +0 -23
- package/vendor/node-addon-api/test/maybe/index.js +0 -38
- package/vendor/node-addon-api/test/memory_management.cc +0 -17
- package/vendor/node-addon-api/test/memory_management.js +0 -9
- package/vendor/node-addon-api/test/movable_callbacks.cc +0 -23
- package/vendor/node-addon-api/test/movable_callbacks.js +0 -21
- package/vendor/node-addon-api/test/name.cc +0 -108
- package/vendor/node-addon-api/test/name.js +0 -59
- package/vendor/node-addon-api/test/napi_child.js +0 -14
- package/vendor/node-addon-api/test/object/delete_property.cc +0 -38
- package/vendor/node-addon-api/test/object/delete_property.js +0 -41
- package/vendor/node-addon-api/test/object/finalizer.cc +0 -29
- package/vendor/node-addon-api/test/object/finalizer.js +0 -28
- package/vendor/node-addon-api/test/object/get_property.cc +0 -34
- package/vendor/node-addon-api/test/object/get_property.js +0 -40
- package/vendor/node-addon-api/test/object/has_own_property.cc +0 -34
- package/vendor/node-addon-api/test/object/has_own_property.js +0 -34
- package/vendor/node-addon-api/test/object/has_property.cc +0 -38
- package/vendor/node-addon-api/test/object/has_property.js +0 -37
- package/vendor/node-addon-api/test/object/object.cc +0 -350
- package/vendor/node-addon-api/test/object/object.js +0 -217
- package/vendor/node-addon-api/test/object/object_deprecated.cc +0 -66
- package/vendor/node-addon-api/test/object/object_deprecated.js +0 -47
- package/vendor/node-addon-api/test/object/object_freeze_seal.cc +0 -25
- package/vendor/node-addon-api/test/object/object_freeze_seal.js +0 -61
- package/vendor/node-addon-api/test/object/set_property.cc +0 -45
- package/vendor/node-addon-api/test/object/set_property.js +0 -30
- package/vendor/node-addon-api/test/object/subscript_operator.cc +0 -58
- package/vendor/node-addon-api/test/object/subscript_operator.js +0 -17
- package/vendor/node-addon-api/test/object_reference.cc +0 -219
- package/vendor/node-addon-api/test/object_reference.js +0 -259
- package/vendor/node-addon-api/test/objectwrap.cc +0 -268
- package/vendor/node-addon-api/test/objectwrap.js +0 -284
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.cc +0 -26
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.js +0 -18
- package/vendor/node-addon-api/test/objectwrap_function.cc +0 -45
- package/vendor/node-addon-api/test/objectwrap_function.js +0 -22
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.cc +0 -30
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.js +0 -13
- package/vendor/node-addon-api/test/objectwrap_removewrap.cc +0 -45
- package/vendor/node-addon-api/test/objectwrap_removewrap.js +0 -40
- package/vendor/node-addon-api/test/objectwrap_worker_thread.js +0 -19
- package/vendor/node-addon-api/test/promise.cc +0 -29
- package/vendor/node-addon-api/test/promise.js +0 -18
- package/vendor/node-addon-api/test/reference.cc +0 -24
- package/vendor/node-addon-api/test/reference.js +0 -14
- package/vendor/node-addon-api/test/run_script.cc +0 -56
- package/vendor/node-addon-api/test/run_script.js +0 -45
- package/vendor/node-addon-api/test/symbol.cc +0 -79
- package/vendor/node-addon-api/test/symbol.js +0 -73
- package/vendor/node-addon-api/test/testUtil.js +0 -54
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.cc +0 -195
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.js +0 -188
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.cc +0 -63
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.js +0 -12
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.cc +0 -115
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.js +0 -14
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.cc +0 -26
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.js +0 -7
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.cc +0 -225
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.js +0 -59
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.cc +0 -42
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.js +0 -53
- package/vendor/node-addon-api/test/thunking_manual.cc +0 -140
- package/vendor/node-addon-api/test/thunking_manual.js +0 -17
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.cc +0 -215
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.js +0 -188
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc +0 -68
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +0 -12
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc +0 -127
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js +0 -14
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc +0 -28
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js +0 -7
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc +0 -237
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.js +0 -59
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc +0 -53
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js +0 -53
- package/vendor/node-addon-api/test/typedarray-bigint.js +0 -58
- package/vendor/node-addon-api/test/typedarray.cc +0 -216
- package/vendor/node-addon-api/test/typedarray.js +0 -69
- package/vendor/node-addon-api/test/version_management.cc +0 -27
- package/vendor/node-addon-api/test/version_management.js +0 -31
- package/vendor/node-addon-api/unit-test/README.md +0 -28
- package/vendor/node-addon-api/unit-test/binding-file-template.js +0 -39
- package/vendor/node-addon-api/unit-test/binding.gyp +0 -72
- package/vendor/node-addon-api/unit-test/exceptions.js +0 -32
- package/vendor/node-addon-api/unit-test/generate-binding-cc.js +0 -61
- package/vendor/node-addon-api/unit-test/injectTestParams.js +0 -101
- package/vendor/node-addon-api/unit-test/listOfTestModules.js +0 -88
- package/vendor/node-addon-api/unit-test/matchModules.js +0 -65
- package/vendor/node-addon-api/unit-test/setup.js +0 -13
- package/vendor/node-addon-api/unit-test/spawnTask.js +0 -26
- package/vendor/node-addon-api/unit-test/test.js +0 -30
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const assert = require('assert');
|
|
4
|
-
|
|
5
|
-
module.exports = require('../common').runTest(test);
|
|
6
|
-
|
|
7
|
-
function test(binding) {
|
|
8
|
-
function testDeleteProperty(nativeDeleteProperty) {
|
|
9
|
-
const obj = { one: 1, two: 2 };
|
|
10
|
-
Object.defineProperty(obj, "three", {configurable: false, value: 3});
|
|
11
|
-
assert.strictEqual(nativeDeleteProperty(obj, 'one'), true);
|
|
12
|
-
assert.strictEqual(nativeDeleteProperty(obj, 'missing'), true);
|
|
13
|
-
|
|
14
|
-
/* Returns true for all cases except when the property is an own non-
|
|
15
|
-
configurable property, in which case, false is returned in non-strict mode. */
|
|
16
|
-
assert.strictEqual(nativeDeleteProperty(obj, 'three'), false);
|
|
17
|
-
assert.deepStrictEqual(obj, { two: 2 });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function testShouldThrowErrorIfKeyIsInvalid(nativeDeleteProperty) {
|
|
21
|
-
assert.throws(() => {
|
|
22
|
-
nativeDeleteProperty(undefined, 'test');
|
|
23
|
-
}, /Cannot convert undefined or null to object/);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const testObj = { 15 : 42 , three: 3};
|
|
27
|
-
|
|
28
|
-
binding.object.deletePropertyWithUint32(testObj,15);
|
|
29
|
-
|
|
30
|
-
assert.strictEqual(testObj.hasOwnProperty(15),false);
|
|
31
|
-
|
|
32
|
-
testDeleteProperty(binding.object.deletePropertyWithNapiValue);
|
|
33
|
-
testDeleteProperty(binding.object.deletePropertyWithNapiWrapperValue);
|
|
34
|
-
testDeleteProperty(binding.object.deletePropertyWithCStyleString);
|
|
35
|
-
testDeleteProperty(binding.object.deletePropertyWithCppStyleString);
|
|
36
|
-
|
|
37
|
-
testShouldThrowErrorIfKeyIsInvalid(binding.object.deletePropertyWithNapiValue);
|
|
38
|
-
testShouldThrowErrorIfKeyIsInvalid(binding.object.deletePropertyWithNapiWrapperValue);
|
|
39
|
-
testShouldThrowErrorIfKeyIsInvalid(binding.object.deletePropertyWithCStyleString);
|
|
40
|
-
testShouldThrowErrorIfKeyIsInvalid(binding.object.deletePropertyWithCppStyleString);
|
|
41
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
#include "napi.h"
|
|
2
|
-
|
|
3
|
-
using namespace Napi;
|
|
4
|
-
|
|
5
|
-
static int dummy;
|
|
6
|
-
|
|
7
|
-
Value AddFinalizer(const CallbackInfo& info) {
|
|
8
|
-
ObjectReference* ref = new ObjectReference;
|
|
9
|
-
*ref = Persistent(Object::New(info.Env()));
|
|
10
|
-
info[0]
|
|
11
|
-
.As<Object>()
|
|
12
|
-
.AddFinalizer([](Napi::Env /*env*/, ObjectReference* ref) {
|
|
13
|
-
ref->Set("finalizerCalled", true);
|
|
14
|
-
delete ref;
|
|
15
|
-
}, ref);
|
|
16
|
-
return ref->Value();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
Value AddFinalizerWithHint(const CallbackInfo& info) {
|
|
20
|
-
ObjectReference* ref = new ObjectReference;
|
|
21
|
-
*ref = Persistent(Object::New(info.Env()));
|
|
22
|
-
info[0]
|
|
23
|
-
.As<Object>()
|
|
24
|
-
.AddFinalizer([](Napi::Env /*env*/, ObjectReference* ref, int* dummy_p) {
|
|
25
|
-
ref->Set("finalizerCalledWithCorrectHint", dummy_p == &dummy);
|
|
26
|
-
delete ref;
|
|
27
|
-
}, ref, &dummy);
|
|
28
|
-
return ref->Value();
|
|
29
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const assert = require('assert');
|
|
4
|
-
const testUtil = require('../testUtil');
|
|
5
|
-
|
|
6
|
-
module.exports = require('../common').runTest(test);
|
|
7
|
-
|
|
8
|
-
function createWeakRef(binding, bindingToTest) {
|
|
9
|
-
return binding.object[bindingToTest]({});
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function test(binding) {
|
|
13
|
-
let obj1;
|
|
14
|
-
let obj2;
|
|
15
|
-
return testUtil.runGCTests([
|
|
16
|
-
'addFinalizer',
|
|
17
|
-
() => {
|
|
18
|
-
obj1 = createWeakRef(binding, 'addFinalizer');
|
|
19
|
-
},
|
|
20
|
-
() => assert.deepStrictEqual(obj1, { finalizerCalled: true }),
|
|
21
|
-
|
|
22
|
-
'addFinalizerWithHint',
|
|
23
|
-
() => {
|
|
24
|
-
obj2 = createWeakRef(binding, 'addFinalizerWithHint');
|
|
25
|
-
},
|
|
26
|
-
() => assert.deepStrictEqual(obj2, { finalizerCalledWithCorrectHint: true })
|
|
27
|
-
]);
|
|
28
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#include "napi.h"
|
|
2
|
-
#include "test_helper.h"
|
|
3
|
-
|
|
4
|
-
using namespace Napi;
|
|
5
|
-
|
|
6
|
-
Value GetPropertyWithNapiValue(const CallbackInfo& info) {
|
|
7
|
-
Object obj = info[0].As<Object>();
|
|
8
|
-
Name key = info[1].As<Name>();
|
|
9
|
-
return MaybeUnwrapOr(obj.Get(static_cast<napi_value>(key)), Value());
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
Value GetPropertyWithNapiWrapperValue(const CallbackInfo& info) {
|
|
13
|
-
Object obj = info[0].As<Object>();
|
|
14
|
-
Name key = info[1].As<Name>();
|
|
15
|
-
return MaybeUnwrapOr(obj.Get(key), Value());
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
Value GetPropertyWithUint32(const CallbackInfo& info) {
|
|
19
|
-
Object obj = info[0].As<Object>();
|
|
20
|
-
Number key = info[1].As<Number>();
|
|
21
|
-
return MaybeUnwrap(obj.Get(key.Uint32Value()));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
Value GetPropertyWithCStyleString(const CallbackInfo& info) {
|
|
25
|
-
Object obj = info[0].As<Object>();
|
|
26
|
-
String jsKey = info[1].As<String>();
|
|
27
|
-
return MaybeUnwrapOr(obj.Get(jsKey.Utf8Value().c_str()), Value());
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
Value GetPropertyWithCppStyleString(const CallbackInfo& info) {
|
|
31
|
-
Object obj = info[0].As<Object>();
|
|
32
|
-
String jsKey = info[1].As<String>();
|
|
33
|
-
return MaybeUnwrapOr(obj.Get(jsKey.Utf8Value()), Value());
|
|
34
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const assert = require('assert');
|
|
4
|
-
|
|
5
|
-
module.exports = require('../common').runTest(test);
|
|
6
|
-
|
|
7
|
-
function test(binding) {
|
|
8
|
-
function testGetProperty(nativeGetProperty) {
|
|
9
|
-
const obj = { test: 1 };
|
|
10
|
-
assert.strictEqual(nativeGetProperty(obj, 'test'), 1);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function testShouldReturnUndefinedIfKeyIsNotPresent(nativeGetProperty) {
|
|
14
|
-
const obj = { };
|
|
15
|
-
assert.strictEqual(nativeGetProperty(obj, 'test'), undefined);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function testShouldThrowErrorIfKeyIsInvalid(nativeGetProperty) {
|
|
19
|
-
assert.throws(() => {
|
|
20
|
-
nativeGetProperty(undefined, 'test');
|
|
21
|
-
}, /Cannot convert undefined or null to object/);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const testObject = { 42: 100 };
|
|
25
|
-
const property = binding.object.getPropertyWithUint32(testObject, 42);
|
|
26
|
-
assert.strictEqual(property,100)
|
|
27
|
-
|
|
28
|
-
const nativeFunctions = [
|
|
29
|
-
binding.object.getPropertyWithNapiValue,
|
|
30
|
-
binding.object.getPropertyWithNapiWrapperValue,
|
|
31
|
-
binding.object.getPropertyWithCStyleString,
|
|
32
|
-
binding.object.getPropertyWithCppStyleString
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
nativeFunctions.forEach((nativeFunction) => {
|
|
36
|
-
testGetProperty(nativeFunction);
|
|
37
|
-
testShouldReturnUndefinedIfKeyIsNotPresent(nativeFunction);
|
|
38
|
-
testShouldThrowErrorIfKeyIsInvalid(nativeFunction);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#include "napi.h"
|
|
2
|
-
#include "test_helper.h"
|
|
3
|
-
|
|
4
|
-
using namespace Napi;
|
|
5
|
-
|
|
6
|
-
Value HasOwnPropertyWithNapiValue(const CallbackInfo& info) {
|
|
7
|
-
Object obj = info[0].As<Object>();
|
|
8
|
-
Name key = info[1].As<Name>();
|
|
9
|
-
return Boolean::New(
|
|
10
|
-
info.Env(),
|
|
11
|
-
MaybeUnwrapOr(obj.HasOwnProperty(static_cast<napi_value>(key)), false));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
Value HasOwnPropertyWithNapiWrapperValue(const CallbackInfo& info) {
|
|
15
|
-
Object obj = info[0].As<Object>();
|
|
16
|
-
Name key = info[1].As<Name>();
|
|
17
|
-
return Boolean::New(info.Env(),
|
|
18
|
-
MaybeUnwrapOr(obj.HasOwnProperty(key), false));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
Value HasOwnPropertyWithCStyleString(const CallbackInfo& info) {
|
|
22
|
-
Object obj = info[0].As<Object>();
|
|
23
|
-
String jsKey = info[1].As<String>();
|
|
24
|
-
return Boolean::New(
|
|
25
|
-
info.Env(),
|
|
26
|
-
MaybeUnwrapOr(obj.HasOwnProperty(jsKey.Utf8Value().c_str()), false));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
Value HasOwnPropertyWithCppStyleString(const CallbackInfo& info) {
|
|
30
|
-
Object obj = info[0].As<Object>();
|
|
31
|
-
String jsKey = info[1].As<String>();
|
|
32
|
-
return Boolean::New(
|
|
33
|
-
info.Env(), MaybeUnwrapOr(obj.HasOwnProperty(jsKey.Utf8Value()), false));
|
|
34
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const assert = require('assert');
|
|
4
|
-
|
|
5
|
-
module.exports = require('../common').runTest(test);
|
|
6
|
-
|
|
7
|
-
function test(binding) {
|
|
8
|
-
function testHasOwnProperty(nativeHasOwnProperty) {
|
|
9
|
-
const obj = { one: 1 };
|
|
10
|
-
|
|
11
|
-
Object.defineProperty(obj, 'two', { value: 2 });
|
|
12
|
-
|
|
13
|
-
assert.strictEqual(nativeHasOwnProperty(obj, 'one'), true);
|
|
14
|
-
assert.strictEqual(nativeHasOwnProperty(obj, 'two'), true);
|
|
15
|
-
assert.strictEqual('toString' in obj, true);
|
|
16
|
-
assert.strictEqual(nativeHasOwnProperty(obj, 'toString'), false);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function testShouldThrowErrorIfKeyIsInvalid(nativeHasOwnProperty) {
|
|
20
|
-
assert.throws(() => {
|
|
21
|
-
nativeHasOwnProperty(undefined, 'test');
|
|
22
|
-
}, /Cannot convert undefined or null to object/);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
testHasOwnProperty(binding.object.hasOwnPropertyWithNapiValue);
|
|
26
|
-
testHasOwnProperty(binding.object.hasOwnPropertyWithNapiWrapperValue);
|
|
27
|
-
testHasOwnProperty(binding.object.hasOwnPropertyWithCStyleString);
|
|
28
|
-
testHasOwnProperty(binding.object.hasOwnPropertyWithCppStyleString);
|
|
29
|
-
|
|
30
|
-
testShouldThrowErrorIfKeyIsInvalid(binding.object.hasOwnPropertyWithNapiValue);
|
|
31
|
-
testShouldThrowErrorIfKeyIsInvalid(binding.object.hasOwnPropertyWithNapiWrapperValue);
|
|
32
|
-
testShouldThrowErrorIfKeyIsInvalid(binding.object.hasOwnPropertyWithCStyleString);
|
|
33
|
-
testShouldThrowErrorIfKeyIsInvalid(binding.object.hasOwnPropertyWithCppStyleString);
|
|
34
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
#include "napi.h"
|
|
2
|
-
#include "test_helper.h"
|
|
3
|
-
|
|
4
|
-
using namespace Napi;
|
|
5
|
-
|
|
6
|
-
Value HasPropertyWithNapiValue(const CallbackInfo& info) {
|
|
7
|
-
Object obj = info[0].As<Object>();
|
|
8
|
-
Name key = info[1].As<Name>();
|
|
9
|
-
return Boolean::New(
|
|
10
|
-
info.Env(), MaybeUnwrapOr(obj.Has(static_cast<napi_value>(key)), false));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
Value HasPropertyWithNapiWrapperValue(const CallbackInfo& info) {
|
|
14
|
-
Object obj = info[0].As<Object>();
|
|
15
|
-
Name key = info[1].As<Name>();
|
|
16
|
-
return Boolean::New(info.Env(), MaybeUnwrapOr(obj.Has(key), false));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
Value HasPropertyWithCStyleString(const CallbackInfo& info) {
|
|
20
|
-
Object obj = info[0].As<Object>();
|
|
21
|
-
String jsKey = info[1].As<String>();
|
|
22
|
-
return Boolean::New(info.Env(),
|
|
23
|
-
MaybeUnwrapOr(obj.Has(jsKey.Utf8Value().c_str()), false));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
Value HasPropertyWithUint32(const CallbackInfo& info) {
|
|
27
|
-
Object obj = info[0].As<Object>();
|
|
28
|
-
Number jsKey = info[1].As<Number>();
|
|
29
|
-
return Boolean::New(info.Env(),
|
|
30
|
-
MaybeUnwrapOr(obj.Has(jsKey.Uint32Value()), false));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
Value HasPropertyWithCppStyleString(const CallbackInfo& info) {
|
|
34
|
-
Object obj = info[0].As<Object>();
|
|
35
|
-
String jsKey = info[1].As<String>();
|
|
36
|
-
return Boolean::New(info.Env(),
|
|
37
|
-
MaybeUnwrapOr(obj.Has(jsKey.Utf8Value()), false));
|
|
38
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const assert = require('assert');
|
|
4
|
-
|
|
5
|
-
module.exports = require('../common').runTest(test);
|
|
6
|
-
|
|
7
|
-
function test(binding) {
|
|
8
|
-
function testHasProperty(nativeHasProperty) {
|
|
9
|
-
const obj = { one: 1 };
|
|
10
|
-
|
|
11
|
-
Object.defineProperty(obj, 'two', { value: 2 });
|
|
12
|
-
|
|
13
|
-
assert.strictEqual(nativeHasProperty(obj, 'one'), true);
|
|
14
|
-
assert.strictEqual(nativeHasProperty(obj, 'two'), true);
|
|
15
|
-
assert.strictEqual('toString' in obj, true);
|
|
16
|
-
assert.strictEqual(nativeHasProperty(obj, 'toString'), true);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function testShouldThrowErrorIfKeyIsInvalid(nativeHasProperty) {
|
|
20
|
-
assert.throws(() => {
|
|
21
|
-
nativeHasProperty(undefined, 'test');
|
|
22
|
-
}, /Cannot convert undefined or null to object/);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const objectWithInt32Key = { 12: 101 };
|
|
26
|
-
assert.strictEqual(binding.object.hasPropertyWithUint32(objectWithInt32Key,12),true);
|
|
27
|
-
|
|
28
|
-
testHasProperty(binding.object.hasPropertyWithNapiValue);
|
|
29
|
-
testHasProperty(binding.object.hasPropertyWithNapiWrapperValue);
|
|
30
|
-
testHasProperty(binding.object.hasPropertyWithCStyleString);
|
|
31
|
-
testHasProperty(binding.object.hasPropertyWithCppStyleString);
|
|
32
|
-
|
|
33
|
-
testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithNapiValue);
|
|
34
|
-
testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithNapiWrapperValue);
|
|
35
|
-
testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithCStyleString);
|
|
36
|
-
testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithCppStyleString);
|
|
37
|
-
}
|
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
#include "napi.h"
|
|
2
|
-
#include "test_helper.h"
|
|
3
|
-
|
|
4
|
-
using namespace Napi;
|
|
5
|
-
|
|
6
|
-
// Native wrappers for testing Object::Get()
|
|
7
|
-
Value GetPropertyWithUint32(const CallbackInfo& info);
|
|
8
|
-
Value GetPropertyWithNapiValue(const CallbackInfo& info);
|
|
9
|
-
Value GetPropertyWithNapiWrapperValue(const CallbackInfo& info);
|
|
10
|
-
Value GetPropertyWithCStyleString(const CallbackInfo& info);
|
|
11
|
-
Value GetPropertyWithCppStyleString(const CallbackInfo& info);
|
|
12
|
-
|
|
13
|
-
// Native wrappers for testing Object::Set()
|
|
14
|
-
Value SetPropertyWithUint32(const CallbackInfo& info);
|
|
15
|
-
Value SetPropertyWithNapiValue(const CallbackInfo& info);
|
|
16
|
-
Value SetPropertyWithNapiWrapperValue(const CallbackInfo& info);
|
|
17
|
-
Value SetPropertyWithCStyleString(const CallbackInfo& info);
|
|
18
|
-
Value SetPropertyWithCppStyleString(const CallbackInfo& info);
|
|
19
|
-
|
|
20
|
-
// Native wrappers for testing Object::Delete()
|
|
21
|
-
Value DeletePropertyWithUint32(const CallbackInfo& info);
|
|
22
|
-
Value DeletePropertyWithNapiValue(const CallbackInfo& info);
|
|
23
|
-
Value DeletePropertyWithNapiWrapperValue(const CallbackInfo& info);
|
|
24
|
-
Value DeletePropertyWithCStyleString(const CallbackInfo& info);
|
|
25
|
-
Value DeletePropertyWithCppStyleString(const CallbackInfo& info);
|
|
26
|
-
|
|
27
|
-
// Native wrappers for testing Object::HasOwnProperty()
|
|
28
|
-
Value HasOwnPropertyWithNapiValue(const CallbackInfo& info);
|
|
29
|
-
Value HasOwnPropertyWithNapiWrapperValue(const CallbackInfo& info);
|
|
30
|
-
Value HasOwnPropertyWithCStyleString(const CallbackInfo& info);
|
|
31
|
-
Value HasOwnPropertyWithCppStyleString(const CallbackInfo& info);
|
|
32
|
-
|
|
33
|
-
// Native wrappers for testing Object::Has()
|
|
34
|
-
Value HasPropertyWithUint32(const CallbackInfo& info);
|
|
35
|
-
Value HasPropertyWithNapiValue(const CallbackInfo& info);
|
|
36
|
-
Value HasPropertyWithNapiWrapperValue(const CallbackInfo& info);
|
|
37
|
-
Value HasPropertyWithCStyleString(const CallbackInfo& info);
|
|
38
|
-
Value HasPropertyWithCppStyleString(const CallbackInfo& info);
|
|
39
|
-
|
|
40
|
-
// Native wrappers for testing Object::AddFinalizer()
|
|
41
|
-
Value AddFinalizer(const CallbackInfo& info);
|
|
42
|
-
Value AddFinalizerWithHint(const CallbackInfo& info);
|
|
43
|
-
|
|
44
|
-
// Native wrappers for testing Object::operator []
|
|
45
|
-
Value SubscriptGetWithCStyleString(const CallbackInfo& info);
|
|
46
|
-
Value SubscriptGetWithCppStyleString(const CallbackInfo& info);
|
|
47
|
-
Value SubscriptGetAtIndex(const CallbackInfo& info);
|
|
48
|
-
void SubscriptSetWithCStyleString(const CallbackInfo& info);
|
|
49
|
-
void SubscriptSetWithCppStyleString(const CallbackInfo& info);
|
|
50
|
-
void SubscriptSetAtIndex(const CallbackInfo& info);
|
|
51
|
-
|
|
52
|
-
static bool testValue = true;
|
|
53
|
-
// Used to test void* Data() integrity
|
|
54
|
-
struct UserDataHolder {
|
|
55
|
-
int32_t value;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
Value TestGetter(const CallbackInfo& info) {
|
|
59
|
-
return Boolean::New(info.Env(), testValue);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
void TestSetter(const CallbackInfo& info) {
|
|
63
|
-
testValue = info[0].As<Boolean>();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
Value TestGetterWithUserData(const CallbackInfo& info) {
|
|
67
|
-
const UserDataHolder* holder = reinterpret_cast<UserDataHolder*>(info.Data());
|
|
68
|
-
return Number::New(info.Env(), holder->value);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
void TestSetterWithUserData(const CallbackInfo& info) {
|
|
72
|
-
UserDataHolder* holder = reinterpret_cast<UserDataHolder*>(info.Data());
|
|
73
|
-
holder->value = info[0].As<Number>().Int32Value();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
Value TestFunction(const CallbackInfo& info) {
|
|
77
|
-
return Boolean::New(info.Env(), true);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
Value TestFunctionWithUserData(const CallbackInfo& info) {
|
|
81
|
-
UserDataHolder* holder = reinterpret_cast<UserDataHolder*>(info.Data());
|
|
82
|
-
return Number::New(info.Env(), holder->value);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
Value EmptyConstructor(const CallbackInfo& info) {
|
|
86
|
-
auto env = info.Env();
|
|
87
|
-
bool isEmpty = info[0].As<Boolean>();
|
|
88
|
-
Object object = isEmpty ? Object() : Object(env, Object::New(env));
|
|
89
|
-
return Boolean::New(env, object.IsEmpty());
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
Value ConstructorFromObject(const CallbackInfo& info) {
|
|
93
|
-
auto env = info.Env();
|
|
94
|
-
Object object = info[0].As<Object>();
|
|
95
|
-
return Object(env, object);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
Array GetPropertyNames(const CallbackInfo& info) {
|
|
99
|
-
Object obj = info[0].As<Object>();
|
|
100
|
-
Array arr = MaybeUnwrap(obj.GetPropertyNames());
|
|
101
|
-
return arr;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
void DefineProperties(const CallbackInfo& info) {
|
|
105
|
-
Object obj = info[0].As<Object>();
|
|
106
|
-
String nameType = info[1].As<String>();
|
|
107
|
-
Env env = info.Env();
|
|
108
|
-
|
|
109
|
-
Boolean trueValue = Boolean::New(env, true);
|
|
110
|
-
UserDataHolder* holder = new UserDataHolder();
|
|
111
|
-
holder->value = 1234;
|
|
112
|
-
|
|
113
|
-
if (nameType.Utf8Value() == "literal") {
|
|
114
|
-
obj.DefineProperties({
|
|
115
|
-
PropertyDescriptor::Accessor(env, obj, "readonlyAccessor", TestGetter),
|
|
116
|
-
PropertyDescriptor::Accessor(env, obj, "readwriteAccessor", TestGetter, TestSetter),
|
|
117
|
-
PropertyDescriptor::Accessor(env, obj, "readonlyAccessorWithUserData", TestGetterWithUserData, napi_property_attributes::napi_default, reinterpret_cast<void*>(holder)),
|
|
118
|
-
PropertyDescriptor::Accessor(env, obj, "readwriteAccessorWithUserData", TestGetterWithUserData, TestSetterWithUserData, napi_property_attributes::napi_default, reinterpret_cast<void*>(holder)),
|
|
119
|
-
|
|
120
|
-
PropertyDescriptor::Accessor<TestGetter>("readonlyAccessorT"),
|
|
121
|
-
PropertyDescriptor::Accessor<TestGetter, TestSetter>(
|
|
122
|
-
"readwriteAccessorT"),
|
|
123
|
-
PropertyDescriptor::Accessor<TestGetterWithUserData>(
|
|
124
|
-
"readonlyAccessorWithUserDataT",
|
|
125
|
-
napi_property_attributes::napi_default,
|
|
126
|
-
reinterpret_cast<void*>(holder)),
|
|
127
|
-
PropertyDescriptor::Accessor<
|
|
128
|
-
TestGetterWithUserData,
|
|
129
|
-
TestSetterWithUserData>("readwriteAccessorWithUserDataT",
|
|
130
|
-
napi_property_attributes::napi_default,
|
|
131
|
-
reinterpret_cast<void*>(holder)),
|
|
132
|
-
|
|
133
|
-
PropertyDescriptor::Value("readonlyValue", trueValue),
|
|
134
|
-
PropertyDescriptor::Value("readwriteValue", trueValue, napi_writable),
|
|
135
|
-
PropertyDescriptor::Value("enumerableValue", trueValue, napi_enumerable),
|
|
136
|
-
PropertyDescriptor::Value("configurableValue", trueValue, napi_configurable),
|
|
137
|
-
PropertyDescriptor::Function(env, obj, "function", TestFunction),
|
|
138
|
-
PropertyDescriptor::Function(env, obj, "functionWithUserData", TestFunctionWithUserData, napi_property_attributes::napi_default, reinterpret_cast<void*>(holder)),
|
|
139
|
-
});
|
|
140
|
-
} else if (nameType.Utf8Value() == "string") {
|
|
141
|
-
// VS2013 has lifetime issues when passing temporary objects into the constructor of another
|
|
142
|
-
// object. It generates code to destruct the object as soon as the constructor call returns.
|
|
143
|
-
// Since this isn't a common case for using std::string objects, I'm refactoring the test to
|
|
144
|
-
// work around the issue.
|
|
145
|
-
std::string str1("readonlyAccessor");
|
|
146
|
-
std::string str2("readwriteAccessor");
|
|
147
|
-
std::string str1a("readonlyAccessorWithUserData");
|
|
148
|
-
std::string str2a("readwriteAccessorWithUserData");
|
|
149
|
-
|
|
150
|
-
std::string str1t("readonlyAccessorT");
|
|
151
|
-
std::string str2t("readwriteAccessorT");
|
|
152
|
-
std::string str1at("readonlyAccessorWithUserDataT");
|
|
153
|
-
std::string str2at("readwriteAccessorWithUserDataT");
|
|
154
|
-
|
|
155
|
-
std::string str3("readonlyValue");
|
|
156
|
-
std::string str4("readwriteValue");
|
|
157
|
-
std::string str5("enumerableValue");
|
|
158
|
-
std::string str6("configurableValue");
|
|
159
|
-
std::string str7("function");
|
|
160
|
-
std::string str8("functionWithUserData");
|
|
161
|
-
|
|
162
|
-
obj.DefineProperties({
|
|
163
|
-
PropertyDescriptor::Accessor(env, obj, str1, TestGetter),
|
|
164
|
-
PropertyDescriptor::Accessor(env, obj, str2, TestGetter, TestSetter),
|
|
165
|
-
PropertyDescriptor::Accessor(env, obj, str1a, TestGetterWithUserData, napi_property_attributes::napi_default, reinterpret_cast<void*>(holder)),
|
|
166
|
-
PropertyDescriptor::Accessor(env, obj, str2a, TestGetterWithUserData, TestSetterWithUserData, napi_property_attributes::napi_default, reinterpret_cast<void*>(holder)),
|
|
167
|
-
|
|
168
|
-
PropertyDescriptor::Accessor<TestGetter>(str1t),
|
|
169
|
-
PropertyDescriptor::Accessor<TestGetter, TestSetter>(str2t),
|
|
170
|
-
PropertyDescriptor::Accessor<TestGetterWithUserData>(str1at,
|
|
171
|
-
napi_property_attributes::napi_default,
|
|
172
|
-
reinterpret_cast<void*>(holder)),
|
|
173
|
-
PropertyDescriptor::Accessor<
|
|
174
|
-
TestGetterWithUserData,
|
|
175
|
-
TestSetterWithUserData>(str2at,
|
|
176
|
-
napi_property_attributes::napi_default,
|
|
177
|
-
reinterpret_cast<void*>(holder)),
|
|
178
|
-
|
|
179
|
-
PropertyDescriptor::Value(str3, trueValue),
|
|
180
|
-
PropertyDescriptor::Value(str4, trueValue, napi_writable),
|
|
181
|
-
PropertyDescriptor::Value(str5, trueValue, napi_enumerable),
|
|
182
|
-
PropertyDescriptor::Value(str6, trueValue, napi_configurable),
|
|
183
|
-
PropertyDescriptor::Function(env, obj, str7, TestFunction),
|
|
184
|
-
PropertyDescriptor::Function(env, obj, str8, TestFunctionWithUserData, napi_property_attributes::napi_default, reinterpret_cast<void*>(holder)),
|
|
185
|
-
});
|
|
186
|
-
} else if (nameType.Utf8Value() == "value") {
|
|
187
|
-
obj.DefineProperties({
|
|
188
|
-
PropertyDescriptor::Accessor(env, obj,
|
|
189
|
-
Napi::String::New(env, "readonlyAccessor"), TestGetter),
|
|
190
|
-
PropertyDescriptor::Accessor(env, obj,
|
|
191
|
-
Napi::String::New(env, "readwriteAccessor"), TestGetter, TestSetter),
|
|
192
|
-
PropertyDescriptor::Accessor(env, obj,
|
|
193
|
-
Napi::String::New(env, "readonlyAccessorWithUserData"), TestGetterWithUserData, napi_property_attributes::napi_default, reinterpret_cast<void*>(holder)),
|
|
194
|
-
PropertyDescriptor::Accessor(env, obj,
|
|
195
|
-
Napi::String::New(env, "readwriteAccessorWithUserData"), TestGetterWithUserData, TestSetterWithUserData, napi_property_attributes::napi_default, reinterpret_cast<void*>(holder)),
|
|
196
|
-
|
|
197
|
-
PropertyDescriptor::Accessor<TestGetter>(
|
|
198
|
-
Napi::String::New(env, "readonlyAccessorT")),
|
|
199
|
-
PropertyDescriptor::Accessor<TestGetter, TestSetter>(
|
|
200
|
-
Napi::String::New(env, "readwriteAccessorT")),
|
|
201
|
-
PropertyDescriptor::Accessor<TestGetterWithUserData>(
|
|
202
|
-
Napi::String::New(env, "readonlyAccessorWithUserDataT"),
|
|
203
|
-
napi_property_attributes::napi_default,
|
|
204
|
-
reinterpret_cast<void*>(holder)),
|
|
205
|
-
PropertyDescriptor::Accessor<
|
|
206
|
-
TestGetterWithUserData, TestSetterWithUserData>(
|
|
207
|
-
Napi::String::New(env, "readwriteAccessorWithUserDataT"),
|
|
208
|
-
napi_property_attributes::napi_default,
|
|
209
|
-
reinterpret_cast<void*>(holder)),
|
|
210
|
-
|
|
211
|
-
PropertyDescriptor::Value(
|
|
212
|
-
Napi::String::New(env, "readonlyValue"), trueValue),
|
|
213
|
-
PropertyDescriptor::Value(
|
|
214
|
-
Napi::String::New(env, "readwriteValue"), trueValue, napi_writable),
|
|
215
|
-
PropertyDescriptor::Value(
|
|
216
|
-
Napi::String::New(env, "enumerableValue"), trueValue, napi_enumerable),
|
|
217
|
-
PropertyDescriptor::Value(
|
|
218
|
-
Napi::String::New(env, "configurableValue"), trueValue, napi_configurable),
|
|
219
|
-
PropertyDescriptor::Function(env, obj,
|
|
220
|
-
Napi::String::New(env, "function"), TestFunction),
|
|
221
|
-
PropertyDescriptor::Function(env, obj,
|
|
222
|
-
Napi::String::New(env, "functionWithUserData"), TestFunctionWithUserData, napi_property_attributes::napi_default, reinterpret_cast<void*>(holder)),
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
void DefineValueProperty(const CallbackInfo& info) {
|
|
228
|
-
Object obj = info[0].As<Object>();
|
|
229
|
-
Name name = info[1].As<Name>();
|
|
230
|
-
Value value = info[2];
|
|
231
|
-
|
|
232
|
-
obj.DefineProperty(PropertyDescriptor::Value(name, value));
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
Value CreateObjectUsingMagic(const CallbackInfo& info) {
|
|
236
|
-
Env env = info.Env();
|
|
237
|
-
Object obj = Object::New(env);
|
|
238
|
-
obj["cp_false"] = false;
|
|
239
|
-
obj["cp_true"] = true;
|
|
240
|
-
obj[std::string("s_true")] = true;
|
|
241
|
-
obj[std::string("s_false")] = false;
|
|
242
|
-
obj["0"] = 0;
|
|
243
|
-
obj[(uint32_t)42] = 120;
|
|
244
|
-
obj["0.0f"] = 0.0f;
|
|
245
|
-
obj["0.0"] = 0.0;
|
|
246
|
-
obj["-1"] = -1;
|
|
247
|
-
obj["foo2"] = u"foo";
|
|
248
|
-
obj[std::string("foo4")] = NAPI_WIDE_TEXT("foo");
|
|
249
|
-
obj[std::string("foo5")] = "foo";
|
|
250
|
-
obj[std::string("foo6")] = std::u16string(NAPI_WIDE_TEXT("foo"));
|
|
251
|
-
obj[std::string("foo7")] = std::string("foo");
|
|
252
|
-
obj[std::string("circular")] = obj;
|
|
253
|
-
obj["circular2"] = obj;
|
|
254
|
-
return obj;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
#ifdef NAPI_CPP_EXCEPTIONS
|
|
258
|
-
Value Sum(const CallbackInfo& info) {
|
|
259
|
-
Object object = info[0].As<Object>();
|
|
260
|
-
int64_t sum = 0;
|
|
261
|
-
|
|
262
|
-
for (const auto& e : object) {
|
|
263
|
-
sum += static_cast<Value>(e.second).As<Number>().Int64Value();
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
return Number::New(info.Env(), sum);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
void Increment(const CallbackInfo& info) {
|
|
270
|
-
Env env = info.Env();
|
|
271
|
-
Object object = info[0].As<Object>();
|
|
272
|
-
|
|
273
|
-
for (auto e : object) {
|
|
274
|
-
int64_t value = static_cast<Value>(e.second).As<Number>().Int64Value();
|
|
275
|
-
++value;
|
|
276
|
-
e.second = Napi::Number::New(env, value);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
#endif // NAPI_CPP_EXCEPTIONS
|
|
280
|
-
|
|
281
|
-
Value InstanceOf(const CallbackInfo& info) {
|
|
282
|
-
Object obj = info[0].As<Object>();
|
|
283
|
-
Function constructor = info[1].As<Function>();
|
|
284
|
-
return Boolean::New(info.Env(), MaybeUnwrap(obj.InstanceOf(constructor)));
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
Object InitObject(Env env) {
|
|
288
|
-
Object exports = Object::New(env);
|
|
289
|
-
|
|
290
|
-
exports["emptyConstructor"] = Function::New(env, EmptyConstructor);
|
|
291
|
-
exports["constructorFromObject"] = Function::New(env, ConstructorFromObject);
|
|
292
|
-
|
|
293
|
-
exports["GetPropertyNames"] = Function::New(env, GetPropertyNames);
|
|
294
|
-
exports["defineProperties"] = Function::New(env, DefineProperties);
|
|
295
|
-
exports["defineValueProperty"] = Function::New(env, DefineValueProperty);
|
|
296
|
-
|
|
297
|
-
exports["getPropertyWithUint32"] = Function::New(env, GetPropertyWithUint32);
|
|
298
|
-
exports["getPropertyWithNapiValue"] = Function::New(env, GetPropertyWithNapiValue);
|
|
299
|
-
exports["getPropertyWithNapiWrapperValue"] = Function::New(env, GetPropertyWithNapiWrapperValue);
|
|
300
|
-
exports["getPropertyWithCStyleString"] = Function::New(env, GetPropertyWithCStyleString);
|
|
301
|
-
exports["getPropertyWithCppStyleString"] = Function::New(env, GetPropertyWithCppStyleString);
|
|
302
|
-
|
|
303
|
-
exports["setPropertyWithUint32"] = Function::New(env, SetPropertyWithUint32);
|
|
304
|
-
exports["setPropertyWithNapiValue"] = Function::New(env, SetPropertyWithNapiValue);
|
|
305
|
-
exports["setPropertyWithNapiWrapperValue"] = Function::New(env, SetPropertyWithNapiWrapperValue);
|
|
306
|
-
exports["setPropertyWithCStyleString"] = Function::New(env, SetPropertyWithCStyleString);
|
|
307
|
-
exports["setPropertyWithCppStyleString"] = Function::New(env, SetPropertyWithCppStyleString);
|
|
308
|
-
|
|
309
|
-
exports["deletePropertyWithUint32"] =
|
|
310
|
-
Function::New(env, DeletePropertyWithUint32);
|
|
311
|
-
exports["deletePropertyWithNapiValue"] = Function::New(env, DeletePropertyWithNapiValue);
|
|
312
|
-
exports["deletePropertyWithNapiWrapperValue"] = Function::New(env, DeletePropertyWithNapiWrapperValue);
|
|
313
|
-
exports["deletePropertyWithCStyleString"] = Function::New(env, DeletePropertyWithCStyleString);
|
|
314
|
-
exports["deletePropertyWithCppStyleString"] = Function::New(env, DeletePropertyWithCppStyleString);
|
|
315
|
-
|
|
316
|
-
exports["hasOwnPropertyWithNapiValue"] = Function::New(env, HasOwnPropertyWithNapiValue);
|
|
317
|
-
exports["hasOwnPropertyWithNapiWrapperValue"] = Function::New(env, HasOwnPropertyWithNapiWrapperValue);
|
|
318
|
-
exports["hasOwnPropertyWithCStyleString"] = Function::New(env, HasOwnPropertyWithCStyleString);
|
|
319
|
-
exports["hasOwnPropertyWithCppStyleString"] = Function::New(env, HasOwnPropertyWithCppStyleString);
|
|
320
|
-
|
|
321
|
-
exports["hasPropertyWithUint32"] = Function::New(env, HasPropertyWithUint32);
|
|
322
|
-
exports["hasPropertyWithNapiValue"] = Function::New(env, HasPropertyWithNapiValue);
|
|
323
|
-
exports["hasPropertyWithNapiWrapperValue"] = Function::New(env, HasPropertyWithNapiWrapperValue);
|
|
324
|
-
exports["hasPropertyWithCStyleString"] = Function::New(env, HasPropertyWithCStyleString);
|
|
325
|
-
exports["hasPropertyWithCppStyleString"] = Function::New(env, HasPropertyWithCppStyleString);
|
|
326
|
-
|
|
327
|
-
exports["createObjectUsingMagic"] = Function::New(env, CreateObjectUsingMagic);
|
|
328
|
-
#ifdef NAPI_CPP_EXCEPTIONS
|
|
329
|
-
exports["sum"] = Function::New(env, Sum);
|
|
330
|
-
exports["increment"] = Function::New(env, Increment);
|
|
331
|
-
#endif // NAPI_CPP_EXCEPTIONS
|
|
332
|
-
|
|
333
|
-
exports["addFinalizer"] = Function::New(env, AddFinalizer);
|
|
334
|
-
exports["addFinalizerWithHint"] = Function::New(env, AddFinalizerWithHint);
|
|
335
|
-
|
|
336
|
-
exports["instanceOf"] = Function::New(env, InstanceOf);
|
|
337
|
-
|
|
338
|
-
exports["subscriptGetWithCStyleString"] =
|
|
339
|
-
Function::New(env, SubscriptGetWithCStyleString);
|
|
340
|
-
exports["subscriptGetWithCppStyleString"] =
|
|
341
|
-
Function::New(env, SubscriptGetWithCppStyleString);
|
|
342
|
-
exports["subscriptGetAtIndex"] = Function::New(env, SubscriptGetAtIndex);
|
|
343
|
-
exports["subscriptSetWithCStyleString"] =
|
|
344
|
-
Function::New(env, SubscriptSetWithCStyleString);
|
|
345
|
-
exports["subscriptSetWithCppStyleString"] =
|
|
346
|
-
Function::New(env, SubscriptSetWithCppStyleString);
|
|
347
|
-
exports["subscriptSetAtIndex"] = Function::New(env, SubscriptSetAtIndex);
|
|
348
|
-
|
|
349
|
-
return exports;
|
|
350
|
-
}
|