|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const buildType = process.config.target_defaults.default_configuration; |
| 4 | +const assert = require('assert'); |
| 5 | + |
| 6 | +test(require(`../build/${buildType}/binding.node`)); |
| 7 | +test(require(`../build/${buildType}/binding_noexcept.node`)); |
| 8 | + |
| 9 | +function test(binding) { |
| 10 | + function testHasProperty(nativeHasProperty) { |
| 11 | + const obj = { one: 1 }; |
| 12 | + |
| 13 | + Object.defineProperty(obj, 'two', { value: 2 }); |
| 14 | + |
| 15 | + assert.strictEqual(nativeHasProperty(obj, 'one'), true); |
| 16 | + assert.strictEqual(nativeHasProperty(obj, 'two'), true); |
| 17 | + assert.strictEqual('toString' in obj, true); |
| 18 | + assert.strictEqual(nativeHasProperty(obj, 'toString'), true); |
| 19 | + } |
| 20 | + |
| 21 | + function testShouldThrowErrorIfKeyIsInvalid(nativeHasProperty) { |
| 22 | + assert.throws(() => { |
| 23 | + nativeHasProperty(undefined, 'test'); |
| 24 | + }, /object was expected/); |
| 25 | + } |
| 26 | + |
| 27 | + testHasProperty(binding.object.hasPropertyWithNapiValue); |
| 28 | + testHasProperty(binding.object.hasPropertyWithNapiWrapperValue); |
| 29 | + testHasProperty(binding.object.hasPropertyWithCStyleString); |
| 30 | + testHasProperty(binding.object.hasPropertyWithCppStyleString); |
| 31 | + |
| 32 | + testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithNapiValue); |
| 33 | + testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithNapiWrapperValue); |
| 34 | + testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithCStyleString); |
| 35 | + testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithCppStyleString); |
| 36 | +} |
0 commit comments