Bug 1144743 part 4. Set the hasPollutedGlobalScope flag correctly when compiling functions. r=luke
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 20 Mar 2015 00:34:07 -0400
changeset 263531 f1962bdd6fb8ffa5461b12aab7e411f172aa009f
parent 263530 f3f6eef1a0cc3a3417fd8bfb29a12f6f7b8b1a4f
child 263532 4fbc8769b1e5a456765d2ccca82e1a5239bbd288
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1144743
milestone39.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 1144743 part 4. Set the hasPollutedGlobalScope flag correctly when compiling functions. r=luke
js/src/frontend/BytecodeEmitter.cpp
js/src/jsapi.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -5396,16 +5396,17 @@ EmitFunc(ExclusiveContext *cx, BytecodeE
                 funbox->setMightAliasLocals();      // inherit mightAliasLocals from parent
             MOZ_ASSERT_IF(outersc->strict(), funbox->strictScript);
 
             // Inherit most things (principals, version, etc) from the parent.
             Rooted<JSScript*> parent(cx, bce->script);
             CompileOptions options(cx, bce->parser->options());
             options.setMutedErrors(parent->mutedErrors())
                    .setCompileAndGo(parent->compileAndGo())
+                   .setHasPollutedScope(parent->hasPollutedGlobalScope())
                    .setSelfHostingMode(parent->selfHosted())
                    .setNoScriptRval(false)
                    .setForEval(false)
                    .setVersion(parent->getVersion());
 
             Rooted<JSObject*> enclosingScope(cx, EnclosingStaticScope(bce));
             Rooted<JSObject*> sourceObject(cx, bce->script->sourceObject());
             Rooted<JSScript*> script(cx, JSScript::Create(cx, enclosingScope, false, options,
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -3951,17 +3951,17 @@ JS_GetFunctionScript(JSContext *cx, Hand
 /*
  * enclosingStaticScope is a static enclosing scope, if any (e.g. a
  * StaticWithObject).  If the enclosing scope is the global scope, this must be
  * null.
  *
  * enclosingDynamicScope is a dynamic scope to use, if it's not the global.
  */
 static bool
-CompileFunction(JSContext *cx, const ReadOnlyCompileOptions &options,
+CompileFunction(JSContext *cx, const ReadOnlyCompileOptions &optionsArg,
                 const char *name, unsigned nargs, const char *const *argnames,
                 SourceBufferHolder &srcBuf,
                 HandleObject enclosingDynamicScope,
                 HandleObject enclosingStaticScope,
                 MutableHandleFunction fun)
 {
     MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
     AssertHeapIsIdle(cx);
@@ -3985,16 +3985,23 @@ CompileFunction(JSContext *cx, const Rea
     }
 
     fun.set(NewScriptedFunction(cx, 0, JSFunction::INTERPRETED, funAtom,
                                 JSFunction::FinalizeKind, TenuredObject,
                                 enclosingDynamicScope));
     if (!fun)
         return false;
 
+    // Make sure to handle cases when we have a polluted scopechain.
+    OwningCompileOptions options(cx);
+    if (!options.copy(cx, optionsArg))
+        return false;
+    if (!enclosingDynamicScope->is<GlobalObject>())
+        options.setHasPollutedScope(true);
+
     if (!frontend::CompileFunctionBody(cx, fun, options, formals, srcBuf,
                                        enclosingStaticScope))
         return false;
 
     return true;
 }
 
 JS_PUBLIC_API(bool)