Bug 1290599 - Part 1: Improve names of events fired by debugger transport r?jryans
Although "close" would be an event name more consistent with usual event naming
(like in DOM APIs), I'm choosing "onClosed" here, because it's more in-line with
what debugger transports use (onPacket, onBulkPacket), it's a minimal change
(only LocalDebuggerTransport is affected) and no update to RDP inspector is needed.
MozReview-Commit-ID: B0YnBOOBSNI
--- a/devtools/shared/transport/transport.js
+++ b/devtools/shared/transport/transport.js
@@ -180,33 +180,33 @@
* The stream to copy from.
* @return Promise
* The promise is resolved when copying completes or
* rejected if any (unexpected) errors occur.
* This object also emits "progress" events for each chunk
* that is copied. See stream-utils.js.
*/
startBulkSend: function (header) {
- this.emit("startBulkSend", header);
+ this.emit("startbulksend", header);
let packet = new BulkPacket(this);
packet.header = header;
this._outgoing.push(packet);
this._flushOutgoing();
return packet.streamReadyForWriting;
},
/**
* Close the transport.
* @param reason nsresult / object (optional)
* The status code or error message that corresponds to the reason for
* closing the transport (likely because a stream closed or failed).
*/
close: function (reason) {
- this.emit("onClosed", reason);
+ this.emit("close", reason);
this.active = false;
this._input.close();
this._scriptableInput.close();
this._output.close();
this._destroyIncoming();
this._destroyAllOutgoing();
if (this.hooks) {
@@ -474,33 +474,33 @@
/**
* Handler triggered by an incoming JSONPacket completing it's |read| method.
* Delivers the packet to this.hooks.onPacket.
*/
_onJSONObjectReady: function (object) {
DevToolsUtils.executeSoon(DevToolsUtils.makeInfallible(() => {
// Ensure the transport is still alive by the time this runs.
if (this.active) {
- this.emit("onPacket", object);
+ this.emit("packet", object);
this.hooks.onPacket(object);
}
}, "DebuggerTransport instance's this.hooks.onPacket"));
},
/**
* Handler triggered by an incoming BulkPacket entering the |read| phase for
* the stream portion of the packet. Delivers info about the incoming
* streaming data to this.hooks.onBulkPacket. See the main comment on the
* transport at the top of this file for more details.
*/
_onBulkReadReady: function (...args) {
DevToolsUtils.executeSoon(DevToolsUtils.makeInfallible(() => {
// Ensure the transport is still alive by the time this runs.
if (this.active) {
- this.emit("onBulkPacket", ...args);
+ this.emit("bulkpacket", ...args);
this.hooks.onBulkPacket(...args);
}
}, "DebuggerTransport instance's this.hooks.onBulkPacket"));
},
/**
* Remove all handlers and references related to the current incoming packet,
* either because it is now complete or because the transport is closing.
@@ -561,34 +561,34 @@
let other = this.other;
if (other) {
DevToolsUtils.executeSoon(DevToolsUtils.makeInfallible(() => {
// Avoid the cost of JSON.stringify() when logging is disabled.
if (flags.wantLogging) {
dumpn("Received packet " + serial + ": " + JSON.stringify(packet, null, 2));
}
if (other.hooks) {
- other.emit("onPacket", packet);
+ other.emit("packet", packet);
other.hooks.onPacket(packet);
}
}, "LocalDebuggerTransport instance's this.other.hooks.onPacket"));
}
},
/**
* Send a streaming bulk packet directly to the onBulkPacket handler of the
* other endpoint.
*
* This case is much simpler than the full DebuggerTransport, since there is
* no primary stream we have to worry about managing while we hand it off to
* others temporarily. Instead, we can just make a single use pipe and be
* done with it.
*/
startBulkSend: function ({actor, type, length}) {
- this.emit("startBulkSend", {actor, type, length});
+ this.emit("startbulksend", {actor, type, length});
let serial = this._serial.count++;
dumpn("Sent bulk packet " + serial + " for actor " + actor);
if (!this.other) {
let error = new Error("startBulkSend: other side of transport missing");
return promise.reject(error);
}
@@ -612,17 +612,17 @@
StreamUtils.copyStream(pipe.inputStream, output, length);
deferred.resolve(copying);
return copying;
},
stream: pipe.inputStream,
done: deferred
};
- this.other.emit("onBulkPacket", packet);
+ this.other.emit("bulkpacket", packet);
this.other.hooks.onBulkPacket(packet);
// Await the result of reading from the stream
deferred.promise.then(() => pipe.inputStream.close(), this.close);
}, "LocalDebuggerTransport instance's this.other.hooks.onBulkPacket"));
// Sender
let sendDeferred = defer();
@@ -739,22 +739,22 @@
} catch (e) {
if (e.result != Cr.NS_ERROR_NULL_POINTER) {
throw e;
}
// In some cases, especially when using messageManagers in non-e10s mode, we reach
// this point with a dead messageManager which only throws errors but does not
// seem to indicate in any other way that it is dead.
}
- this.emit("onClosed");
+ this.emit("close");
this.hooks.onClosed();
},
receiveMessage: function ({data}) {
- this.emit("onPacket", data);
+ this.emit("packet", data);
this.hooks.onPacket(data);
},
send: function (packet) {
this.emit("send", packet);
try {
this._sender.sendAsyncMessage(this._messageName, packet);
} catch (e) {
--- a/devtools/shared/transport/websocket-transport.js
+++ b/devtools/shared/transport/websocket-transport.js
@@ -33,17 +33,17 @@ WebSocketDebuggerTransport.prototype = {
}
},
startBulkSend() {
throw new Error("Bulk send is not supported by WebSocket transport");
},
close() {
- this.emit("onClosed");
+ this.emit("close");
this.active = false;
this.socket.removeEventListener("message", this);
this.socket.removeEventListener("close", this);
this.socket.close();
this.socket = null;
if (this.hooks) {
@@ -64,16 +64,16 @@ WebSocketDebuggerTransport.prototype = {
},
onMessage({ data }) {
if (typeof data !== "string") {
throw new Error("Binary messages are not supported by WebSocket transport");
}
let object = JSON.parse(data);
- this.emit("onPacket", object);
+ this.emit("packet", object);
if (this.hooks) {
this.hooks.onPacket(object);
}
},
};
module.exports = WebSocketDebuggerTransport;