Bug 1306937 - use XHTML NS by default when creating highlighter nodes;r=pbro
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 30 Nov 2016 11:22:17 +0100
changeset 324859 db231dc73bf45a837ea21f04a8906646cfac5c17
parent 324858 f0cbd37fec30ac0a2cace54a2a87e7d6b6e34733
child 324860 3a542aaed86b9769901bf1262a9be833077a803a
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewerspbro
bugs1306937
milestone53.0a1
Bug 1306937 - use XHTML NS by default when creating highlighter nodes;r=pbro MozReview-Commit-ID: 6OI5AzfWlD6
devtools/server/actors/highlighters/utils/markup.js
--- a/devtools/server/actors/highlighters/utils/markup.js
+++ b/devtools/server/actors/highlighters/utils/markup.js
@@ -29,16 +29,17 @@ exports.addPseudoClassLock = (...args) =
 
 exports.removePseudoClassLock = (...args) =>
   lazyContainer.DOMUtils.removePseudoClassLock(...args);
 
 exports.getCSSStyleRules = (...args) =>
   lazyContainer.DOMUtils.getCSSStyleRules(...args);
 
 const SVG_NS = "http://www.w3.org/2000/svg";
+const XHTML_NS = "http://www.w3.org/1999/xhtml";
 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 const STYLESHEET_URI = "resource://devtools/server/actors/" +
                        "highlighters.css";
 // How high is the infobar (px).
 const INFOBAR_HEIGHT = 34;
 // What's the size of the infobar arrow (px).
 const INFOBAR_ARROW_SIZE = 9;
 
@@ -176,33 +177,28 @@ function createSVGNode(win, options) {
 }
 exports.createSVGNode = createSVGNode;
 
 /**
  * Helper function that creates DOM nodes.
  * @param {Window} This window's document will be used to create the element
  * @param {Object} Options for the node include:
  * - nodeType: the type of node, defaults to "div".
- * - namespace: if passed, doc.createElementNS will be used instead of
- *   doc.creatElement.
+ * - namespace: the namespace to use to create the node, defaults to XHTML namespace.
  * - attributes: a {name:value} object to be used as attributes for the node.
  * - prefix: a string that will be used to prefix the values of the id and class
  *   attributes.
  * - parent: if provided, the newly created element will be appended to this
  *   node.
  */
 function createNode(win, options) {
   let type = options.nodeType || "div";
+  let namespace = options.namespace || XHTML_NS;
 
-  let node;
-  if (options.namespace) {
-    node = win.document.createElementNS(options.namespace, type);
-  } else {
-    node = win.document.createElement(type);
-  }
+  let node = win.document.createElementNS(namespace, type);
 
   for (let name in options.attributes || {}) {
     let value = options.attributes[name];
     if (options.prefix && (name === "class" || name === "id")) {
       value = options.prefix + value;
     }
     node.setAttribute(name, value);
   }