зеркало из https://github.com/mozilla/gecko-dev.git
Bug 885463 - Warn about 'yield' without operand. r=Waldo.
This commit is contained in:
Родитель
d1c02ea68b
Коммит
015a216e4f
|
@ -4425,6 +4425,11 @@ Parser<ParseHandler>::returnStatementOrYieldExpression()
|
|||
(isYield && (next == TOK_YIELD || next == TOK_RB || next == TOK_RP ||
|
||||
next == TOK_COLON || next == TOK_COMMA)))
|
||||
{
|
||||
if (isYield) {
|
||||
if (!reportWithOffset(ParseWarning, false, pos().begin, JSMSG_YIELD_WITHOUT_OPERAND))
|
||||
return null();
|
||||
}
|
||||
|
||||
exprNode = null();
|
||||
if (!isYield)
|
||||
pc->funHasReturnVoid = true;
|
||||
|
|
|
@ -38,3 +38,64 @@ if (typeof assertThrowsValue === 'undefined') {
|
|||
throw new Error(fullmsg);
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof assertWarning === 'undefined') {
|
||||
var assertWarning = function assertWarning(f, errorClass, msg) {
|
||||
var hadWerror = options().split(",").indexOf("werror") !== -1;
|
||||
|
||||
// Ensure the "werror" option is disabled.
|
||||
if (hadWerror)
|
||||
options("werror");
|
||||
|
||||
try {
|
||||
f();
|
||||
} catch (exc) {
|
||||
if (hadWerror)
|
||||
options("werror");
|
||||
|
||||
// print() rather than throw a different exception value, in case
|
||||
// the caller wants exc.stack.
|
||||
if (msg)
|
||||
print("assertWarning: " + msg);
|
||||
print("assertWarning: Unexpected exception calling " + f +
|
||||
" with warnings-as-errors disabled");
|
||||
throw exc;
|
||||
}
|
||||
|
||||
// Enable the "werror" option.
|
||||
options("werror");
|
||||
|
||||
try {
|
||||
assertThrowsInstanceOf(f, errorClass, msg);
|
||||
} catch (exc) {
|
||||
if (msg)
|
||||
print("assertWarning: " + msg);
|
||||
throw exc;
|
||||
} finally {
|
||||
if (!hadWerror)
|
||||
options("werror");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof assertNoWarning === 'undefined') {
|
||||
var assertNoWarning = function assertWarning(f, msg) {
|
||||
// Ensure the "werror" option is enabled.
|
||||
var hadWerror = options().split(",").indexOf("werror") !== -1;
|
||||
if (!hadWerror)
|
||||
options("werror");
|
||||
|
||||
try {
|
||||
f();
|
||||
} catch (exc) {
|
||||
if (msg)
|
||||
print("assertNoWarning: " + msg);
|
||||
print("assertNoWarning: Unexpected exception calling " + f +
|
||||
"with warnings-as-errors enabled");
|
||||
throw exc;
|
||||
} finally {
|
||||
if (!hadWerror)
|
||||
options("werror");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
// yield without an operand causes a warning. See bug 885463.
|
||||
|
||||
load(libdir + "asserts.js");
|
||||
|
||||
assertWarning(() => Function("yield"), SyntaxError,
|
||||
"yield followed by EOF should cause a warning");
|
||||
assertWarning(() => Function("yield;"), SyntaxError,
|
||||
"yield followed by semicolon should cause a warning");
|
||||
assertWarning(() => Function("yield\n print('ok');"), SyntaxError,
|
||||
"yield followed by newline should cause a warning");
|
||||
|
||||
assertWarning(() => eval("(function () { yield; })"), SyntaxError,
|
||||
"yield followed by semicolon in eval code should cause a warning");
|
||||
assertWarning(() => eval("(function () { yield })"), SyntaxError,
|
||||
"yield followed by } in eval code should cause a warning");
|
||||
|
||||
assertNoWarning(() => Function("yield 0;"),
|
||||
"yield with an operand should be fine");
|
||||
assertNoWarning(() => Function("yield 0"),
|
||||
"yield with an operand should be fine, even without a semicolon");
|
||||
|
||||
print("\npassed - all those warnings are normal and there's no real way to suppress them");
|
|
@ -322,7 +322,7 @@ MSG_DEF(JSMSG_INVALID_FOR_IN_INIT, 268, 0, JSEXN_SYNTAXERR, "for-in loop let
|
|||
MSG_DEF(JSMSG_CLEARED_SCOPE, 269, 0, JSEXN_TYPEERR, "attempt to run compile-and-go script on a cleared scope")
|
||||
MSG_DEF(JSMSG_MALFORMED_ESCAPE, 270, 1, JSEXN_SYNTAXERR, "malformed {0} character escape sequence")
|
||||
MSG_DEF(JSMSG_BAD_GENEXP_BODY, 271, 1, JSEXN_SYNTAXERR, "illegal use of {0} in generator expression")
|
||||
MSG_DEF(JSMSG_UNUSED272, 272, 0, JSEXN_NONE, "")
|
||||
MSG_DEF(JSMSG_YIELD_WITHOUT_OPERAND, 272, 0, JSEXN_SYNTAXERR, "yield without a value is deprecated, and illegal in ES6 (use 'yield undefined' instead)")
|
||||
MSG_DEF(JSMSG_UNNAMED_FUNCTION_STMT, 273, 0, JSEXN_SYNTAXERR, "function statement requires a name")
|
||||
MSG_DEF(JSMSG_CCW_REQUIRED, 274, 1, JSEXN_TYPEERR, "{0}: argument must be an object from a different compartment")
|
||||
MSG_DEF(JSMSG_DEBUG_BAD_RESUMPTION, 275, 0, JSEXN_TYPEERR, "debugger resumption value must be undefined, {throw: val}, {return: val}, or null")
|
||||
|
|
Загрузка…
Ссылка в новой задаче