Bug 1454827 - Source actor spec should use `source` instead of `onSource`. r=jryans,yulia draft
authorMicah Tigley <mtigley@mozilla.com>
Sat, 07 Jul 2018 17:56:59 -0400
changeset 816233 511ff8021c54bbae97c77e3dbdb1499e4a98fd4f
parent 815369 6073ee7046a78b946c48c9b96c22d6310b23b036
push id115784
push userbmo:mtigley@mozilla.com
push dateTue, 10 Jul 2018 19:52:21 +0000
reviewersjryans, yulia
bugs1454827
milestone63.0a1
Bug 1454827 - Source actor spec should use `source` instead of `onSource`. r=jryans,yulia MozReview-Commit-ID: 5cE95Sn0xEC
devtools/server/actors/source.js
devtools/shared/specs/source.js
--- a/devtools/server/actors/source.js
+++ b/devtools/server/actors/source.js
@@ -144,17 +144,17 @@ const SourceActor = ActorClassWithSpec(s
                           isInlineSource, contentType }) {
     this._threadActor = thread;
     this._originalUrl = originalUrl;
     this._source = source;
     this._generatedSource = generatedSource;
     this._contentType = contentType;
     this._isInlineSource = isInlineSource;
 
-    this.onSource = this.onSource.bind(this);
+    this.source = this.source.bind(this);
     this._invertSourceMap = this._invertSourceMap.bind(this);
     this._encodeAndSetSourceMapURL = this._encodeAndSetSourceMapURL.bind(this);
     this._getSourceText = this._getSourceText.bind(this);
 
     this._mapSourceToAddon();
 
     if (this.threadActor.sources.isPrettyPrinted(this.url)) {
       this._init = this.prettyPrint(
@@ -182,28 +182,28 @@ const SourceActor = ActorClassWithSpec(s
     return this._threadActor;
   },
   get sources() {
     return this._threadActor.sources;
   },
   get dbg() {
     return this.threadActor.dbg;
   },
-  get source() {
+  get sourceData() {
     return this._source;
   },
   get generatedSource() {
     return this._generatedSource;
   },
   get breakpointActorMap() {
     return this.threadActor.breakpointActorMap;
   },
   get url() {
-    if (this.source) {
-      return getSourceURL(this.source, this.threadActor._parent.window);
+    if (this.sourceData) {
+      return getSourceURL(this.sourceData, this.threadActor._parent.window);
     }
     return this._originalUrl;
   },
   get addonID() {
     return this._addonID;
   },
   get addonPath() {
     return this._addonPath;
@@ -216,17 +216,17 @@ const SourceActor = ActorClassWithSpec(s
   get isCacheEnabled() {
     if (this.threadActor._parent._getCacheDisabled) {
       return !this.threadActor._parent._getCacheDisabled();
     }
     return true;
   },
 
   form: function() {
-    const source = this.source || this.generatedSource;
+    const source = this.sourceData || this.generatedSource;
     // This might not have a source or a generatedSource because we
     // treat HTML pages with inline scripts as a special SourceActor
     // that doesn't have either
     let introductionUrl = null;
     if (source && source.introductionScript) {
       introductionUrl = source.introductionScript.source.url;
     }
 
@@ -333,54 +333,54 @@ const SourceActor = ActorClassWithSpec(s
     }
   },
 
   _getSourceText: function() {
     const toResolvedContent = t => ({
       content: t,
       contentType: this._contentType
     });
-    const isWasm = this.source && this.source.introductionType === "wasm";
+    const isWasm = this.sourceData && this.sourceData.introductionType === "wasm";
 
-    const genSource = this.generatedSource || this.source;
+    const genSource = this.generatedSource || this.sourceData;
     return this.threadActor.sources.fetchSourceMap(genSource).then(map => {
       if (map) {
         try {
           const sourceContent = map.sourceContentFor(this.url);
           if (sourceContent) {
             return toResolvedContent(sourceContent);
           }
         } catch (error) {
           this._reportLoadSourceError(error, map);
           throw error;
         }
       }
 
       if (isWasm && this.dbg.allowWasmBinarySource) {
-        const wasm = this.source.binary;
+        const wasm = this.sourceData.binary;
         const buffer = wasm.buffer;
         assert(
           wasm.byteOffset === 0 && wasm.byteLength === buffer.byteLength,
           "Typed array from wasm source binary must cover entire buffer"
         );
         return toResolvedContent(buffer);
       }
 
       // Use `source.text` if it exists, is not the "no source" string, and
       // the content type of the source is JavaScript or it is synthesized
       // wasm. It will be "no source" if the Debugger API wasn't able to load
       // the source because sources were discarded
       // (javascript.options.discardSystemSource == true). Re-fetch non-JS
       // sources to get the contentType from the headers.
-      if (this.source &&
-          this.source.text !== "[no source]" &&
+      if (this.sourceData &&
+          this.sourceData.text !== "[no source]" &&
           this._contentType &&
           (this._contentType.includes("javascript") ||
            this._contentType === "text/wasm")) {
-        return toResolvedContent(this.source.text);
+        return toResolvedContent(this.sourceData.text);
       }
 
       // Only load the HTML page source from cache (which exists when
       // there are inline sources). Otherwise, we can't trust the
       // cache because we are most likely here because we are
       // fetching the original text for sourcemapped code, and the
       // page hasn't requested it before (if it has, it was a
       // previous debugging session).
@@ -455,17 +455,17 @@ const SourceActor = ActorClassWithSpec(s
             lines.add(line);
           }
         }
 
         return sortLines(lines);
       });
     }
 
-    const lines = this.getExecutableOffsets(this.source, true);
+    const lines = this.getExecutableOffsets(this.sourceData, true);
     return sortLines(lines);
   },
 
   /**
    * Extract all executable offsets from the given script
    * @param String url - extract offsets of the script with this url
    * @param Boolean onlyLine - will return only the line number
    * @return Set - Executable offsets/lines of the script
@@ -479,17 +479,17 @@ const SourceActor = ActorClassWithSpec(s
     }
 
     return offsets;
   },
 
   /**
    * Handler for the "source" packet.
    */
-  onSource: function() {
+  source: function() {
     return Promise.resolve(this._init)
       .then(this._getSourceText)
       .then(({ content, contentType }) => {
         if (typeof content === "object" && content && content.constructor &&
             content.constructor.name === "ArrayBuffer") {
           return {
             source: arrayBufferGrip(content, this.threadActor.threadLifetimePool),
             contentType,
@@ -497,38 +497,38 @@ const SourceActor = ActorClassWithSpec(s
         }
         return {
           source: createValueGrip(content, this.threadActor.threadLifetimePool,
             this.threadActor.objectGrip),
           contentType: contentType
         };
       })
       .catch(error => {
-        reportError(error, "Got an exception during SA_onSource: ");
+        reportError(error, "Got an exception during SA_source: ");
         throw new Error("Could not load the source for " + this.url + ".\n" +
                         DevToolsUtils.safeErrorString(error));
       });
   },
 
   /**
    * Handler for the "prettyPrint" packet.
    */
   prettyPrint: function(indent) {
     this.threadActor.sources.prettyPrint(this.url, indent);
     return this._getSourceText()
       .then(this._sendToPrettyPrintWorker(indent))
       .then(this._invertSourceMap)
       .then(this._encodeAndSetSourceMapURL)
       .then(() => {
         // We need to reset `_init` now because we have already done the work of
-        // pretty printing, and don't want onSource to wait forever for
+        // pretty printing, and don't want source() to wait forever for
         // initialization to complete.
         this._init = null;
       })
-      .then(this.onSource)
+      .then(this.source)
       .catch(error => {
         this.disablePrettyPrint();
         throw new Error(DevToolsUtils.safeErrorString(error));
       });
   },
 
   /**
    * Return a function that sends a request to the pretty print worker, waits on
@@ -591,17 +591,17 @@ const SourceActor = ActorClassWithSpec(s
 
   /**
    * Save the source map back to our thread's ThreadSources object so that
    * stepping, breakpoints, debugger statements, etc can use it. If we are
    * pretty printing a source mapped source, we need to compose the existing
    * source map with our new one.
    */
   _encodeAndSetSourceMapURL: function({ map: sm }) {
-    const source = this.generatedSource || this.source;
+    const source = this.generatedSource || this.sourceData;
     const sources = this.threadActor.sources;
 
     return sources.getSourceMap(source).then(prevMap => {
       if (prevMap) {
         // Compose the source maps
         this._oldSourceMapping = {
           url: source.sourceMapURL,
           map: prevMap
@@ -617,30 +617,30 @@ const SourceActor = ActorClassWithSpec(s
       actorSources.setSourceMapHard(source, null, sm);
     });
   },
 
   /**
    * Handler for the "disablePrettyPrint" packet.
    */
   disablePrettyPrint: function() {
-    const source = this.generatedSource || this.source;
+    const source = this.generatedSource || this.sourceData;
     const sources = this.threadActor.sources;
 
     sources.clearSourceMapCache(source.sourceMapURL, { hard: true });
 
     if (this._oldSourceMapping) {
       sources.setSourceMapHard(source,
                                this._oldSourceMapping.url,
                                this._oldSourceMapping.map);
       this._oldSourceMapping = null;
     }
 
     this.threadActor.sources.disablePrettyPrint(this.url);
-    return this.onSource();
+    return this.source();
   },
 
   /**
    * Handler for the "blackbox" packet.
    */
   blackbox: function() {
     this.threadActor.sources.blackBox(this.url);
     if (this.threadActor.state == "paused"
@@ -787,27 +787,27 @@ const SourceActor = ActorClassWithSpec(s
    * @returns A Promise that resolves to the given BreakpointActor.
    */
   _setBreakpoint: function(actor, noSliding) {
     const { originalLocation } = actor;
     const { originalLine, originalSourceActor } = originalLocation;
 
     if (!this.isSourceMapped) {
       const generatedLocation = GeneratedLocation.fromOriginalLocation(originalLocation);
-      const isWasm = this.source && this.source.introductionType === "wasm";
+      const isWasm = this.sourceData && this.sourceData.introductionType === "wasm";
       if (!this._setBreakpointAtGeneratedLocation(actor, generatedLocation) &&
           !noSliding &&
           !isWasm) {
         const query = { line: originalLine };
         // For most cases, we have a real source to query for. The
         // only time we don't is for HTML pages. In that case we want
         // to query for scripts in an HTML page based on its URL, as
         // there could be several sources within an HTML page.
-        if (this.source) {
-          query.source = this.source;
+        if (this.sourceData) {
+          query.source = this.sourceData;
         } else {
           query.url = this.url;
         }
         const scripts = this.dbg.findScripts(query);
 
         // Never do breakpoint sliding for column breakpoints.
         // Additionally, never do breakpoint sliding if no scripts
         // exist on this line.
@@ -873,17 +873,17 @@ const SourceActor = ActorClassWithSpec(s
         } else {
           actor.originalLocation = actualLocation;
           this.breakpointActorMap.setActor(actualLocation, actor);
         }
       }
 
       return Promise.resolve(actor);
     }
-    return this.sources.getAllGeneratedLocations(originalLocation)
+    return this.sourceDatas.getAllGeneratedLocations(originalLocation)
       .then((generatedLocations) => {
         this._setBreakpointAtAllGeneratedLocations(
           actor,
           generatedLocations
         );
 
         return actor;
       });
--- a/devtools/shared/specs/source.js
+++ b/devtools/shared/specs/source.js
@@ -4,34 +4,41 @@
 "use strict";
 
 const {Arg, RetVal, generateActorSpec} = require("devtools/shared/protocol");
 
 const sourceSpec = generateActorSpec({
   typeName: "source",
 
   methods: {
-    getExecutableLines: { response: { lines: RetVal("json") } },
-    onSource: {
-      request: { type: "source" },
+    getExecutableLines: {
+      response: {
+        lines: RetVal("json")
+      }
+    },
+    source: {
       response: RetVal("json")
     },
     prettyPrint: {
       request: { indent: Arg(0, "number") },
       response: RetVal("json")
     },
     disablePrettyPrint: {
       response: RetVal("json")
     },
     setPausePoints: {
       request: {
         pausePoints: Arg(0, "json"),
       }
     },
-    blackbox: { response: { pausedInSource: RetVal("boolean") } },
+    blackbox: {
+      response: {
+        pausedInSource: RetVal("boolean")
+      }
+    },
     unblackbox: {},
     setBreakpoint: {
       request: {
         location: {
           line: Arg(0, "number"),
           column: Arg(1, "nullable:number")
         },
         condition: Arg(2, "nullable:string"),