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