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 118 matching lines...) Loading... |
129 O.sloppy.call(O); | 129 O.sloppy.call(O); |
130 O.sloppy.call(O, 1, 2); | 130 O.sloppy.call(O, 1, 2); |
131 O.sloppy.call(O, 1, 2, 3, 4, 5, 6); | 131 O.sloppy.call(O, 1, 2, 3, 4, 5, 6); |
132 O.sloppy.call(O, 1, 2, 3); | 132 O.sloppy.call(O, 1, 2, 3); |
133 })(); | 133 })(); |
134 | 134 |
135 | 135 |
136 (function testUnmappedArguments() { | 136 (function testUnmappedArguments() { |
137 // Strict/Unmapped arguments should always be used for functions with rest | 137 // Strict/Unmapped arguments should always be used for functions with rest |
138 // parameters | 138 // parameters |
139 assertThrows(function(...rest) { return arguments.caller; }, TypeError); | |
140 assertThrows(function(...rest) { return arguments.callee; }, TypeError); | 139 assertThrows(function(...rest) { return arguments.callee; }, TypeError); |
141 // TODO(caitp): figure out why this doesn't throw sometimes, even though the | 140 // TODO(caitp): figure out why this doesn't throw sometimes, even though the |
142 // getter always does =) | 141 // getter always does =) |
143 // assertThrows(function(...rest) { arguments.caller = 1; }, TypeError); | |
144 // assertThrows(function(...rest) { arguments.callee = 1; }, TypeError); | 142 // assertThrows(function(...rest) { arguments.callee = 1; }, TypeError); |
145 })(); | 143 })(); |
146 | 144 |
147 | 145 |
148 (function testNoAliasArgumentsStrict() { | 146 (function testNoAliasArgumentsStrict() { |
149 ((function() { | 147 ((function() { |
150 "use strict"; | 148 "use strict"; |
151 return (function strictF(a, ...rest) { | 149 return (function strictF(a, ...rest) { |
152 arguments[0] = 1; | 150 arguments[0] = 1; |
153 assertEquals(3, a); | 151 assertEquals(3, a); |
(...skipping 79 matching lines...) Loading... |
233 (function TestRestObjectPattern() { | 231 (function TestRestObjectPattern() { |
234 function f(...{length, 0: firstName, 1: lastName}) { | 232 function f(...{length, 0: firstName, 1: lastName}) { |
235 return `Hello ${lastName}, ${firstName}! Called with ${length} args!`; | 233 return `Hello ${lastName}, ${firstName}! Called with ${length} args!`; |
236 } | 234 } |
237 assertEquals("Hello Ross, Bob! Called with 4 args!", f("Bob", "Ross", 0, 0)); | 235 assertEquals("Hello Ross, Bob! Called with 4 args!", f("Bob", "Ross", 0, 0)); |
238 | 236 |
239 var f2 = (...{length, 0: firstName, 1: lastName}) => | 237 var f2 = (...{length, 0: firstName, 1: lastName}) => |
240 `Hello ${lastName}, ${firstName}! Called with ${length} args!`; | 238 `Hello ${lastName}, ${firstName}! Called with ${length} args!`; |
241 assertEquals("Hello Ross, Bob! Called with 4 args!", f2("Bob", "Ross", 0, 0)); | 239 assertEquals("Hello Ross, Bob! Called with 4 args!", f2("Bob", "Ross", 0, 0)); |
242 })(); | 240 })(); |
OLD | NEW |