Bug 896274 - Allow an object's form to be an actor id. r=jimb
authorDave Camp <dcamp@mozilla.com>
Sun, 21 Jul 2013 11:02:30 -0700
changeset 152530 caddb1d95e348d4c1fa96c4e3c0b80968586ffa0
parent 152529 bbb8b9bf2578384b389264f33eaca9ce6f934b47
child 152531 db96c1377702f6ad584039f9074979d77dc2fee1
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimb
bugs896274
milestone25.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 896274 - Allow an object's form to be an actor id. r=jimb
toolkit/devtools/server/protocol.js
toolkit/devtools/server/tests/unit/test_protocol_children.js
--- a/toolkit/devtools/server/protocol.js
+++ b/toolkit/devtools/server/protocol.js
@@ -249,22 +249,23 @@ types.addActorType = function(name) {
       // find the actor registered with this actorID.
       if (ctx instanceof Actor) {
         return ctx.conn.getActor(v);
       }
 
       // Reading a response on the client side, check for an
       // existing front on the connection, and create the front
       // if it isn't found.
-      let front = ctx.conn.getActor(v.actor);
+      let actorID = typeof(v) === "string" ? v : v.actor;
+      let front = ctx.conn.getActor(actorID);
       if (front) {
         front.form(v, detail, ctx);
       } else {
         front = new type.frontClass(ctx.conn, v, detail, ctx)
-        front.actorID = v.actor;
+        front.actorID = actorID;
         ctx.marshallPool().manage(front);
       }
       return front;
     },
     write: (v, ctx, detail) => {
       // If returning a response from the server side, make sure
       // the actor is added to a parent object and return its form.
       if (v instanceof Actor) {
--- a/toolkit/devtools/server/tests/unit/test_protocol_children.js
+++ b/toolkit/devtools/server/tests/unit/test_protocol_children.js
@@ -38,16 +38,19 @@ let ChildActor = protocol.ActorClass({
   },
 
   destroy: function() {
     protocol.Actor.prototype.destroy.call(this);
     this.destroyed = true;
   },
 
   form: function(detail) {
+    if (detail === "actorid") {
+      return this.actorID;
+    }
     return {
       actor: this.actorID,
       childID: this.childID,
       detail: detail
     };
   },
 
   echo: method(function(str) {
@@ -67,16 +70,24 @@ let ChildActor = protocol.ActorClass({
 
   getDetail2: method(function() {
     return this;
   }, {
     // This also exercises return-value-as-packet.
     response: RetVal("childActor#detail2"),
   }),
 
+  getIDDetail: method(function() {
+    return this;
+  }, {
+    response: {
+      idDetail: RetVal("childActor#actorid")
+    }
+  }),
+
   getSibling: method(function(id) {
     return this.parent().getChild(id);
   }, {
     request: { id: Arg(0) },
     response: { sibling: RetVal("childActor") }
   }),
 
   emitEvents: method(function() {
@@ -122,17 +133,20 @@ let ChildFront = protocol.FrontClass(Chi
     this.destroyed = true;
     protocol.Front.prototype.destroy.call(this);
   },
 
   marshallPool: function() { return this.parent() },
 
   toString: function() "[child front " + this.childID + "]",
 
-  form: function(form) {
+  form: function(form, detail) {
+    if (detail === "actorid") {
+      return;
+    }
     this.childID = form.childID;
     this.detail = form.detail;
   },
 
   onEvent1: preEvent("event1", function(a, b, c) {
     this.event1arg3 = c;
   }),
 });
@@ -300,16 +314,22 @@ function run_test()
     }).then(() => {
       return childFront.getDetail2();
     }).then(ret => {
       trace.expectSend({"type":"getDetail2","to":"<actorid>"});
       trace.expectReceive({"actor":"<actorid>","childID":"child1","detail":"detail2","from":"<actorid>"});
       do_check_true(ret === childFront);
       do_check_eq(childFront.detail, "detail2");
     }).then(() => {
+      return childFront.getIDDetail();
+    }).then(ret => {
+      trace.expectSend({"type":"getIDDetail","to":"<actorid>"});
+      trace.expectReceive({"idDetail": childFront.actorID,"from":"<actorid>"});
+      do_check_true(ret === childFront);
+    }).then(() => {
       return childFront.getSibling("siblingID");
     }).then(ret => {
       trace.expectSend({"type":"getSibling","id":"siblingID","to":"<actorid>"});
       trace.expectReceive({"sibling":{"actor":"<actorid>","childID":"siblingID"},"from":"<actorid>"});
 
       expectRootChildren(2);
     }).then(ret => {
       return rootFront.getTemporaryChild("temp1").then(temp1 => {