зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1296814 - Remove Parser::reportBadReturn and report simpler errors that don't use the offset of a node as location. r=arai
--HG-- extra : rebase_source : bb602d66d581b46a5b321137013d05e09ce60350
This commit is contained in:
Родитель
43a9efa314
Коммит
e72e3de588
|
@ -901,21 +901,6 @@ Parser<ParseHandler>::parse()
|
|||
return pn;
|
||||
}
|
||||
|
||||
template <typename ParseHandler>
|
||||
bool
|
||||
Parser<ParseHandler>::reportBadReturn(Node pn, ParseReportKind kind,
|
||||
unsigned errnum, unsigned anonerrnum)
|
||||
{
|
||||
JSAutoByteString name;
|
||||
if (JSAtom* atom = pc->functionBox()->function()->name()) {
|
||||
if (!AtomToPrintableString(context, atom, &name))
|
||||
return false;
|
||||
} else {
|
||||
errnum = anonerrnum;
|
||||
}
|
||||
return reportWithNode(kind, pc->sc()->strict(), pn, errnum, name.ptr());
|
||||
}
|
||||
|
||||
/*
|
||||
* Strict mode forbids introducing new definitions for 'eval', 'arguments', or
|
||||
* for any strict mode reserved keyword.
|
||||
|
@ -5962,10 +5947,9 @@ Parser<ParseHandler>::returnStatement(YieldHandling yieldHandling)
|
|||
if (!pn)
|
||||
return null();
|
||||
|
||||
/* Disallow "return v;" in legacy generators. */
|
||||
if (pc->isLegacyGenerator() && exprNode) {
|
||||
/* Disallow "return v;" in legacy generators. */
|
||||
reportBadReturn(pn, ParseError, JSMSG_BAD_GENERATOR_RETURN,
|
||||
JSMSG_BAD_ANON_GENERATOR_RETURN);
|
||||
errorAt(begin, JSMSG_BAD_GENERATOR_RETURN);
|
||||
return null();
|
||||
}
|
||||
|
||||
|
@ -6080,8 +6064,7 @@ Parser<ParseHandler>::yieldExpression(InHandling inHandling)
|
|||
)
|
||||
{
|
||||
/* As in Python (see PEP-255), disallow return v; in generators. */
|
||||
reportBadReturn(null(), ParseError, JSMSG_BAD_GENERATOR_RETURN,
|
||||
JSMSG_BAD_ANON_GENERATOR_RETURN);
|
||||
errorAt(begin, JSMSG_BAD_FUNCTION_YIELD);
|
||||
return null();
|
||||
}
|
||||
|
||||
|
|
|
@ -1437,8 +1437,6 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
|
|||
|
||||
static Node null() { return ParseHandler::null(); }
|
||||
|
||||
bool reportBadReturn(Node pn, ParseReportKind kind, unsigned errnum, unsigned anonerrnum);
|
||||
|
||||
JSAtom* prefixAccessorName(PropertyType propType, HandleAtom propAtom);
|
||||
|
||||
TokenPos pos() const { return tokenStream.currentToken().pos; }
|
||||
|
|
|
@ -186,7 +186,6 @@ MSG_DEF(JSMSG_AS_AFTER_IMPORT_STAR, 0, JSEXN_SYNTAXERR, "missing keyword 'as'
|
|||
MSG_DEF(JSMSG_AS_AFTER_RESERVED_WORD, 1, JSEXN_SYNTAXERR, "missing keyword 'as' after reserved word '{0}'")
|
||||
MSG_DEF(JSMSG_ASYNC_GENERATOR, 0, JSEXN_SYNTAXERR, "generator function or method can't be async")
|
||||
MSG_DEF(JSMSG_AWAIT_IN_DEFAULT, 0, JSEXN_SYNTAXERR, "await can't be used in default expression")
|
||||
MSG_DEF(JSMSG_BAD_ANON_GENERATOR_RETURN, 0, JSEXN_TYPEERR, "anonymous generator function returns a value")
|
||||
MSG_DEF(JSMSG_BAD_ARROW_ARGS, 0, JSEXN_SYNTAXERR, "invalid arrow-function arguments (parentheses around the arrow-function may help)")
|
||||
MSG_DEF(JSMSG_BAD_BINDING, 1, JSEXN_SYNTAXERR, "redefining {0} is deprecated")
|
||||
MSG_DEF(JSMSG_BAD_CONST_DECL, 0, JSEXN_SYNTAXERR, "missing = in const declaration")
|
||||
|
@ -200,7 +199,8 @@ MSG_DEF(JSMSG_BAD_FOR_EACH_LOOP, 0, JSEXN_SYNTAXERR, "invalid for each loo
|
|||
MSG_DEF(JSMSG_BAD_FOR_LEFTSIDE, 0, JSEXN_SYNTAXERR, "invalid for-in/of left-hand side")
|
||||
MSG_DEF(JSMSG_LEXICAL_DECL_DEFINES_LET,0, JSEXN_SYNTAXERR, "a lexical declaration can't define a 'let' binding")
|
||||
MSG_DEF(JSMSG_LET_STARTING_FOROF_LHS, 0, JSEXN_SYNTAXERR, "an expression X in 'for (X of Y)' must not start with 'let'")
|
||||
MSG_DEF(JSMSG_BAD_GENERATOR_RETURN, 1, JSEXN_TYPEERR, "generator function {0} returns a value")
|
||||
MSG_DEF(JSMSG_BAD_FUNCTION_YIELD, 0, JSEXN_TYPEERR, "can't use 'yield' in a function that can return a value")
|
||||
MSG_DEF(JSMSG_BAD_GENERATOR_RETURN, 0, JSEXN_TYPEERR, "generator function can't return a value")
|
||||
MSG_DEF(JSMSG_BAD_GENEXP_BODY, 1, JSEXN_SYNTAXERR, "illegal use of {0} in generator expression")
|
||||
MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 0, JSEXN_REFERENCEERR, "invalid increment/decrement operand")
|
||||
MSG_DEF(JSMSG_BAD_METHOD_DEF, 0, JSEXN_SYNTAXERR, "bad method definition")
|
||||
|
|
|
@ -20,7 +20,7 @@ function test()
|
|||
printBugNumber(BUGNUMBER);
|
||||
printStatus (summary);
|
||||
|
||||
expect = /TypeError: anonymous generator function returns a value/;
|
||||
expect = /TypeError: can't use 'yield' in a function that can return a value/;
|
||||
try
|
||||
{
|
||||
var gen = eval('(function() { { return 5; } yield 3; })');
|
||||
|
|
|
@ -20,7 +20,7 @@ function test()
|
|||
printBugNumber(BUGNUMBER);
|
||||
printStatus (summary);
|
||||
|
||||
expect = "generator function foo returns a value";
|
||||
expect = "can't use 'yield' in a function that can return a value";
|
||||
try
|
||||
{
|
||||
actual = 'No Error';
|
||||
|
@ -32,7 +32,7 @@ function test()
|
|||
}
|
||||
reportCompare(expect, actual, summary + ": 1");
|
||||
|
||||
expect = "generator function foo returns a value";
|
||||
expect = "generator function can't return a value";
|
||||
try
|
||||
{
|
||||
actual = 'No Error';
|
||||
|
@ -44,7 +44,7 @@ function test()
|
|||
}
|
||||
reportCompare(expect, actual, summary + ": 2");
|
||||
|
||||
expect = "generator function foo returns a value";
|
||||
expect = "can't use 'yield' in a function that can return a value";
|
||||
try
|
||||
{
|
||||
actual = 'No Error';
|
||||
|
@ -56,7 +56,7 @@ function test()
|
|||
}
|
||||
reportCompare(expect, actual, summary + ": 3");
|
||||
|
||||
expect = "generator function foo returns a value";
|
||||
expect = "generator function can't return a value";
|
||||
try
|
||||
{
|
||||
actual = 'No Error';
|
||||
|
|
|
@ -1162,7 +1162,7 @@ add_test({
|
|||
|
||||
self.assertTestResult(False)
|
||||
self.assertInLog(TEST_FAIL_STRING)
|
||||
self.assertInLog("TypeError: generator function run_test returns a value at")
|
||||
self.assertInLog("TypeError: generator function can't return a value at")
|
||||
self.assertInLog("test_error.js:4")
|
||||
self.assertNotInLog(TEST_PASS_STRING)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче