Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: test/mjsunit/harmony/generators-parsing.js

Issue 12646003: Add parser support for generators. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: Fix bad initialization list in last preparser commit Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/token.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 // Flags: --harmony-generators
29
30 // Test basic generator syntax.
31
32 // Yield statements.
33 function* g() { yield 3; yield 4; }
34
35 // Yield expressions.
36 function* g() { (yield 3) + (yield 4); }
37
38 // You can have a generator in strict mode.
39 function* g() { "use strict"; yield 3; yield 4; }
40
41 // Generator expression.
42 (function* () { yield 3; });
43
44 // Named generator expression.
45 (function* g() { yield 3; });
46
47 // A generator without a yield is specified as causing an early error. This
48 // behavior is currently unimplemented. See
49 // https://bugs.ecmascript.org/show_bug.cgi?id=1283.
50 function* g() { }
51
52 // A YieldExpression in the RHS of a YieldExpression is currently specified as
53 // causing an early error. This behavior is currently unimplemented. See
54 // https://bugs.ecmascript.org/show_bug.cgi?id=1283.
55 function* g() { yield yield 1; }
56 function* g() { yield 3 + (yield 4); }
57
58 // Generator definitions with a name of "yield" are not specifically ruled out
59 // by the spec, as the `yield' name is outside the generator itself. However,
60 // in strict-mode, "yield" is an invalid identifier.
61 function* yield() { (yield 3) + (yield 4); }
62 assertThrows("function* yield() { \"use strict\"; (yield 3) + (yield 4); }",
63 SyntaxError);
64
65 // In classic mode, yield is a normal identifier, outside of generators.
66 function yield(yield) { yield: yield (yield + yield (0)); }
67
68 // Yield is always valid as a key in an object literal.
69 ({ yield: 1 });
70 function* g() { yield ({ yield: 1 }) }
71 function* g() { yield ({ get yield() { return 1; }}) }
72
73 // Checks that yield is a valid label in classic mode, but not valid in a strict
74 // mode or in generators.
75 function f() { yield: 1 }
76 assertThrows("function f() { \"use strict\"; yield: 1 }", SyntaxError)
77 assertThrows("function f*() { yield: 1 }", SyntaxError)
arv (Not doing code reviews) 2013/04/04 20:56:11 This should be function* f()
Michael Starzinger 2013/04/05 08:36:04 See https://codereview.chromium.org/13575010/ for
78
79 // Yield is only a keyword in the body of the generator, not in nested
80 // functions.
81 function* g() { function f() { yield (yield + yield (0)); } }
82
83 // Yield needs a RHS.
84 assertThrows("function* g() { yield; }", SyntaxError);
85
86 // Yield in a generator is not an identifier.
87 assertThrows("function* g() { yield = 10; }", SyntaxError);
88
89 // Yield binds very loosely, so this parses as "yield (3 + yield 4)", which is
90 // invalid.
91 assertThrows("function* g() { yield 3 + yield 4; }", SyntaxError);
92
93 // Yield is still a future-reserved-word in strict mode
94 assertThrows("function f() { \"use strict\"; var yield = 13; }", SyntaxError);
95
96 // The name of the NFE is let-bound in G, so is invalid.
97 assertThrows("function* g() { yield (function yield() {}); }", SyntaxError);
98
99 // In generators, yield is invalid as a formal argument name.
100 assertThrows("function* g(yield) { yield (10); }", SyntaxError);
OLDNEW
« no previous file with comments | « src/token.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698