Bug 956376 - Part 2: Support Debugger#findSource in WebReplay. r=jimb
☠☠ backed out by 9c13dbdf4cc9 ☠ ☠
authorTooru Fujisawa <arai_a@mac.com>
Mon, 27 Aug 2018 08:17:39 +0900
changeset 481751 d96d56907ce0a58521bb129e64fc8b4c01eb816a
parent 481750 ee0b4798b061602ef9e12eb539e4187f59ce4ca2
child 481752 37f94ae472d60f1004844c09146c9eb3b3522055
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewersjimb
bugs956376
milestone63.0a1
Bug 956376 - Part 2: Support Debugger#findSource in WebReplay. r=jimb
devtools/server/actors/replay/debugger.js
devtools/server/actors/replay/replay.js
--- a/devtools/server/actors/replay/debugger.js
+++ b/devtools/server/actors/replay/debugger.js
@@ -165,21 +165,33 @@ ReplayDebugger.prototype = {
     return this._sendRequest({ type: "findConsoleMessages" });
   },
 
   /////////////////////////////////////////////////////////
   // ScriptSource methods
   /////////////////////////////////////////////////////////
 
   _getSource(id) {
-    if (!this._scriptSources[id]) {
-      const data = this._sendRequest({ type: "getSource", id });
-      this._scriptSources[id] = new ReplayDebuggerScriptSource(this, data);
+    const source = this._scriptSources[id];
+    if (source) {
+      return source;
     }
-    return this._scriptSources[id];
+    return this._addSource(this._sendRequest({ type: "getSource", id }));
+  },
+
+  _addSource(data) {
+    if (!this._scriptSources[data.id]) {
+      this._scriptSources[data.id] = new ReplayDebuggerScriptSource(this, data);
+    }
+    return this._scriptSources[data.id];
+  },
+
+  findSources() {
+    const data = this._sendRequest({ type: "findSources" });
+    return data.map(source => this._addSource(source));
   },
 
   /////////////////////////////////////////////////////////
   // Object methods
   /////////////////////////////////////////////////////////
 
   _getObject(id) {
     if (id && !this._objects[id]) {
--- a/devtools/server/actors/replay/replay.js
+++ b/devtools/server/actors/replay/replay.js
@@ -460,16 +460,32 @@ function getScriptData(id) {
     lineCount: script.lineCount,
     sourceStart: script.sourceStart,
     sourceLength: script.sourceLength,
     displayName: script.displayName,
     url: script.url,
   };
 }
 
+function getSourceData(id) {
+  const source = gScriptSources.getObject(id);
+  const introductionScript = gScripts.getId(source.introductionScript);
+  return {
+    id: id,
+    text: source.text,
+    url: source.url,
+    displayURL: source.displayURL,
+    elementAttributeName: source.elementAttributeName,
+    introductionScript,
+    introductionOffset: introductionScript ? source.introductionOffset : undefined,
+    introductionType: source.introductionType,
+    sourceMapURL: source.sourceMapURL,
+  };
+}
+
 function forwardToScript(name) {
   return request => gScripts.getObject(request.id)[name](request.value);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 // Handlers
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -490,30 +506,26 @@ const gRequestHandlers = {
   getNewScript(request) {
     return getScriptData(gScripts.lastId());
   },
 
   getContent(request) {
     return RecordReplayControl.getContent(request.url);
   },
 
+  findSources(request) {
+    const sources = [];
+    gScriptSources.forEach((id) => {
+      sources.push(getSourceData(id));
+    });
+    return sources;
+  },
+
   getSource(request) {
-    const source = gScriptSources.getObject(request.id);
-    const introductionScript = gScripts.getId(source.introductionScript);
-    return {
-      id: request.id,
-      text: source.text,
-      url: source.url,
-      displayURL: source.displayURL,
-      elementAttributeName: source.elementAttributeName,
-      introductionScript,
-      introductionOffset: introductionScript ? source.introductionOffset : undefined,
-      introductionType: source.introductionType,
-      sourceMapURL: source.sourceMapURL,
-    };
+    return getSourceData(request.id);
   },
 
   getObject(request) {
     const object = gPausedObjects.getObject(request.id);
     if (object instanceof Debugger.Object) {
       return {
         id: request.id,
         kind: "Object",