Bug 1325213 - Fix lots of eslint errors in devtools/shared/. r=jryans

MozReview-Commit-ID: 2XxhfV8ih0S

--HG--
extra : rebase_source : 48cda848a23c57d3301db5e563ad8f5f20064862
This commit is contained in:
Tim Nguyen 2016-12-30 15:01:42 +01:00
parent 5c9dc72fcc
commit d62604fd8b
40 changed files with 969 additions and 800 deletions

View File

@ -117,20 +117,9 @@ devtools/server/tests/browser/**
devtools/server/tests/mochitest/**
devtools/server/tests/unit/**
devtools/shared/apps/**
devtools/shared/client/**
devtools/shared/discovery/**
devtools/shared/gcli/**
!devtools/shared/gcli/templater.js
devtools/shared/heapsnapshot/**
devtools/shared/layout/**
devtools/shared/performance/**
!devtools/shared/platform/**
devtools/shared/qrcode/**
devtools/shared/security/**
devtools/shared/shims/**
devtools/shared/tests/**
!devtools/shared/tests/unit/test_csslexer.js
devtools/shared/touch/**
devtools/shared/transport/**
!devtools/shared/transport/transport.js
!devtools/shared/transport/websocket-transport.js

View File

@ -6,9 +6,8 @@
"use strict";
const {Cc, Ci, Cu, Cr} = require("chrome");
const {Cc, Ci, Cr} = require("chrome");
const EventEmitter = require("devtools/shared/event-emitter");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
const { DebuggerServer } = require("devtools/server/main");
const { DebuggerClient } = require("devtools/shared/client/main");
const Services = require("Services");
@ -70,8 +69,10 @@ const REMOTE_TIMEOUT = "devtools.debugger.remote-timeout";
* . Connection.Events.CONNECTING Trying to connect to host:port
* . Connection.Events.CONNECTED Connection is successful
* . Connection.Events.DISCONNECTING Trying to disconnect from server
* . Connection.Events.DISCONNECTED Disconnected (at client request, or because of a timeout or connection error)
* . Connection.Events.STATUS_CHANGED The connection status (connection.status) has changed
* . Connection.Events.DISCONNECTED Disconnected (at client request,
* or because of a timeout or connection error)
* . Connection.Events.STATUS_CHANGED The connection status (connection.status)
* has changed
* . Connection.Events.TIMEOUT Connection timeout
* . Connection.Events.HOST_CHANGED Host has changed
* . Connection.Events.PORT_CHANGED Port has changed
@ -168,8 +169,9 @@ Connection.prototype = {
},
set host(value) {
if (this._host && this._host == value)
if (this._host && this._host == value) {
return;
}
this._host = value;
this.emit(Connection.Events.HOST_CHANGED);
},
@ -179,8 +181,9 @@ Connection.prototype = {
},
set port(value) {
if (this._port && this._port == value)
if (this._port && this._port == value) {
return;
}
this._port = value;
this.emit(Connection.Events.PORT_CHANGED);
},
@ -334,8 +337,9 @@ Connection.prototype = {
},
_setStatus: function (value) {
if (this._status && this._status == value)
if (this._status && this._status == value) {
return;
}
this._status = value;
this.emit(value);
this.emit(Connection.Events.STATUS_CHANGED, value);
@ -357,7 +361,9 @@ Connection.prototype = {
this.log("disconnected (unexpected)");
break;
case Connection.Status.CONNECTING:
this.log("connection error. Possible causes: USB port not connected, port not forwarded (adb forward), wrong host or port, remote debugging not enabled on the device.");
this.log("connection error. Possible causes: USB port not connected, port not " +
"forwarded (adb forward), wrong host or port, remote debugging not " +
"enabled on the device.");
break;
default:
this.log("disconnected");

File diff suppressed because it is too large Load Diff

View File

@ -47,8 +47,8 @@ const REPLY_TIMEOUT = 5000;
const { XPCOMUtils } = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
XPCOMUtils.defineLazyGetter(this, "converter", () => {
let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
createInstance(Ci.nsIScriptableUnicodeConverter);
let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Ci.nsIScriptableUnicodeConverter);
conv.charset = "utf8";
return conv;
});
@ -77,7 +77,8 @@ function log(msg) {
function Transport(port) {
EventEmitter.decorate(this);
try {
this.socket = new UDPSocket(port, false, Services.scriptSecurityManager.getSystemPrincipal());
this.socket = new UDPSocket(port, false,
Services.scriptSecurityManager.getSystemPrincipal());
this.socket.joinMulticast(ADDRESS);
this.socket.asyncListen(this);
} catch (e) {
@ -146,7 +147,8 @@ function LocalDevice() {
Cc["@mozilla.org/settingsService;1"].getService(Ci.nsISettingsService);
Services.obs.addObserver(this, "mozsettings-changed", false);
}
this._get(); // Trigger |_get| to load name eagerly
// Trigger |_get| to load name eagerly
this._get();
}
LocalDevice.SETTING = "devtools.discovery.device";
@ -344,7 +346,8 @@ Discovery.prototype = {
_startListeningForScan: function () {
if (this._transports.scan) {
return; // Already listening
// Already listening
return;
}
log("LISTEN FOR SCAN");
this._transports.scan = new this.Transport(SCAN_PORT);
@ -353,7 +356,8 @@ Discovery.prototype = {
_stopListeningForScan: function () {
if (!this._transports.scan) {
return; // Not listening
// Not listening
return;
}
this._transports.scan.off("message", this._onRemoteScan);
this._transports.scan.destroy();
@ -362,7 +366,8 @@ Discovery.prototype = {
_startListeningForUpdate: function () {
if (this._transports.update) {
return; // Already listening
// Already listening
return;
}
log("LISTEN FOR UPDATE");
this._transports.update = new this.Transport(UPDATE_PORT);
@ -371,7 +376,8 @@ Discovery.prototype = {
_stopListeningForUpdate: function () {
if (!this._transports.update) {
return; // Not listening
// Not listening
return;
}
this._transports.update.off("message", this._onRemoteUpdate);
this._transports.update.destroy();

View File

@ -0,0 +1,6 @@
"use strict";
module.exports = {
// Extend from the shared list of defined globals for mochitests.
"extends": "../../../../.eslintrc.xpcshell.js"
};

View File

@ -8,7 +8,6 @@ var Cu = Components.utils;
const { require } =
Cu.import("resource://devtools/shared/Loader.jsm", {});
const Services = require("Services");
const promise = require("promise");
const defer = require("devtools/shared/defer");
const EventEmitter = require("devtools/shared/event-emitter");
const discovery = require("devtools/shared/discovery/discovery");

View File

@ -9,7 +9,7 @@
* and LegacyPerformanceRecording for helper methods to access data.
*/
const PerformanceRecordingCommon = exports.PerformanceRecordingCommon = {
exports.PerformanceRecordingCommon = {
// Private fields, only needed when a recording is started or stopped.
_console: false,
_imported: false,
@ -35,18 +35,32 @@ const PerformanceRecordingCommon = exports.PerformanceRecordingCommon = {
* Helper methods for returning the status of the recording.
* These methods should be consistent on both the front and actor.
*/
isRecording: function () { return this._recording; },
isCompleted: function () { return this._completed || this.isImported(); },
isFinalizing: function () { return !this.isRecording() && !this.isCompleted(); },
isConsole: function () { return this._console; },
isImported: function () { return this._imported; },
isRecording: function () {
return this._recording;
},
isCompleted: function () {
return this._completed || this.isImported();
},
isFinalizing: function () {
return !this.isRecording() && !this.isCompleted();
},
isConsole: function () {
return this._console;
},
isImported: function () {
return this._imported;
},
/**
* Helper methods for returning configuration for the recording.
* These methods should be consistent on both the front and actor.
*/
getConfiguration: function () { return this._configuration; },
getLabel: function () { return this._label; },
getConfiguration: function () {
return this._configuration;
},
getLabel: function () {
return this._label;
},
/**
* Gets duration of this recording, in milliseconds.
@ -59,25 +73,43 @@ const PerformanceRecordingCommon = exports.PerformanceRecordingCommon = {
// the duration from the profiler; if between recording and being finalized,
// use the last estimated duration.
if (this.isRecording()) {
return this._estimatedDuration = Date.now() - this._localStartTime;
} else {
return this._duration || this._estimatedDuration || 0;
this._estimatedDuration = Date.now() - this._localStartTime;
return this._estimatedDuration;
}
return this._duration || this._estimatedDuration || 0;
},
/**
* Helper methods for returning recording data.
* These methods should be consistent on both the front and actor.
*/
getMarkers: function () { return this._markers; },
getFrames: function () { return this._frames; },
getMemory: function () { return this._memory; },
getTicks: function () { return this._ticks; },
getAllocations: function () { return this._allocations; },
getProfile: function () { return this._profile; },
getHostSystemInfo: function () { return this._systemHost; },
getClientSystemInfo: function () { return this._systemClient; },
getStartingBufferStatus: function () { return this._startingBufferStatus; },
getMarkers: function () {
return this._markers;
},
getFrames: function () {
return this._frames;
},
getMemory: function () {
return this._memory;
},
getTicks: function () {
return this._ticks;
},
getAllocations: function () {
return this._allocations;
},
getProfile: function () {
return this._profile;
},
getHostSystemInfo: function () {
return this._systemHost;
},
getClientSystemInfo: function () {
return this._systemClient;
},
getStartingBufferStatus: function () {
return this._startingBufferStatus;
},
getAllData: function () {
let label = this.getLabel();
@ -92,6 +124,18 @@ const PerformanceRecordingCommon = exports.PerformanceRecordingCommon = {
let systemHost = this.getHostSystemInfo();
let systemClient = this.getClientSystemInfo();
return { label, duration, markers, frames, memory, ticks, allocations, profile, configuration, systemHost, systemClient };
return {
label,
duration,
markers,
frames,
memory,
ticks,
allocations,
profile,
configuration,
systemHost,
systemClient
};
},
};

View File

@ -3,7 +3,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { Cc, Ci, Cu, Cr } = require("chrome");
loader.lazyRequireGetter(this, "extend",
"sdk/util/object", true);
@ -16,7 +15,8 @@ function mapRecordingOptions(type, options) {
if (type === "profiler") {
return {
entries: options.bufferSize,
interval: options.sampleFrequency ? (1000 / (options.sampleFrequency * 1000)) : void 0
interval: options.sampleFrequency ? (1000 / (options.sampleFrequency * 1000))
: void 0
};
}
@ -568,7 +568,8 @@ UniqueStacks.prototype.getOrAddFrameIndex = function (frame) {
let implementationIndex = this.getOrAddStringIndex(frame.implementation);
// Super dumb.
let hash = `${locationIndex} ${implementationIndex || ""} ${frame.line || ""} ${frame.category || ""}`;
let hash = `${locationIndex} ${implementationIndex || ""} ` +
`${frame.line || ""} ${frame.category || ""}`;
let index = frameHash[hash];
if (index !== undefined) {

View File

@ -0,0 +1,6 @@
"use strict";
module.exports = {
// Extend from the shared list of defined globals for mochitests.
"extends": "../../../.eslintrc.xpcshell.js"
};

View File

@ -1,7 +1,10 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* exported require */
"use strict";
var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
var { utils: Cu } = Components;
var { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if allocations data received from the performance actor is properly
* converted to something that follows the same structure as the samples data
@ -65,9 +67,15 @@ var EXPECTED_OUTPUT = {
},
"data": [
null,
[ null, 1 ], // x (A:1:2)
[ 1, 2 ], // x (A:1:2) > y (B:3:4)
[ 2, 3 ] // x (A:1:2) > y (B:3:4) > C:5:6
// x (A:1:2)
[ null, 1 ],
// x (A:1:2) > y (B:3:4)
[ 1, 2 ],
// x (A:1:2) > y (B:3:4) > C:5:6
[ 2, 3 ]
]
},
frameTable: {

View File

@ -4,7 +4,6 @@
"use strict";
const { Cu } = require("chrome");
const promise = require("promise");
const defer = require("devtools/shared/defer");

View File

@ -0,0 +1,6 @@
"use strict";
module.exports = {
// Extend from the shared list of defined globals for mochitests.
"extends": "../../../../.eslintrc.xpcshell.js"
};

View File

@ -8,7 +8,6 @@
var { Ci, Cc } = require("chrome");
var Services = require("Services");
var promise = require("promise");
var defer = require("devtools/shared/defer");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
var { dumpn, dumpv } = DevToolsUtils;
@ -408,7 +407,8 @@ OOBCert.Client.prototype = {
}),
_createRandom() {
const length = 16; // 16 bytes / 128 bits
// 16 bytes / 128 bits
const length = 16;
let rng = Cc["@mozilla.org/security/random-generator;1"]
.createInstance(Ci.nsIRandomGenerator);
let bytes = rng.generateRandomBytes(length);
@ -545,9 +545,11 @@ OOBCert.Server.prototype = {
switch (authResult) {
case AuthenticationResult.ALLOW_PERSIST:
case AuthenticationResult.ALLOW:
break; // Further processing
// Further processing
break;
default:
return authResult; // Abort for any negative results
// Abort for any negative results
return authResult;
}
// Examine additional data for authentication

View File

@ -7,7 +7,6 @@
"use strict";
var { Ci, Cc } = require("chrome");
var promise = require("promise");
var defer = require("devtools/shared/defer");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
DevToolsUtils.defineLazyGetter(this, "localCertService", () => {

View File

@ -6,7 +6,7 @@
"use strict";
var { Ci, Cc, CC, Cr, Cu } = require("chrome");
var { Ci, Cc, CC, Cr } = require("chrome");
// Ensure PSM is initialized to support TLS sockets
Cc["@mozilla.org/psm;1"].getService(Ci.nsISupports);
@ -143,7 +143,8 @@ var _getTransport = Task.async(function* (settings) {
let attempt = yield _attemptTransport(settings);
if (attempt.transport) {
return attempt.transport; // Success
// Success
return attempt.transport;
}
// If the server cert failed validation, store a temporary override and make
@ -156,7 +157,8 @@ var _getTransport = Task.async(function* (settings) {
attempt = yield _attemptTransport(settings);
if (attempt.transport) {
return attempt.transport; // Success
// Success
return attempt.transport;
}
throw new Error("Connection failed even after cert override");
@ -356,7 +358,7 @@ function _storeCertOverride(s, host, port) {
let overrideBits = Ci.nsICertOverrideService.ERROR_UNTRUSTED |
Ci.nsICertOverrideService.ERROR_MISMATCH;
certOverrideService.rememberValidityOverride(host, port, cert, overrideBits,
true /* temporary */);
true /* temporary */); // eslint-disable-line
}
/**

View File

@ -0,0 +1,6 @@
"use strict";
module.exports = {
// Extend from the shared list of defined globals for mochitests.
"extends": "../../../../../testing/mochitest/chrome.eslintrc.js"
};

View File

@ -9,7 +9,9 @@
</head>
<body>
<script>
window.onload = function() {
"use strict";
window.onload = function () {
const {require} = Components.utils.import("resource://devtools/shared/Loader.jsm", {});
const Services = require("Services");
const {DebuggerClient} = require("devtools/shared/client/main");
@ -47,7 +49,7 @@ window.onload = function() {
let client = new DebuggerClient(transport);
let onUnexpectedClose = () => {
do_throw("Closed unexpectedly");
ok(false, "Closed unexpectedly");
};
client.addListener("closed", onUnexpectedClose);
@ -70,7 +72,7 @@ window.onload = function() {
DebuggerServer.destroy();
});
}
};
</script>
</body>
</html>

View File

@ -2,20 +2,14 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
var Cr = Components.results;
var CC = Components.Constructor;
/* exported defer, DebuggerClient, initTestDebuggerServer */
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
const { require } =
Cu.import("resource://devtools/shared/Loader.jsm", {});
const promise = require("promise");
const defer = require("devtools/shared/defer");
const { Task } = require("devtools/shared/task");
const Services = require("Services");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
const xpcInspector = require("xpcInspector");
const { DebuggerServer } = require("devtools/server/main");
const { DebuggerClient } = require("devtools/shared/client/main");
@ -31,43 +25,43 @@ Services.prefs.setBoolPref("devtools.debugger.remote-enabled", true);
// Fast timeout for TLS tests
Services.prefs.setIntPref("devtools.remote.tls-handshake-timeout", 1000);
// Convert an nsIScriptError 'aFlags' value into an appropriate string.
function scriptErrorFlagsToKind(aFlags) {
var kind;
if (aFlags & Ci.nsIScriptError.warningFlag)
// Convert an nsIScriptError 'flags' value into an appropriate string.
function scriptErrorFlagsToKind(flags) {
let kind;
if (flags & Ci.nsIScriptError.warningFlag) {
kind = "warning";
if (aFlags & Ci.nsIScriptError.exceptionFlag)
}
if (flags & Ci.nsIScriptError.exceptionFlag) {
kind = "exception";
else
} else {
kind = "error";
}
if (aFlags & Ci.nsIScriptError.strictFlag)
if (flags & Ci.nsIScriptError.strictFlag) {
kind = "strict " + kind;
}
return kind;
}
// Register a console listener, so console messages don't just disappear
// into the ether.
var errorCount = 0;
var listener = {
observe: function (aMessage) {
errorCount++;
observe: function (message) {
let string;
try {
// If we've been given an nsIScriptError, then we can print out
// something nicely formatted, for tools like Emacs to pick up.
var scriptError = aMessage.QueryInterface(Ci.nsIScriptError);
dump(aMessage.sourceName + ":" + aMessage.lineNumber + ": " +
scriptErrorFlagsToKind(aMessage.flags) + ": " +
aMessage.errorMessage + "\n");
var string = aMessage.errorMessage;
} catch (x) {
message.QueryInterface(Ci.nsIScriptError);
dump(message.sourceName + ":" + message.lineNumber + ": " +
scriptErrorFlagsToKind(message.flags) + ": " +
message.errorMessage + "\n");
string = message.errorMessage;
} catch (ex) {
// Be a little paranoid with message, as the whole goal here is to lose
// no information.
try {
var string = "" + aMessage.message;
} catch (x) {
var string = "<error converting error message to string>";
string = "" + message.message;
} catch (e) {
string = "<error converting error message to string>";
}
}
@ -77,7 +71,7 @@ var listener = {
}
// Print in most cases, but ignore the "strict" messages
if (!(aMessage.flags & Ci.nsIScriptError.strictFlag)) {
if (!(message.flags & Ci.nsIScriptError.strictFlag)) {
do_print("head_dbg.js got console message: " + string + "\n");
}
}

View File

@ -38,7 +38,8 @@ add_task(function* () {
serverAuth.allowConnection = () => {
return DebuggerServer.AuthenticationResult.ALLOW;
};
serverAuth.receiveOOB = () => oobData.promise; // Skip prompt for tests
// Skip prompt for tests
serverAuth.receiveOOB = () => oobData.promise;
let listener = DebuggerServer.createListener();
ok(listener, "Socket listener created");
@ -98,7 +99,8 @@ add_task(function* () {
serverAuth.allowConnection = () => {
return DebuggerServer.AuthenticationResult.ALLOW;
};
serverAuth.receiveOOB = () => oobData.promise; // Skip prompt for tests
// Skip prompt for tests
serverAuth.receiveOOB = () => oobData.promise;
let listener = DebuggerServer.createListener();
ok(listener, "Socket listener created");
@ -161,7 +163,8 @@ add_task(function* () {
serverAuth.allowConnection = () => {
return DebuggerServer.AuthenticationResult.ALLOW;
};
serverAuth.receiveOOB = () => oobData.promise; // Skip prompt for tests
// Skip prompt for tests
serverAuth.receiveOOB = () => oobData.promise;
let clientAuth = new AuthenticatorType.Client();
clientAuth.sendOOB = ({ oob }) => {
@ -215,7 +218,8 @@ add_task(function* () {
serverAuth.allowConnection = () => {
return DebuggerServer.AuthenticationResult.ALLOW;
};
serverAuth.receiveOOB = () => oobData.promise; // Skip prompt for tests
// Skip prompt for tests
serverAuth.receiveOOB = () => oobData.promise;
let clientAuth = new AuthenticatorType.Client();
clientAuth.sendOOB = ({ oob }) => {

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { ActorPool, appendExtraActors, createExtraActors } =
require("devtools/server/actors/common");
const { RootActor } = require("devtools/server/actors/root");
@ -9,8 +11,8 @@ const { DebuggerServer } = require("devtools/server/main");
const promise = require("promise");
var gTestGlobals = [];
DebuggerServer.addTestGlobal = function (aGlobal) {
gTestGlobals.push(aGlobal);
DebuggerServer.addTestGlobal = function (global) {
gTestGlobals.push(global);
};
// A mock tab list, for use by tests. This simply presents each global in
@ -20,18 +22,18 @@ DebuggerServer.addTestGlobal = function (aGlobal) {
// As implemented now, we consult gTestGlobals when we're constructed, not
// when we're iterated over, so tests have to add their globals before the
// root actor is created.
function TestTabList(aConnection) {
this.conn = aConnection;
function TestTabList(connection) {
this.conn = connection;
// An array of actors for each global added with
// DebuggerServer.addTestGlobal.
this._tabActors = [];
// A pool mapping those actors' names to the actors.
this._tabActorPool = new ActorPool(aConnection);
this._tabActorPool = new ActorPool(connection);
for (let global of gTestGlobals) {
let actor = new TestTabActor(aConnection, global);
let actor = new TestTabActor(connection, global);
actor.selected = false;
this._tabActors.push(actor);
this._tabActorPool.addActor(actor);
@ -40,7 +42,7 @@ function TestTabList(aConnection) {
this._tabActors[0].selected = true;
}
aConnection.addActorPool(this._tabActorPool);
connection.addActorPool(this._tabActorPool);
}
TestTabList.prototype = {
@ -50,18 +52,18 @@ TestTabList.prototype = {
}
};
function createRootActor(aConnection) {
let root = new RootActor(aConnection, {
tabList: new TestTabList(aConnection),
function createRootActor(connection) {
let root = new RootActor(connection, {
tabList: new TestTabList(connection),
globalActorFactories: DebuggerServer.globalActorFactories
});
root.applicationType = "xpcshell-tests";
return root;
}
function TestTabActor(aConnection, aGlobal) {
this.conn = aConnection;
this._global = aGlobal;
function TestTabActor(connection, global) {
this.conn = connection;
this._global = global;
this._threadActor = new ThreadActor(this, this._global);
this.conn.addActor(this._threadActor);
this._attached = false;
@ -96,7 +98,7 @@ TestTabActor.prototype = {
return response;
},
onAttach: function (aRequest) {
onAttach: function (request) {
this._attached = true;
let response = { type: "tabAttached", threadActor: this._threadActor.actorID };
@ -105,9 +107,9 @@ TestTabActor.prototype = {
return response;
},
onDetach: function (aRequest) {
onDetach: function (request) {
if (!this._attached) {
return { "error":"wrongState" };
return { "error": "wrongState" };
}
return { type: "detached" };
},

View File

@ -9,10 +9,13 @@
* specific path.
*/
(function (factory) { // Module boilerplate
if (this.module && module.id.indexOf("event-emitter") >= 0) { // require
(function (factory) {
// Module boilerplate
if (this.module && module.id.indexOf("event-emitter") >= 0) {
// require
factory.call(this, require, exports, module);
} else { // Cu.import
} else {
// Cu.import
const Cu = Components.utils;
const { require } =
Cu.import("resource://devtools/shared/Loader.jsm", {});

View File

@ -30,7 +30,7 @@ add_task(function* () {
});
add_task(function* () {
var object = {
let object = {
x: 1,
y: "foo",
z: true

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
exports.exerciseLazyRequire = (name, path) => {
const o = {};
loader.lazyRequireGetter(o, name, path);

View File

@ -1,13 +1,12 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
var Cr = Components.results;
/* exported DevToolsUtils, DevToolsLoader */
const {require, DevToolsLoader, devtools} = Cu.import("resource://devtools/shared/Loader.jsm", {});
"use strict";
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
const { require, DevToolsLoader } = Cu.import("resource://devtools/shared/Loader.jsm", {});
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
const flags = require("devtools/shared/flags");
@ -23,25 +22,22 @@ do_register_cleanup(() => {
// failures, set this to true.
var ALLOW_CONSOLE_ERRORS = false;
var errorCount = 0;
var listener = {
observe: function (aMessage) {
errorCount++;
observe: function (message) {
let string;
try {
// If we've been given an nsIScriptError, then we can print out
// something nicely formatted, for tools like Emacs to pick up.
var scriptError = aMessage.QueryInterface(Ci.nsIScriptError);
dump(aMessage.sourceName + ":" + aMessage.lineNumber + ": " +
scriptErrorFlagsToKind(aMessage.flags) + ": " +
aMessage.errorMessage + "\n");
var string = aMessage.errorMessage;
} catch (x) {
message.QueryInterface(Ci.nsIScriptError);
dump(message.sourceName + ":" + message.lineNumber + ": " +
scriptErrorFlagsToKind(message.flags) + ": " +
message.errorMessage + "\n");
string = message.errorMessage;
} catch (ex) {
// Be a little paranoid with message, as the whole goal here is to lose
// no information.
try {
var string = "" + aMessage.message;
} catch (x) {
var string = "<error converting error message to string>";
string = "" + message.message;
} catch (e) {
string = "<error converting error message to string>";
}
}

View File

@ -2,6 +2,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test DevToolsUtils.assert
ALLOW_CONSOLE_ERRORS = true;
@ -32,5 +34,6 @@ function run_test() {
}
ok(assertionFailed,
"The assertion should have failed, which should throw an error when assertions are enabled.");
"The assertion should have failed, which should throw an error when assertions " +
"are enabled.");
}

View File

@ -2,6 +2,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test async-utils.js
const {Task} = require("devtools/shared/task");
@ -60,12 +62,13 @@ function test_async_return(async) {
function test_async_throw(async) {
let obj = {
method: async(function* () {
throw "boom";
throw new Error("boom");
})
};
return obj.method().then(null, error => {
do_check_eq(error, "boom");
do_check_true(error instanceof Error);
do_check_eq(error.message, "boom");
});
}
@ -116,7 +119,6 @@ function test_async_once() {
function test_async_invoke() {
return Task.spawn(function* () {
function func(a, b, expectedThis, callback) {
"use strict";
do_check_eq(a, "foo");
do_check_eq(b, "bar");
do_check_eq(this, expectedThis);
@ -127,13 +129,11 @@ function test_async_invoke() {
let callResult = yield promiseCall(func, "foo", "bar", undefined);
do_check_eq(callResult, "foobar");
// Test invoke.
let obj = { method: func };
let invokeResult = yield promiseInvoke(obj, obj.method, "foo", "bar", obj);
do_check_eq(invokeResult, "foobar");
// Test passing multiple values to the callback.
function multipleResults(callback) {
callback("foo", "bar");
@ -144,14 +144,14 @@ function test_async_invoke() {
do_check_eq(results[0], "foo");
do_check_eq(results[1], "bar");
// Test throwing from the function.
function thrower() {
throw "boom";
throw new Error("boom");
}
yield promiseCall(thrower).then(null, error => {
do_check_eq(error, "boom");
do_check_true(error instanceof Error);
do_check_eq(error.message, "boom");
});
});
}

View File

@ -11,19 +11,19 @@ var seenMessages = 0;
var seenTypes = 0;
var callback = {
onConsoleAPICall: function (aMessage) {
if (aMessage.consoleID && aMessage.consoleID == "addon/foo") {
do_check_eq(aMessage.level, "warn");
do_check_eq(aMessage.arguments[0], "Warning from foo");
onConsoleAPICall: function (message) {
if (message.consoleID && message.consoleID == "addon/foo") {
do_check_eq(message.level, "warn");
do_check_eq(message.arguments[0], "Warning from foo");
seenTypes |= 1;
} else if (aMessage.originAttributes &&
aMessage.originAttributes.addonId == "bar") {
do_check_eq(aMessage.level, "error");
do_check_eq(aMessage.arguments[0], "Error from bar");
} else if (message.originAttributes &&
message.originAttributes.addonId == "bar") {
do_check_eq(message.level, "error");
do_check_eq(message.arguments[0], "Error from bar");
seenTypes |= 2;
} else {
do_check_eq(aMessage.level, "log");
do_check_eq(aMessage.arguments[0], "Hello from default console");
do_check_eq(message.level, "log");
do_check_eq(message.arguments[0], "Hello from default console");
seenTypes |= 4;
}
seenMessages++;

View File

@ -1,13 +1,13 @@
/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test DevToolsUtils.defineLazyPrototypeGetter
function Class() {}
DevToolsUtils.defineLazyPrototypeGetter(Class.prototype, "foo", () => []);
function run_test() {
test_prototype_attributes();
test_instance_attributes();

View File

@ -11,7 +11,6 @@
*/
var { executeSoon } = require("devtools/shared/DevToolsUtils");
var promise = require("promise");
var defer = require("devtools/shared/defer");
var Services = require("Services");

View File

@ -2,6 +2,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test ThreadSafeDevToolsUtils.flatten
function run_test() {

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Ensure that each instance of the Dev Tools loader contains its own loader
* instance, and also returns unique objects. This ensures there is no sharing

View File

@ -2,6 +2,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test ThreadSafeDevToolsUtils.isSet
function run_test() {

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test require
// Ensure that DevtoolsLoader.require doesn't spawn multiple

View File

@ -1,6 +1,9 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { devtools } = Cu.import("resource://devtools/shared/Loader.jsm", {});
// Test devtools.lazyRequireGetter
function run_test() {
@ -18,7 +21,8 @@ function run_test() {
const o2 = {};
let loader = new DevToolsLoader();
// We have to init the loader by loading any module before lazyRequireGetter is available
// We have to init the loader by loading any module before
// lazyRequireGetter is available
loader.require("devtools/shared/DevToolsUtils");
loader.lazyRequireGetter(o2, name, path);

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test require using "raw!".
function run_test() {

View File

@ -2,6 +2,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test DevToolsUtils.safeErrorString
function run_test() {

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test stack.js.
function run_test() {

View File

@ -1,7 +1,7 @@
/* 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/. */
/* globals addMessageListener, sendAsyncMessage */
/* globals addMessageListener, sendAsyncMessage, docShell */
"use strict";
const { utils: Cu } = Components;

View File

@ -1,6 +1,9 @@
/* 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/. */
/* global XPCNativeWrapper */
"use strict";
const { Ci, Cu } = require("chrome");
@ -272,12 +275,14 @@ SimulatorCore.prototype = {
}
}
let unwrapped = XPCNativeWrapper.unwrap(target);
/* eslint-disable no-inline-comments */
unwrapped.sendTouchEvent(name, clone([0]), // event type, id
clone([evt.clientX]), // x
clone([evt.clientY]), // y
clone([1]), clone([1]), // rx, ry
clone([0]), clone([0]), // rotation, force
1); // count
/* eslint-enable no-inline-comments */
return;
}
let document = target.ownerDocument;
@ -339,10 +344,10 @@ SimulatorCore.prototype = {
let utils = content.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
let allowZoom = {},
minZoom = {},
maxZoom = {},
autoSize = {};
let allowZoom = {};
let minZoom = {};
let maxZoom = {};
let autoSize = {};
utils.getViewportInfo(content.innerWidth, content.innerHeight, {},
allowZoom, minZoom, maxZoom, {}, {}, autoSize);
@ -352,14 +357,15 @@ SimulatorCore.prototype = {
// delay. But Firefox didn't support this property now, we can't get
// this value from utils.getVisitedDependentComputedStyle() to check
// if we should suppress 300ms delay.
/* eslint-disable no-inline-comments */
if (!allowZoom.value || // user-scalable = no
minZoom.value === maxZoom.value || // minimum-scale = maximum-scale
autoSize.value // width = device-width
) {
/* eslint-enable no-inline-comments */
return 0;
} else {
return 300;
}
return 300;
}
};