]>
Commit | Line | Data |
---|---|---|
ed1e77d3 A |
1 | function test(actual, expected) { |
2 | if (actual !== expected) | |
3 | throw new Error('bad value: ' + actual); | |
4 | } | |
5 | ||
6 | function testArguments(check) { | |
7 | (function () { | |
8 | check(arguments, []); | |
9 | }()); | |
10 | ||
11 | (function (a, b, c) { | |
12 | check(arguments, [a, b, c]); | |
13 | }()); | |
14 | ||
15 | (function () { | |
16 | 'use strict'; | |
17 | check(arguments, []); | |
18 | }()); | |
19 | ||
20 | (function (a, b, c) { | |
21 | 'use strict'; | |
22 | check(arguments, [a, b, c]); | |
23 | }()); | |
24 | } | |
25 | ||
26 | testArguments(function (args) { | |
27 | var iteratorMethod = args[Symbol.iterator]; | |
28 | test(iteratorMethod, Array.prototype.values); | |
29 | var descriptor = Object.getOwnPropertyDescriptor(args, Symbol.iterator); | |
30 | test(descriptor.writable, true); | |
31 | test(descriptor.configurable, true); | |
32 | test(descriptor.enumerable, false); | |
33 | test(descriptor.value, iteratorMethod); | |
34 | }); | |
35 | ||
36 | testArguments(function (args, expected) { | |
37 | var iterator = args[Symbol.iterator](); | |
38 | test(iterator.toString(), '[object Array Iterator]'); | |
39 | var index = 0; | |
40 | for (var value of iterator) { | |
41 | test(value, expected[index++]); | |
42 | } | |
43 | test(args.length, index); | |
44 | ||
45 | var index = 0; | |
46 | for (var value of args) { | |
47 | test(value, expected[index++]); | |
48 | } | |
49 | test(args.length, index); | |
50 | }); | |
51 | ||
52 | testArguments(function (args) { | |
53 | var symbols = Object.getOwnPropertySymbols(args); | |
54 | test(symbols.length, 1); | |
55 | test(symbols[0], Symbol.iterator); | |
56 | }); | |
57 | ||
58 | testArguments(function (args) { | |
59 | 'use strict'; | |
60 | args[Symbol.iterator] = 'not throw error'; | |
61 | }); | |
62 | ||
63 | testArguments(function (args) { | |
64 | 'use strict'; | |
65 | delete args[Symbol.iterator]; | |
66 | test(args[Symbol.iterator], undefined); | |
67 | ||
68 | var symbols = Object.getOwnPropertySymbols(args); | |
69 | test(symbols.length, 0); | |
70 | }); |