Bug 1165486 - Detect with scopes at parse time using the static scope chain instead of treating it as a polluted global. (r=luke)
☠☠ backed out by b7e3bb16f653 ☠ ☠
authorShu-yu Guo <shu@rfrn.org>
Mon, 15 Jun 2015 17:38:01 -0700
changeset 279770 63bd369e5349f7e5d547a138854fa8ca3f7c1171
parent 279769 1e35269a8062ed01f08d5e27f5cb63fcc30aea47
child 279771 53fcddbe4cfb5bc6042ca08d04383c85d9ef8bf0
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1165486
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 1165486 - Detect with scopes at parse time using the static scope chain instead of treating it as a polluted global. (r=luke)
js/src/frontend/Parser.cpp
js/src/frontend/SharedContext.h
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -629,16 +629,25 @@ FunctionBox::FunctionBox(ExclusiveContex
         //
         //   with (o) { eval("(function() { (function() { g(); })(); })();"); } }
         //
         // In this case, the inner anonymous function needs to inherit the
         // setting of |inWith| from the outer one.
         FunctionBox* parent = outerpc->sc->asFunctionBox();
         if (parent && parent->inWith)
             inWith = true;
+    } else {
+        // This is like the above case, but when inside eval.
+        //
+        // For example:
+        //
+        //   with(o) { eval("(function() { g(); })();"); }
+        //
+        // In this case, the static scope chain tells us the presence of with.
+        inWith = outerpc->sc->asGlobalSharedContext()->inWith();
     }
 }
 
 template <typename ParseHandler>
 FunctionBox*
 Parser<ParseHandler>::newFunctionBox(Node fn, JSFunction* fun, ParseContext<ParseHandler>* outerpc,
                                      Directives inheritedDirectives, GeneratorKind generatorKind)
 {
--- a/js/src/frontend/SharedContext.h
+++ b/js/src/frontend/SharedContext.h
@@ -275,16 +275,24 @@ class GlobalSharedContext : public Share
             if (it.type() == StaticScopeIter<CanGC>::Function &&
                 !it.fun().isArrow())
             {
                 return FunctionAllowsSyntax(&it.fun(), allowed);
             }
         }
         return false;
     }
+
+    bool inWith() const {
+        for (StaticScopeIter<CanGC> it(context, topStaticScope_); !it.done(); it++) {
+            if (it.type() == StaticScopeIter<CanGC>::With)
+                return true;
+        }
+        return false;
+    }
 };
 
 class FunctionBox : public ObjectBox, public SharedContext
 {
   public:
     Bindings        bindings;               /* bindings for this function */
     uint32_t        bufStart;
     uint32_t        bufEnd;