Bug 1491759 - Replaced eval with loadSubScript from loadPrivilegedScript() in specialpowersAPI.js r=JuniorHsu
authorvinoth <cegvinoth@gmail.com>
Mon, 08 Oct 2018 15:54:48 +0000
changeset 495875 1bae9022b97eed6aa80b4c6beb800eb7e105ce7e
parent 495874 2a9f2418655a1c0e544145490f278bab751392ab
child 495876 39ca0cb416f9da20198b93a3214df1aa2683efcc
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJuniorHsu
bugs1491759
milestone64.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 1491759 - Replaced eval with loadSubScript from loadPrivilegedScript() in specialpowersAPI.js r=JuniorHsu Differential Revision: https://phabricator.services.mozilla.com/D7975
testing/specialpowers/content/specialpowersAPI.js
--- a/testing/specialpowers/content/specialpowersAPI.js
+++ b/testing/specialpowers/content/specialpowersAPI.js
@@ -506,23 +506,26 @@ SpecialPowersAPI.prototype = {
   },
 
   /*
    * Load a privileged script that runs same-process. This is different from
    * |loadChromeScript|, which will run in the parent process in e10s mode.
    */
   loadPrivilegedScript(aFunction) {
     var str = "(" + aFunction.toString() + ")();";
-    var systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
-    var sb = Cu.Sandbox(systemPrincipal);
+    let gGlobalObject = Cu.getGlobalForObject(this);
+    let sb = Cu.Sandbox(gGlobalObject);
     var window = this.window.get();
     var mc = new window.MessageChannel();
     sb.port = mc.port1;
     try {
-      sb.eval(str);
+      Cu.importGlobalProperties(["URL", "Blob"]);
+      let blob = new Blob([str], {type: "application/javascript"});
+      let blobUrl = URL.createObjectURL(blob);
+      Services.scriptloader.loadSubScript(blobUrl, sb);
     } catch (e) {
       throw wrapIfUnwrapped(e);
     }
 
     return mc.port2;
   },
 
   loadChromeScript(urlOrFunction, sandboxOptions) {