Bug 1452235 part 3. Stop using nsIDOMSerializer from JS. r=qdot
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 09 Apr 2018 16:30:32 -0400
changeset 412424 04c975671b123b6ff23f2b0a77ed66a9b5f0a067
parent 412423 a53d6207c403caa86b205e56aa15dd49b5aeb7ae
child 412425 224c47afe070ac65aa4f66957b1d986b137f76ea
push id101925
push userbzbarsky@mozilla.com
push dateMon, 09 Apr 2018 20:31:32 +0000
treeherdermozilla-inbound@17eff95cd1e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1452235
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 1452235 part 3. Stop using nsIDOMSerializer from JS. r=qdot MozReview-Commit-ID: JbWGcfbmM4b
dom/base/test/chrome/test_domparsing.xul
dom/base/test/unit/head_xml.js
js/xpconnect/src/Sandbox.cpp
js/xpconnect/src/xpcprivate.h
toolkit/components/reader/ReaderMode.jsm
--- a/dom/base/test/chrome/test_domparsing.xul
+++ b/dom/base/test/chrome/test_domparsing.xul
@@ -65,18 +65,17 @@ runTest(new DOMParser(), new XMLSerializ
   parser.init();
   throws(function() {
     parser.init();
   }, "NS_ERROR_UNEXPECTED", "init method should throw when called twice");
 }
 
 runTest(Cc["@mozilla.org/xmlextras/domparser;1"]
         .createInstance(Ci.nsIDOMParser),
-        Cc["@mozilla.org/xmlextras/xmlserializer;1"]
-        .createInstance(Ci.nsIDOMSerializer));
+        new XMLSerializer());
 
 function runTest(parser, serializer) {
   is(typeof parser.parseFromString, "function", "parseFromString should exist");
   is(typeof parser.parseFromBuffer, "function", "parseFromBuffer should exist");
   is(typeof parser.parseFromStream, "function", "parseFromStream should exist");
   is(typeof parser.init, "function", "init should exist");
 
   is(typeof serializer.serializeToString, "function", "serializeToString should exist");
--- a/dom/base/test/unit/head_xml.js
+++ b/dom/base/test/unit/head_xml.js
@@ -8,22 +8,23 @@ const I                    = Ci;
 const C                    = Cc;
 
 const nsIFile         = I.nsIFile;
 const nsIProperties        = I.nsIProperties;
 const nsIFileInputStream   = I.nsIFileInputStream;
 const nsIInputStream       = I.nsIInputStream;
 
 const nsIDOMParser         = I.nsIDOMParser;
-const nsIDOMSerializer     = I.nsIDOMSerializer;
 const nsIDOMDocument       = I.nsIDOMDocument;
 const nsIDOMElement        = I.nsIDOMElement;
 const nsIDOMNode           = I.nsIDOMNode;
 const nsIDOMNodeList       = I.nsIDOMNodeList;
 
+Cu.importGlobalProperties(["XMLSerializer"]);
+
 function DOMParser() {
   var parser = C["@mozilla.org/xmlextras/domparser;1"].createInstance(nsIDOMParser);
   parser.init();
   return parser;
 }
 
 var __testsDirectory = null;
 
@@ -53,18 +54,17 @@ function ParseXML(data) {
 
   Assert.equal(data instanceof nsIInputStream, true);
   
   return DOMParser().parseFromStream(data, "UTF-8", data.available(),
                                      "application/xml");
 }
 
 function DOMSerializer() {
-  return C["@mozilla.org/xmlextras/xmlserializer;1"]
-          .createInstance(nsIDOMSerializer);
+  return new XMLSerializer();
 }
 
 function SerializeXML(node) {
   return DOMSerializer().serializeToString(node);
 }
 
 function roundtrip(obj) {
   if (typeof(obj) == "string") {
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -51,16 +51,17 @@
 #include "mozilla/dom/FileReaderBinding.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/TextDecoderBinding.h"
 #include "mozilla/dom/TextEncoderBinding.h"
 #include "mozilla/dom/UnionConversions.h"
 #include "mozilla/dom/URLBinding.h"
 #include "mozilla/dom/URLSearchParamsBinding.h"
 #include "mozilla/dom/XMLHttpRequest.h"
+#include "mozilla/dom/XMLSerializerBinding.h"
 #include "mozilla/dom/FormDataBinding.h"
 #include "mozilla/DeferredFinalize.h"
 
 using namespace mozilla;
 using namespace JS;
 using namespace xpc;
 
 using mozilla::dom::DestroyProtoAndIfaceCache;
@@ -827,16 +828,18 @@ xpc::GlobalProperties::Parse(JSContext* 
         } else if (!strcmp(name.ptr(), "TextEncoder")) {
             TextEncoder = true;
         } else if (!strcmp(name.ptr(), "URL")) {
             URL = true;
         } else if (!strcmp(name.ptr(), "URLSearchParams")) {
             URLSearchParams = true;
         } else if (!strcmp(name.ptr(), "XMLHttpRequest")) {
             XMLHttpRequest = true;
+        } else if (!strcmp(name.ptr(), "XMLSerializer")) {
+            XMLSerializer = true;
         } else if (!strcmp(name.ptr(), "atob")) {
             atob = true;
         } else if (!strcmp(name.ptr(), "btoa")) {
             btoa = true;
         } else if (!strcmp(name.ptr(), "caches")) {
             caches = true;
         } else if (!strcmp(name.ptr(), "crypto")) {
             crypto = true;
@@ -920,16 +923,20 @@ xpc::GlobalProperties::Define(JSContext*
     if (URLSearchParams &&
         !dom::URLSearchParamsBinding::GetConstructorObject(cx))
         return false;
 
     if (XMLHttpRequest &&
         !dom::XMLHttpRequestBinding::GetConstructorObject(cx))
         return false;
 
+    if (XMLSerializer &&
+        !dom::XMLSerializerBinding::GetConstructorObject(cx))
+        return false;
+
     if (atob &&
         !JS_DefineFunction(cx, obj, "atob", Atob, 1, 0))
         return false;
 
     if (btoa &&
         !JS_DefineFunction(cx, obj, "btoa", Btoa, 1, 0))
         return false;
 
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -2618,16 +2618,17 @@ struct GlobalProperties {
     bool InspectorUtils : 1;
     bool MessageChannel: 1;
     bool NodeFilter : 1;
     bool TextDecoder : 1;
     bool TextEncoder : 1;
     bool URL : 1;
     bool URLSearchParams : 1;
     bool XMLHttpRequest : 1;
+    bool XMLSerializer : 1;
 
     // Ad-hoc property names we implement.
     bool atob : 1;
     bool btoa : 1;
     bool caches : 1;
     bool crypto : 1;
     bool fetch : 1;
     bool indexedDB : 1;
--- a/toolkit/components/reader/ReaderMode.jsm
+++ b/toolkit/components/reader/ReaderMode.jsm
@@ -27,17 +27,17 @@ const CLASSES_TO_PRESERVE = [
   "visuallyhidden",
   "wp-caption",
   "wp-caption-text",
 ];
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
-Cu.importGlobalProperties(["XMLHttpRequest"]);
+Cu.importGlobalProperties(["XMLHttpRequest", "XMLSerializer"]);
 
 ChromeUtils.defineModuleGetter(this, "CommonUtils", "resource://services-common/utils.js");
 ChromeUtils.defineModuleGetter(this, "EventDispatcher", "resource://gre/modules/Messaging.jsm");
 ChromeUtils.defineModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
 ChromeUtils.defineModuleGetter(this, "ReaderWorker", "resource://gre/modules/reader/ReaderWorker.jsm");
 ChromeUtils.defineModuleGetter(this, "TelemetryStopwatch", "resource://gre/modules/TelemetryStopwatch.jsm");
 ChromeUtils.defineModuleGetter(this, "LanguageDetector", "resource:///modules/translation/LanguageDetector.jsm");
 
@@ -466,18 +466,17 @@ var ReaderMode = {
     let uriParam = {
       spec: doc.baseURIObject.spec,
       host: doc.baseURIObject.host,
       prePath: doc.baseURIObject.prePath,
       scheme: doc.baseURIObject.scheme,
       pathBase: Services.io.newURI(".", null, doc.baseURIObject).spec
     };
 
-    let serializer = Cc["@mozilla.org/xmlextras/xmlserializer;1"].
-                     createInstance(Ci.nsIDOMSerializer);
+    let serializer = new XMLSerializer();
     let serializedDoc = serializer.serializeToString(doc);
 
     let options = {
       classesToPreserve: CLASSES_TO_PRESERVE,
     };
 
     let article = null;
     try {