summaryrefslogtreecommitdiffstats
path: root/js/src
diff options
context:
space:
mode:
Diffstat (limited to 'js/src')
-rw-r--r--js/src/frontend/Parser.cpp23
-rw-r--r--js/src/frontend/Parser.h2
-rw-r--r--js/src/js.msg4
-rw-r--r--js/src/tests/js1_7/geniter/regress-352197.js2
-rw-r--r--js/src/tests/js1_8/genexps/regress-683738.js8
5 files changed, 10 insertions, 29 deletions
diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp
index b494cc966..0099ed19d 100644
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -909,21 +909,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()->explicitName()) {
- 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.
@@ -6023,10 +6008,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();
}
@@ -6141,8 +6125,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_GENERATOR_RETURN);
return null();
}
diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h
index efbaebafd..27a10458b 100644
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -1445,8 +1445,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; }
diff --git a/js/src/js.msg b/js/src/js.msg
index a276dab94..42a48c3a5 100644
--- a/js/src/js.msg
+++ b/js/src/js.msg
@@ -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")
diff --git a/js/src/tests/js1_7/geniter/regress-352197.js b/js/src/tests/js1_7/geniter/regress-352197.js
index 7982e12ee..495717af7 100644
--- a/js/src/tests/js1_7/geniter/regress-352197.js
+++ b/js/src/tests/js1_7/geniter/regress-352197.js
@@ -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; })');
diff --git a/js/src/tests/js1_8/genexps/regress-683738.js b/js/src/tests/js1_8/genexps/regress-683738.js
index de563645d..b0309a90e 100644
--- a/js/src/tests/js1_8/genexps/regress-683738.js
+++ b/js/src/tests/js1_8/genexps/regress-683738.js
@@ -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';