define-own-prop-length-coercion-order-set.js (1413B)
1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 author: André Bargull 6 esid: sec-arraysetlength 7 description: > 8 [[Value]] is coerced to number before current descriptor's [[Writable]] check. 9 info: | 10 ArraySetLength ( A, Desc ) 11 12 [...] 13 3. Let newLen be ? ToUint32(Desc.[[Value]]). 14 4. Let numberLen be ? ToNumber(Desc.[[Value]]). 15 [...] 16 7. Let oldLenDesc be OrdinaryGetOwnProperty(A, "length"). 17 [...] 18 12. If oldLenDesc.[[Writable]] is false, return false. 19 features: [Symbol, Symbol.toPrimitive, Reflect, Reflect.set] 20 includes: [compareArray.js] 21 ---*/ 22 23 var array = [1, 2, 3]; 24 var hints = []; 25 var length = {}; 26 length[Symbol.toPrimitive] = function(hint) { 27 hints.push(hint); 28 Object.defineProperty(array, "length", {writable: false}); 29 return 0; 30 }; 31 32 assert.throws(TypeError, function() { 33 "use strict"; 34 array.length = length; 35 }, '`"use strict"; array.length = length` throws a TypeError exception'); 36 assert.compareArray(hints, ["number", "number"], 'The value of hints is expected to be ["number", "number"]'); 37 38 39 array = [1, 2, 3]; 40 hints = []; 41 42 assert( 43 !Reflect.set(array, "length", length), 44 'The value of !Reflect.set(array, "length", length) is expected to be true' 45 ); 46 assert.compareArray(hints, ["number", "number"], 'The value of hints is expected to be ["number", "number"]'); 47 48 reportCompare(0, 0);