Bug 1170716 - Part 2: Report unreachable code after return statement as JSEXN_NONE. r=jandem

This commit is contained in:
Tooru Fujisawa 2015-06-11 13:14:13 +09:00
parent e6c52001a6
commit e897dd83b1
2 changed files with 25 additions and 36 deletions

View File

@ -2,47 +2,36 @@
load(libdir + "class.js");
if (options().indexOf("werror") == -1)
options("werror");
function testWarn(code, lineNumber, columnNumber) {
var caught = false;
try {
eval(code);
} catch (e) {
caught = true;
assertEq(e.constructor, SyntaxError);
assertEq(e.lineNumber, lineNumber);
assertEq(e.columnNumber, columnNumber);
}
assertEq(caught, true, "warning should be caught for " + code);
enableLastWarning();
eval(code);
var warning = getLastWarning();
assertEq(warning !== null, true, "warning should be caught for " + code);
assertEq(warning.name, "None");
assertEq(warning.lineNumber, lineNumber);
assertEq(warning.columnNumber, columnNumber);
caught = false;
try {
Reflect.parse(code);
} catch (e) {
caught = true;
assertEq(e.constructor, SyntaxError);
}
assertEq(caught, true, "warning should be caught for " + code);
clearLastWarning();
Reflect.parse(code);
warning = getLastWarning();
assertEq(warning !== null, true, "warning should be caught for " + code);
assertEq(warning.name, "None");
// Warning generated by Reflect.parse has line/column number for Reflect.parse
// itself, not parsed code.
disableLastWarning();
}
function testPass(code) {
var caught = false;
try {
eval(code);
} catch (e) {
caught = true;
}
assertEq(caught, false, "warning should not be caught for " + code);
enableLastWarning();
eval(code);
var warning = getLastWarning();
assertEq(warning, null, "warning should not be caught for " + code);
caught = false;
try {
Reflect.parse(code);
} catch (e) {
caught = true;
}
assertEq(caught, false, "warning should not be caught for " + code);
clearLastWarning();
Reflect.parse(code);
warning = getLastWarning();
assertEq(warning, null, "warning should not be caught for " + code);
disableLastWarning();
}
testPass(`

View File

@ -311,7 +311,7 @@ MSG_DEF(JSMSG_SEMI_AFTER_FOR_COND, 0, JSEXN_SYNTAXERR, "missing ; after for-
MSG_DEF(JSMSG_SEMI_AFTER_FOR_INIT, 0, JSEXN_SYNTAXERR, "missing ; after for-loop initializer")
MSG_DEF(JSMSG_SEMI_BEFORE_STMNT, 0, JSEXN_SYNTAXERR, "missing ; before statement")
MSG_DEF(JSMSG_SOURCE_TOO_LONG, 0, JSEXN_RANGEERR, "source is too long")
MSG_DEF(JSMSG_STMT_AFTER_RETURN, 0, JSEXN_SYNTAXERR, "unreachable code after return statement")
MSG_DEF(JSMSG_STMT_AFTER_RETURN, 0, JSEXN_NONE, "unreachable code after return statement")
MSG_DEF(JSMSG_STRICT_CODE_WITH, 0, JSEXN_SYNTAXERR, "strict mode code may not contain 'with' statements")
MSG_DEF(JSMSG_STRICT_FUNCTION_STATEMENT, 0, JSEXN_SYNTAXERR, "in strict mode code, functions may be declared only at top level or immediately within another function")
MSG_DEF(JSMSG_TEMPLSTR_UNTERM_EXPR, 0, JSEXN_SYNTAXERR, "missing } in template string")