source-object-length-set-elem-prop-err.js (1307B)
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 esid: sec-array.from 6 description: > 7 TypeError is thrown if CreateDataProperty fails. 8 (items is not iterable) 9 info: | 10 Array.from ( items [ , mapfn [ , thisArg ] ] ) 11 12 [...] 13 4. Let usingIterator be ? GetMethod(items, @@iterator). 14 5. If usingIterator is not undefined, then 15 [...] 16 6. NOTE: items is not an Iterable so assume it is an array-like object. 17 [...] 18 12. Repeat, while k < len 19 [...] 20 e. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue). 21 [...] 22 23 CreateDataPropertyOrThrow ( O, P, V ) 24 25 [...] 26 3. Let success be ? CreateDataProperty(O, P, V). 27 4. If success is false, throw a TypeError exception. 28 ---*/ 29 30 var items = { 31 length: 1, 32 }; 33 34 var A1 = function(_length) { 35 this.length = 0; 36 Object.preventExtensions(this); 37 }; 38 39 assert.throws(TypeError, function() { 40 Array.from.call(A1, items); 41 }, 'Array.from.call(A1, items) throws a TypeError exception'); 42 43 var A2 = function(_length) { 44 Object.defineProperty(this, "0", { 45 writable: true, 46 configurable: false, 47 }); 48 }; 49 50 assert.throws(TypeError, function() { 51 Array.from.call(A2, items); 52 }, 'Array.from.call(A2, items) throws a TypeError exception'); 53 54 reportCompare(0, 0);