Bug 1265313 - Fix Annex B.3.5 handling with body-level lexicals. (r=jorendorff)
authorShu-yu Guo <shu@rfrn.org>
Wed, 20 Apr 2016 14:52:12 -0700
changeset 332046 c2564073b2bb4de52c77d295c4a4546c528b632c
parent 332045 315627acd221535a346a0a7461efdd4a01d8fc28
child 332047 d9ebe0f67883212df579984595f447f655eb332b
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1265313
milestone48.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 1265313 - Fix Annex B.3.5 handling with body-level lexicals. (r=jorendorff)
js/src/frontend/Parser.cpp
js/src/tests/ecma_6/LexicalEnvironment/var-in-catch-body-annex-b.js
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -4014,17 +4014,17 @@ Parser<ParseHandler>::PossibleError::tra
 
 template <typename ParseHandler>
 static inline bool
 HasOuterLexicalBinding(ParseContext<ParseHandler>* pc, StmtInfoPC* stmt, HandleAtom atom)
 {
     while (stmt->enclosingScope) {
         stmt = LexicalLookup(pc, atom, stmt->enclosingScope);
         if (!stmt)
-            return false;
+            break;
         if (stmt->type == StmtType::BLOCK)
             return true;
     }
 
     // Even if the binding doesn't appear in any blocks, it might still be a
     // body-level lexical.
     return pc->isBodyLevelLexicallyDeclaredName(atom);
 }
--- a/js/src/tests/ecma_6/LexicalEnvironment/var-in-catch-body-annex-b.js
+++ b/js/src/tests/ecma_6/LexicalEnvironment/var-in-catch-body-annex-b.js
@@ -37,16 +37,27 @@ assertThrowsInstanceOf(function () {
        function f() {
          try {} catch (x) {
            const x;
          }
        }
        `);
 }, SyntaxError);
 
+// Tests that redeclaring a var inside the catch is not allowed if there's a
+// body-level lexical.
+assertThrowsInstanceOf(function () {
+  eval(`
+    let x;
+    try {} catch (x) {
+      var x;
+    }
+    `);
+}, SyntaxError);
+
 var log = '';
 var x = 'global-x';
 
 function g() {
   x = 'g';
   try { throw 8; } catch (x) {
     var x = 42;
     log += x;