Bug 1453869 part 9. Stop creating DOMParser by contract in devtools. r=tromey
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 20 Apr 2018 23:04:40 -0400
changeset 414944 7ff0d0f4e9ab0e6e7c895c13beef16f8ab58d122
parent 414943 72056af41ae0bfb73e74f19717365a0fa8e0370a
child 414945 0eb930d1397933817466885fdf22d4502f8cf6b3
push id63028
push userapavel@mozilla.com
push dateSat, 21 Apr 2018 09:35:05 +0000
treeherderautoland@fe56c460afa1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstromey
bugs1453869
milestone61.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 1453869 part 9. Stop creating DOMParser by contract in devtools. r=tromey There are some extra hoops here because devtools has a lint to prevent Cu.importGlobalProperties, which is the normal way one would import a WebIDL constructor. MozReview-Commit-ID: 2mdNI6N1z5B
devtools/client/shared/AppCacheUtils.jsm
devtools/client/shared/test/unit/test_VariablesView_filtering-without-controller.js
devtools/server/actors/inspector/walker.js
devtools/server/tests/unit/test_nativewrappers.js
devtools/shared/builtin-modules.js
--- a/devtools/client/shared/AppCacheUtils.jsm
+++ b/devtools/client/shared/AppCacheUtils.jsm
@@ -26,16 +26,17 @@
 "use strict";
 
 var { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", {});
 var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm", {});
 var { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
 
 var { gDevTools } = require("devtools/client/framework/devtools");
 var Services = require("Services");
+var { globals } = require("devtools/shared/builtin-modules");
 
 this.EXPORTED_SYMBOLS = ["AppCacheUtils"];
 
 function AppCacheUtils(documentOrUri) {
   this._parseManifest = this._parseManifest.bind(this);
 
   if (documentOrUri) {
     if (typeof documentOrUri == "string") {
@@ -612,10 +613,10 @@ XPCOMUtils.defineLazyGetter(this, "l10n"
   .createBundle("chrome://devtools/locale/appcacheutils.properties"));
 
 XPCOMUtils.defineLazyGetter(this, "appcacheservice", function() {
   return Cc["@mozilla.org/network/application-cache-service;1"]
            .getService(Ci.nsIApplicationCacheService);
 });
 
 XPCOMUtils.defineLazyGetter(this, "_DOMParser", function() {
-  return Cc["@mozilla.org/xmlextras/domparser;1"].createInstance(Ci.nsIDOMParser);
+  return globals.DOMParser();
 });
--- a/devtools/client/shared/test/unit/test_VariablesView_filtering-without-controller.js
+++ b/devtools/client/shared/test/unit/test_VariablesView_filtering-without-controller.js
@@ -2,21 +2,23 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 // Test that VariablesView._doSearch() works even without an attached
 // VariablesViewController (bug 1196341).
-
-const DOMParser = Cc["@mozilla.org/xmlextras/domparser;1"]
-                    .createInstance(Ci.nsIDOMParser);
 const { VariablesView } =
   ChromeUtils.import("resource://devtools/client/shared/widgets/VariablesView.jsm", {});
+const { require } =
+  ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
+const { globals } = require("devtools/shared/builtin-modules");
+
+const DOMParser = new globals.DOMParser();
 
 function run_test() {
   let doc = DOMParser.parseFromString("<div>", "text/html");
   let container = doc.body.firstChild;
   ok(container, "Got a container.");
 
   let vv = new VariablesView(container, { searchEnabled: true });
   let scope = vv.addScope("Test scope");
--- a/devtools/server/actors/inspector/walker.js
+++ b/devtools/server/actors/inspector/walker.js
@@ -29,19 +29,16 @@ loader.lazyRequireGetter(this, "NodeList
 loader.lazyRequireGetter(this, "LayoutActor", "devtools/server/actors/layout", true);
 loader.lazyRequireGetter(this, "getLayoutChangesObserver", "devtools/server/actors/reflow", true);
 loader.lazyRequireGetter(this, "releaseLayoutChangesObserver", "devtools/server/actors/reflow", true);
 loader.lazyRequireGetter(this, "WalkerSearch", "devtools/server/actors/utils/walker-search", true);
 
 loader.lazyServiceGetter(this, "eventListenerService",
   "@mozilla.org/eventlistenerservice;1", "nsIEventListenerService");
 
-loader.lazyServiceGetter(this, "DOMParser",
-  "@mozilla.org/xmlextras/domparser;1", "nsIDOMParser");
-
 // Minimum delay between two "new-mutations" events.
 const MUTATIONS_THROTTLING_DELAY = 100;
 // List of mutation types that should -not- be throttled.
 const IMMEDIATE_MUTATIONS = [
   "documentUnload",
   "frameLoad",
   "newRoot",
   "pseudoClassLock",
@@ -1254,17 +1251,17 @@ var WalkerActor = protocol.ActorClassWit
    * @param {NodeActor} node The node.
    * @param {string} value The piece of HTML content.
    */
   setOuterHTML: function(node, value) {
     if (isNodeDead(node)) {
       return;
     }
 
-    let parsedDOM = DOMParser.parseFromString(value, "text/html");
+    let parsedDOM = new DOMParser().parseFromString(value, "text/html");
     let rawNode = node.rawNode;
     let parentNode = rawNode.parentNode;
 
     // Special case for head and body.  Setting document.body.outerHTML
     // creates an extra <head> tag, and document.head.outerHTML creates
     // an extra <body>.  So instead we will call replaceChild with the
     // parsed DOM, assuming that they aren't trying to set both tags at once.
     if (rawNode.tagName === "BODY") {
--- a/devtools/server/tests/unit/test_nativewrappers.js
+++ b/devtools/server/tests/unit/test_nativewrappers.js
@@ -15,17 +15,19 @@ function run_test() {
       Assert.ok(false);
     }
   };
 
   g.eval("function stopMe(arg) {debugger;}");
 
   let g2 = testGlobal("test2");
   g2.g = g;
-  g2.eval("(" + function createBadEvent() {
-    let parser = Cc["@mozilla.org/xmlextras/domparser;1"]
-        .createInstance(Ci.nsIDOMParser);
+  // Not using the "stringify a function" trick because that runs afoul of the
+  // Cu.importGlobalProperties lint and we don't need it here anyway.
+  g2.eval(`(function createBadEvent() {
+    Cu.importGlobalProperties(["DOMParser"]);
+    let parser = new DOMParser();
     let doc = parser.parseFromString("<foo></foo>", "text/xml");
     g.stopMe(doc.createEvent("MouseEvent"));
-  } + ")()");
+  } )()`);
 
   dbg.enabled = false;
 }
--- a/devtools/shared/builtin-modules.js
+++ b/devtools/shared/builtin-modules.js
@@ -27,32 +27,34 @@ const {
 // Create a single Sandbox to access global properties needed in this module.
 // Sandbox are memory expensive, so we should create as little as possible.
 const {
   atob,
   btoa,
   ChromeUtils,
   CSS,
   CSSRule,
+  DOMParser,
   Event,
   FileReader,
   FormData,
   indexedDB,
   InspectorUtils,
   TextDecoder,
   TextEncoder,
   URL,
   XMLHttpRequest,
 } = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(), {
   wantGlobalProperties: [
     "atob",
     "btoa",
     "ChromeUtils",
     "CSS",
     "CSSRule",
+    "DOMParser",
     "Event",
     "FileReader",
     "FormData",
     "indexedDB",
     "TextDecoder",
     "TextEncoder",
     "InspectorUtils",
     "URL",
@@ -259,16 +261,17 @@ exports.globals = {
   //     ... code ...
   //   });
   //
   // Bug 1248830 will work out a better plan here for our content module
   // loading needs, especially as we head towards devtools.html.
   define(factory) {
     factory(this.require, this.exports, this.module);
   },
+  DOMParser,
   Element: Ci.nsIDOMElement,
   Event,
   FormData,
   isWorker: false,
   loader: {
     lazyGetter: defineLazyGetter,
     lazyImporter: defineLazyModuleGetter,
     lazyServiceGetter: defineLazyServiceGetter,
@@ -310,17 +313,14 @@ lazyGlobal("setTimeout", () => {
   return require("resource://gre/modules/Timer.jsm").setTimeout;
 });
 lazyGlobal("clearInterval", () => {
   return require("resource://gre/modules/Timer.jsm").clearInterval;
 });
 lazyGlobal("setInterval", () => {
   return require("resource://gre/modules/Timer.jsm").setInterval;
 });
-lazyGlobal("DOMParser", () => {
-  return CC("@mozilla.org/xmlextras/domparser;1", "nsIDOMParser");
-});
 lazyGlobal("WebSocket", () => {
   return Services.appShell.hiddenDOMWindow.WebSocket;
 });
 lazyGlobal("indexedDB", () => {
   return require("devtools/shared/indexed-db").createDevToolsIndexedDB(indexedDB);
 });