Bug 1165486 - Use JS::CompileForNonSyntacticScope in Gecko where we used to set polluted global scope. (r=bz, rs=bholley)
authorShu-yu Guo <shu@rfrn.org>
Sun, 21 Jun 2015 11:49:57 -0700
changeset 280716 1c9b3671def48c26edb06cf58e0de2e3db406da7
parent 280715 bfca45fd1f11dfbe826e5334fe07d85c4b6f6dbd
child 280717 63b4dd8b552eeb71b5111e646f750fe549455f17
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)
reviewersbz, bholley
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 - Use JS::CompileForNonSyntacticScope in Gecko where we used to set polluted global scope. (r=bz, rs=bholley)
dom/base/nsFrameMessageManager.cpp
js/xpconnect/loader/mozJSSubScriptLoader.cpp
--- a/dom/base/nsFrameMessageManager.cpp
+++ b/dom/base/nsFrameMessageManager.cpp
@@ -1780,18 +1780,17 @@ nsMessageManagerScriptExecutor::TryCache
     JS::Rooted<JSScript*> script(cx);
 
     if (aRunInGlobalScope) {
       if (!JS::Compile(cx, options, srcBuf, &script)) {
         return;
       }
     } else {
       // We're going to run these against some non-global scope.
-      options.setHasPollutedScope(true);
-      if (!JS::Compile(cx, options, srcBuf, &script)) {
+      if (!JS::CompileForNonSyntacticScope(cx, options, srcBuf, &script)) {
         return;
       }
     }
 
     aScriptp.set(script);
 
     nsAutoCString scheme;
     uri->GetScheme(scheme);
--- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -141,35 +141,39 @@ PrepareScript(nsIURI* uri,
         JS::SourceBufferHolder srcBuf(scriptBuf, scriptLength,
                                       JS::SourceBufferHolder::GiveOwnership);
 
         if (NS_FAILED(rv)) {
             return ReportError(cx, LOAD_ERROR_BADCHARSET, uri);
         }
 
         if (!reuseGlobal) {
-            options.setHasPollutedScope(!JS_IsGlobalObject(targetObj));
-            JS::Compile(cx, options, srcBuf, script);
+            if (JS_IsGlobalObject(targetObj))
+                JS::Compile(cx, options, srcBuf, script);
+            else
+                JS::CompileForNonSyntacticScope(cx, options, srcBuf, script);
         } else {
             AutoObjectVector scopeChain(cx);
             if (!JS_IsGlobalObject(targetObj) &&
                 !scopeChain.append(targetObj)) {
                 return NS_ERROR_OUT_OF_MEMORY;
             }
             // XXXbz do we really not care if the compile fails???
             JS::CompileFunction(cx, scopeChain, options, nullptr, 0, nullptr,
                                 srcBuf, function);
         }
     } else {
         // We only use lazy source when no special encoding is specified because
         // the lazy source loader doesn't know the encoding.
         if (!reuseGlobal) {
-            options.setSourceIsLazy(true)
-                   .setHasPollutedScope(!JS_IsGlobalObject(targetObj));
-            JS::Compile(cx, options, buf, len, script);
+            options.setSourceIsLazy(true);
+            if (JS_IsGlobalObject(targetObj))
+                JS::Compile(cx, options, buf, len, script);
+            else
+                JS::CompileForNonSyntacticScope(cx, options, buf, len, script);
         } else {
             AutoObjectVector scopeChain(cx);
             if (!JS_IsGlobalObject(targetObj) &&
                 !scopeChain.append(targetObj)) {
                 return NS_ERROR_OUT_OF_MEMORY;
             }
             // XXXbz do we really not care if the compile fails???
             JS::CompileFunction(cx, scopeChain, options, nullptr, 0, nullptr,