Bug 1053898 - Update DocumentWalker constructor to use optional object argument;r=pbro
MozReview-Commit-ID: I8AiM5rXPFd
--- a/devtools/server/actors/inspector/document-walker.js
+++ b/devtools/server/actors/inspector/document-walker.js
@@ -15,30 +15,33 @@ const SKIP_TO_PARENT = "SKIP_TO_PARENT";
const SKIP_TO_SIBLING = "SKIP_TO_SIBLING";
/**
* Wrapper for inDeepTreeWalker. Adds filtering to the traversal methods.
* See inDeepTreeWalker for more information about the methods.
*
* @param {DOMNode} node
* @param {Window} rootWin
- * @param {Number} whatToShow
- * See nodeFilterConstants / inIDeepTreeWalker for options.
- * @param {Function} filter
- * A custom filter function Taking in a DOMNode and returning an Int. See
- * WalkerActor.nodeFilter for an example.
- * @param {String} skipTo
- * Either SKIP_TO_PARENT or SKIP_TO_SIBLING. If the provided node is not compatible
- * with the filter function for this walker, try to find a compatible one either
- * in the parents or in the siblings of the node.
+ * @param {Object}
+ * - {Number} whatToShow
+ * See nodeFilterConstants / inIDeepTreeWalker for options.
+ * - {Function} filter
+ * A custom filter function Taking in a DOMNode and returning an Int. See
+ * WalkerActor.nodeFilter for an example.
+ * - {String} skipTo
+ * Either SKIP_TO_PARENT or SKIP_TO_SIBLING. If the provided node is not
+ * compatible with the filter function for this walker, try to find a compatible
+ * one either in the parents or in the siblings of the node.
*/
function DocumentWalker(node, rootWin,
- whatToShow = nodeFilterConstants.SHOW_ALL,
- filter = standardTreeWalkerFilter,
- skipTo = SKIP_TO_PARENT) {
+ {
+ whatToShow = nodeFilterConstants.SHOW_ALL,
+ filter = standardTreeWalkerFilter,
+ skipTo = SKIP_TO_PARENT
+ } = {}) {
if (Cu.isDeadWrapper(rootWin) || !rootWin.location) {
throw new Error("Got an invalid root window in DocumentWalker");
}
this.walker = Cc["@mozilla.org/inspector/deep-tree-walker;1"]
.createInstance(Ci.inIDeepTreeWalker);
this.walker.showAnonymousContent = true;
this.walker.showSubDocuments = true;
--- a/devtools/server/actors/inspector/walker.js
+++ b/devtools/server/actors/inspector/walker.js
@@ -194,20 +194,20 @@ var WalkerActor = protocol.ActorClassWit
},
toString: function() {
return "[WalkerActor " + this.actorID + "]";
},
getDocumentWalker: function(node, whatToShow, skipTo) {
// Allow native anon content (like <video> controls) if preffed on
- let nodeFilter = this.showAllAnonymousContent
+ let filter = this.showAllAnonymousContent
? allAnonymousContentTreeWalkerFilter
: standardTreeWalkerFilter;
- return new DocumentWalker(node, this.rootWin, whatToShow, nodeFilter, skipTo);
+ return new DocumentWalker(node, this.rootWin, {whatToShow, filter, skipTo});
},
destroy: function() {
if (this._destroyed) {
return;
}
this._destroyed = true;
protocol.Actor.prototype.destroy.call(this);
--- a/devtools/server/tests/mochitest/test_inspector-anonymous.html
+++ b/devtools/server/tests/mochitest/test_inspector-anonymous.html
@@ -75,19 +75,21 @@ window.onload = function() {
addAsyncTest(async function testNativeAnonymousStartingNode() {
info("Tests attaching an element that a walker can't see.");
let serverWalker = DebuggerServer.searchAllConnectionsForActor(gWalker.actorID);
let docwalker = new _documentWalker(
gInspectee.querySelector("select"),
gInspectee.defaultView,
- nodeFilterConstants.SHOW_ALL,
- () => {
- return nodeFilterConstants.FILTER_ACCEPT;
+ {
+ whatToShow: nodeFilterConstants.SHOW_ALL,
+ filter: () => {
+ return nodeFilterConstants.FILTER_ACCEPT;
+ }
}
);
let scrollbar = docwalker.lastChild();
is(scrollbar.tagName, "scrollbar", "An anonymous child has been fetched");
let node = await serverWalker.attachElement(scrollbar);
ok(node, "A response has arrived");