Reflect.parse("yield 0") should throw a SyntaxError (bug 632028, r=brendan)

This commit is contained in:
Dave Herman 2011-02-11 17:01:39 -08:00
Родитель 7c5d404068
Коммит 28ec320f81
3 изменённых файлов: 18 добавлений и 7 удалений

Просмотреть файл

@ -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() { } }",