Bug 1228841 - Part 1: Remove conditional catch consumers in js/. r=evilpie
authorTooru Fujisawa <arai_a@mac.com>
Tue, 05 Dec 2017 09:42:39 +0900
changeset 708625 129e385252093fd9fa06667c863c77ca2148dee8
parent 708624 e441cdecaa27e4ed7638f1b12fc376e6fab4d1b6
child 708626 5e4cbc76568b6ea32330e0ef2b55c898b5095d8b
push id92403
push userVYV03354@nifty.ne.jp
push dateWed, 06 Dec 2017 22:18:41 +0000
reviewersevilpie
bugs1228841
milestone59.0a1
Bug 1228841 - Part 1: Remove conditional catch consumers in js/. r=evilpie
js/src/jit-test/lib/nightly-only.js
js/src/jit-test/lib/syntax.js
js/src/jit-test/tests/baseline/classConstructor-AnyScripted.js
js/src/jit-test/tests/basic/bug593663-regexp.js
js/src/jit-test/tests/debug/Frame-onStep-12.js
js/src/jit-test/tests/gc/bug-1259490.js
js/src/jit-test/tests/ion/bug1293542.js
js/src/jit-test/tests/ion/bug799185-4.js
js/src/jit-test/tests/ion/bug799185-5.js
js/src/jit-test/tests/ion/bug799185-7.js
js/src/jit-test/tests/ion/throw.js
js/src/jit-test/tests/parser/arrow-rest.js
js/src/tests/ecma_3_1/Object/regress-444787.js
js/src/tests/ecma_6/ArrowFunctions/arrow-not-as-end-of-statement.js
js/src/tests/ecma_6/Class/newTargetEval.js
js/src/tests/ecma_6/Class/outerBinding.js
js/src/tests/ecma_6/Class/superCallThisInit.js
js/src/tests/ecma_6/Expressions/destructuring-pattern-parenthesized.js
js/src/tests/js1_5/extensions/regress-104077.js
js/src/tests/js1_7/extensions/regress-350312.js
js/src/tests/js1_8_5/reflect-parse/Match.js
js/src/tests/js1_8_5/reflect-parse/PatternAsserts.js
js/src/tests/js1_8_5/reflect-parse/builderExceptions.js
--- a/js/src/jit-test/lib/nightly-only.js
+++ b/js/src/jit-test/lib/nightly-only.js
@@ -6,15 +6,18 @@
 
 // Call the function f. On beta and release, expect it to throw an error that is
 // an instance of error.
 function nightlyOnly(error, f) {
   if (getBuildConfiguration().release_or_beta) {
     try {
       f();
       throw new Error("use of feature expected to fail on release and beta, but succeeded; please update test");
-    } catch (e if e instanceof error) {
+    } catch (e) {
+      if (!(e instanceof error)) {
+        throw e;
+      }
       // All is well.
     }
   } else {
     f();
   }
 }
