• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../../common');
3const assert = require('assert');
4
5// Test passing NULL to object-related N-APIs.
6const { testNull } = require(`./build/${common.buildType}/test_object`);
7
8const expectedForProperty = {
9  envIsNull: 'Invalid argument',
10  objectIsNull: 'Invalid argument',
11  keyIsNull: 'Invalid argument',
12  valueIsNull: 'Invalid argument'
13};
14assert.deepStrictEqual(testNull.setProperty(), expectedForProperty);
15assert.deepStrictEqual(testNull.getProperty(), expectedForProperty);
16assert.deepStrictEqual(testNull.hasProperty(), expectedForProperty);
17assert.deepStrictEqual(testNull.hasOwnProperty(), expectedForProperty);
18// It's OK not to want the result of a deletion.
19assert.deepStrictEqual(testNull.deleteProperty(),
20                       Object.assign({},
21                                     expectedForProperty,
22                                     { valueIsNull: 'napi_ok' }));
23assert.deepStrictEqual(testNull.setNamedProperty(), expectedForProperty);
24assert.deepStrictEqual(testNull.getNamedProperty(), expectedForProperty);
25assert.deepStrictEqual(testNull.hasNamedProperty(), expectedForProperty);
26
27const expectedForElement = {
28  envIsNull: 'Invalid argument',
29  objectIsNull: 'Invalid argument',
30  valueIsNull: 'Invalid argument'
31};
32assert.deepStrictEqual(testNull.setElement(), expectedForElement);
33assert.deepStrictEqual(testNull.getElement(), expectedForElement);
34assert.deepStrictEqual(testNull.hasElement(), expectedForElement);
35// It's OK not to want the result of a deletion.
36assert.deepStrictEqual(testNull.deleteElement(),
37                       Object.assign({},
38                                     expectedForElement,
39                                     { valueIsNull: 'napi_ok' }));
40
41assert.deepStrictEqual(testNull.defineProperties(), {
42  envIsNull: 'Invalid argument',
43  objectIsNull: 'Invalid argument',
44  descriptorListIsNull: 'Invalid argument',
45  utf8nameIsNull: 'Invalid argument',
46  methodIsNull: 'Invalid argument',
47});
48
49// `expectedForElement` also works for the APIs below.
50assert.deepStrictEqual(testNull.getPropertyNames(), expectedForElement);
51assert.deepStrictEqual(testNull.getAllPropertyNames(), expectedForElement);
52assert.deepStrictEqual(testNull.getPrototype(), expectedForElement);
53