forked from mirrors/gecko-dev
Bug 1278357 - Clean up code style in transport.js. r=tromey
MozReview-Commit-ID: 3uFu6AhOfbg
This commit is contained in:
parent
9d0ac66004
commit
e1d147bbfc
2 changed files with 337 additions and 335 deletions
|
|
@ -133,6 +133,7 @@ devtools/shared/tests/**
|
|||
!devtools/shared/tests/unit/test_csslexer.js
|
||||
devtools/shared/touch/**
|
||||
devtools/shared/transport/**
|
||||
!devtools/shared/transport/transport.js
|
||||
devtools/shared/webconsole/test/**
|
||||
devtools/shared/worker/**
|
||||
|
||||
|
|
|
|||
|
|
@ -1,29 +1,28 @@
|
|||
/* -*- indent-tabs-mode: nil; 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";
|
||||
|
||||
/* global Pipe, ScriptableInputStream, uneval */
|
||||
|
||||
// TODO: Get rid of this code once the marionette server loads transport.js as
|
||||
// an SDK module (see bug 1000814)
|
||||
(function (factory) { // Module boilerplate
|
||||
if (this.module && module.id.indexOf("transport") >= 0) { // require
|
||||
(function (factory) {
|
||||
if (this.module && module.id.indexOf("transport") >= 0) {
|
||||
// require
|
||||
factory.call(this, require, exports);
|
||||
} else { // loadSubScript
|
||||
if (this.require) {
|
||||
} else if (this.require) {
|
||||
// loadSubScript
|
||||
factory.call(this, require, this);
|
||||
} else {
|
||||
// Cu.import
|
||||
const Cu = Components.utils;
|
||||
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
|
||||
factory.call(this, require, this);
|
||||
}
|
||||
}
|
||||
}).call(this, function (require, exports) {
|
||||
|
||||
"use strict";
|
||||
|
||||
const { Cc, Ci, Cr, Cu, CC } = require("chrome");
|
||||
const Services = require("Services");
|
||||
const { Cc, Ci, Cr, CC } = require("chrome");
|
||||
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
||||
const { dumpn, dumpv } = DevToolsUtils;
|
||||
const StreamUtils = require("devtools/shared/transport/stream-utils");
|
||||
|
|
@ -43,7 +42,7 @@
|
|||
|
||||
const PACKET_HEADER_MAX = 200;
|
||||
|
||||
/**
|
||||
/**
|
||||
* An adapter that handles data transfers between the debugger client and
|
||||
* server. It can work with both nsIPipe and nsIServerSocket transports so
|
||||
* long as the properly created input and output streams are specified.
|
||||
|
|
@ -222,7 +221,9 @@
|
|||
/**
|
||||
* The currently outgoing packet (at the top of the queue).
|
||||
*/
|
||||
get _currentOutgoing() { return this._outgoing[0]; },
|
||||
get _currentOutgoing() {
|
||||
return this._outgoing[0];
|
||||
},
|
||||
|
||||
/**
|
||||
* Flush data to the outgoing stream. Waits until the output stream notifies
|
||||
|
|
@ -239,7 +240,7 @@
|
|||
}
|
||||
|
||||
if (this._outgoing.length > 0) {
|
||||
var threadManager = Cc["@mozilla.org/thread-manager;1"].getService();
|
||||
let threadManager = Cc["@mozilla.org/thread-manager;1"].getService();
|
||||
this._output.asyncWait(this, 0, 0, threadManager.currentThread);
|
||||
}
|
||||
},
|
||||
|
|
@ -278,9 +279,8 @@
|
|||
if (e.result != Cr.NS_BASE_STREAM_WOULD_BLOCK) {
|
||||
this.close(e.result);
|
||||
return;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
this._flushOutgoing();
|
||||
|
|
@ -349,11 +349,12 @@
|
|||
/**
|
||||
* Called when the stream is either readable or closed.
|
||||
*/
|
||||
onInputStreamReady:
|
||||
DevToolsUtils.makeInfallible(function (stream) {
|
||||
onInputStreamReady: DevToolsUtils.makeInfallible(function (stream) {
|
||||
try {
|
||||
while (stream.available() && this._incomingEnabled &&
|
||||
this._processIncoming(stream, stream.available())) {}
|
||||
this._processIncoming(stream, stream.available())) {
|
||||
// Loop until there is nothing more to process
|
||||
}
|
||||
this._waitForIncoming();
|
||||
} catch (e) {
|
||||
if (e.result != Cr.NS_BASE_STREAM_WOULD_BLOCK) {
|
||||
|
|
@ -387,7 +388,8 @@
|
|||
dumpv("Creating a new packet from incoming");
|
||||
|
||||
if (!this._readHeader(stream)) {
|
||||
return false; // Not enough data to read packet type
|
||||
// Not enough data to read packet type
|
||||
return false;
|
||||
}
|
||||
|
||||
// Attempt to create a new Packet by trying to parse each possible
|
||||
|
|
@ -513,7 +515,7 @@
|
|||
|
||||
exports.DebuggerTransport = DebuggerTransport;
|
||||
|
||||
/**
|
||||
/**
|
||||
* An adapter that handles data transfers between the debugger client and
|
||||
* server when they both run in the same process. It presents the same API as
|
||||
* DebuggerTransport, but instead of transmitting serialized messages across a
|
||||
|
|
@ -530,11 +532,8 @@
|
|||
this.other = other;
|
||||
this.hooks = null;
|
||||
|
||||
/*
|
||||
* A packet number, shared between this and this.other. This isn't used
|
||||
* by the protocol at all, but it makes the packet traces a lot easier to
|
||||
* follow.
|
||||
*/
|
||||
// A packet number, shared between this and this.other. This isn't used by the
|
||||
// protocol at all, but it makes the packet traces a lot easier to follow.
|
||||
this._serial = this.other ? this.other._serial : { count: 0 };
|
||||
this.close = this.close.bind(this);
|
||||
}
|
||||
|
|
@ -549,7 +548,7 @@
|
|||
|
||||
let serial = this._serial.count++;
|
||||
if (dumpn.wantLogging) {
|
||||
/* Check 'from' first, as 'echo' packets have both. */
|
||||
// Check 'from' first, as 'echo' packets have both.
|
||||
if (packet.from) {
|
||||
dumpn("Packet " + serial + " sent from " + uneval(packet.from));
|
||||
} else if (packet.to) {
|
||||
|
|
@ -588,7 +587,8 @@
|
|||
|
||||
dumpn("Sent bulk packet " + serial + " for actor " + actor);
|
||||
if (!this.other) {
|
||||
return;
|
||||
let error = new Error("startBulkSend: other side of transport missing");
|
||||
return promise.reject(error);
|
||||
}
|
||||
|
||||
let pipe = new Pipe(true, true, 0, 0, null);
|
||||
|
|
@ -688,7 +688,7 @@
|
|||
// an unfrozen object.
|
||||
if (object.hasOwnProperty(prop) && typeof object === "object" &&
|
||||
!Object.isFrozen(object)) {
|
||||
this._deepFreeze(o[prop]);
|
||||
this._deepFreeze(object[prop]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -696,7 +696,7 @@
|
|||
|
||||
exports.LocalDebuggerTransport = LocalDebuggerTransport;
|
||||
|
||||
/**
|
||||
/**
|
||||
* A transport for the debugging protocol that uses nsIMessageSenders to
|
||||
* exchange packets with servers running in child processes.
|
||||
*
|
||||
|
|
@ -717,7 +717,7 @@
|
|||
this._messageName = "debug:" + prefix + ":packet";
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* To avoid confusion, we use 'message' to mean something that
|
||||
* nsIMessageSender conveys, and 'packet' to mean a remote debugging
|
||||
* protocol packet.
|
||||
|
|
@ -754,18 +754,19 @@
|
|||
|
||||
exports.ChildDebuggerTransport = ChildDebuggerTransport;
|
||||
|
||||
// WorkerDebuggerTransport is defined differently depending on whether we are
|
||||
// on the main thread or a worker thread. In the former case, we are required
|
||||
// by the devtools loader, and isWorker will be false. Otherwise, we are
|
||||
// required by the worker loader, and isWorker will be true.
|
||||
//
|
||||
// Each worker debugger supports only a single connection to the main thread.
|
||||
// However, its theoretically possible for multiple servers to connect to the
|
||||
// same worker. Consequently, each transport has a connection id, to allow
|
||||
// messages from multiple connections to be multiplexed on a single channel.
|
||||
// WorkerDebuggerTransport is defined differently depending on whether we are
|
||||
// on the main thread or a worker thread. In the former case, we are required
|
||||
// by the devtools loader, and isWorker will be false. Otherwise, we are
|
||||
// required by the worker loader, and isWorker will be true.
|
||||
//
|
||||
// Each worker debugger supports only a single connection to the main thread.
|
||||
// However, its theoretically possible for multiple servers to connect to the
|
||||
// same worker. Consequently, each transport has a connection id, to allow
|
||||
// messages from multiple connections to be multiplexed on a single channel.
|
||||
|
||||
if (!this.isWorker) {
|
||||
(function () { // Main thread
|
||||
// Main thread
|
||||
(function () {
|
||||
/**
|
||||
* A transport that uses a WorkerDebugger to send packets from the main
|
||||
* thread to a worker thread.
|
||||
|
|
@ -817,8 +818,9 @@
|
|||
exports.WorkerDebuggerTransport = WorkerDebuggerTransport;
|
||||
}).call(this);
|
||||
} else {
|
||||
(function () { // Worker thread
|
||||
/*
|
||||
// Worker thread
|
||||
(function () {
|
||||
/**
|
||||
* A transport that uses a WorkerDebuggerGlobalScope to send packets from a
|
||||
* worker thread to the main thread.
|
||||
*/
|
||||
|
|
@ -869,5 +871,4 @@
|
|||
exports.WorkerDebuggerTransport = WorkerDebuggerTransport;
|
||||
}).call(this);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue