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); 17// eslint-disable-next-line no-prototype-builtins 18assert.deepStrictEqual(testNull.hasOwnProperty(), expectedForProperty); 19// It's OK not to want the result of a deletion. 20assert.deepStrictEqual(testNull.deleteProperty(), 21 Object.assign({}, 22 expectedForProperty, 23 { valueIsNull: 'napi_ok' })); 24assert.deepStrictEqual(testNull.setNamedProperty(), expectedForProperty); 25assert.deepStrictEqual(testNull.getNamedProperty(), expectedForProperty); 26assert.deepStrictEqual(testNull.hasNamedProperty(), expectedForProperty); 27 28const expectedForElement = { 29 envIsNull: 'Invalid argument', 30 objectIsNull: 'Invalid argument', 31 valueIsNull: 'Invalid argument', 32}; 33assert.deepStrictEqual(testNull.setElement(), expectedForElement); 34assert.deepStrictEqual(testNull.getElement(), expectedForElement); 35assert.deepStrictEqual(testNull.hasElement(), expectedForElement); 36// It's OK not to want the result of a deletion. 37assert.deepStrictEqual(testNull.deleteElement(), 38 Object.assign({}, 39 expectedForElement, 40 { valueIsNull: 'napi_ok' })); 41 42assert.deepStrictEqual(testNull.defineProperties(), { 43 envIsNull: 'Invalid argument', 44 objectIsNull: 'Invalid argument', 45 descriptorListIsNull: 'Invalid argument', 46 utf8nameIsNull: 'Invalid argument', 47 methodIsNull: 'Invalid argument', 48}); 49 50// `expectedForElement` also works for the APIs below. 51assert.deepStrictEqual(testNull.getPropertyNames(), expectedForElement); 52assert.deepStrictEqual(testNull.getAllPropertyNames(), expectedForElement); 53assert.deepStrictEqual(testNull.getPrototype(), expectedForElement); 54