Bug 1128918 - Store original location in BreakpointActor;r=jlong
authorEddy Bruël <ejpbruel@gmail.com>
Tue, 10 Feb 2015 10:43:13 +0100
changeset 242052 49be6ef4d093f1cfd75f12baa664e0def551b4f7
parent 242051 c077e79e1771278a7587c46c5a81e6f8d0a67c46
child 242053 ac7e4337f0af30e10ef41312d806e08a1b0fda44
push id634
push usermozilla@noorenberghe.ca
push dateTue, 10 Feb 2015 22:34:30 +0000
reviewersjlong
bugs1128918
milestone38.0a1
Bug 1128918 - Store original location in BreakpointActor;r=jlong
toolkit/devtools/server/actors/script.js
--- a/toolkit/devtools/server/actors/script.js
+++ b/toolkit/devtools/server/actors/script.js
@@ -2034,18 +2034,18 @@ ThreadActor.prototype = {
       return false;
     }
 
     // Set any stored breakpoints.
     let endLine = aScript.startLine + aScript.lineCount - 1;
     let source = this.sources.createNonSourceMappedActor(aScript.source);
     for (let bpActor of this.breakpointActorMap.findActors({ sourceActor: source })) {
       // Limit the search to the line numbers contained in the new script.
-      if (bpActor.location.line >= aScript.startLine
-          && bpActor.location.line <= endLine) {
+      if (bpActor.generatedLocation.line >= aScript.startLine
+          && bpActor.generatedLocation.line <= endLine) {
         source.setBreakpointForActor(bpActor);
       }
     }
 
     // Go ahead and establish the source actors for this script, which
     // fetches sourcemaps if available and sends onNewSource
     // notifications
     this.sources.createSourceActors(aScript.source);
@@ -2756,27 +2756,31 @@ SourceActor.prototype = {
     });
   },
 
   /** Get or create the BreakpointActor for the breakpoint at the given location.
    *
    * NB: This will override a pre-existing BreakpointActor's condition with
    * the given the location's condition.
    *
-   * @param Object location
-   *        The breakpoint location. See BreakpointStore.prototype.setActor
-   *        for more information.
+   * @param Object originalLocation
+   *        The original location of the breakpoint.
+   * @param Object generatedLocation
+   *        The generated location of the breakpoint.
    * @returns BreakpointActor
    */
