(binding)
| 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(Object.prototype.hasOwnProperty.call(testObj, 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 | } |
nothing calls this directly
no test coverage detected