OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-rest-parameters | 5 // Flags: --harmony-rest-parameters |
6 | 6 |
7 (function testRestIndex() { | 7 (function testRestIndex() { |
8 assertEquals(5, (function(...args) { return args.length; })(1,2,3,4,5)); | 8 assertEquals(5, (function(...args) { return args.length; })(1,2,3,4,5)); |
9 assertEquals(4, (function(a, ...args) { return args.length; })(1,2,3,4,5)); | 9 assertEquals(4, (function(a, ...args) { return args.length; })(1,2,3,4,5)); |
10 assertEquals(3, (function(a, b, ...args) { return args.length; })(1,2,3,4,5)); | 10 assertEquals(3, (function(a, b, ...args) { return args.length; })(1,2,3,4,5)); |
11 assertEquals(2, (function(a, b, c, ...args) { | 11 assertEquals(2, (function(a, b, c, ...args) { |
12 return args.length; })(1,2,3,4,5)); | 12 return args.length; })(1,2,3,4,5)); |
13 assertEquals(1, (function(a, b, c, d, ...args) { | 13 assertEquals(1, (function(a, b, c, d, ...args) { |
14 return args.length; })(1,2,3,4,5)); | 14 return args.length; })(1,2,3,4,5)); |
15 assertEquals(0, (function(a, b, c, d, e, ...args) { | 15 assertEquals(0, (function(a, b, c, d, e, ...args) { |
16 return args.length; })(1,2,3,4,5)); | 16 return args.length; })(1,2,3,4,5)); |
17 })(); | 17 })(); |
18 | 18 |
19 function strictTest(a, b, ...c) { | 19 var strictTest = (function() { |
20 "use strict"; | 20 "use strict"; |
21 assertEquals(Array, c.constructor); | 21 return function strictTest(a, b, ...c) { |
22 assertTrue(Array.isArray(c)); | 22 assertEquals(Array, c.constructor); |
| 23 assertTrue(Array.isArray(c)); |
23 | 24 |
24 var expectedLength = arguments.length >= 3 ? arguments.length - 2 : 0; | 25 var expectedLength = arguments.length >= 3 ? arguments.length - 2 : 0; |
25 assertEquals(expectedLength, c.length); | 26 assertEquals(expectedLength, c.length); |
26 | 27 |
27 for (var i = 2, j = 0; i < arguments.length; ++i) { | 28 for (var i = 2, j = 0; i < arguments.length; ++i) { |
28 assertEquals(c[j++], arguments[i]); | 29 assertEquals(c[j++], arguments[i]); |
29 } | 30 } |
30 } | 31 }; |
| 32 })(); |
31 | 33 |
32 function sloppyTest(a, b, ...c) { | 34 function sloppyTest(a, b, ...c) { |
33 assertEquals(Array, c.constructor); | 35 assertEquals(Array, c.constructor); |
34 assertTrue(Array.isArray(c)); | 36 assertTrue(Array.isArray(c)); |
35 | 37 |
36 var expectedLength = arguments.length >= 3 ? arguments.length - 2 : 0; | 38 var expectedLength = arguments.length >= 3 ? arguments.length - 2 : 0; |
37 assertEquals(expectedLength, c.length); | 39 assertEquals(expectedLength, c.length); |
38 | 40 |
39 for (var i = 2, j = 0; i < arguments.length; ++i) { | 41 for (var i = 2, j = 0; i < arguments.length; ++i) { |
40 assertEquals(c[j++], arguments[i]); | 42 assertEquals(c[j++], arguments[i]); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 assertThrows(function(...rest) { return arguments.caller; }, TypeError); | 139 assertThrows(function(...rest) { return arguments.caller; }, TypeError); |
138 assertThrows(function(...rest) { return arguments.callee; }, TypeError); | 140 assertThrows(function(...rest) { return arguments.callee; }, TypeError); |
139 // TODO(caitp): figure out why this doesn't throw sometimes, even though the | 141 // TODO(caitp): figure out why this doesn't throw sometimes, even though the |
140 // getter always does =) | 142 // getter always does =) |
141 // assertThrows(function(...rest) { arguments.caller = 1; }, TypeError); | 143 // assertThrows(function(...rest) { arguments.caller = 1; }, TypeError); |
142 // assertThrows(function(...rest) { arguments.callee = 1; }, TypeError); | 144 // assertThrows(function(...rest) { arguments.callee = 1; }, TypeError); |
143 })(); | 145 })(); |
144 | 146 |
145 | 147 |
146 (function testNoAliasArgumentsStrict() { | 148 (function testNoAliasArgumentsStrict() { |
| 149 "use strict"; |
147 function strictF(a, ...rest) { | 150 function strictF(a, ...rest) { |
148 "use strict"; | |
149 arguments[0] = 1; | 151 arguments[0] = 1; |
150 assertEquals(3, a); | 152 assertEquals(3, a); |
151 arguments[1] = 2; | 153 arguments[1] = 2; |
152 assertArrayEquals([4, 5], rest); | 154 assertArrayEquals([4, 5], rest); |
153 } | 155 } |
154 strictF(3, 4, 5); | 156 strictF(3, 4, 5); |
155 })(); | 157 })(); |
156 | 158 |
157 | 159 |
158 (function testNoAliasArgumentsSloppy() { | 160 (function testNoAliasArgumentsSloppy() { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 args.push(arguments[i]); | 207 args.push(arguments[i]); |
206 } | 208 } |
207 assertEquals(args, b); | 209 assertEquals(args, b); |
208 } | 210 } |
209 } | 211 } |
210 | 212 |
211 var c = new Child(1, 2, 3); | 213 var c = new Child(1, 2, 3); |
212 assertEquals([1, 2, 3], c.child); | 214 assertEquals([1, 2, 3], c.child); |
213 assertEquals([1, 2, 3], c.base); | 215 assertEquals([1, 2, 3], c.base); |
214 })(); | 216 })(); |
OLD | NEW |