Bug 1278625 - move SimpleStringFront to specs/string.js; r?ejpbruel draft
authorTom Tromey <tom@tromey.com>
Tue, 16 Aug 2016 11:01:33 -0600
changeset 401940 583bfd3eee246398f67705549e9d8d3ee941ecad
parent 401225 a40f5f49614b1b6d6f656d5b715619e295c95281
child 528610 56401bf98842118e1eafaea18a69df8aef8e30b6
push id26589
push userbmo:ttromey@mozilla.com
push dateWed, 17 Aug 2016 19:45:13 +0000
reviewersejpbruel
bugs1278625
milestone51.0a1
Bug 1278625 - move SimpleStringFront to specs/string.js; r?ejpbruel MozReview-Commit-ID: Ib11CZwL4pP
devtools/server/tests/unit/test_protocol_longstring.js
devtools/shared/fronts/string.js
devtools/shared/specs/string.js
--- a/devtools/server/tests/unit/test_protocol_longstring.js
+++ b/devtools/server/tests/unit/test_protocol_longstring.js
@@ -4,16 +4,19 @@
 /**
  * Test simple requests using the protocol helpers.
  */
 var protocol = require("devtools/shared/protocol");
 var {RetVal, Arg, Option} = protocol;
 var events = require("sdk/event/core");
 var {LongStringActor} = require("devtools/server/actors/string");
 
+// The test implicitly relies on this.
+require("devtools/shared/fronts/string");
+
 function simpleHello() {
   return {
     from: "root",
     applicationType: "xpcshell-tests",
     traits: [],
   };
 }
 
--- a/devtools/shared/fronts/string.js
+++ b/devtools/shared/fronts/string.js
@@ -1,17 +1,16 @@
 /* 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 {DebuggerServer} = require("devtools/server/main");
 const promise = require("promise");
-const {Class} = require("sdk/core/heritage");
-const {longStringSpec} = require("devtools/shared/specs/string");
+const {longStringSpec, SimpleStringFront} = require("devtools/shared/specs/string");
 const protocol = require("devtools/shared/protocol");
 
 const LongStringFront = protocol.FrontClass(longStringSpec, {
   initialize: function (client) {
     protocol.Front.prototype.initialize.call(this, client);
   },
 
   destroy: function () {
@@ -40,40 +39,9 @@ const LongStringFront = protocol.FrontCl
 
       this.strPromise = promiseRest(this.initial);
     }
     return this.strPromise;
   }
 });
 
 exports.LongStringFront = LongStringFront;
-
-/**
- * When a caller is expecting a LongString actor but the string is already available on
- * client, the SimpleStringFront can be used as it shares the same API as a
- * LongStringFront but will not make unnecessary trips to the server.
- */
-exports.SimpleStringFront = Class({
-  initialize: function (str) {
-    this.str = str;
-  },
-
-  get length() {
-    return this.str.length;
-  },
-
-  get initial() {
-    return this.str;
-  },
-
-  string: function () {
-    return promise.resolve(this.str);
-  },
-
-  substring: function (start, end) {
-    return promise.resolve(this.str.substring(start, end));
-  },
-
-  release: function () {
-    this.str = null;
-    return promise.resolve(undefined);
-  }
-});
+exports.SimpleStringFront = SimpleStringFront;
--- a/devtools/shared/specs/string.js
+++ b/devtools/shared/specs/string.js
@@ -1,18 +1,17 @@
 /* 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 {Arg, RetVal, generateActorSpec} = protocol;
-
-loader.lazyRequireGetter(this, "SimpleStringFront",
-                         "devtools/shared/fronts/string", true);
+const promise = require("promise");
+const {Class} = require("sdk/core/heritage");
 
 const longStringSpec = generateActorSpec({
   typeName: "longstractor",
 
   methods: {
     substring: {
       request: {
         start: Arg(0),
@@ -21,16 +20,50 @@ const longStringSpec = generateActorSpec
       response: { substring: RetVal() },
     },
     release: { release: true },
   },
 });
 
 exports.longStringSpec = longStringSpec;
 
+/**
+ * When a caller is expecting a LongString actor but the string is already available on
+ * client, the SimpleStringFront can be used as it shares the same API as a
+ * LongStringFront but will not make unnecessary trips to the server.
+ */
+const SimpleStringFront = Class({
+  initialize: function (str) {
+    this.str = str;
+  },
+
+  get length() {
+    return this.str.length;
+  },
+
+  get initial() {
+    return this.str;
+  },
+
+  string: function () {
+    return promise.resolve(this.str);
+  },
+
+  substring: function (start, end) {
+    return promise.resolve(this.str.substring(start, end));
+  },
+
+  release: function () {
+    this.str = null;
+    return promise.resolve(undefined);
+  }
+});
+
+exports.SimpleStringFront = SimpleStringFront;
+
 // The long string actor needs some custom marshalling, because it is sometimes
 // returned as a primitive rather than a complete form.
 
 var stringActorType = protocol.types.getType("longstractor");
 protocol.types.addType("longstring", {
   _actor: true,
   write: (value, context, detail) => {
     if (!(context instanceof protocol.Actor)) {
@@ -42,13 +75,13 @@ protocol.types.addType("longstring", {
     }
     return stringActorType.write(value, context, detail);
   },
   read: (value, context, detail) => {
     if (context instanceof protocol.Actor) {
       throw Error("Passing a longstring as an argument isn't supported.");
     }
     if (typeof (value) === "string") {
-      return SimpleStringFront(value);
+      return new SimpleStringFront(value);
     }
     return stringActorType.read(value, context, detail);
   }
 });