Bug 1277971 - Use ActorClassWithSpec for the EnvironmentActor; r=ejpbruel
authorNick Fitzgerald <fitzgen@gmail.com>
Mon, 06 Jun 2016 10:24:34 -0700
changeset 325695 700dc64a74adacf9d6e5c37129288ea86d25fb3a
parent 325694 8badc9fb7730f469c35daa3a8534958021159d6d
child 325696 a325b8ebc11559ec0c555615896985d0508c99cf
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersejpbruel
bugs1277971
milestone49.0a1
Bug 1277971 - Use ActorClassWithSpec for the EnvironmentActor; r=ejpbruel
devtools/server/actors/environment.js
devtools/shared/specs/environment.js
devtools/shared/specs/moz.build
--- a/devtools/server/actors/environment.js
+++ b/devtools/server/actors/environment.js
@@ -1,31 +1,30 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2; js-indent-level: 2 -*- */
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
-const { ActorClass, Arg, RetVal, method } = require("devtools/shared/protocol");
+const { ActorClassWithSpec } = require("devtools/shared/protocol");
 const { createValueGrip } = require("devtools/server/actors/object");
+const { environmentSpec } = require("devtools/shared/specs/environment");
 
 /**
  * Creates an EnvironmentActor. EnvironmentActors are responsible for listing
  * the bindings introduced by a lexical environment and assigning new values to
  * those identifier bindings.
  *
  * @param Debugger.Environment aEnvironment
  *        The lexical environment that will be used to create the actor.
  * @param ThreadActor aThreadActor
  *        The parent thread actor that contains this environment.
  */
-let EnvironmentActor = ActorClass({
-  typeName: "environment",
-
+let EnvironmentActor = ActorClassWithSpec(environmentSpec, {
   initialize: function (environment, threadActor) {
     this.obj = environment;
     this.threadActor = threadActor;
   },
 
   /**
    * Return an environment form for use in a protocol message.
    */
@@ -71,17 +70,17 @@ let EnvironmentActor = ActorClass({
    * Handle a protocol request to change the value of a variable bound in this
    * lexical environment.
    *
    * @param string name
    *        The name of the variable to be changed.
    * @param any value
    *        The value to be assigned.
    */
-  assign: method(function (name, value) {
+  assign: function (name, value) {
     // TODO: enable the commented-out part when getVariableDescriptor lands
     // (bug 725815).
     /* let desc = this.obj.getVariableDescriptor(name);
 
     if (!desc.writable) {
       return { error: "immutableBinding",
                message: "Changing the value of an immutable binding is not " +
                         "allowed" };
@@ -95,28 +94,23 @@ let EnvironmentActor = ActorClass({
           error: "threadWouldRun",
           message: "Assigning a value would cause the debuggee to run"
         };
       } else {
         throw e;
       }
     }
     return { from: this.actorID };
-  }, {
-    request: {
-      name: Arg(1),
-      value: Arg(2)
-    }
-  }),
+  },
 
   /**
    * Handle a protocol request to fully enumerate the bindings introduced by the
    * lexical environment.
    */
-  bindings: method(function () {
+  bindings: function () {
     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;
     }
@@ -194,17 +188,12 @@ let EnvironmentActor = ActorClass({
           this.registeredPool, this.threadActor.objectGrip);
         descForm.set = createValueGrip(desc.set || undefined,
           this.registeredPool, this.threadActor.objectGrip);
       }
       bindings.variables[name] = descForm;
     }
 
     return bindings;
-  }, {
-    request: {},
-    response: {
-      bindings: RetVal("json")
-    }
-  })
+  }
 });
 
 exports.EnvironmentActor = EnvironmentActor;
new file mode 100644
--- /dev/null
+++ b/devtools/shared/specs/environment.js
@@ -0,0 +1,27 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const {Arg, RetVal, generateActorSpec} = require("devtools/shared/protocol");
+
+const environmentSpec = generateActorSpec({
+  typeName: "environment",
+
+  methods: {
+    assign: {
+      request: {
+        name: Arg(1),
+        value: Arg(2)
+      }
+    },
+    bindings: {
+      request: {},
+      response: {
+        bindings: RetVal("json")
+      }
+    },
+  },
+});
+
+exports.environmentSpec = environmentSpec;
--- a/devtools/shared/specs/moz.build
+++ b/devtools/shared/specs/moz.build
@@ -7,16 +7,17 @@
 DevToolsModules(
     'actor-registry.js',
     'addons.js',
     'animation.js',
     'breakpoint.js',
     'call-watcher.js',
     'canvas.js',
     'css-properties.js',
+    'environment.js',
     'frame.js',
     'heap-snapshot-file.js',
     'highlighters.js',
     'inspector.js',
     'node.js',
     'preference.js',
     'script.js',
     'settings.js',