--- a/js/src/jit-test/lib/syntax.js
+++ b/js/src/jit-test/lib/syntax.js
@@ -179,24 +179,16 @@ function test_syntax(postfixes, check_er
   test("try {} catch (e ");
   test("try {} catch (e) ");
   test("try {} catch (e) { ");
   test("try {} catch (e) {} ");
   test("try {} catch (e) {} finally ");
   test("try {} catch (e) {} finally { ");
   test("try {} catch (e) {} finally {} ");
 
-  test("try {} catch (e if ");
-  test("try {} catch (e if e  ");
-  test("try {} catch (e if e instanceof ");
-  test("try {} catch (e if e instanceof x ");
-  test("try {} catch (e if e instanceof x) ");
-  test("try {} catch (e if e instanceof x) { ");
-  test("try {} catch (e if e instanceof x) {} ");
-
   // ---- Declarations ----
 
   // var
 
   test("var ");
   test("var x ");
   test("var x = ");
   test("var x = 1 ");
--- a/js/src/jit-test/tests/baseline/classConstructor-AnyScripted.js
+++ b/js/src/jit-test/tests/baseline/classConstructor-AnyScripted.js
@@ -13,9 +13,12 @@ class foo {
 
 // Compile foo()
 for (let i = 0; i < 11; i++)
     new foo();
 
 try {
     test(foo);
     throw new Error("Invoking a class constructor without new must throw");
-} catch (e if e instanceof TypeError) { }
+} catch (e) {
+    if (!(e instanceof TypeError))
+        throw e;
+}
--- a/js/src/jit-test/tests/basic/bug593663-regexp.js
+++ b/js/src/jit-test/tests/basic/bug593663-regexp.js
@@ -2,17 +2,19 @@
  * Ensure that flat matches with metachars in them don't have their metachars
  * interpreted as special.
  */
 
 function isPatternSyntaxError(pattern) {
     try {
         new RegExp(pattern);
         return false;
-    } catch (e if e instanceof SyntaxError) {
+    } catch (e) {
+        if (!(e instanceof SyntaxError))
+            throw e;
         return true;
     }
 }
 
 // Bug example.
 assertEq("1+2".replace("1+2", "$&+3"), "1+2+3");
 assertEq("1112".replace("1+2", ""), "1112");
 
--- a/js/src/jit-test/tests/debug/Frame-onStep-12.js
+++ b/js/src/jit-test/tests/debug/Frame-onStep-12.js
@@ -82,29 +82,16 @@ testOne("testCatchFinally",
            throw new TypeError();
          } catch (e) {
            ${bitOfCode}
          } finally {            // +6
          }                      // +7
          nothing();             // +8
         `, "1689");
 
-// The same but without a finally clause.  This relies on a
-// SpiderMonkey extension, because otherwise there's no way to see
-// extra instructions at the end of a catch.
-testOne("testCatch",
-        `try {
-           throw new TypeError();
-         } catch (e if e instanceof TypeError) {
-           ${bitOfCode}
-         } catch (e) {          // +6
-         }                      // +7
-         nothing();             // +8
-        `, "189");
-
 // Test the instruction at the end of a "finally" clause.
 testOne("testFinally",
         `try {
          } finally {
            ${bitOfCode}
          }                      // +6
          nothing();             // +7
         `, "178");
--- a/js/src/jit-test/tests/gc/bug-1259490.js
+++ b/js/src/jit-test/tests/gc/bug-1259490.js
@@ -1,9 +1,13 @@
-try { eval("3 ** 4") } catch (e if e instanceof SyntaxError) { quit(); };
+try { eval("3 ** 4") } catch (e) {
+    if (!(e instanceof SyntaxError))
+        throw e;
+    quit();
+}
 eval(`
 
 gczeal(8);
 for (var k = 0; k < 99; ++k) {
     uneval(-(0 ** (Object | 0 * Object)))
 }
 
 `)
--- a/js/src/jit-test/tests/ion/bug1293542.js
+++ b/js/src/jit-test/tests/ion/bug1293542.js
@@ -1,7 +1,11 @@
 
-try { eval("3 ** 4") } catch (e if e instanceof SyntaxError) { quit(); };
+try { eval("3 ** 4") } catch (e) {
+    if (!(e instanceof SyntaxError))
+        throw e;
+    quit();
+}
 
 var f = new Function("x", "return (x ** (1 / ~4294967297)) && x");
 for (var i = 0; i < 2; ++i) {
     assertEq(f(-Infinity), 0);
 }
--- a/js/src/jit-test/tests/ion/bug799185-4.js
+++ b/js/src/jit-test/tests/ion/bug799185-4.js
@@ -1,9 +1,12 @@
 function foo(aObject)
 {
     try { }
-    catch (ex if (ex.name == "TypeError")) { }
+    catch (ex) {
+        if (ex.name != "TypeError")
+            throw ex;
+    }
     try { Object.getPrototypeOf(aObject); }
     catch (ex) { }
 }
 
 foo(true);
--- a/js/src/jit-test/tests/ion/bug799185-5.js
+++ b/js/src/jit-test/tests/ion/bug799185-5.js
@@ -1,19 +1,26 @@
 function foo(aObject)
 {
     try {
         try {
             if (!aObject)
                 return;
         }
-        catch (ex if (ex.name == "TypeError")) { }
+        catch (ex) {
+            if (ex.name != "TypeError")
+                throw ex;
+        }
         finally {
         }
         undefined.x;
     }
-    catch (ex if (ex.name == "TypeError")) { }
-    catch (ex if (ex.name == "TypeError")) { }
+    catch (ex) {
+        if (ex.name != "TypeError")
+            throw ex;
+        if (ex.name != "TypeError")
+            throw ex;
+    }
     finally {
     }
 }
 
 foo(true);
--- a/js/src/jit-test/tests/ion/bug799185-7.js
+++ b/js/src/jit-test/tests/ion/bug799185-7.js
@@ -2,26 +2,19 @@ var y = undefined;
 
 try {} catch (x) {
     try {} catch (x) {
         try {} catch (x) {
         }
     }
 }
 
-try {} catch (x if y) {
-    try {} catch (x if y) {
-        try {} catch (x if y) {
-        }
-    }
-}
-
 while (false) {
-    try {} catch ({x,y} if x) {
-        try {} catch ({a,b,c,d} if a) {
+    try {} catch ({x,y}) {
+        try {} catch ({a,b,c,d}) {
             if (b) break;
             if (c) continue;
         }
     } finally {}
 }
 
 Label1:
 for (let foo = 0; foo < 0; foo++) {
--- a/js/src/jit-test/tests/ion/throw.js
+++ b/js/src/jit-test/tests/ion/throw.js
@@ -95,17 +95,18 @@ for (var i = 0; i < 100; i++) {
 }
 assertEq(count, 4500);
 
 function test5() {
     var res = 0;
     for (var i=0; i<40; i++) {
 	try {
 	    throw i;
-	} catch (e if e % 2) {
-	    res += e;
 	} catch (e) {
-	    res += e * 3;
+          if (e % 2)
+	       res += e;
+          else
+	       res += e * 3;
 	}
     }
     return res;
 }
 assertEq(test5(), 1540);
--- a/js/src/jit-test/tests/parser/arrow-rest.js
+++ b/js/src/jit-test/tests/parser/arrow-rest.js
@@ -130,20 +130,16 @@ function* f(x) { yield ...a)=>
 `, 23);
 
 // throw statement
 
 testThrow(`
 throw ...a) =>
 `, 6);
 
-testThrow(`
-try {} catch (x if ...a) =>
-`, 19);
-
 // class
 
 testThrow(`
 class A extends ...a) =>
 `, 16);
 
 // conditional expression
 
--- a/js/src/tests/ecma_3_1/Object/regress-444787.js
+++ b/js/src/tests/ecma_3_1/Object/regress-444787.js
@@ -48,24 +48,23 @@ function test()
 
     try
     {
       eval('instance = new ' + type.name);
       expect = type.prototype;
       actual = Object.getPrototypeOf(instance);
       reportCompare(expect, actual, summary + ': new ' + type.name);
     }
-    catch(ex if ex instanceof TypeError)
-    {
-      print('Ignore ' + ex);
-    }
-    catch(ex)
-    {
-      actual = ex + '';
-      reportCompare(expect, actual, summary + ': new ' + type.name);
+    catch(ex) {
+      if (ex instanceof TypeError) {
+        print('Ignore ' + ex);
+      } else {
+        actual = ex + '';
+        reportCompare(expect, actual, summary + ': new ' + type.name);
+      }
     }
 
   }
 
   types = [null, undefined];
 
   for (i = 0; i < types.length; i++)
   {
--- a/js/src/tests/ecma_6/ArrowFunctions/arrow-not-as-end-of-statement.js
+++ b/js/src/tests/ecma_6/ArrowFunctions/arrow-not-as-end-of-statement.js
@@ -67,32 +67,16 @@ assertEq(gen.next().value, 99);
 assertEq(gen.next().done, true);
 
 switch (1)
 {
   case a => {}:
    break;
 }
 
-try
-{
-  // Catch guards are non-standard, so ignore a syntax error.
-  eval(`try
-  {
-  }
-  catch (x if a => {})
-  {
-  }`);
-}
-catch (e)
-{
-  assertEq(e instanceof SyntaxError, true,
-           "should only have thrown SyntaxError, instead got " + e);
-}
-
 assertEq(0[a => {}], undefined);
 
 class Y {};
 class X extends Y { constructor() { super[a => {}](); } };
 
 if (a => {})
   assertEq(true, true);
 else
--- a/js/src/tests/ecma_6/Class/newTargetEval.js
+++ b/js/src/tests/ecma_6/Class/newTargetEval.js
@@ -1,23 +1,29 @@
 // Eval of new.target is invalid outside functions.
 try {
     eval('new.target');
     assertEq(false, true);
-} catch (e if e instanceof SyntaxError) { }
+} catch (e) {
+    if (!(e instanceof SyntaxError))
+        throw e;
+}
 
 // new.target is invalid inside eval inside top-level arrow functions
 assertThrowsInstanceOf(() => eval('new.target'), SyntaxError);
 
 // new.target is invalid inside indirect eval.
 let ieval = eval;
 try {
     (function () { return ieval('new.target'); })();
     assertEq(false, true);
-} catch (e if e instanceof SyntaxError) { }
+} catch (e) {
+    if (!(e instanceof SyntaxError))
+        throw e;
+}
 
 function assertNewTarget(expected) {
     assertEq(eval('new.target'), expected);
     assertEq((()=>eval('new.target'))(), expected);
 
     // Also test nestings "by induction"
     assertEq(eval('eval("new.target")'), expected);
     assertEq(eval("eval('eval(`new.target`)')"), expected);
--- a/js/src/tests/ecma_6/Class/outerBinding.js
+++ b/js/src/tests/ecma_6/Class/outerBinding.js
@@ -23,17 +23,20 @@ assertEq(Foo, 5);
     // That...didn't actually work, right?
     assertEq(typeof PermanentBinding, "function");
 }
 
 evaluate("const globalConstant = 0; var earlyError = true;");
 
 try {
     evaluate("earlyError = false; class globalConstant { constructor() { } }");
-} catch (e if e instanceof SyntaxError) { }
+} catch (e) {
+    if (!(e instanceof SyntaxError))
+        throw e;
+}
 assertEq(earlyError, true);
 
 function strictEvalShadows() {
     "use strict";
     let x = 4;
     eval(`class x { constructor() { } }
            assertEq(typeof x, "function");
          `);
--- a/js/src/tests/ecma_6/Class/superCallThisInit.js
+++ b/js/src/tests/ecma_6/Class/superCallThisInit.js
@@ -2,17 +2,20 @@ function base() { this.prop = 42; }
 
 class testInitialize extends base {
     constructor() {
         // A poor man's assertThrowsInstanceOf, as arrow functions are currently
         // disabled in this context
         try {
             this;
             throw new Error();
-        } catch (e if e instanceof ReferenceError) { }
+        } catch (e) {
+            if (!(e instanceof ReferenceError))
+                throw e;
+        }
         super();
         assertEq(this.prop, 42);
     }
 }
 assertEq(new testInitialize().prop, 42);
 
 // super() twice is a no-go.
 class willThrow extends base {
--- a/js/src/tests/ecma_6/Expressions/destructuring-pattern-parenthesized.js
+++ b/js/src/tests/ecma_6/Expressions/destructuring-pattern-parenthesized.js
@@ -91,18 +91,19 @@ Function("var a, b; [(demolition['man' +
 
 function classesEnabled()
 {
   try
   {
     new Function("class B { constructor() { } }; class D extends B { constructor() { super(); } }");
     return true;
   }
-  catch (e if e instanceof SyntaxError)
-  {
+  catch (e) {
+    if (!(e instanceof SyntaxError))
+      throw e;
     return false;
   }
 }
 
 if (classesEnabled())
 {
   Function("var a, b; var obj = { x() { [(super.man), b] = [1, 2]; } };")();
   Function("var a, b; var obj = { x() { [(super[8]) = 'motel', b] = [1, 2]; } };")();
--- a/js/src/tests/js1_5/extensions/regress-104077.js
+++ b/js/src/tests/js1_5/extensions/regress-104077.js
@@ -65,18 +65,19 @@ function addValues_3(obj)
     }
     finally
     {
       try
       {
         sum +=1;
         print("In finally block of addValues_3() function: sum = " + sum);
       }
-      catch (e if e == 42)
-      {
+      catch (e) {
+        if (e != 42)
+          throw e;
         sum +=1;
         print('In finally catch block of addValues_3() function: sum = ' + sum + ', e = ' + e);
       }
       finally
       {
         sum +=1;
         print("In finally finally block of addValues_3() function: sum = " + sum);
         return sum;
@@ -127,25 +128,26 @@ function addValues_4(obj)
     }
     finally
     {
       try
       {
         sum += 1;
         print("In finally block of addValues_4() function: sum = " + sum);
       }
-      catch (e if e == 42)
-      {
-        sum += 1;
-        print("In 1st finally catch block of addValues_4() function: sum = " + sum + ", e = " + e);
-      }
-      catch (e if e == 43)
-      {
-        sum += 1;
-        print("In 2nd finally catch block of addValues_4() function: sum = " + sum + ", e = " + e);
+      catch (e) {
+        if (e == 42) {
+          sum += 1;
+          print("In 1st finally catch block of addValues_4() function: sum = " + sum + ", e = " + e);
+        } else if (e == 43) {
+          sum += 1;
+          print("In 2nd finally catch block of addValues_4() function: sum = " + sum + ", e = " + e);
+        } else {
+          throw e;
+        }
       }
       finally
       {
         sum += 1;
         print("In finally finally block of addValues_4() function: sum = " + sum);
         return sum;
       }
     }
--- a/js/src/tests/js1_7/extensions/regress-350312.js
+++ b/js/src/tests/js1_7/extensions/regress-350312.js
@@ -19,17 +19,19 @@ function test()
   printBugNumber(BUGNUMBER);
   printStatus (summary);
 
   var iter;
   function* gen()
   {
     try {
       yield iter;
-    } catch (e if e == null) {
+    } catch (e) {
+      if (e != null)
+        throw e;
       actual += 'CATCH,';
       print("CATCH");
     } finally {
       actual += 'FINALLY';
       print("FINALLY");
     }
   }
 
--- a/js/src/tests/js1_8_5/reflect-parse/Match.js
+++ b/js/src/tests/js1_8_5/reflect-parse/Match.js
@@ -17,26 +17,30 @@ var Match =
         match: function(act) {
             return match(act, this.template);
         },
 
         matches: function(act) {
             try {
                 return this.match(act);
             }
-            catch (e if e instanceof MatchError) {
+            catch (e) {
+                if (!(e instanceof MatchError))
+                    throw e;
                 return false;
             }
         },
 
         assert: function(act, message) {
             try {
                 return this.match(act);
             }
-            catch (e if e instanceof MatchError) {
+            catch (e) {
+                if (!(e instanceof MatchError))
+                    throw e;
                 throw new Error((message || "failed match") + ": " + e.message);
             }
         },
 
         toString: () => "[object Pattern]"
     };
 
     Pattern.ANY = new Pattern;
--- a/js/src/tests/js1_8_5/reflect-parse/PatternAsserts.js
+++ b/js/src/tests/js1_8_5/reflect-parse/PatternAsserts.js
@@ -81,13 +81,15 @@ function assertDecl(src, patt) {
     assertLocalDecl(src, patt);
     assertGlobalDecl(src, patt);
     assertBlockDecl(src, patt);
 }
 
 function assertError(src, errorType) {
     try {
         Reflect.parse(src);
-    } catch (expected if expected instanceof errorType) {
+    } catch (expected) {
+        if (!(expected instanceof errorType))
+            throw expected;
         return;
     }
     throw new Error("expected " + errorType.name + " for " + uneval(src));
 }
--- a/js/src/tests/js1_8_5/reflect-parse/builderExceptions.js
+++ b/js/src/tests/js1_8_5/reflect-parse/builderExceptions.js
@@ -1,13 +1,15 @@
 // |reftest| skip-if(!xulRuntime.shell)
 // Ensure that exceptions thrown by builder methods propagate.
 var thrown = false;
 try {
     Reflect.parse("42", { builder: { program: function() { throw "expected" } } });
-} catch (e if e === "expected") {
+} catch (e) {
+    if (e !== "expected")
+        throw e;
     thrown = true;
 }
 if (!thrown)
     throw new Error("builder exception not propagated");
 
 if (typeof reportCompare === 'function')
     reportCompare(true, true);