blob: c2b351e2ff4e476dde630c960f944d361081e862 [file] [log] [blame]
keith_miller@apple.combcc77f22016-07-15 06:03:25 +00001// Copyright 2015 Microsoft Corporation. All rights reserved.
2// This code is governed by the license found in the LICENSE file.
3/*---
4es6id: 22.1.2.1
5description: Map function without thisArg on non strict mode
6info: >
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 ...
25flags: [noStrict]
26---*/
27
28var list = {
29 '0': 41,
30 '1': 42,
31 '2': 43,
32 length: 3
33};
34var calls = [];
35
36function mapFn (value) {
37 calls.push({
38 args: arguments,
39 thisArg: this
40 });
41 return value * 2;
42}
43
44var result = Array.from(list, mapFn);
45
46assert.sameValue(result.length, 3, 'result.length');
47assert.sameValue(result[0], 82, 'result[0]');
48assert.sameValue(result[1], 84, 'result[1]');
49assert.sameValue(result[2], 86, 'result[2]');
50
51assert.sameValue(calls.length, 3, 'calls.length');
52
53assert.sameValue(calls[0].args.length, 2, 'calls[0].args.length');
54assert.sameValue(calls[0].args[0], 41, 'calls[0].args[0]');
55assert.sameValue(calls[0].args[1], 0, 'calls[0].args[1]');
56assert.sameValue(calls[0].thisArg, this, 'calls[0].thisArg');
57
58assert.sameValue(calls[1].args.length, 2, 'calls[1].args.length');
59assert.sameValue(calls[1].args[0], 42, 'calls[1].args[0]');
60assert.sameValue(calls[1].args[1], 1, 'calls[1].args[1]');
61assert.sameValue(calls[1].thisArg, this, 'calls[1].thisArg');
62
63assert.sameValue(calls[2].args.length, 2, 'calls[2].args.length');
64assert.sameValue(calls[2].args[0], 43, 'calls[2].args[0]');
65assert.sameValue(calls[2].args[1], 2, 'calls[2].args[1]');
66assert.sameValue(calls[2].thisArg, this, 'calls[2].thisArg');