Bug 1443923 - part1: Return script location for shadow host in NodeActor form;r=bgrins draft
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 05 Jul 2018 09:47:56 +0200
changeset 822567 c793484450420f097dea057e18397577e0346f72
parent 822473 0b9c0b211eb3d84c5afdb64f4a91d079d0aa4c75
child 822568 3aec1de65b8fbf4e0c2ea3c5b408db56fac97f27
push id117402
push userjdescottes@mozilla.com
push dateWed, 25 Jul 2018 13:32:04 +0000
reviewersbgrins
bugs1443923
milestone63.0a1
Bug 1443923 - part1: Return script location for shadow host in NodeActor form;r=bgrins MozReview-Commit-ID: CLmOqqAa123
devtools/server/actors/inspector/node.js
devtools/shared/fronts/node.js
--- a/devtools/server/actors/inspector/node.js
+++ b/devtools/server/actors/inspector/node.js
@@ -121,16 +121,17 @@ const NodeActor = protocol.ActorClassWit
       displayType: this.displayType,
 
       // doctype attributes
       name: this.rawNode.name,
       publicId: this.rawNode.publicId,
       systemId: this.rawNode.systemId,
 
       attrs: this.writeAttrs(),
+      customElementLocation: this.getCustomElementLocation(),
       isBeforePseudoElement: isBeforePseudoElement(this.rawNode),
       isAfterPseudoElement: isAfterPseudoElement(this.rawNode),
       isAnonymous: isAnonymous(this.rawNode),
       isNativeAnonymous: isNativeAnonymous(this.rawNode),
       isXBLAnonymous: isXBLAnonymous(this.rawNode),
       isShadowAnonymous: isShadowAnonymous(this.rawNode),
       isShadowRoot: shadowRoot,
       shadowRootMode: getShadowRootMode(this.rawNode),
@@ -346,16 +347,46 @@ const NodeActor = protocol.ActorClassWit
     listenerArray.sort((a, b) => {
       return a.type.localeCompare(b.type);
     });
 
     return listenerArray;
   },
 
   /**
+   * Retrieve the script location of the custom element definition for this node, when
+   * relevant. To be linked to a custom element definition
+   */
+  getCustomElementLocation: function() {
+    // Get a reference to the custom element definition function.
+    const name = this.rawNode.localName;
+
+    const customElementsRegistry = this.rawNode.ownerGlobal.customElements;
+    const customElement = customElementsRegistry && customElementsRegistry.get(name);
+    if (!customElement) {
+      return undefined;
+    }
+    // Create debugger object for the customElement function.
+    const global = Cu.getGlobalForObject(customElement);
+    const dbg = this.parent().targetActor.makeDebugger();
+    const globalDO = dbg.addDebuggee(global);
+    const customElementDO = globalDO.makeDebuggeeValue(customElement);
+
+    // Return undefined if we can't find a script for the custom element definition.
+    if (!customElementDO.script) {
+      return undefined;
+    }
+
+    return {
+      url: customElementDO.script.url,
+      line: customElementDO.script.startLine,
+    };
+  },
+
+  /**
    * Process a handler
    *
    * @param  {Node} node
    *         The node for which we want information.
    * @param  {Array} listenerArray
    *         listenerArray contains all event objects that we have gathered
    *         so far.
    * @param  {Debugger} dbg
--- a/devtools/shared/fronts/node.js
+++ b/devtools/shared/fronts/node.js
@@ -314,16 +314,20 @@ const NodeFront = FrontClassWithSpec(nod
   get shadowRootMode() {
     return this._form.shadowRootMode;
   },
 
   get isShadowHost() {
     return this._form.isShadowHost;
   },
 
+  get customElementLocation() {
+    return this._form.customElementLocation;
+  },
+
   get isDirectShadowHostChild() {
     return this._form.isDirectShadowHostChild;
   },
 
   // doctype properties
   get name() {
     return this._form.name;
   },