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 (function testRestIndex() { | 5 (function testRestIndex() { |
6 assertEquals(5, (function(...args) { return args.length; })(1,2,3,4,5)); | 6 assertEquals(5, (function(...args) { return args.length; })(1,2,3,4,5)); |
7 assertEquals(4, (function(a, ...args) { return args.length; })(1,2,3,4,5)); | 7 assertEquals(4, (function(a, ...args) { return args.length; })(1,2,3,4,5)); |
8 assertEquals(3, (function(a, b, ...args) { return args.length; })(1,2,3,4,5)); | 8 assertEquals(3, (function(a, b, ...args) { return args.length; })(1,2,3,4,5)); |
9 assertEquals(2, (function(a, b, c, ...args) { | 9 assertEquals(2, (function(a, b, c, ...args) { |
10 return args.length; })(1,2,3,4,5)); | 10 return args.length; })(1,2,3,4,5)); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 function(){ eval("(class{foo(...rest) {'use strict';}});") }, SyntaxError); | 210 function(){ eval("(class{foo(...rest) {'use strict';}});") }, SyntaxError); |
211 | 211 |
212 assertThrows( | 212 assertThrows( |
213 function(){ eval("function(a, ...rest){'use strict';}") }, SyntaxError); | 213 function(){ eval("function(a, ...rest){'use strict';}") }, SyntaxError); |
214 assertThrows( | 214 assertThrows( |
215 function(){ eval("(a, ...rest) => {'use strict';}") }, SyntaxError); | 215 function(){ eval("(a, ...rest) => {'use strict';}") }, SyntaxError); |
216 assertThrows( | 216 assertThrows( |
217 function(){ eval("(class{foo(a, ...rest) {'use strict';}});") }, | 217 function(){ eval("(class{foo(a, ...rest) {'use strict';}});") }, |
218 SyntaxError); | 218 SyntaxError); |
219 })(); | 219 })(); |
| 220 |
| 221 (function TestRestArrayPattern() { |
| 222 function f(...[a, b, c]) { return a + b + c; } |
| 223 assertEquals(6, f(1, 2, 3)); |
| 224 assertEquals("123", f(1, "2", 3)); |
| 225 assertEquals(NaN, f(1)); |
| 226 |
| 227 var f2 = (...[a, b, c]) => a + b + c; |
| 228 assertEquals(6, f2(1, 2, 3)); |
| 229 assertEquals("123", f2(1, "2", 3)); |
| 230 assertEquals(NaN, f2(1)); |
| 231 })(); |
| 232 |
| 233 (function TestRestObjectPattern() { |
| 234 function f(...{length, 0: firstName, 1: lastName}) { |
| 235 return `Hello ${lastName}, ${firstName}! Called with ${length} args!`; |
| 236 } |
| 237 assertEquals("Hello Ross, Bob! Called with 4 args!", f("Bob", "Ross", 0, 0)); |
| 238 |
| 239 var f2 = (...{length, 0: firstName, 1: lastName}) => |
| 240 `Hello ${lastName}, ${firstName}! Called with ${length} args!`; |
| 241 assertEquals("Hello Ross, Bob! Called with 4 args!", f2("Bob", "Ross", 0, 0)); |
| 242 })(); |
OLD | NEW |