js/src/tests/ecma_6/Generators/syntax.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // This file was written by Andy Wingo <wingo@igalia.com> and originally
michael@0 2 // contributed to V8 as generators-parsing.js, available here:
michael@0 3 //
michael@0 4 // http://code.google.com/p/v8/source/browse/branches/bleeding_edge/test/mjsunit/harmony/generators-parsing.js
michael@0 5
michael@0 6 function assertSyntaxError(str) {
michael@0 7 var msg;
michael@0 8 var evil = eval;
michael@0 9 try {
michael@0 10 // Non-direct eval.
michael@0 11 evil(str);
michael@0 12 } catch (exc) {
michael@0 13 if (exc instanceof SyntaxError)
michael@0 14 return;
michael@0 15 msg = "Assertion failed: expected SyntaxError, got " + exc;
michael@0 16 }
michael@0 17 if (msg === undefined)
michael@0 18 msg = "Assertion failed: expected SyntaxError, but no exception thrown";
michael@0 19 throw new Error(msg + " - " + str);
michael@0 20 }
michael@0 21
michael@0 22 // Yield statements.
michael@0 23 function* g() { yield 3; yield 4; }
michael@0 24
michael@0 25 // Yield expressions.
michael@0 26 function* g() { (yield 3) + (yield 4); }
michael@0 27
michael@0 28 // You can have a generator in strict mode.
michael@0 29 function* g() { "use strict"; yield 3; yield 4; }
michael@0 30
michael@0 31 // Generators can have return statements also, which internally parse to a kind
michael@0 32 // of yield expression.
michael@0 33 function* g() { yield 1; return; }
michael@0 34 function* g() { yield 1; return 2; }
michael@0 35 function* g() { yield 1; return 2; yield "dead"; }
michael@0 36
michael@0 37 // Generator expression.
michael@0 38 (function* () { yield 3; });
michael@0 39
michael@0 40 // Named generator expression.
michael@0 41 (function* g() { yield 3; });
michael@0 42
michael@0 43 // Generators do not have to contain yield expressions.
michael@0 44 function* g() { }
michael@0 45
michael@0 46 // YieldExpressions can occur in the RHS of a YieldExpression.
michael@0 47 function* g() { yield yield 1; }
michael@0 48 function* g() { yield 3 + (yield 4); }
michael@0 49
michael@0 50 // Generator definitions with a name of "yield" are not specifically ruled out
michael@0 51 // by the spec, as the `yield' name is outside the generator itself. However,
michael@0 52 // in strict-mode, "yield" is an invalid identifier.
michael@0 53 function* yield() { (yield 3) + (yield 4); }
michael@0 54 assertSyntaxError("function* yield() { 'use strict'; (yield 3) + (yield 4); }");
michael@0 55
michael@0 56 // In classic mode, yield is a normal identifier, outside of generators.
michael@0 57 function yield(yield) { yield: yield (yield + yield (0)); }
michael@0 58
michael@0 59 // Yield is always valid as a key in an object literal.
michael@0 60 ({ yield: 1 });
michael@0 61 function* g() { yield ({ yield: 1 }) }
michael@0 62 function* g() { yield ({ get yield() { return 1; }}) }
michael@0 63
michael@0 64 // Yield is a valid property name.
michael@0 65 function* g(obj) { yield obj.yield; }
michael@0 66
michael@0 67 // Checks that yield is a valid label in classic mode, but not valid in a strict
michael@0 68 // mode or in generators.
michael@0 69 function f() { yield: 1 }
michael@0 70 assertSyntaxError("function f() { 'use strict'; yield: 1 }")
michael@0 71 assertSyntaxError("function* g() { yield: 1 }")
michael@0 72
michael@0 73 // Yield is only a keyword in the body of the generator, not in nested
michael@0 74 // functions.
michael@0 75 function* g() { function f(yield) { yield (yield + yield (0)); } }
michael@0 76
michael@0 77 // Yield needs a RHS.
michael@0 78 assertSyntaxError("function* g() { yield; }");
michael@0 79
michael@0 80 // Yield in a generator is not an identifier.
michael@0 81 assertSyntaxError("function* g() { yield = 10; }");
michael@0 82
michael@0 83 // Yield binds very loosely, so this parses as "yield (3 + yield 4)", which is
michael@0 84 // invalid.
michael@0 85 assertSyntaxError("function* g() { yield 3 + yield 4; }");
michael@0 86
michael@0 87 // Yield is still a future-reserved-word in strict mode
michael@0 88 assertSyntaxError("function f() { 'use strict'; var yield = 13; }");
michael@0 89
michael@0 90 // The name of the NFE is let-bound in G, so is invalid.
michael@0 91 assertSyntaxError("function* g() { yield (function yield() {}); }");
michael@0 92
michael@0 93 // In generators, yield is invalid as a formal argument name.
michael@0 94 assertSyntaxError("function* g(yield) { yield (10); }");
michael@0 95
michael@0 96 if (typeof reportCompare == "function")
michael@0 97 reportCompare(true, true);

mercurial