calling-from-valid-1-noStrict.js (2602B)
1 // Copyright 2015 Microsoft Corporation. All rights reserved. 2 // This code is governed by the license found in the LICENSE file. 3 /*--- 4 esid: sec-array.from 5 description: Map function without thisArg on non strict mode 6 info: | 7 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ) 8 9 ... 10 10. Let len be ToLength(Get(arrayLike, "length")). 11 11. ReturnIfAbrupt(len). 12 12. If IsConstructor(C) is true, then 13 a. Let A be Construct(C, «len»). 14 13. Else, 15 b. Let A be ArrayCreate(len). 16 14. ReturnIfAbrupt(A). 17 15. Let k be 0. 18 16. Repeat, while k < len 19 a. Let Pk be ToString(k). 20 b. Let kValue be Get(arrayLike, Pk). 21 c. ReturnIfAbrupt(kValue). 22 d. If mapping is true, then 23 i. Let mappedValue be Call(mapfn, T, «kValue, k»). 24 ... 25 flags: [noStrict] 26 ---*/ 27 28 var list = { 29 '0': 41, 30 '1': 42, 31 '2': 43, 32 length: 3 33 }; 34 var calls = []; 35 36 function mapFn(value) { 37 calls.push({ 38 args: arguments, 39 thisArg: this 40 }); 41 return value * 2; 42 } 43 44 var result = Array.from(list, mapFn); 45 46 assert.sameValue(result.length, 3, 'The value of result.length is expected to be 3'); 47 assert.sameValue(result[0], 82, 'The value of result[0] is expected to be 82'); 48 assert.sameValue(result[1], 84, 'The value of result[1] is expected to be 84'); 49 assert.sameValue(result[2], 86, 'The value of result[2] is expected to be 86'); 50 51 assert.sameValue(calls.length, 3, 'The value of calls.length is expected to be 3'); 52 53 assert.sameValue(calls[0].args.length, 2, 'The value of calls[0].args.length is expected to be 2'); 54 assert.sameValue(calls[0].args[0], 41, 'The value of calls[0].args[0] is expected to be 41'); 55 assert.sameValue(calls[0].args[1], 0, 'The value of calls[0].args[1] is expected to be 0'); 56 assert.sameValue(calls[0].thisArg, this, 'The value of calls[0].thisArg is expected to be this'); 57 58 assert.sameValue(calls[1].args.length, 2, 'The value of calls[1].args.length is expected to be 2'); 59 assert.sameValue(calls[1].args[0], 42, 'The value of calls[1].args[0] is expected to be 42'); 60 assert.sameValue(calls[1].args[1], 1, 'The value of calls[1].args[1] is expected to be 1'); 61 assert.sameValue(calls[1].thisArg, this, 'The value of calls[1].thisArg is expected to be this'); 62 63 assert.sameValue(calls[2].args.length, 2, 'The value of calls[2].args.length is expected to be 2'); 64 assert.sameValue(calls[2].args[0], 43, 'The value of calls[2].args[0] is expected to be 43'); 65 assert.sameValue(calls[2].args[1], 2, 'The value of calls[2].args[1] is expected to be 2'); 66 assert.sameValue(calls[2].thisArg, this, 'The value of calls[2].thisArg is expected to be this'); 67 68 reportCompare(0, 0);