iter-map-fn-this-non-strict.js (1606B)
1 // Copyright (C) 2015 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-array.from 5 description: > 6 `this` value of mapping function in non-strict mode (traversed via iterator) 7 info: | 8 [...] 9 2. If mapfn is undefined, let mapping be false. 10 3. else 11 a. If IsCallable(mapfn) is false, throw a TypeError exception. 12 b. If thisArg was supplied, let T be thisArg; else let T be undefined. 13 c. Let mapping be true 14 [...] 15 6. If usingIterator is not undefined, then 16 [...] 17 g. Repeat 18 [...] 19 vii. If mapping is true, then 20 1. Let mappedValue be Call(mapfn, T, «nextValue, k»). 21 features: [Symbol.iterator] 22 flags: [noStrict] 23 ---*/ 24 25 var thisVals = []; 26 var nextResult = { 27 done: false, 28 value: {} 29 }; 30 var nextNextResult = { 31 done: false, 32 value: {} 33 }; 34 var mapFn = function() { 35 thisVals.push(this); 36 }; 37 var items = {}; 38 var global = function() { 39 return this; 40 }(); 41 42 items[Symbol.iterator] = function() { 43 return { 44 next: function() { 45 var result = nextResult; 46 nextResult = nextNextResult; 47 nextNextResult = { 48 done: true 49 }; 50 51 return result; 52 } 53 }; 54 }; 55 56 Array.from(items, mapFn); 57 58 assert.sameValue(thisVals.length, 2, 'The value of thisVals.length is expected to be 2'); 59 assert.sameValue(thisVals[0], global, 'The value of thisVals[0] is expected to equal the value of global'); 60 assert.sameValue(thisVals[1], global, 'The value of thisVals[1] is expected to equal the value of global'); 61 62 reportCompare(0, 0);