Bug 808791: JS debug server: construct environment forms correctly, using Debugger.Environment.prototype.callee. r=past
authorJim Blandy <jimb@mozilla.com>
Mon, 14 Jan 2013 16:15:58 -0800
changeset 128700 ae9b3bb6b75a612f028c0e0d3799b65379f18acd
parent 128699 49e48938f65ce2d920a9e0d46c33cf9de7626cd6
child 128701 fabb72141c554e15a1f4b4195feebfdaf843cab1
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs808791
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 808791: JS debug server: construct environment forms correctly, using Debugger.Environment.prototype.callee. r=past
toolkit/devtools/debugger/server/dbg-script-actors.js
--- a/toolkit/devtools/debugger/server/dbg-script-actors.js
+++ b/toolkit/devtools/debugger/server/dbg-script-actors.js
@@ -1655,22 +1655,17 @@ update(ObjectActor.prototype, {
 
     let envActor = this.threadActor.createEnvironmentActor(this.obj.environment,
                                                            this.registeredPool);
     if (!envActor) {
       return { error: "notDebuggee",
                message: "cannot access the environment of this function." };
     }
 
-    // XXX: the following call of env.form() won't work until bug 747514 lands.
-    // We can't get to the frame that defined this function's environment,
-    // neither here, nor during ObjectActor's construction. Luckily, we don't
-    // use the 'scope' request in the debugger frontend.
-    return { name: this.obj.name || null,
-             scope: envActor.form(this.obj) };
+    return { from: this.actorID, scope: envActor.form() };
   }),
 
   /**
    * Handle a protocol request to provide the parameters of a function.
    *
    * @param aRequest object
    *        The protocol request object.
    */
@@ -1842,20 +1837,22 @@ FrameActor.prototype = {
    */
   form: function FA_form() {
     let form = { actor: this.actorID,
                  type: this.frame.type };
     if (this.frame.type === "call") {
       form.callee = this.threadActor.createValueGrip(this.frame.callee);
     }
 
-    let envActor = this.threadActor
-                       .createEnvironmentActor(this.frame.environment,
-                                               this.frameLifetimePool);
-    form.environment = envActor ? envActor.form(this.frame) : envActor;
+    if (this.frame.environment) {
+      let envActor = this.threadActor
+        .createEnvironmentActor(this.frame.environment,
+                                this.frameLifetimePool);
+      form.environment = envActor.form();
+    }
     form.this = this.threadActor.createValueGrip(this.frame.this);
     form.arguments = this._args();
     if (this.frame.script) {
       form.where = { url: this.frame.script.url,
                      line: this.frame.script.getOffsetLine(this.frame.offset) };
     }
 
     if (!this.frame.older) {
@@ -1990,90 +1987,71 @@ function EnvironmentActor(aEnvironment, 
   this.obj = aEnvironment;
   this.threadActor = aThreadActor;
 }
 
 EnvironmentActor.prototype = {
   actorPrefix: "environment",
 
   /**
-   * Returns an environment form for use in a protocol message. Note that the
-   * requirement of passing the frame as a parameter is only temporary, since
-   * when bug 747514 lands, the environment will have a callee property that
-   * will contain it.
-   *
-   * @param Debugger.Frame aObject
-   *        The stack frame object whose environment bindings are being
-   *        generated.
+   * Return an environment form for use in a protocol message.
    */
-  form: function EA_form(aObject) {
-    // Debugger.Frame might be dead by the time we get here, which will cause
-    // accessing its properties to throw.
-    if (!aObject.live) {
-      return undefined;
+  form: function EA_form() {
+    let form = { actor: this.actorID };
+
+    // What is this environment's type?
+    if (this.obj.type == "declarative") {
+      form.type = this.obj.callee ? "function" : "block";
+    } else {
+      form.type = this.obj.type;
     }
 
-    let parent;
+    // Does this environment have a parent?
     if (this.obj.parent) {
-      let thread = this.threadActor;
-      parent = thread.createEnvironmentActor(this.obj.parent,
-                                             this.registeredPool);
+      form.parent = (this.threadActor
+                     .createEnvironmentActor(this.obj.parent,
+                                             this.registeredPool)
+                     .form());
     }
-    // Deduce the frame that created the parent scope in order to pass it to
-    // parent.form(). TODO: this can be removed after bug 747514 is done.
-    let parentFrame = aObject;
-    if (this.obj.type == "declarative" && aObject.older) {
-      parentFrame = aObject.older;
-    }
-    let form = { actor: this.actorID,
-                 parent: parent ? parent.form(parentFrame) : parent };
 
-    if (this.obj.type == "with") {
-      form.type = "with";
-      form.object = this.threadActor.createValueGrip(this.obj.object);
-    } else if (this.obj.type == "object") {
-      form.type = "object";
+    // Does this environment reflect the properties of an object as variables?
+    if (this.obj.type == "object" || this.obj.type == "with") {
       form.object = this.threadActor.createValueGrip(this.obj.object);
-    } else { // this.obj.type == "declarative"
-      if (aObject.callee) {
-        form.type = "function";
-        form.function = this.threadActor.createValueGrip(aObject.callee);
-      } else {
-        form.type = "block";
-      }
-      form.bindings = this._bindings(aObject);
+    }
+
+    // Is this the environment created for a function call?
+    if (this.obj.callee) {
+      form.function = this.threadActor.createValueGrip(this.obj.callee);
+    }
+
+    // Shall we list this environment's bindings?
+    if (this.obj.type == "declarative") {
+      form.bindings = this._bindings();
     }
 
     return form;
   },
 
   /**
    * Return the identifier bindings object as required by the remote protocol
-   * specification. Note that the requirement of passing the frame as a
-   * parameter is only temporary, since when bug 747514 lands, the environment
-   * will have a callee property that will contain it.
-   *
-   * @param Debugger.Frame aObject [optional]
-   *        The stack frame whose environment bindings are being generated. When
-   *        left unspecified, the bindings do not contain an 'arguments'
-   *        property.
+   * specification.
    */
-  _bindings: function EA_bindings(aObject) {
+  _bindings: function EA_bindings() {
     let bindings = { arguments: [], variables: {} };
 
     // TODO: this part should be removed in favor of the commented-out part
     // below when getVariableDescriptor lands (bug 725815).
     if (typeof this.obj.getVariable != "function") {
     //if (typeof this.obj.getVariableDescriptor != "function") {
       return bindings;
     }
 
     let parameterNames;
-    if (aObject && aObject.callee) {
-      parameterNames = aObject.callee.parameterNames;
+    if (this.obj.callee) {
+      parameterNames = this.obj.callee.parameterNames;
     }
     for each (let name in parameterNames) {
       let arg = {};
       // TODO: this part should be removed in favor of the commented-out part
       // below when getVariableDescriptor lands (bug 725815).
       let desc = {
         value: this.obj.getVariable(name),
         configurable: false,