Bug 1170716 - Part 2: Report unreachable code after return statement as JSEXN_NONE. r=jandem
authorTooru Fujisawa <arai_a@mac.com>
Thu, 11 Jun 2015 13:14:13 +0900
changeset 248232 dcb1893ec57928420ad86e5302c48b468ff6c778
parent 248231 6e36d0a459997873cf57c015ca1b99c448eebf03
child 248233 53a469d716069514b3b42852dff262cba89e66d4
push id28893
push userkwierso@gmail.com
push dateFri, 12 Jun 2015 00:02:58 +0000
treeherderautoland@8cf9d3e497f9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1170716
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1170716 - Part 2: Report unreachable code after return statement as JSEXN_NONE. r=jandem
js/src/jit-test/tests/basic/statement-after-return.js
js/src/js.msg
--- a/js/src/jit-test/tests/basic/statement-after-return.js
+++ b/js/src/jit-test/tests/basic/statement-after-return.js
@@ -1,53 +1,42 @@
 // Warning should be shown for unreachable statement after return (bug 1151931).
 
 load(libdir + "class.js");
 
-if (options().indexOf("werror") == -1)
-  options("werror");
+function testWarn(code, lineNumber, columnNumber) {
+  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);
 
-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);
-
-  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(`
 function f() {
   return (
     1 + 2
   );
 }
--- a/js/src/js.msg
+++ b/js/src/js.msg
@@ -306,17 +306,17 @@ MSG_DEF(JSMSG_REDECLARED_PARAM,        1
 MSG_DEF(JSMSG_RESERVED_ID,             1, JSEXN_SYNTAXERR, "{0} is a reserved identifier")
 MSG_DEF(JSMSG_REST_WITH_DEFAULT,       0, JSEXN_SYNTAXERR, "rest parameter may not have a default")
 MSG_DEF(JSMSG_SELFHOSTED_TOP_LEVEL_LEXICAL, 1, JSEXN_SYNTAXERR, "self-hosted code cannot contain top-level {0} declarations")
 MSG_DEF(JSMSG_SELFHOSTED_UNBOUND_NAME, 0, JSEXN_TYPEERR, "self-hosted code may not contain unbound name lookups")
 MSG_DEF(JSMSG_SEMI_AFTER_FOR_COND,     0, JSEXN_SYNTAXERR, "missing ; after for-loop condition")
 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")
 MSG_DEF(JSMSG_SIMD_NOT_A_VECTOR,       2, JSEXN_TYPEERR, "expecting a SIMD {0} object as argument {1}")
 MSG_DEF(JSMSG_TOO_MANY_CASES,          0, JSEXN_INTERNALERR, "too many switch cases")
 MSG_DEF(JSMSG_TOO_MANY_CATCH_VARS,     0, JSEXN_SYNTAXERR, "too many catch variables")
 MSG_DEF(JSMSG_TOO_MANY_CON_ARGS,       0, JSEXN_SYNTAXERR, "too many constructor arguments")
 MSG_DEF(JSMSG_TOO_MANY_DEFAULTS,       0, JSEXN_SYNTAXERR, "more than one switch default")