-  _getOrCreateBreakpointActor: function (location, condition) {
-    let actor = this.breakpointActorMap.getActor(location);
+  _getOrCreateBreakpointActor: function (originalLocation, generatedLocation,
+                                         condition)
+  {
+    let actor = this.breakpointActorMap.getActor(generatedLocation);
     if (!actor) {
-      actor = new BreakpointActor(this.threadActor, location, condition);
+      actor = new BreakpointActor(this.threadActor, originalLocation,
+                                  generatedLocation, condition);
       this.threadActor.threadLifetimePool.addActor(actor);
-      this.breakpointActorMap.setActor(location, actor);
+      this.breakpointActorMap.setActor(generatedLocation, actor);
       return actor;
     }
 
     actor.condition = condition;
     return actor;
   },
 
   /**
@@ -2867,40 +2871,44 @@ SourceActor.prototype = {
    * @param Number originalLine
    *        The line number of the breakpoint in the original source.
    * @param Number originalColumn
    *        The column number of the breakpoint in the original source.
    * @param String condition
    *        A condition for the breakpoint.
    */
   setBreakpoint: function (originalLine, originalColumn, condition) {
-    return this.threadActor.sources.getGeneratedLocation({
+    let originalLocation = {
       sourceActor: this,
       line: originalLine,
       column: originalColumn
-    }).then(generatedLocation => {
-      let actor = this._getOrCreateBreakpointActor(generatedLocation, condition);
-
+    };
+
+    return this.threadActor.sources.getGeneratedLocation(originalLocation)
+                                   .then(generatedLocation => {
+      let actor = this._getOrCreateBreakpointActor(originalLocation,
+                                                   generatedLocation,
+                                                   condition);
       return generatedLocation.sourceActor.setBreakpointForActor(actor);
     });
   },
 
   /*
    * Set the given BreakpointActor as breakpoint handler on all scripts that
    * match the given location for which the BreakpointActor is not already a
    * breakpoint handler.
    *
    * @param BreakpointActor actor
    *        The BreakpointActor to set as breakpoint handler.
    */
   setBreakpointForActor: function (actor) {
     let generatedLocation = {
       sourceActor: this,
-      line: actor.location.line,
-      column: actor.location.column
+      line: actor.generatedLocation.line,
+      column: actor.generatedLocation.column
     };
 
     let { line: generatedLine, column: generatedColumn } = generatedLocation;
 
     // Find all scripts matching the given location. We will almost always have
     // a `source` object to query, but multiple inline HTML scripts are all
     // represented by a single SourceActor even though they have separate source
     // objects, so we need to query based on the url of the page for them.
@@ -2971,17 +2979,17 @@ SourceActor.prototype = {
       if (existingActor) {
         actor.onDelete();
         this.breakpointActorMap.deleteActor(generatedLocation);
         return {
           actor: existingActor.actorID,
           actualLocation
         };
       } else {
-        actor.location = actualLocation;
+        actor.generatedLocation = actualLocation;
         this.breakpointActorMap.deleteActor(generatedLocation);
         this.breakpointActorMap.setActor(actualLocation, actor);
       }
     }
 
     setBreakpointOnEntryPoints(this.threadActor, actor, entryPoints);
 
     return {
@@ -4635,33 +4643,39 @@ FrameActor.prototype.requestTypes = {
 
 /**
  * Creates a BreakpointActor. BreakpointActors exist for the lifetime of their
  * containing thread and are responsible for deleting breakpoints, handling
  * breakpoint hits and associating breakpoints with scripts.
  *
  * @param ThreadActor aThreadActor
  *        The parent thread actor that contains this breakpoint.
- * @param object aLocation
- *        Optional. An object with the following properties:
+ * @param object aOriginalLocation
+ *        An object with the following properties:
+ *        - sourceActor: A SourceActor that represents the source
+ *        - line: the specified line
+ *        - column: the specified column
+ * @param object aGeneratedLocation
+ *        An object with the following properties:
  *        - sourceActor: A SourceActor that represents the source
  *        - line: the specified line
  *        - column: the specified column
  * @param string aCondition
  *        Optional. A condition which, when false, will cause the breakpoint to
  *        be skipped.
  */
-function BreakpointActor(aThreadActor, aLocation, aCondition)
+function BreakpointActor(aThreadActor, aOriginalLocation, aGeneratedLocation, aCondition)
 {
   // The set of Debugger.Script instances that this breakpoint has been set
   // upon.
   this.scripts = new Set();
 
   this.threadActor = aThreadActor;
-  this.location = aLocation;
+  this.originalLocation = aOriginalLocation;
+  this.generatedLocation = aGeneratedLocation;
   this.condition = aCondition;
 }
 
 BreakpointActor.prototype = {
   actorPrefix: "breakpoint",
   condition: null,
 
   hasScript: function (aScript) {
@@ -4740,20 +4754,18 @@ BreakpointActor.prototype = {
   /**
    * Handle a protocol request to remove this breakpoint.
    *
    * @param aRequest object
    *        The protocol request object.
    */
   onDelete: function (aRequest) {
     // Remove from the breakpoint store.
-    if (this.location) {
-      this.threadActor.breakpointActorMap.deleteActor(
-        update({}, this.location, { source: this.location.sourceActor.form() })
-      );
+    if (this.generatedLocation) {
+      this.threadActor.breakpointActorMap.deleteActor(this.generatedLocation);
     }
     this.threadActor.threadLifetimePool.removeActor(this);
     // Remove the actual breakpoint from the associated scripts.
     this.removeScripts();
     return { from: this.actorID };
   }
 };