diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 1f37702a284b..035eeef8581a 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -634,6 +634,15 @@ FunctionBox::FunctionBox(ExclusiveContext* cx, ObjectBox* traceListHead, JSFunct 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(); } } diff --git a/js/src/frontend/SharedContext.h b/js/src/frontend/SharedContext.h index 8599f68d7eef..85c9ad47b459 100644 --- a/js/src/frontend/SharedContext.h +++ b/js/src/frontend/SharedContext.h @@ -280,6 +280,14 @@ class GlobalSharedContext : public SharedContext } return false; } + + bool inWith() const { + for (StaticScopeIter it(context, topStaticScope_); !it.done(); it++) { + if (it.type() == StaticScopeIter::With) + return true; + } + return false; + } }; class FunctionBox : public ObjectBox, public SharedContext