11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst vm = require('vm'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst getSetSymbolReceivingFunction = Symbol('sym-1'); 71cb0ef41Sopenharmony_ciconst getSetSymbolReceivingNumber = Symbol('sym-2'); 81cb0ef41Sopenharmony_ciconst symbolReceivingNumber = Symbol('sym-3'); 91cb0ef41Sopenharmony_ciconst unknownSymbolReceivingNumber = Symbol('sym-4'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst window = createWindow(); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst descriptor1 = Object.getOwnPropertyDescriptor( 141cb0ef41Sopenharmony_ci window.globalProxy, 151cb0ef41Sopenharmony_ci 'getSetPropReceivingFunction' 161cb0ef41Sopenharmony_ci); 171cb0ef41Sopenharmony_ciassert.strictEqual(typeof descriptor1.get, 'function'); 181cb0ef41Sopenharmony_ciassert.strictEqual(typeof descriptor1.set, 'function'); 191cb0ef41Sopenharmony_ciassert.strictEqual(descriptor1.configurable, true); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciconst descriptor2 = Object.getOwnPropertyDescriptor( 221cb0ef41Sopenharmony_ci window.globalProxy, 231cb0ef41Sopenharmony_ci 'getSetPropReceivingNumber' 241cb0ef41Sopenharmony_ci); 251cb0ef41Sopenharmony_ciassert.strictEqual(typeof descriptor2.get, 'function'); 261cb0ef41Sopenharmony_ciassert.strictEqual(typeof descriptor2.set, 'function'); 271cb0ef41Sopenharmony_ciassert.strictEqual(descriptor2.configurable, true); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ciconst descriptor3 = Object.getOwnPropertyDescriptor( 301cb0ef41Sopenharmony_ci window.globalProxy, 311cb0ef41Sopenharmony_ci 'propReceivingNumber' 321cb0ef41Sopenharmony_ci); 331cb0ef41Sopenharmony_ciassert.strictEqual(descriptor3.value, 44); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciconst descriptor4 = Object.getOwnPropertyDescriptor( 361cb0ef41Sopenharmony_ci window.globalProxy, 371cb0ef41Sopenharmony_ci 'unknownPropReceivingNumber' 381cb0ef41Sopenharmony_ci); 391cb0ef41Sopenharmony_ciassert.strictEqual(descriptor4, undefined); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ciconst descriptor5 = Object.getOwnPropertyDescriptor( 421cb0ef41Sopenharmony_ci window.globalProxy, 431cb0ef41Sopenharmony_ci getSetSymbolReceivingFunction 441cb0ef41Sopenharmony_ci); 451cb0ef41Sopenharmony_ciassert.strictEqual(typeof descriptor5.get, 'function'); 461cb0ef41Sopenharmony_ciassert.strictEqual(typeof descriptor5.set, 'function'); 471cb0ef41Sopenharmony_ciassert.strictEqual(descriptor5.configurable, true); 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ciconst descriptor6 = Object.getOwnPropertyDescriptor( 501cb0ef41Sopenharmony_ci window.globalProxy, 511cb0ef41Sopenharmony_ci getSetSymbolReceivingNumber 521cb0ef41Sopenharmony_ci); 531cb0ef41Sopenharmony_ciassert.strictEqual(typeof descriptor6.get, 'function'); 541cb0ef41Sopenharmony_ciassert.strictEqual(typeof descriptor6.set, 'function'); 551cb0ef41Sopenharmony_ciassert.strictEqual(descriptor6.configurable, true); 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ciconst descriptor7 = Object.getOwnPropertyDescriptor( 581cb0ef41Sopenharmony_ci window.globalProxy, 591cb0ef41Sopenharmony_ci symbolReceivingNumber 601cb0ef41Sopenharmony_ci); 611cb0ef41Sopenharmony_ciassert.strictEqual(descriptor7.value, 48); 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ciconst descriptor8 = Object.getOwnPropertyDescriptor( 641cb0ef41Sopenharmony_ci window.globalProxy, 651cb0ef41Sopenharmony_ci unknownSymbolReceivingNumber 661cb0ef41Sopenharmony_ci); 671cb0ef41Sopenharmony_ciassert.strictEqual(descriptor8, undefined); 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ciconst descriptor9 = Object.getOwnPropertyDescriptor( 701cb0ef41Sopenharmony_ci window.globalProxy, 711cb0ef41Sopenharmony_ci 'getSetPropThrowing' 721cb0ef41Sopenharmony_ci); 731cb0ef41Sopenharmony_ciassert.strictEqual(typeof descriptor9.get, 'function'); 741cb0ef41Sopenharmony_ciassert.strictEqual(typeof descriptor9.set, 'function'); 751cb0ef41Sopenharmony_ciassert.strictEqual(descriptor9.configurable, true); 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ciconst descriptor10 = Object.getOwnPropertyDescriptor( 781cb0ef41Sopenharmony_ci window.globalProxy, 791cb0ef41Sopenharmony_ci 'nonWritableProp' 801cb0ef41Sopenharmony_ci); 811cb0ef41Sopenharmony_ciassert.strictEqual(descriptor10.value, 51); 821cb0ef41Sopenharmony_ciassert.strictEqual(descriptor10.writable, false); 831cb0ef41Sopenharmony_ci 841cb0ef41Sopenharmony_ci// Regression test for GH-42962. This assignment should not throw. 851cb0ef41Sopenharmony_ciwindow.globalProxy.getSetPropReceivingFunction = () => {}; 861cb0ef41Sopenharmony_ciassert.strictEqual(window.globalProxy.getSetPropReceivingFunction, 42); 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ciwindow.globalProxy.getSetPropReceivingNumber = 143; 891cb0ef41Sopenharmony_ciassert.strictEqual(window.globalProxy.getSetPropReceivingNumber, 43); 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ciwindow.globalProxy.propReceivingNumber = 144; 921cb0ef41Sopenharmony_ciassert.strictEqual(window.globalProxy.propReceivingNumber, 144); 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ciwindow.globalProxy.unknownPropReceivingNumber = 145; 951cb0ef41Sopenharmony_ciassert.strictEqual(window.globalProxy.unknownPropReceivingNumber, 145); 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ciwindow.globalProxy[getSetSymbolReceivingFunction] = () => {}; 981cb0ef41Sopenharmony_ciassert.strictEqual(window.globalProxy[getSetSymbolReceivingFunction], 46); 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ciwindow.globalProxy[getSetSymbolReceivingNumber] = 147; 1011cb0ef41Sopenharmony_ciassert.strictEqual(window.globalProxy[getSetSymbolReceivingNumber], 47); 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ciwindow.globalProxy[symbolReceivingNumber] = 148; 1041cb0ef41Sopenharmony_ciassert.strictEqual(window.globalProxy[symbolReceivingNumber], 148); 1051cb0ef41Sopenharmony_ci 1061cb0ef41Sopenharmony_ciwindow.globalProxy[unknownSymbolReceivingNumber] = 149; 1071cb0ef41Sopenharmony_ciassert.strictEqual(window.globalProxy[unknownSymbolReceivingNumber], 149); 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ciassert.throws( 1101cb0ef41Sopenharmony_ci () => (window.globalProxy.getSetPropThrowing = 150), 1111cb0ef41Sopenharmony_ci new Error('setter called') 1121cb0ef41Sopenharmony_ci); 1131cb0ef41Sopenharmony_ciassert.strictEqual(window.globalProxy.getSetPropThrowing, 50); 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ciassert.throws( 1161cb0ef41Sopenharmony_ci () => (window.globalProxy.nonWritableProp = 151), 1171cb0ef41Sopenharmony_ci new TypeError('Cannot redefine property: nonWritableProp') 1181cb0ef41Sopenharmony_ci); 1191cb0ef41Sopenharmony_ciassert.strictEqual(window.globalProxy.nonWritableProp, 51); 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_cifunction createWindow() { 1221cb0ef41Sopenharmony_ci const obj = {}; 1231cb0ef41Sopenharmony_ci vm.createContext(obj); 1241cb0ef41Sopenharmony_ci Object.defineProperty(obj, 'getSetPropReceivingFunction', { 1251cb0ef41Sopenharmony_ci get: common.mustCall(() => 42), 1261cb0ef41Sopenharmony_ci set: common.mustCall(), 1271cb0ef41Sopenharmony_ci configurable: true, 1281cb0ef41Sopenharmony_ci }); 1291cb0ef41Sopenharmony_ci Object.defineProperty(obj, 'getSetPropReceivingNumber', { 1301cb0ef41Sopenharmony_ci get: common.mustCall(() => 43), 1311cb0ef41Sopenharmony_ci set: common.mustCall(), 1321cb0ef41Sopenharmony_ci configurable: true, 1331cb0ef41Sopenharmony_ci }); 1341cb0ef41Sopenharmony_ci obj.propReceivingNumber = 44; 1351cb0ef41Sopenharmony_ci Object.defineProperty(obj, getSetSymbolReceivingFunction, { 1361cb0ef41Sopenharmony_ci get: common.mustCall(() => 46), 1371cb0ef41Sopenharmony_ci set: common.mustCall(), 1381cb0ef41Sopenharmony_ci configurable: true, 1391cb0ef41Sopenharmony_ci }); 1401cb0ef41Sopenharmony_ci Object.defineProperty(obj, getSetSymbolReceivingNumber, { 1411cb0ef41Sopenharmony_ci get: common.mustCall(() => 47), 1421cb0ef41Sopenharmony_ci set: common.mustCall(), 1431cb0ef41Sopenharmony_ci configurable: true, 1441cb0ef41Sopenharmony_ci }); 1451cb0ef41Sopenharmony_ci obj[symbolReceivingNumber] = 48; 1461cb0ef41Sopenharmony_ci Object.defineProperty(obj, 'getSetPropThrowing', { 1471cb0ef41Sopenharmony_ci get: common.mustCall(() => 50), 1481cb0ef41Sopenharmony_ci set: common.mustCall(() => { 1491cb0ef41Sopenharmony_ci throw new Error('setter called'); 1501cb0ef41Sopenharmony_ci }), 1511cb0ef41Sopenharmony_ci configurable: true, 1521cb0ef41Sopenharmony_ci }); 1531cb0ef41Sopenharmony_ci Object.defineProperty(obj, 'nonWritableProp', { 1541cb0ef41Sopenharmony_ci value: 51, 1551cb0ef41Sopenharmony_ci writable: false, 1561cb0ef41Sopenharmony_ci }); 1571cb0ef41Sopenharmony_ci 1581cb0ef41Sopenharmony_ci obj.globalProxy = vm.runInContext('this', obj); 1591cb0ef41Sopenharmony_ci 1601cb0ef41Sopenharmony_ci return obj; 1611cb0ef41Sopenharmony_ci} 162