| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 // Yield is always valid as a key in an object literal. | 68 // Yield is always valid as a key in an object literal. |
| 69 ({ yield: 1 }); | 69 ({ yield: 1 }); |
| 70 function* g() { yield ({ yield: 1 }) } | 70 function* g() { yield ({ yield: 1 }) } |
| 71 function* g() { yield ({ get yield() { return 1; }}) } | 71 function* g() { yield ({ get yield() { return 1; }}) } |
| 72 | 72 |
| 73 // Checks that yield is a valid label in classic mode, but not valid in a strict | 73 // Checks that yield is a valid label in classic mode, but not valid in a strict |
| 74 // mode or in generators. | 74 // mode or in generators. |
| 75 function f() { yield: 1 } | 75 function f() { yield: 1 } |
| 76 assertThrows("function f() { \"use strict\"; yield: 1 }", SyntaxError) | 76 assertThrows("function f() { \"use strict\"; yield: 1 }", SyntaxError) |
| 77 assertThrows("function f*() { yield: 1 }", SyntaxError) | 77 assertThrows("function* g() { yield: 1 }", SyntaxError) |
| 78 | 78 |
| 79 // Yield is only a keyword in the body of the generator, not in nested | 79 // Yield is only a keyword in the body of the generator, not in nested |
| 80 // functions. | 80 // functions. |
| 81 function* g() { function f() { yield (yield + yield (0)); } } | 81 function* g() { function f() { yield (yield + yield (0)); } } |
| 82 | 82 |
| 83 // Yield needs a RHS. | 83 // Yield needs a RHS. |
| 84 assertThrows("function* g() { yield; }", SyntaxError); | 84 assertThrows("function* g() { yield; }", SyntaxError); |
| 85 | 85 |
| 86 // Yield in a generator is not an identifier. | 86 // Yield in a generator is not an identifier. |
| 87 assertThrows("function* g() { yield = 10; }", SyntaxError); | 87 assertThrows("function* g() { yield = 10; }", SyntaxError); |
| 88 | 88 |
| 89 // Yield binds very loosely, so this parses as "yield (3 + yield 4)", which is | 89 // Yield binds very loosely, so this parses as "yield (3 + yield 4)", which is |
| 90 // invalid. | 90 // invalid. |
| 91 assertThrows("function* g() { yield 3 + yield 4; }", SyntaxError); | 91 assertThrows("function* g() { yield 3 + yield 4; }", SyntaxError); |
| 92 | 92 |
| 93 // Yield is still a future-reserved-word in strict mode | 93 // Yield is still a future-reserved-word in strict mode |
| 94 assertThrows("function f() { \"use strict\"; var yield = 13; }", SyntaxError); | 94 assertThrows("function f() { \"use strict\"; var yield = 13; }", SyntaxError); |
| 95 | 95 |
| 96 // The name of the NFE is let-bound in G, so is invalid. | 96 // The name of the NFE is let-bound in G, so is invalid. |
| 97 assertThrows("function* g() { yield (function yield() {}); }", SyntaxError); | 97 assertThrows("function* g() { yield (function yield() {}); }", SyntaxError); |
| 98 | 98 |
| 99 // In generators, yield is invalid as a formal argument name. | 99 // In generators, yield is invalid as a formal argument name. |
| 100 assertThrows("function* g(yield) { yield (10); }", SyntaxError); | 100 assertThrows("function* g(yield) { yield (10); }", SyntaxError); |
| OLD | NEW |