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

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

Issue 177683002: Mode clean-up pt 1: rename classic/non-strict mode to sloppy mode (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 function* g() { yield yield 1; } 61 function* g() { yield yield 1; }
62 function* g() { yield 3 + (yield 4); } 62 function* g() { yield 3 + (yield 4); }
63 63
64 // Generator definitions with a name of "yield" are not specifically ruled out 64 // Generator definitions with a name of "yield" are not specifically ruled out
65 // by the spec, as the `yield' name is outside the generator itself. However, 65 // by the spec, as the `yield' name is outside the generator itself. However,
66 // in strict-mode, "yield" is an invalid identifier. 66 // in strict-mode, "yield" is an invalid identifier.
67 function* yield() { (yield 3) + (yield 4); } 67 function* yield() { (yield 3) + (yield 4); }
68 assertThrows("function* yield() { \"use strict\"; (yield 3) + (yield 4); }", 68 assertThrows("function* yield() { \"use strict\"; (yield 3) + (yield 4); }",
69 SyntaxError); 69 SyntaxError);
70 70
71 // In classic mode, yield is a normal identifier, outside of generators. 71 // In sloppy mode, yield is a normal identifier, outside of generators.
72 function yield(yield) { yield: yield (yield + yield (0)); } 72 function yield(yield) { yield: yield (yield + yield (0)); }
73 73
74 // Yield is always valid as a key in an object literal. 74 // Yield is always valid as a key in an object literal.
75 ({ yield: 1 }); 75 ({ yield: 1 });
76 function* g() { yield ({ yield: 1 }) } 76 function* g() { yield ({ yield: 1 }) }
77 function* g() { yield ({ get yield() { return 1; }}) } 77 function* g() { yield ({ get yield() { return 1; }}) }
78 78
79 // Checks that yield is a valid label in classic mode, but not valid in a strict 79 // Checks that yield is a valid label in sloppy mode, but not valid in a strict
80 // mode or in generators. 80 // mode or in generators.
81 function f() { yield: 1 } 81 function f() { yield: 1 }
82 assertThrows("function f() { \"use strict\"; yield: 1 }", SyntaxError) 82 assertThrows("function f() { \"use strict\"; yield: 1 }", SyntaxError)
83 assertThrows("function* g() { yield: 1 }", SyntaxError) 83 assertThrows("function* g() { yield: 1 }", SyntaxError)
84 84
85 // Yield is only a keyword in the body of the generator, not in nested 85 // Yield is only a keyword in the body of the generator, not in nested
86 // functions. 86 // functions.
87 function* g() { function f() { yield (yield + yield (0)); } } 87 function* g() { function f() { yield (yield + yield (0)); } }
88 88
89 // Yield needs a RHS. 89 // Yield needs a RHS.
90 assertThrows("function* g() { yield; }", SyntaxError); 90 assertThrows("function* g() { yield; }", SyntaxError);
91 91
92 // Yield in a generator is not an identifier. 92 // Yield in a generator is not an identifier.
93 assertThrows("function* g() { yield = 10; }", SyntaxError); 93 assertThrows("function* g() { yield = 10; }", SyntaxError);
94 94
95 // Yield binds very loosely, so this parses as "yield (3 + yield 4)", which is 95 // Yield binds very loosely, so this parses as "yield (3 + yield 4)", which is
96 // invalid. 96 // invalid.
97 assertThrows("function* g() { yield 3 + yield 4; }", SyntaxError); 97 assertThrows("function* g() { yield 3 + yield 4; }", SyntaxError);
98 98
99 // Yield is still a future-reserved-word in strict mode 99 // Yield is still a future-reserved-word in strict mode
100 assertThrows("function f() { \"use strict\"; var yield = 13; }", SyntaxError); 100 assertThrows("function f() { \"use strict\"; var yield = 13; }", SyntaxError);
101 101
102 // The name of the NFE is let-bound in G, so is invalid. 102 // The name of the NFE is let-bound in G, so is invalid.
103 assertThrows("function* g() { yield (function yield() {}); }", SyntaxError); 103 assertThrows("function* g() { yield (function yield() {}); }", SyntaxError);
104 104
105 // In generators, yield is invalid as a formal argument name. 105 // In generators, yield is invalid as a formal argument name.
106 assertThrows("function* g(yield) { yield (10); }", SyntaxError); 106 assertThrows("function* g(yield) { yield (10); }", SyntaxError);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698