| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 TestDefaultBeforeInitializingYield() { | 5 (function TestDefaultBeforeInitializingYield() { |
| 6 var y = 0; | 6 var y = 0; |
| 7 var z = 0; | 7 var z = 0; |
| 8 function* f1(x = (y = 1)) { z = 1 }; | 8 function* f1(x = (y = 1)) { z = 1 }; |
| 9 assertEquals(0, y); | 9 assertEquals(0, y); |
| 10 assertEquals(0, z); | 10 assertEquals(0, z); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 assertEquals(1, f12(1).next().value); | 44 assertEquals(1, f12(1).next().value); |
| 45 function* f13({x}, y, [z], v) { var x, y, z; return x*y*z*v } | 45 function* f13({x}, y, [z], v) { var x, y, z; return x*y*z*v } |
| 46 assertEquals(210, f13({x: 2}, 3, [5], 7).next().value); | 46 assertEquals(210, f13({x: 2}, 3, [5], 7).next().value); |
| 47 | 47 |
| 48 function* f20({x}) { function x() { return 2 }; return x(); } | 48 function* f20({x}) { function x() { return 2 }; return x(); } |
| 49 assertEquals(2, f20({x: 1}).next().value); | 49 assertEquals(2, f20({x: 1}).next().value); |
| 50 // Annex B 3.3 function hoisting is blocked by the conflicting x declaration | 50 // Annex B 3.3 function hoisting is blocked by the conflicting x declaration |
| 51 function* f21({x}) { { function x() { return 2 } } return x; } | 51 function* f21({x}) { { function x() { return 2 } } return x; } |
| 52 assertEquals(1, f21({x: 1}).next().value); | 52 assertEquals(1, f21({x: 1}).next().value); |
| 53 | 53 |
| 54 assertThrows("'use strict'; function* f(x) { let x = 0; }", SyntaxError); | 54 // These errors are not recognized in lazy parsing; see mjsunit/bugs/bug-2728.
js |
| 55 assertThrows("'use strict'; function* f({x}) { let x = 0; }", SyntaxError); | 55 assertThrows("'use strict'; (function* f(x) { let x = 0; })()", SyntaxError); |
| 56 assertThrows("'use strict'; function* f(x) { const x = 0; }", SyntaxError); | 56 assertThrows("'use strict'; (function* f({x}) { let x = 0; })()", SyntaxError)
; |
| 57 assertThrows("'use strict'; function* f({x}) { const x = 0; }", SyntaxError); | 57 assertThrows("'use strict'; (function* f(x) { const x = 0; })()", SyntaxError)
; |
| 58 assertThrows("'use strict'; (function* f({x}) { const x = 0; })()", SyntaxErro
r); |
| 58 }()); | 59 }()); |
| 59 | 60 |
| 60 (function TestDefaults() { | 61 (function TestDefaults() { |
| 61 function* f1(x = 1) { return x } | 62 function* f1(x = 1) { return x } |
| 62 assertEquals(1, f1().next().value); | 63 assertEquals(1, f1().next().value); |
| 63 assertEquals(1, f1(undefined).next().value); | 64 assertEquals(1, f1(undefined).next().value); |
| 64 assertEquals(2, f1(2).next().value); | 65 assertEquals(2, f1(2).next().value); |
| 65 assertEquals(null, f1(null).next().value); | 66 assertEquals(null, f1(null).next().value); |
| 66 | 67 |
| 67 function* f2(x, y = x) { return x + y; } | 68 function* f2(x, y = x) { return x + y; } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 assertEquals(1, (function*(x, y = 1, z, v = 2, ...a) {}).length); | 309 assertEquals(1, (function*(x, y = 1, z, v = 2, ...a) {}).length); |
| 309 })(); | 310 })(); |
| 310 | 311 |
| 311 (function TestDirectiveThrows() { | 312 (function TestDirectiveThrows() { |
| 312 "use strict"; | 313 "use strict"; |
| 313 | 314 |
| 314 assertThrows("(function*(x=1){'use strict';})", SyntaxError); | 315 assertThrows("(function*(x=1){'use strict';})", SyntaxError); |
| 315 assertThrows("(function*(a, x=1){'use strict';})", SyntaxError); | 316 assertThrows("(function*(a, x=1){'use strict';})", SyntaxError); |
| 316 assertThrows("(function*({x}){'use strict';})", SyntaxError); | 317 assertThrows("(function*({x}){'use strict';})", SyntaxError); |
| 317 })(); | 318 })(); |
| OLD | NEW |