11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci// Testing api calls for objects 61cb0ef41Sopenharmony_ciconst test_object = require(`./build/${common.buildType}/test_object`); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst object = { 101cb0ef41Sopenharmony_ci hello: 'world', 111cb0ef41Sopenharmony_ci array: [ 121cb0ef41Sopenharmony_ci 1, 94, 'str', 12.321, { test: 'obj in arr' }, 131cb0ef41Sopenharmony_ci ], 141cb0ef41Sopenharmony_ci newObject: { 151cb0ef41Sopenharmony_ci test: 'obj in obj', 161cb0ef41Sopenharmony_ci }, 171cb0ef41Sopenharmony_ci}; 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciassert.strictEqual(test_object.Get(object, 'hello'), 'world'); 201cb0ef41Sopenharmony_ciassert.strictEqual(test_object.GetNamed(object, 'hello'), 'world'); 211cb0ef41Sopenharmony_ciassert.deepStrictEqual(test_object.Get(object, 'array'), 221cb0ef41Sopenharmony_ci [1, 94, 'str', 12.321, { test: 'obj in arr' }]); 231cb0ef41Sopenharmony_ciassert.deepStrictEqual(test_object.Get(object, 'newObject'), 241cb0ef41Sopenharmony_ci { test: 'obj in obj' }); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ciassert(test_object.Has(object, 'hello')); 271cb0ef41Sopenharmony_ciassert(test_object.HasNamed(object, 'hello')); 281cb0ef41Sopenharmony_ciassert(test_object.Has(object, 'array')); 291cb0ef41Sopenharmony_ciassert(test_object.Has(object, 'newObject')); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ciconst newObject = test_object.New(); 321cb0ef41Sopenharmony_ciassert(test_object.Has(newObject, 'test_number')); 331cb0ef41Sopenharmony_ciassert.strictEqual(newObject.test_number, 987654321); 341cb0ef41Sopenharmony_ciassert.strictEqual(newObject.test_string, 'test string'); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci{ 371cb0ef41Sopenharmony_ci // Verify that napi_get_property() walks the prototype chain. 381cb0ef41Sopenharmony_ci function MyObject() { 391cb0ef41Sopenharmony_ci this.foo = 42; 401cb0ef41Sopenharmony_ci this.bar = 43; 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci MyObject.prototype.bar = 44; 441cb0ef41Sopenharmony_ci MyObject.prototype.baz = 45; 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci const obj = new MyObject(); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci assert.strictEqual(test_object.Get(obj, 'foo'), 42); 491cb0ef41Sopenharmony_ci assert.strictEqual(test_object.Get(obj, 'bar'), 43); 501cb0ef41Sopenharmony_ci assert.strictEqual(test_object.Get(obj, 'baz'), 45); 511cb0ef41Sopenharmony_ci assert.strictEqual(test_object.Get(obj, 'toString'), 521cb0ef41Sopenharmony_ci Object.prototype.toString); 531cb0ef41Sopenharmony_ci} 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci{ 561cb0ef41Sopenharmony_ci // Verify that napi_has_own_property() fails if property is not a name. 571cb0ef41Sopenharmony_ci [true, false, null, undefined, {}, [], 0, 1, () => { }].forEach((value) => { 581cb0ef41Sopenharmony_ci assert.throws(() => { 591cb0ef41Sopenharmony_ci test_object.HasOwn({}, value); 601cb0ef41Sopenharmony_ci }, /^Error: A string or symbol was expected$/); 611cb0ef41Sopenharmony_ci }); 621cb0ef41Sopenharmony_ci} 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci{ 651cb0ef41Sopenharmony_ci // Verify that napi_has_own_property() does not walk the prototype chain. 661cb0ef41Sopenharmony_ci const symbol1 = Symbol(); 671cb0ef41Sopenharmony_ci const symbol2 = Symbol(); 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci function MyObject() { 701cb0ef41Sopenharmony_ci this.foo = 42; 711cb0ef41Sopenharmony_ci this.bar = 43; 721cb0ef41Sopenharmony_ci this[symbol1] = 44; 731cb0ef41Sopenharmony_ci } 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci MyObject.prototype.bar = 45; 761cb0ef41Sopenharmony_ci MyObject.prototype.baz = 46; 771cb0ef41Sopenharmony_ci MyObject.prototype[symbol2] = 47; 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci const obj = new MyObject(); 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci assert.strictEqual(test_object.HasOwn(obj, 'foo'), true); 821cb0ef41Sopenharmony_ci assert.strictEqual(test_object.HasOwn(obj, 'bar'), true); 831cb0ef41Sopenharmony_ci assert.strictEqual(test_object.HasOwn(obj, symbol1), true); 841cb0ef41Sopenharmony_ci assert.strictEqual(test_object.HasOwn(obj, 'baz'), false); 851cb0ef41Sopenharmony_ci assert.strictEqual(test_object.HasOwn(obj, 'toString'), false); 861cb0ef41Sopenharmony_ci assert.strictEqual(test_object.HasOwn(obj, symbol2), false); 871cb0ef41Sopenharmony_ci} 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ci{ 901cb0ef41Sopenharmony_ci // test_object.Inflate increases all properties by 1 911cb0ef41Sopenharmony_ci const cube = { 921cb0ef41Sopenharmony_ci x: 10, 931cb0ef41Sopenharmony_ci y: 10, 941cb0ef41Sopenharmony_ci z: 10, 951cb0ef41Sopenharmony_ci }; 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ci assert.deepStrictEqual(test_object.Inflate(cube), { x: 11, y: 11, z: 11 }); 981cb0ef41Sopenharmony_ci assert.deepStrictEqual(test_object.Inflate(cube), { x: 12, y: 12, z: 12 }); 991cb0ef41Sopenharmony_ci assert.deepStrictEqual(test_object.Inflate(cube), { x: 13, y: 13, z: 13 }); 1001cb0ef41Sopenharmony_ci cube.t = 13; 1011cb0ef41Sopenharmony_ci assert.deepStrictEqual( 1021cb0ef41Sopenharmony_ci test_object.Inflate(cube), { x: 14, y: 14, z: 14, t: 14 }); 1031cb0ef41Sopenharmony_ci 1041cb0ef41Sopenharmony_ci const sym1 = Symbol('1'); 1051cb0ef41Sopenharmony_ci const sym2 = Symbol('2'); 1061cb0ef41Sopenharmony_ci const sym3 = Symbol('3'); 1071cb0ef41Sopenharmony_ci const sym4 = Symbol('4'); 1081cb0ef41Sopenharmony_ci const object2 = { 1091cb0ef41Sopenharmony_ci [sym1]: '@@iterator', 1101cb0ef41Sopenharmony_ci [sym2]: sym3, 1111cb0ef41Sopenharmony_ci }; 1121cb0ef41Sopenharmony_ci 1131cb0ef41Sopenharmony_ci assert(test_object.Has(object2, sym1)); 1141cb0ef41Sopenharmony_ci assert(test_object.Has(object2, sym2)); 1151cb0ef41Sopenharmony_ci assert.strictEqual(test_object.Get(object2, sym1), '@@iterator'); 1161cb0ef41Sopenharmony_ci assert.strictEqual(test_object.Get(object2, sym2), sym3); 1171cb0ef41Sopenharmony_ci assert(test_object.Set(object2, 'string', 'value')); 1181cb0ef41Sopenharmony_ci assert(test_object.SetNamed(object2, 'named_string', 'value')); 1191cb0ef41Sopenharmony_ci assert(test_object.Set(object2, sym4, 123)); 1201cb0ef41Sopenharmony_ci assert(test_object.Has(object2, 'string')); 1211cb0ef41Sopenharmony_ci assert(test_object.HasNamed(object2, 'named_string')); 1221cb0ef41Sopenharmony_ci assert(test_object.Has(object2, sym4)); 1231cb0ef41Sopenharmony_ci assert.strictEqual(test_object.Get(object2, 'string'), 'value'); 1241cb0ef41Sopenharmony_ci assert.strictEqual(test_object.Get(object2, sym4), 123); 1251cb0ef41Sopenharmony_ci} 1261cb0ef41Sopenharmony_ci 1271cb0ef41Sopenharmony_ci{ 1281cb0ef41Sopenharmony_ci // Wrap a pointer in a JS object, then verify the pointer can be unwrapped. 1291cb0ef41Sopenharmony_ci const wrapper = {}; 1301cb0ef41Sopenharmony_ci test_object.Wrap(wrapper); 1311cb0ef41Sopenharmony_ci 1321cb0ef41Sopenharmony_ci assert(test_object.Unwrap(wrapper)); 1331cb0ef41Sopenharmony_ci} 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_ci{ 1361cb0ef41Sopenharmony_ci // Verify that wrapping doesn't break an object's prototype chain. 1371cb0ef41Sopenharmony_ci const wrapper = {}; 1381cb0ef41Sopenharmony_ci const protoA = { protoA: true }; 1391cb0ef41Sopenharmony_ci Object.setPrototypeOf(wrapper, protoA); 1401cb0ef41Sopenharmony_ci test_object.Wrap(wrapper); 1411cb0ef41Sopenharmony_ci 1421cb0ef41Sopenharmony_ci assert(test_object.Unwrap(wrapper)); 1431cb0ef41Sopenharmony_ci assert(wrapper.protoA); 1441cb0ef41Sopenharmony_ci} 1451cb0ef41Sopenharmony_ci 1461cb0ef41Sopenharmony_ci{ 1471cb0ef41Sopenharmony_ci // Verify the pointer can be unwrapped after inserting in the prototype chain. 1481cb0ef41Sopenharmony_ci const wrapper = {}; 1491cb0ef41Sopenharmony_ci const protoA = { protoA: true }; 1501cb0ef41Sopenharmony_ci Object.setPrototypeOf(wrapper, protoA); 1511cb0ef41Sopenharmony_ci test_object.Wrap(wrapper); 1521cb0ef41Sopenharmony_ci 1531cb0ef41Sopenharmony_ci const protoB = { protoB: true }; 1541cb0ef41Sopenharmony_ci Object.setPrototypeOf(protoB, Object.getPrototypeOf(wrapper)); 1551cb0ef41Sopenharmony_ci Object.setPrototypeOf(wrapper, protoB); 1561cb0ef41Sopenharmony_ci 1571cb0ef41Sopenharmony_ci assert(test_object.Unwrap(wrapper)); 1581cb0ef41Sopenharmony_ci assert(wrapper.protoA, true); 1591cb0ef41Sopenharmony_ci assert(wrapper.protoB, true); 1601cb0ef41Sopenharmony_ci} 1611cb0ef41Sopenharmony_ci 1621cb0ef41Sopenharmony_ci{ 1631cb0ef41Sopenharmony_ci // Verify that objects can be type-tagged and type-tag-checked. 1641cb0ef41Sopenharmony_ci const obj1 = test_object.TypeTaggedInstance(0); 1651cb0ef41Sopenharmony_ci const obj2 = test_object.TypeTaggedInstance(1); 1661cb0ef41Sopenharmony_ci const obj3 = test_object.TypeTaggedInstance(2); 1671cb0ef41Sopenharmony_ci const obj4 = test_object.TypeTaggedInstance(3); 1681cb0ef41Sopenharmony_ci const external = test_object.TypeTaggedExternal(2); 1691cb0ef41Sopenharmony_ci const plainExternal = test_object.PlainExternal(); 1701cb0ef41Sopenharmony_ci 1711cb0ef41Sopenharmony_ci // Verify that we do not allow type tag indices greater than the largest 1721cb0ef41Sopenharmony_ci // available index. 1731cb0ef41Sopenharmony_ci assert.throws(() => test_object.TypeTaggedInstance(39), { 1741cb0ef41Sopenharmony_ci name: 'RangeError', 1751cb0ef41Sopenharmony_ci message: 'Invalid type index', 1761cb0ef41Sopenharmony_ci }); 1771cb0ef41Sopenharmony_ci assert.throws(() => test_object.TypeTaggedExternal(39), { 1781cb0ef41Sopenharmony_ci name: 'RangeError', 1791cb0ef41Sopenharmony_ci message: 'Invalid type index', 1801cb0ef41Sopenharmony_ci }); 1811cb0ef41Sopenharmony_ci 1821cb0ef41Sopenharmony_ci // Verify that type tags are correctly accepted. 1831cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(0, obj1), true); 1841cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(1, obj2), true); 1851cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(2, obj3), true); 1861cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(3, obj4), true); 1871cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(2, external), true); 1881cb0ef41Sopenharmony_ci 1891cb0ef41Sopenharmony_ci // Verify that wrongly tagged objects are rejected. 1901cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(0, obj2), false); 1911cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(1, obj1), false); 1921cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(0, obj3), false); 1931cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(1, obj4), false); 1941cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(2, obj4), false); 1951cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(3, obj3), false); 1961cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(4, obj3), false); 1971cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(0, external), false); 1981cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(1, external), false); 1991cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(3, external), false); 2001cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(4, external), false); 2011cb0ef41Sopenharmony_ci 2021cb0ef41Sopenharmony_ci // Verify that untagged objects are rejected. 2031cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(0, {}), false); 2041cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(1, {}), false); 2051cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(0, plainExternal), false); 2061cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(1, plainExternal), false); 2071cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(2, plainExternal), false); 2081cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(3, plainExternal), false); 2091cb0ef41Sopenharmony_ci assert.strictEqual(test_object.CheckTypeTag(4, plainExternal), false); 2101cb0ef41Sopenharmony_ci} 2111cb0ef41Sopenharmony_ci 2121cb0ef41Sopenharmony_ci{ 2131cb0ef41Sopenharmony_ci // Verify that normal and nonexistent properties can be deleted. 2141cb0ef41Sopenharmony_ci const sym = Symbol(); 2151cb0ef41Sopenharmony_ci const obj = { foo: 'bar', [sym]: 'baz' }; 2161cb0ef41Sopenharmony_ci 2171cb0ef41Sopenharmony_ci assert.strictEqual('foo' in obj, true); 2181cb0ef41Sopenharmony_ci assert.strictEqual(sym in obj, true); 2191cb0ef41Sopenharmony_ci assert.strictEqual('does_not_exist' in obj, false); 2201cb0ef41Sopenharmony_ci assert.strictEqual(test_object.Delete(obj, 'foo'), true); 2211cb0ef41Sopenharmony_ci assert.strictEqual('foo' in obj, false); 2221cb0ef41Sopenharmony_ci assert.strictEqual(sym in obj, true); 2231cb0ef41Sopenharmony_ci assert.strictEqual('does_not_exist' in obj, false); 2241cb0ef41Sopenharmony_ci assert.strictEqual(test_object.Delete(obj, sym), true); 2251cb0ef41Sopenharmony_ci assert.strictEqual('foo' in obj, false); 2261cb0ef41Sopenharmony_ci assert.strictEqual(sym in obj, false); 2271cb0ef41Sopenharmony_ci assert.strictEqual('does_not_exist' in obj, false); 2281cb0ef41Sopenharmony_ci} 2291cb0ef41Sopenharmony_ci 2301cb0ef41Sopenharmony_ci{ 2311cb0ef41Sopenharmony_ci // Verify that non-configurable properties are not deleted. 2321cb0ef41Sopenharmony_ci const obj = {}; 2331cb0ef41Sopenharmony_ci 2341cb0ef41Sopenharmony_ci Object.defineProperty(obj, 'foo', { configurable: false }); 2351cb0ef41Sopenharmony_ci assert.strictEqual(test_object.Delete(obj, 'foo'), false); 2361cb0ef41Sopenharmony_ci assert.strictEqual('foo' in obj, true); 2371cb0ef41Sopenharmony_ci} 2381cb0ef41Sopenharmony_ci 2391cb0ef41Sopenharmony_ci{ 2401cb0ef41Sopenharmony_ci // Verify that prototype properties are not deleted. 2411cb0ef41Sopenharmony_ci function Foo() { 2421cb0ef41Sopenharmony_ci this.foo = 'bar'; 2431cb0ef41Sopenharmony_ci } 2441cb0ef41Sopenharmony_ci 2451cb0ef41Sopenharmony_ci Foo.prototype.foo = 'baz'; 2461cb0ef41Sopenharmony_ci 2471cb0ef41Sopenharmony_ci const obj = new Foo(); 2481cb0ef41Sopenharmony_ci 2491cb0ef41Sopenharmony_ci assert.strictEqual(obj.foo, 'bar'); 2501cb0ef41Sopenharmony_ci assert.strictEqual(test_object.Delete(obj, 'foo'), true); 2511cb0ef41Sopenharmony_ci assert.strictEqual(obj.foo, 'baz'); 2521cb0ef41Sopenharmony_ci assert.strictEqual(test_object.Delete(obj, 'foo'), true); 2531cb0ef41Sopenharmony_ci assert.strictEqual(obj.foo, 'baz'); 2541cb0ef41Sopenharmony_ci} 2551cb0ef41Sopenharmony_ci 2561cb0ef41Sopenharmony_ci{ 2571cb0ef41Sopenharmony_ci // Verify that napi_get_property_names gets the right set of property names, 2581cb0ef41Sopenharmony_ci // i.e.: includes prototypes, only enumerable properties, skips symbols, 2591cb0ef41Sopenharmony_ci // and includes indices and converts them to strings. 2601cb0ef41Sopenharmony_ci 2611cb0ef41Sopenharmony_ci const object = Object.create({ 2621cb0ef41Sopenharmony_ci inherited: 1, 2631cb0ef41Sopenharmony_ci }); 2641cb0ef41Sopenharmony_ci 2651cb0ef41Sopenharmony_ci const fooSymbol = Symbol('foo'); 2661cb0ef41Sopenharmony_ci 2671cb0ef41Sopenharmony_ci object.normal = 2; 2681cb0ef41Sopenharmony_ci object[fooSymbol] = 3; 2691cb0ef41Sopenharmony_ci Object.defineProperty(object, 'unenumerable', { 2701cb0ef41Sopenharmony_ci value: 4, 2711cb0ef41Sopenharmony_ci enumerable: false, 2721cb0ef41Sopenharmony_ci writable: true, 2731cb0ef41Sopenharmony_ci configurable: true, 2741cb0ef41Sopenharmony_ci }); 2751cb0ef41Sopenharmony_ci Object.defineProperty(object, 'writable', { 2761cb0ef41Sopenharmony_ci value: 4, 2771cb0ef41Sopenharmony_ci enumerable: true, 2781cb0ef41Sopenharmony_ci writable: true, 2791cb0ef41Sopenharmony_ci configurable: false, 2801cb0ef41Sopenharmony_ci }); 2811cb0ef41Sopenharmony_ci Object.defineProperty(object, 'configurable', { 2821cb0ef41Sopenharmony_ci value: 4, 2831cb0ef41Sopenharmony_ci enumerable: true, 2841cb0ef41Sopenharmony_ci writable: false, 2851cb0ef41Sopenharmony_ci configurable: true, 2861cb0ef41Sopenharmony_ci }); 2871cb0ef41Sopenharmony_ci object[5] = 5; 2881cb0ef41Sopenharmony_ci 2891cb0ef41Sopenharmony_ci assert.deepStrictEqual(test_object.GetPropertyNames(object), 2901cb0ef41Sopenharmony_ci ['5', 2911cb0ef41Sopenharmony_ci 'normal', 2921cb0ef41Sopenharmony_ci 'writable', 2931cb0ef41Sopenharmony_ci 'configurable', 2941cb0ef41Sopenharmony_ci 'inherited']); 2951cb0ef41Sopenharmony_ci 2961cb0ef41Sopenharmony_ci assert.deepStrictEqual(test_object.GetSymbolNames(object), 2971cb0ef41Sopenharmony_ci [fooSymbol]); 2981cb0ef41Sopenharmony_ci 2991cb0ef41Sopenharmony_ci assert.deepStrictEqual(test_object.GetEnumerableWritableNames(object), 3001cb0ef41Sopenharmony_ci ['5', 3011cb0ef41Sopenharmony_ci 'normal', 3021cb0ef41Sopenharmony_ci 'writable', 3031cb0ef41Sopenharmony_ci fooSymbol, 3041cb0ef41Sopenharmony_ci 'inherited']); 3051cb0ef41Sopenharmony_ci 3061cb0ef41Sopenharmony_ci assert.deepStrictEqual(test_object.GetOwnWritableNames(object), 3071cb0ef41Sopenharmony_ci ['5', 3081cb0ef41Sopenharmony_ci 'normal', 3091cb0ef41Sopenharmony_ci 'unenumerable', 3101cb0ef41Sopenharmony_ci 'writable', 3111cb0ef41Sopenharmony_ci fooSymbol]); 3121cb0ef41Sopenharmony_ci 3131cb0ef41Sopenharmony_ci assert.deepStrictEqual(test_object.GetEnumerableConfigurableNames(object), 3141cb0ef41Sopenharmony_ci ['5', 3151cb0ef41Sopenharmony_ci 'normal', 3161cb0ef41Sopenharmony_ci 'configurable', 3171cb0ef41Sopenharmony_ci fooSymbol, 3181cb0ef41Sopenharmony_ci 'inherited']); 3191cb0ef41Sopenharmony_ci 3201cb0ef41Sopenharmony_ci assert.deepStrictEqual(test_object.GetOwnConfigurableNames(object), 3211cb0ef41Sopenharmony_ci ['5', 3221cb0ef41Sopenharmony_ci 'normal', 3231cb0ef41Sopenharmony_ci 'unenumerable', 3241cb0ef41Sopenharmony_ci 'configurable', 3251cb0ef41Sopenharmony_ci fooSymbol]); 3261cb0ef41Sopenharmony_ci} 3271cb0ef41Sopenharmony_ci 3281cb0ef41Sopenharmony_ci// Verify that passing NULL to napi_set_property() results in the correct 3291cb0ef41Sopenharmony_ci// error. 3301cb0ef41Sopenharmony_ciassert.deepStrictEqual(test_object.TestSetProperty(), { 3311cb0ef41Sopenharmony_ci envIsNull: 'Invalid argument', 3321cb0ef41Sopenharmony_ci objectIsNull: 'Invalid argument', 3331cb0ef41Sopenharmony_ci keyIsNull: 'Invalid argument', 3341cb0ef41Sopenharmony_ci valueIsNull: 'Invalid argument', 3351cb0ef41Sopenharmony_ci}); 3361cb0ef41Sopenharmony_ci 3371cb0ef41Sopenharmony_ci// Verify that passing NULL to napi_has_property() results in the correct 3381cb0ef41Sopenharmony_ci// error. 3391cb0ef41Sopenharmony_ciassert.deepStrictEqual(test_object.TestHasProperty(), { 3401cb0ef41Sopenharmony_ci envIsNull: 'Invalid argument', 3411cb0ef41Sopenharmony_ci objectIsNull: 'Invalid argument', 3421cb0ef41Sopenharmony_ci keyIsNull: 'Invalid argument', 3431cb0ef41Sopenharmony_ci resultIsNull: 'Invalid argument', 3441cb0ef41Sopenharmony_ci}); 3451cb0ef41Sopenharmony_ci 3461cb0ef41Sopenharmony_ci// Verify that passing NULL to napi_get_property() results in the correct 3471cb0ef41Sopenharmony_ci// error. 3481cb0ef41Sopenharmony_ciassert.deepStrictEqual(test_object.TestGetProperty(), { 3491cb0ef41Sopenharmony_ci envIsNull: 'Invalid argument', 3501cb0ef41Sopenharmony_ci objectIsNull: 'Invalid argument', 3511cb0ef41Sopenharmony_ci keyIsNull: 'Invalid argument', 3521cb0ef41Sopenharmony_ci resultIsNull: 'Invalid argument', 3531cb0ef41Sopenharmony_ci}); 3541cb0ef41Sopenharmony_ci 3551cb0ef41Sopenharmony_ci{ 3561cb0ef41Sopenharmony_ci const obj = { x: 'a', y: 'b', z: 'c' }; 3571cb0ef41Sopenharmony_ci 3581cb0ef41Sopenharmony_ci test_object.TestSeal(obj); 3591cb0ef41Sopenharmony_ci 3601cb0ef41Sopenharmony_ci assert.strictEqual(Object.isSealed(obj), true); 3611cb0ef41Sopenharmony_ci 3621cb0ef41Sopenharmony_ci assert.throws(() => { 3631cb0ef41Sopenharmony_ci obj.w = 'd'; 3641cb0ef41Sopenharmony_ci }, /Cannot add property w, object is not extensible/); 3651cb0ef41Sopenharmony_ci 3661cb0ef41Sopenharmony_ci assert.throws(() => { 3671cb0ef41Sopenharmony_ci delete obj.x; 3681cb0ef41Sopenharmony_ci }, /Cannot delete property 'x' of #<Object>/); 3691cb0ef41Sopenharmony_ci 3701cb0ef41Sopenharmony_ci // Sealed objects allow updating existing properties, 3711cb0ef41Sopenharmony_ci // so this should not throw. 3721cb0ef41Sopenharmony_ci obj.x = 'd'; 3731cb0ef41Sopenharmony_ci} 3741cb0ef41Sopenharmony_ci 3751cb0ef41Sopenharmony_ci{ 3761cb0ef41Sopenharmony_ci const obj = { x: 10, y: 10, z: 10 }; 3771cb0ef41Sopenharmony_ci 3781cb0ef41Sopenharmony_ci test_object.TestFreeze(obj); 3791cb0ef41Sopenharmony_ci 3801cb0ef41Sopenharmony_ci assert.strictEqual(Object.isFrozen(obj), true); 3811cb0ef41Sopenharmony_ci 3821cb0ef41Sopenharmony_ci assert.throws(() => { 3831cb0ef41Sopenharmony_ci obj.x = 10; 3841cb0ef41Sopenharmony_ci }, /Cannot assign to read only property 'x' of object '#<Object>/); 3851cb0ef41Sopenharmony_ci 3861cb0ef41Sopenharmony_ci assert.throws(() => { 3871cb0ef41Sopenharmony_ci obj.w = 15; 3881cb0ef41Sopenharmony_ci }, /Cannot add property w, object is not extensible/); 3891cb0ef41Sopenharmony_ci 3901cb0ef41Sopenharmony_ci assert.throws(() => { 3911cb0ef41Sopenharmony_ci delete obj.x; 3921cb0ef41Sopenharmony_ci }, /Cannot delete property 'x' of #<Object>/); 3931cb0ef41Sopenharmony_ci} 394