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 --harmony-classes |
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) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 var fn = (a, b, ...c) => c; | 173 var fn = (a, b, ...c) => c; |
174 assertEquals([], fn()); | 174 assertEquals([], fn()); |
175 assertEquals([], fn(1, 2)); | 175 assertEquals([], fn(1, 2)); |
176 assertEquals([3], fn(1, 2, 3)); | 176 assertEquals([3], fn(1, 2, 3)); |
177 assertEquals([3, 4], fn(1, 2, 3, 4)); | 177 assertEquals([3, 4], fn(1, 2, 3, 4)); |
178 assertEquals([3, 4, 5], fn(1, 2, 3, 4, 5)); | 178 assertEquals([3, 4, 5], fn(1, 2, 3, 4, 5)); |
179 assertThrows("var x = ...y => y;", SyntaxError); | 179 assertThrows("var x = ...y => y;", SyntaxError); |
180 assertEquals([], ((...args) => args)()); | 180 assertEquals([], ((...args) => args)()); |
181 assertEquals([1,2,3], ((...args) => args)(1,2,3)); | 181 assertEquals([1,2,3], ((...args) => args)(1,2,3)); |
182 })();*/ | 182 })();*/ |
| 183 |
| 184 |
| 185 (function testRestParamsWithNewTarget() { |
| 186 "use strict"; |
| 187 class Base { |
| 188 constructor(...a) { |
| 189 this.base = a; |
| 190 assertEquals(arguments.length, a.length); |
| 191 var args = []; |
| 192 for (var i = 0; i < arguments.length; ++i) { |
| 193 args.push(arguments[i]); |
| 194 } |
| 195 assertEquals(args, a); |
| 196 } |
| 197 } |
| 198 class Child extends Base { |
| 199 constructor(...b) { |
| 200 super(1, 2, 3); |
| 201 this.child = b; |
| 202 assertEquals(arguments.length, b.length); |
| 203 var args = []; |
| 204 for (var i = 0; i < arguments.length; ++i) { |
| 205 args.push(arguments[i]); |
| 206 } |
| 207 assertEquals(args, b); |
| 208 } |
| 209 } |
| 210 |
| 211 var c = new Child(1, 2, 3); |
| 212 assertEquals([1, 2, 3], c.child); |
| 213 assertEquals([1, 2, 3], c.base); |
| 214 })(); |
OLD | NEW |