this-constructor-with-readonly-elements.js (1712B)
1 // |reftest| async 2 // Copyright (C) 2023 Igalia, S.L. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-array.fromasync 7 description: > 8 Overwrites non-writable element properties on an instance of a custom 9 this-value 10 info: | 11 3.j.ii.8. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). 12 ... 13 3.k.vii.6. Perform ? CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). 14 includes: [asyncHelpers.js] 15 flags: [async] 16 features: [Array.fromAsync] 17 ---*/ 18 19 asyncTest(async function () { 20 function MyArray() { 21 this.length = 4; 22 for (let ix = 0; ix < this.length; ix++) { 23 Object.defineProperty(this, ix, { 24 enumerable: true, 25 writable: false, 26 configurable: true, 27 value: 99 28 }); 29 } 30 } 31 32 let result = await Array.fromAsync.call(MyArray, [0, 1, 2]); 33 assert.sameValue(result.length, 3, "Length property is overwritten"); 34 assert.sameValue(result[0], 0, "Read-only element 0 is overwritten"); 35 assert.sameValue(result[1], 1, "Read-only element 1 is overwritten"); 36 assert.sameValue(result[2], 2, "Read-only element 2 is overwritten"); 37 assert.sameValue(result[3], 99, "Element 3 is not overwritten"); 38 39 result = await Array.fromAsync.call(MyArray, { 40 length: 3, 41 0: 0, 42 1: 1, 43 2: 2, 44 3: 3 // ignored 45 }); 46 assert.sameValue(result.length, 3, "Length property is overwritten"); 47 assert.sameValue(result[0], 0, "Read-only element 0 is overwritten"); 48 assert.sameValue(result[1], 1, "Read-only element 1 is overwritten"); 49 assert.sameValue(result[2], 2, "Read-only element 2 is overwritten"); 50 assert.sameValue(result[3], 99, "Element 3 is not overwritten"); 51 });