-
Notifications
You must be signed in to change notification settings - Fork 471
/
Copy pathhas_property.js
37 lines (28 loc) · 1.39 KB
/
has_property.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
const assert = require('assert');
module.exports = require('../common').runTest(test);
function test (binding) {
function testHasProperty (nativeHasProperty) {
const obj = { one: 1 };
Object.defineProperty(obj, 'two', { value: 2 });
assert.strictEqual(nativeHasProperty(obj, 'one'), true);
assert.strictEqual(nativeHasProperty(obj, 'two'), true);
assert.strictEqual('toString' in obj, true);
assert.strictEqual(nativeHasProperty(obj, 'toString'), true);
}
function testShouldThrowErrorIfKeyIsInvalid (nativeHasProperty) {
assert.throws(() => {
nativeHasProperty(undefined, 'test');
}, /Cannot convert undefined or null to object/);
}
const objectWithInt32Key = { 12: 101 };
assert.strictEqual(binding.object.hasPropertyWithUint32(objectWithInt32Key, 12), true);
testHasProperty(binding.object.hasPropertyWithNapiValue);
testHasProperty(binding.object.hasPropertyWithNapiWrapperValue);
testHasProperty(binding.object.hasPropertyWithCStyleString);
testHasProperty(binding.object.hasPropertyWithCppStyleString);
testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithNapiValue);
testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithNapiWrapperValue);
testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithCStyleString);
testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithCppStyleString);
}