Bug 1306937 - use XHTML NS by default when creating highlighter nodes;r=pbro draft
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 30 Nov 2016 11:22:17 +0100
changeset 445857 1d0e4130febaa0a0e775f1b16c4cc468c804fbda
parent 445856 c13bbb8d680fb48d6dccf3e0f8e83a0201f9738b
child 538652 8aa9d6afd303b6f0c332779730cbf6f5098d3a86
push id37644
push userjdescottes@mozilla.com
push dateWed, 30 Nov 2016 13:36:27 +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);
   }