mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-31 22:25:30 +00:00
Reflect.parse("yield 0") should throw a SyntaxError (bug 632028, r=brendan)
This commit is contained in:
parent
7c5d404068
commit
28ec320f81
@ -5797,12 +5797,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
|
||||
#if JS_HAS_GENERATORS
|
||||
case TOK_YIELD:
|
||||
if (!cg->inFunction()) {
|
||||
ReportCompileErrorNumber(cx, CG_TS(cg), pn, JSREPORT_ERROR,
|
||||
JSMSG_BAD_RETURN_OR_YIELD,
|
||||
js_yield_str);
|
||||
return JS_FALSE;
|
||||
}
|
||||
JS_ASSERT(cg->inFunction());
|
||||
if (pn->pn_kid) {
|
||||
if (!js_EmitTree(cx, cg, pn->pn_kid))
|
||||
return JS_FALSE;
|
||||
|
@ -4786,8 +4786,13 @@ Parser::returnOrYield(bool useAssignExpr)
|
||||
return NULL;
|
||||
|
||||
#if JS_HAS_GENERATORS
|
||||
if (tt == TOK_YIELD)
|
||||
if (tt == TOK_YIELD) {
|
||||
if (!tc->inFunction()) {
|
||||
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_RETURN_OR_YIELD, js_yield_str);
|
||||
return NULL;
|
||||
}
|
||||
tc->flags |= TCF_FUN_IS_GENERATOR;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This is ugly, but we don't want to require a semicolon. */
|
||||
|
@ -390,6 +390,17 @@ assertStmt("try { } catch (e if foo) { } catch (e if bar) { } catch (e) { } fina
|
||||
catchClause(ident("e"), null, blockStmt([])) ],
|
||||
blockStmt([])));
|
||||
|
||||
// Bug 632028: yield outside of a function should throw
|
||||
(function() {
|
||||
var threw = false;
|
||||
try {
|
||||
Reflect.parse("yield 0");
|
||||
} catch (expected) {
|
||||
threw = true;
|
||||
}
|
||||
assertEq(threw, true);
|
||||
})();
|
||||
|
||||
// redeclarations (TOK_NAME nodes with lexdef)
|
||||
|
||||
assertStmt("function f() { function g() { } function g() { } }",
|
||||
|
Loading…
Reference in New Issue
Block a user