Bug 1451018 - Convert SymbolActor to protocol.js; r=yulia.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Wed, 18 Apr 2018 15:04:03 +0200
changeset 472109 1d4d0038e10aed3211da445f680f1957108b4efa
parent 472108 6e065d127de03d7fee8575a474c5bfaba4f54caf
child 472110 4421b373b86a8cb14b4f92dc5c7735f92925f9b1
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyulia
bugs1451018
milestone61.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 1451018 - Convert SymbolActor to protocol.js; r=yulia. MozReview-Commit-ID: AW2uxeN1tpM
devtools/server/actors/object/symbol.js
devtools/server/tests/unit/test_symbolactor.js
devtools/shared/specs/index.js
devtools/shared/specs/moz.build
devtools/shared/specs/symbol.js
--- a/devtools/server/actors/object/symbol.js
+++ b/devtools/server/actors/object/symbol.js
@@ -1,80 +1,77 @@
 /* -*- 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 protocol = require("devtools/shared/protocol");
+const { symbolSpec } = require("devtools/shared/specs/symbol");
 loader.lazyRequireGetter(this, "createValueGrip", "devtools/server/actors/object/utils", true);
 
 /**
  * Creates an actor for the specified symbol.
  *
  * @param symbol Symbol
  *        The symbol.
  */
-function SymbolActor(symbol) {
-  this.symbol = symbol;
-}
-
-SymbolActor.prototype = {
-  actorPrefix: "symbol",
+const SymbolActor = protocol.ActorClassWithSpec(symbolSpec, {
+  initialize(symbol) {
+    protocol.Actor.prototype.initialize.call(this);
+    this.symbol = symbol;
+  },
 
   rawValue: function() {
     return this.symbol;
   },
 
   destroy: function() {
     // Because symbolActors is not a weak map, we won't automatically leave
     // it so we need to manually leave on destroy so that we don't leak
     // memory.
     this._releaseActor();
   },
 
   /**
    * Returns a grip for this actor for returning in a protocol message.
    */
-  grip: function() {
+  form: function() {
     let form = {
-      type: "symbol",
+      type: this.typeName,
       actor: this.actorID,
     };
     let name = getSymbolName(this.symbol);
     if (name !== undefined) {
       // Create a grip for the name because it might be a longString.
       form.name = createValueGrip(name, this.registeredPool);
     }
     return form;
   },
 
   /**
    * Handle a request to release this SymbolActor instance.
    */
-  onRelease: function() {
+  release: function() {
     // TODO: also check if registeredPool === threadActor.threadLifetimePool
     // when the web console moves away from manually releasing pause-scoped
     // actors.
     this._releaseActor();
     this.registeredPool.removeActor(this);
     return {};
   },
 
   _releaseActor: function() {
     if (this.registeredPool && this.registeredPool.symbolActors) {
       delete this.registeredPool.symbolActors[this.symbol];
     }
   }
-};
-
-SymbolActor.prototype.requestTypes = {
-  "release": SymbolActor.prototype.onRelease
-};
+});
 
 const symbolProtoToString = Symbol.prototype.toString;
 
 function getSymbolName(symbol) {
   const name = symbolProtoToString.call(symbol).slice("Symbol(".length, -1);
   return name || undefined;
 }
 
@@ -87,21 +84,21 @@ function getSymbolName(symbol) {
  *        The actor pool where the new actor will be added.
  */
 function symbolGrip(sym, pool) {
   if (!pool.symbolActors) {
     pool.symbolActors = Object.create(null);
   }
 
   if (sym in pool.symbolActors) {
-    return pool.symbolActors[sym].grip();
+    return pool.symbolActors[sym].form();
   }
 
   let actor = new SymbolActor(sym);
   pool.addActor(actor);
   pool.symbolActors[sym] = actor;
-  return actor.grip();
+  return actor.form();
 }
 
 module.exports = {
   SymbolActor,
   symbolGrip,
 };
--- a/devtools/server/tests/unit/test_symbolactor.js
+++ b/devtools/server/tests/unit/test_symbolactor.js
@@ -3,17 +3,17 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const { SymbolActor } = require("devtools/server/actors/object/symbol");
 
 function run_test() {
   test_SA_destroy();
-  test_SA_grip();
+  test_SA_form();
   test_SA_raw();
 }
 
 const SYMBOL_NAME = "abc";
 const TEST_SYMBOL = Symbol(SYMBOL_NAME);
 
 function makeMockSymbolActor() {
   let symbol = TEST_SYMBOL;
@@ -30,20 +30,20 @@ function makeMockSymbolActor() {
 function test_SA_destroy() {
   let actor = makeMockSymbolActor();
   strictEqual(actor.registeredPool.symbolActors[TEST_SYMBOL], actor);
 
   actor.destroy();
   strictEqual(TEST_SYMBOL in actor.registeredPool.symbolActors, false);
 }
 
-function test_SA_grip() {
+function test_SA_form() {
   let actor = makeMockSymbolActor();
-  let grip = actor.grip();
-  strictEqual(grip.type, "symbol");
-  strictEqual(grip.actor, actor.actorID);
-  strictEqual(grip.name, SYMBOL_NAME);
+  let form = actor.form();
+  strictEqual(form.type, "symbol");
+  strictEqual(form.actor, actor.actorID);
+  strictEqual(form.name, SYMBOL_NAME);
 }
 
 function test_SA_raw() {
   let actor = makeMockSymbolActor();
   strictEqual(actor.rawValue(), TEST_SYMBOL);
 }
--- a/devtools/shared/specs/index.js
+++ b/devtools/shared/specs/index.js
@@ -195,16 +195,21 @@ const Types = exports.__TypesForTests = 
     front: "devtools/shared/fronts/styles",
   },
   {
     types: ["mediarule", "stylesheet", "stylesheets"],
     spec: "devtools/shared/specs/stylesheets",
     front: "devtools/shared/fronts/stylesheets",
   },
   {
+    types: ["symbol"],
+    spec: "devtools/shared/specs/symbol",
+    front: null,
+  },
+  {
     types: ["symbolIterator"],
     spec: "devtools/shared/specs/symbol-iterator",
     front: null,
   },
   {
     types: ["tab"],
     spec: "devtools/shared/specs/tab",
     front: null,
--- a/devtools/shared/specs/moz.build
+++ b/devtools/shared/specs/moz.build
@@ -36,16 +36,17 @@ DevToolsModules(
     'reflow.js',
     'script.js',
     'source.js',
     'storage.js',
     'string.js',
     'styles.js',
     'stylesheets.js',
     'symbol-iterator.js',
+    'symbol.js',
     'tab.js',
     'timeline.js',
     'webaudio.js',
     'webextension-inspected-window.js',
     'webextension-parent.js',
     'webgl.js',
     'worker.js'
 )
new file mode 100644
--- /dev/null
+++ b/devtools/shared/specs/symbol.js
@@ -0,0 +1,22 @@
+/* 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 {
+  generateActorSpec,
+} = require("devtools/shared/protocol");
+
+const symbolSpec = generateActorSpec({
+  typeName: "symbol",
+
+  methods: {
+    release: {
+      request: {},
+      response: {}
+    },
+  }
+});
+
+exports.symbolSpec = symbolSpec;