Bug 1227978 - Remove unecessary usages of promiseInvoke, rdpInvoke r=jlongster

This commit is contained in:
Alexandre Poirot 2016-01-08 06:59:34 -08:00
parent 9ece33dcf7
commit 96c6e9a4dc
10 changed files with 37 additions and 107 deletions

View File

@ -5,7 +5,7 @@
const constants = require('../constants');
const promise = require('promise');
const { asPaused, rdpInvoke } = require('../utils');
const { asPaused } = require('../utils');
const { PROMISE } = require('devtools/client/shared/redux/middleware/promise');
const {
getSource, getBreakpoint, getBreakpoints, makeLocationId
@ -55,7 +55,7 @@ function addBreakpoint(location, condition) {
const sourceClient = gThreadClient.source(
getSource(getState(), bp.location.actor)
);
const [response, bpClient] = yield rdpInvoke(sourceClient, sourceClient.setBreakpoint, {
const [response, bpClient] = yield sourceClient.setBreakpoint({
line: bp.location.line,
column: bp.location.column,
condition: bp.condition
@ -105,7 +105,7 @@ function _removeOrDisableBreakpoint(location, isDisabled) {
type: constants.REMOVE_BREAKPOINT,
breakpoint: bp,
disabled: isDisabled,
[PROMISE]: rdpInvoke(bpClient, bpClient.remove)
[PROMISE]: bpClient.remove()
});
}
}

View File

@ -4,7 +4,7 @@
"use strict";
const constants = require("../constants");
const { rdpInvoke, asPaused } = require("../utils");
const { asPaused } = require("../utils");
const { reportException } = require("devtools/shared/DevToolsUtils");
const FETCH_EVENT_LISTENERS_DELAY = 200; // ms
@ -50,7 +50,7 @@ function fetchEventListeners() {
}
const _getListeners = Task.async(function*() {
const response = yield rdpInvoke(gThreadClient, gThreadClient.eventListeners);
const response = yield gThreadClient.eventListeners();
// Make sure all the listeners are sorted by the event type, since
// they"re not guaranteed to be clustered together.
@ -86,7 +86,7 @@ const _getDefinitionSite = Task.async(function*(aFunction) {
let response;
try {
response = yield rdpInvoke(grip, grip.getDefinitionSite);
response = yield grip.getDefinitionSite();
}
catch(e) {
// Don't make this error fatal, because it would break the entire events pane.

View File

@ -5,7 +5,6 @@
const constants = require('../constants');
const promise = require('promise');
const { rdpInvoke } = require('../utils');
const { dumpn } = require("devtools/shared/DevToolsUtils");
const { PROMISE, HISTOGRAM_ID } = require('devtools/client/shared/redux/middleware/promise');
const { getSource, getSourceText } = require('../queries');
@ -62,7 +61,7 @@ function loadSources() {
return {
type: constants.LOAD_SOURCES,
[PROMISE]: Task.spawn(function*() {
const response = yield rdpInvoke(gThreadClient, gThreadClient.getSources);
const response = yield gThreadClient.getSources();
// Top-level breakpoints may pause the entire loading process
// because scripts are executed as they are loaded, so the
@ -104,8 +103,7 @@ function blackbox(source, shouldBlackBox) {
type: constants.BLACKBOX,
source: source,
[PROMISE]: Task.spawn(function*() {
yield rdpInvoke(client,
shouldBlackBox ? client.blackBox : client.unblackBox);
yield shouldBlackBox ? client.blackBox() : client.unblackBox();
return {
isBlackBoxed: shouldBlackBox
}
@ -143,13 +141,10 @@ function togglePrettyPrint(source) {
}
if (wantPretty) {
response = yield rdpInvoke(sourceClient,
sourceClient.prettyPrint,
Prefs.editorTabSize);
response = yield sourceClient.prettyPrint(Prefs.editorTabSize);
}
else {
response = yield rdpInvoke(sourceClient,
sourceClient.disablePrettyPrint);
response = yield sourceClient.disablePrettyPrint();
}
// Remove the cached source AST from the Parser, to avoid getting
@ -186,7 +181,7 @@ function loadSourceText(source) {
let histogram = Services.telemetry.getHistogramById(histogramId);
let startTime = Date.now();
const response = yield rdpInvoke(sourceClient, sourceClient.source);
const response = yield sourceClient.source();
histogram.add(Date.now() - startTime);

View File

@ -3,30 +3,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { promiseInvoke } = require("devtools/shared/async-utils");
const { reportException } = require("devtools/shared/DevToolsUtils");
// RDP utils
function rdpInvoke(client, method, ...args) {
return (promiseInvoke(client, method, ...args)
.then((packet) => {
if (packet.error) {
let { error, message } = packet;
const err = new Error(error + ": " + message);
err.rdpError = error;
err.rdpMessage = message;
throw err;
}
return packet;
}));
}
function asPaused(client, func) {
if (client.state != "paused") {
return Task.spawn(function*() {
yield rdpInvoke(client, client.interrupt);
yield client.interrupt();
let result;
try {
@ -35,11 +17,11 @@ function asPaused(client, func) {
catch(e) {
// Try to put the debugger back in a working state by resuming
// it
yield rdpInvoke(client, client.resume);
yield client.resume();
throw e;
}
yield rdpInvoke(client, client.resume);
yield client.resume();
return result;
});
} else {
@ -93,7 +75,6 @@ function deleteIn(destObj, path) {
}
module.exports = {
rdpInvoke,
asPaused,
handleError,
onReducerEvents,

View File

@ -54,8 +54,8 @@ function test() {
yield actions.togglePrettyPrint(source);
ok(false, "The promise for a prettified source should be rejected!");
} catch(error) {
ok(error.rdpError, "Error came from a RDP request");
ok(error.rdpError.includes("prettyPrintError"),
ok(error.error, "Error came from a RDP request");
ok(error.error.includes("prettyPrintError"),
"The promise was correctly rejected with a meaningful message.");
}

View File

@ -27,7 +27,7 @@ function test(){
yield doInterrupt(gPanel);
let source = gThreadClient.source(getSourceForm(gSources, SECOND_SOURCE_VALUE));
yield rdpInvoke(source, source.setBreakpoint, {
yield source.setBreakpoint({
line: 6
});
yield doResume(gPanel);

View File

@ -16,7 +16,6 @@ var { DebuggerServer } = require("devtools/server/main");
var { DebuggerClient, ObjectClient } = require("devtools/shared/client/main");
var { AddonManager } = Cu.import("resource://gre/modules/AddonManager.jsm", {});
var EventEmitter = require("devtools/shared/event-emitter");
const { promiseInvoke } = require("devtools/shared/async-utils");
var { Toolbox } = require("devtools/client/framework/toolbox")
// Override promise with deprecated-sync-thenables
@ -887,26 +886,14 @@ function attachAddonActorForUrl(aClient, aUrl) {
return deferred.promise;
}
function rdpInvoke(aClient, aMethod, ...args) {
return promiseInvoke(aClient, aMethod, ...args)
.then((packet) => {
let { error, message } = packet;
if (error) {
throw new Error(error + ": " + message);
}
return packet;
});
}
function doResume(aPanel) {
const threadClient = aPanel.panelWin.gThreadClient;
return rdpInvoke(threadClient, threadClient.resume);
return threadClient.resume();
}
function doInterrupt(aPanel) {
const threadClient = aPanel.panelWin.gThreadClient;
return rdpInvoke(threadClient, threadClient.interrupt);
return threadClient.interrupt();
}
function pushPrefs(...aPrefs) {
@ -1036,11 +1023,7 @@ function close(client) {
function listTabs(client) {
info("Listing tabs.");
return new Promise(function (resolve) {
client.listTabs(function (response) {
resolve(response);
});
});
return client.listTabs();
}
function findTab(tabs, url) {
@ -1121,7 +1104,7 @@ function waitForWorkerClose(workerClient) {
function resume(threadClient) {
info("Resuming thread.");
return rdpInvoke(threadClient, threadClient.resume);
return threadClient.resume();
}
function findSource(sources, url) {
@ -1161,12 +1144,12 @@ function waitForPause(threadClient) {
function setBreakpoint(sourceClient, location) {
info("Setting breakpoint.\n");
return rdpInvoke(sourceClient, sourceClient.setBreakpoint, location);
return sourceClient.setBreakpoint(location);
}
function source(sourceClient) {
info("Getting source.\n");
return rdpInvoke(sourceClient, sourceClient.source);
return sourceClient.source();
}
// Return a promise with a reference to jsterm, opening the split

View File

@ -10,7 +10,6 @@ var promise = require("promise");
var {getInplaceEditorForSpan: inplaceEditor} = require("devtools/client/shared/inplace-editor");
var clipboard = require("sdk/clipboard");
var {setTimeout, clearTimeout} = require("sdk/timers");
var {promiseInvoke} = require("devtools/shared/async-utils");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
// All test are asynchronous
@ -763,10 +762,7 @@ function contextMenuClick(element) {
function registerTabActor(client, options) {
let moduleUrl = options.moduleUrl;
// Since client.listTabs doesn't use promises we need to
// 'promisify' it using 'promiseInvoke' helper method.
// This helps us to chain all promises and catch errors.
return promiseInvoke(client, client.listTabs).then(response => {
return client.listTabs().then(response => {
let config = {
prefix: options.prefix,
constructor: options.actorClass,

View File

@ -32,7 +32,7 @@ function* newConnectedDebuggerClient(opts) {
yield promiseInvoke(client, client.connect);
var root = yield promiseInvoke(client, client.listTabs);
var root = yield client.listTabs();
return {
client: client,

View File

@ -12,7 +12,6 @@ const { require, loader } = Cu.import("resource://devtools/shared/Loader.jsm", {
const { worker } = Cu.import("resource://devtools/shared/worker/loader.js", {})
const promise = require("promise");
const { Task } = Cu.import("resource://gre/modules/Task.jsm", {});
const { promiseInvoke } = require("devtools/shared/async-utils");
const Services = require("Services");
// Always log packets when running tests. runxpcshelltests.py will throw
@ -149,7 +148,7 @@ function close(client) {
function listTabs(client) {
dump("Listing tabs.\n");
return rdpRequest(client, client.listTabs);
return client.listTabs();
}
function findTab(tabs, title) {
@ -164,7 +163,7 @@ function findTab(tabs, title) {
function attachTab(client, tab) {
dump("Attaching to tab with title '" + tab.title + "'.\n");
return rdpRequest(client, client.attachTab, tab.actor);
return client.attachTab(tab.actor);
}
function waitForNewSource(threadClient, url) {
@ -176,17 +175,17 @@ function waitForNewSource(threadClient, url) {
function attachThread(tabClient, options = {}) {
dump("Attaching to thread.\n");
return rdpRequest(tabClient, tabClient.attachThread, options);
return tabClient.attachThread(options);
}
function resume(threadClient) {
dump("Resuming thread.\n");
return rdpRequest(threadClient, threadClient.resume);
return threadClient.resume();
}
function getSources(threadClient) {
dump("Getting sources.\n");
return rdpRequest(threadClient, threadClient.getSources);
return threadClient.getSources();
}
function findSource(sources, url) {
@ -206,7 +205,7 @@ function waitForPause(threadClient) {
function setBreakpoint(sourceClient, location) {
dump("Setting breakpoint.\n");
return rdpRequest(sourceClient, sourceClient.setBreakpoint, location);
return sourceClient.setBreakpoint(location);
}
function dumpn(msg) {
@ -686,30 +685,6 @@ function executeOnNextTickAndWaitForPause(action, client) {
return paused;
}
/**
* Create a promise that is resolved with the server's response to the client's
* Remote Debugger Protocol request. If a response with the `error` property is
* received, the promise is rejected. Any extra arguments passed in are
* forwarded to the method invocation.
*
* See `setBreakpoint` below, for example usage.
*
* @param DebuggerClient/ThreadClient/SourceClient/etc client
* @param Function method
* @param any args
* @returns Promise
*/
function rdpRequest(client, method, ...args) {
return promiseInvoke(client, method, ...args)
.then(response => {
const { error, message } = response;
if (error) {
throw new Error(error + ": " + message);
}
return response;
});
}
/**
* Interrupt JS execution for the specified thread.
*
@ -718,7 +693,7 @@ function rdpRequest(client, method, ...args) {
*/
function interrupt(threadClient) {
dumpn("Interrupting.");
return rdpRequest(threadClient, threadClient.interrupt);
return threadClient.interrupt();
}
/**
@ -745,7 +720,7 @@ function resumeAndWaitForPause(client, threadClient) {
function stepIn(client, threadClient) {
dumpn("Stepping in.");
const paused = waitForPause(client);
return rdpRequest(threadClient, threadClient.stepIn)
return threadClient.stepIn()
.then(() => paused);
}
@ -760,7 +735,7 @@ function stepIn(client, threadClient) {
*/
function getFrames(threadClient, first, count) {
dumpn("Getting frames.");
return rdpRequest(threadClient, threadClient.getFrames, first, count);
return threadClient.getFrames(first, count);
}
/**
@ -771,7 +746,7 @@ function getFrames(threadClient, first, count) {
*/
function blackBox(sourceClient) {
dumpn("Black boxing source: " + sourceClient.actor);
return rdpRequest(sourceClient, sourceClient.blackBox);
return sourceClient.blackBox();
}
/**
@ -782,7 +757,7 @@ function blackBox(sourceClient) {
*/
function unBlackBox(sourceClient) {
dumpn("Un-black boxing source: " + sourceClient.actor);
return rdpRequest(sourceClient, sourceClient.unblackBox);
return sourceClient.unblackBox();
}
/**
@ -794,7 +769,7 @@ function unBlackBox(sourceClient) {
*/
function getSourceContent(sourceClient) {
dumpn("Getting source content for " + sourceClient.actor);
return rdpRequest(sourceClient, sourceClient.source);
return sourceClient.source();
}
/**