Bug 1278625 - move SimpleStringFront to specs/string.js; r?ejpbruel
MozReview-Commit-ID: Ib11CZwL4pP
--- 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);
}
});