Bug 1466691 - Replace callback style in favor of promise for SourceClient methods. r=jryans

MozReview-Commit-ID: F78igLUlqn6

--HG--
extra : rebase_source : 193383f22b3d6ac55df69948619ba2a9115e7235
This commit is contained in:
Alexandre Poirot 2018-06-05 01:09:43 -07:00
Родитель 6deecdeacf
Коммит f9d8e10a27
40 изменённых файлов: 70 добавлений и 134 удалений

Просмотреть файл

@ -105,10 +105,7 @@ function test() {
let source = gThreadClient.source(item.attachment.source);
let deferred = promise.defer();
source.setBreakpoint(location, ({ error, message }, bpClient) => {
if (error) {
deferred.reject(error + ": " + message);
}
source.setBreakpoint(location).then(([response, bpClient]) => {
deferred.resolve(bpClient);
});
return deferred.promise;

Просмотреть файл

@ -36,7 +36,7 @@ function findSource() {
}
function prettyPrintSource() {
gThreadClient.source(gSource).prettyPrint(4, testPrettyPrinted);
gThreadClient.source(gSource).prettyPrint(4).then(testPrettyPrinted);
}
function testPrettyPrinted({ error, source }) {
@ -47,7 +47,7 @@ function testPrettyPrinted({ error, source }) {
}
function disablePrettyPrint() {
gThreadClient.source(gSource).disablePrettyPrint(testUgly);
gThreadClient.source(gSource).disablePrettyPrint().then(testUgly);
}
function testUgly({ error, source }) {

Просмотреть файл

@ -42,7 +42,7 @@ function findSource() {
}
function prettyPrintSource(source) {
gThreadClient.source(gSource).prettyPrint(2, runCode);
gThreadClient.source(gSource).prettyPrint(2).then(runCode);
}
function runCode({ error }) {
@ -62,13 +62,11 @@ function testDbgStatement(event, { why, frame }) {
function setBreakpoint() {
gThreadClient.source(gSource).setBreakpoint(
{ line: BP_LOCATION.line,
column: BP_LOCATION.column },
({ error, actualLocation }) => {
ok(!error, "error should not exist");
column: BP_LOCATION.column })
.then(([{ actualLocation }]) => {
ok(!actualLocation, "actualLocation should not exist");
testStepping();
}
);
});
}
function testStepping() {

Просмотреть файл

@ -47,7 +47,7 @@ function findSource() {
}
function prettyPrint() {
gThreadClient.source(gSource).prettyPrint(2, runCode);
gThreadClient.source(gSource).prettyPrint(2).then(runCode);
}
function runCode({ error }) {
@ -66,7 +66,7 @@ function testDbgStatement(event, { frame, why }) {
}
function disablePrettyPrint() {
gThreadClient.source(gSource).disablePrettyPrint(testUgly);
gThreadClient.source(gSource).disablePrettyPrint().then(testUgly);
}
function testUgly({ error, source }) {

Просмотреть файл

@ -66,9 +66,7 @@ function testSetBreakpoint() {
gDebugger.gThreadClient.interrupt(aResponse => {
let source = gDebugger.gThreadClient.source(sourceForm);
source.setBreakpoint({ line: 5 }, aResponse => {
ok(!aResponse.error,
"Should be able to set a breakpoint in a coffee source file.");
source.setBreakpoint({ line: 5 }).then(([aResponse]) => {
ok(!aResponse.actualLocation,
"Should be able to set a breakpoint on line 5.");
@ -84,9 +82,7 @@ function testSetBreakpointBlankLine() {
let sourceForm = getSourceForm(gSources, COFFEE_URL);
let source = gDebugger.gThreadClient.source(sourceForm);
source.setBreakpoint({ line: 8 }, aResponse => {
ok(!aResponse.error,
"Should be able to set a breakpoint in a coffee source file on a blank line.");
source.setBreakpoint({ line: 8 }).then(([aResponse]) => {
ok(!aResponse.isPending,
"Should not be a pending breakpoint.");
ok(!aResponse.actualLocation,

Просмотреть файл

@ -69,10 +69,7 @@ function testSetBreakpoint() {
let sourceForm = getSourceForm(gSources, JS_URL);
let source = gDebugger.gThreadClient.source(sourceForm);
source.setBreakpoint({ line: 7 }, aResponse => {
ok(!aResponse.error,
"Should be able to set a breakpoint in a js file.");
source.setBreakpoint({ line: 7 }).then(([aResponse]) => {
gDebugger.gClient.addOneTimeListener("resumed", () => {
waitForCaretAndScopes(gPanel, 7).then(() => {
// Make sure that we have JavaScript stack frames.

Просмотреть файл

@ -50,9 +50,7 @@ function testSetBreakpoint() {
let sourceForm = getSourceForm(gSources, JS_URL);
let source = gDebugger.gThreadClient.source(sourceForm);
source.setBreakpoint({ line: 30 }, aResponse => {
ok(!aResponse.error,
"Should be able to set a breakpoint in a js file.");
source.setBreakpoint({ line: 30 }).then(([aResponse]) => {
ok(!aResponse.actualLocation,
"Should be able to set a breakpoint on line 30.");

Просмотреть файл

@ -93,9 +93,7 @@ function testSetBreakpoint() {
let sourceForm = getSourceForm(gSources, JS_URL);
let source = gDebugger.gThreadClient.source(sourceForm);
source.setBreakpoint({ line: 3, column: 18 }, aResponse => {
ok(!aResponse.error,
"Should be able to set a breakpoint in a js file.");
source.setBreakpoint({ line: 3, column: 18 }).then(([aResponse]) => {
ok(!aResponse.actualLocation,
"Should be able to set a breakpoint on line 3 and column 18.");

Просмотреть файл

@ -47,7 +47,7 @@ function test() {
yield threadClient.interrupt();
let sourceForm = getSourceForm(Sources, COFFEE_URL);
let source = threadClient.source(sourceForm);
let response = yield source.setBreakpoint({ line: 5 });
let [response] = yield source.setBreakpoint({ line: 5 });
ok(!response.error,
"Should be able to set a breakpoint in a coffee source file.");

Просмотреть файл

@ -45,8 +45,7 @@ function test_black_box() {
const source = gThreadClient.source(packet.source);
source.setBreakpoint({
line: 2
}, function(response) {
Assert.ok(!response.error, "Should be able to set breakpoint.");
}).then(function() {
gThreadClient.resume(test_black_box_breakpoint);
});
}

Просмотреть файл

@ -35,9 +35,8 @@ function test_black_box() {
const source = gThreadClient.source(packet.frame.where.source);
source.setBreakpoint({
line: 4
}, function({error}, bpClient) {
}).then(function([response, bpClient]) {
gBpClient = bpClient;
Assert.ok(!error, "Should not get an error: " + error);
gThreadClient.resume(test_black_box_dbg_statement);
});
});

Просмотреть файл

@ -42,10 +42,7 @@ function test_black_box() {
const source = gThreadClient.source(packet.source);
source.setBreakpoint({
line: 2
}, function(response) {
Assert.ok(!response.error, "Should be able to set breakpoint.");
test_black_box_paused();
});
}).then(test_black_box_paused);
}
});

Просмотреть файл

@ -40,7 +40,7 @@ function test_simple_breakpoint() {
line: gDebuggee.line0 + 3
};
source.setBreakpoint(location, function(response, bpClient) {
source.setBreakpoint(location).then(function([response, bpClient]) {
gThreadClient.addOneTimeListener("paused", function(event, packet) {
// Check the return value.
Assert.equal(packet.type, "paused");

Просмотреть файл

@ -47,7 +47,11 @@ function test_breakpoint_running() {
});
const source = gThreadClient.source(packet.frame.where.source);
source.setBreakpoint(location, function(response) {
source.setBreakpoint(location).then(function() {
executeSoon(function() {
gClient.close().then(gCallback);
});
}, function(response) {
// Eval scripts don't stick around long enough for the breakpoint to be set,
// so just make sure we got the expected response from the actor.
Assert.notEqual(response.error, "noScript");

Просмотреть файл

@ -39,7 +39,7 @@ function test_child_breakpoint() {
const source = gThreadClient.source(packet.frame.where.source);
const location = { line: gDebuggee.line0 + 3 };
source.setBreakpoint(location, function(response, bpClient) {
source.setBreakpoint(location).then(function([response, bpClient]) {
// actualLocation is not returned when breakpoints don't skip forward.
Assert.equal(response.actualLocation, undefined);

Просмотреть файл

@ -40,7 +40,7 @@ function test_child_skip_breakpoint() {
const source = gThreadClient.source(packet.frame.where.source);
const location = { line: gDebuggee.line0 + 3 };
source.setBreakpoint(location, function(response, bpClient) {
source.setBreakpoint(location).then(function([response, bpClient]) {
// Check that the breakpoint has properly skipped forward one line.
Assert.equal(response.actualLocation.source.actor, source.actor);
Assert.equal(response.actualLocation.line, location.line + 1);

Просмотреть файл

@ -40,7 +40,7 @@ function test_nested_breakpoint() {
const source = gThreadClient.source(packet.frame.where.source);
const location = { line: gDebuggee.line0 + 5 };
source.setBreakpoint(location, function(response, bpClient) {
source.setBreakpoint(location).then(function([response, bpClient]) {
// Check that the breakpoint has properly skipped forward one line.
Assert.equal(response.actualLocation.source.actor, source.actor);
Assert.equal(response.actualLocation.line, location.line + 1);

Просмотреть файл

@ -40,7 +40,7 @@ function test_second_child_skip_breakpoint() {
const source = gThreadClient.source(packet.frame.where.source);
const location = { line: gDebuggee.line0 + 6 };
source.setBreakpoint(location, function(response, bpClient) {
source.setBreakpoint(location).then(function([response, bpClient]) {
// Check that the breakpoint has properly skipped forward one line.
Assert.equal(response.actualLocation.source.actor, source.actor);
Assert.equal(response.actualLocation.line, location.line + 1);

Просмотреть файл

@ -48,7 +48,7 @@ function test_child_skip_breakpoint() {
const source = gThreadClient.source(packet.source);
const location = { line: gDebuggee.line0 + 3 };
source.setBreakpoint(location, function(response, bpClient) {
source.setBreakpoint(location).then(function([response, bpClient]) {
// Check that the breakpoint has properly skipped forward one line.
Assert.equal(response.actualLocation.source.actor, source.actor);
Assert.equal(response.actualLocation.line, location.line + 1);

Просмотреть файл

@ -40,7 +40,7 @@ function test_remove_breakpoint() {
const source = gThreadClient.source(packet.frame.where.source);
const location = { line: gDebuggee.line0 + 2 };
source.setBreakpoint(location, function(response, bpClient) {
source.setBreakpoint(location).then(function([response, bpClient]) {
gThreadClient.addOneTimeListener("paused", function(event, packet) {
// Check the return value.
Assert.equal(packet.type, "paused");

Просмотреть файл

@ -40,7 +40,7 @@ function test_child_breakpoint() {
const source = gThreadClient.source(packet.frame.where.source);
const location = { line: gDebuggee.line0 + 3 };
source.setBreakpoint(location, function(response, bpClient) {
source.setBreakpoint(location).then(function([response, bpClient]) {
// actualLocation is not returned when breakpoints don't skip forward.
Assert.equal(response.actualLocation, undefined);

Просмотреть файл

@ -40,7 +40,7 @@ function test_child_breakpoint() {
const source = gThreadClient.source(packet.frame.where.source);
const location = { line: gDebuggee.line0 + 2 };
source.setBreakpoint(location, function(response, bpClient) {
source.setBreakpoint(location).then(function([response, bpClient]) {
// actualLocation is not returned when breakpoints don't skip forward.
Assert.equal(response.actualLocation, undefined);

Просмотреть файл

@ -44,7 +44,7 @@ function test_child_skip_breakpoint() {
const source = gThreadClient.source(packet.frame.where.source);
const location = { line: gDebuggee.line0 + 3};
source.setBreakpoint(location, function(response, bpClient) {
source.setBreakpoint(location).then(function([response, bpClient]) {
// Check that the breakpoint has properly skipped forward one line.
Assert.equal(response.actualLocation.source.actor, source.actor);
Assert.equal(response.actualLocation.line, location.line + 1);
@ -71,7 +71,7 @@ function test_child_skip_breakpoint() {
// Set many breakpoints at the same location.
function set_breakpoints(source, location) {
Assert.notEqual(gCount, NUM_BREAKPOINTS);
source.setBreakpoint(location, function(response, bpClient) {
source.setBreakpoint(location).then(function([response, bpClient]) {
// Check that the breakpoint has properly skipped forward one line.
Assert.equal(response.actualLocation.source.actor, source.actor);
Assert.equal(response.actualLocation.line, location.line + 1);

Просмотреть файл

@ -40,7 +40,7 @@ function test_simple_breakpoint() {
const source = gThreadClient.source(packet.frame.where.source);
const location = { line: gDebuggee.line0 + 2 };
source.setBreakpoint(location, async function(response, bpClient) {
source.setBreakpoint(location).then(async function([response, bpClient]) {
const testCallbacks = [
function(packet) {
// Check that the stepping worked.

Просмотреть файл

@ -40,7 +40,7 @@ function test_simple_breakpoint() {
const source = gThreadClient.source(packet.frame.where.source);
const location = { line: gDebuggee.line0 + 2 };
source.setBreakpoint(location, async function(response, bpClient) {
source.setBreakpoint(location).then(async function([response, bpClient]) {
const testCallbacks = [
function(packet) {
// Check that the stepping worked.

Просмотреть файл

@ -45,7 +45,7 @@ function test_column_breakpoint() {
};
let timesBreakpointHit = 0;
source.setBreakpoint(location, function(response, bpClient) {
source.setBreakpoint(location).then(function([response, bpClient]) {
gThreadClient.addListener("paused", function onPaused(event, packet) {
Assert.equal(packet.type, "paused");
Assert.equal(packet.why.type, "breakpoint");

Просмотреть файл

@ -62,15 +62,13 @@ function set_breakpoints(event, packet) {
let first, second;
const source = gThreadClient.source(packet.frame.where.source);
source.setBreakpoint(firstLocation, function({ error, actualLocation },
breakpointClient) {
Assert.ok(!error, "Should not get an error setting the breakpoint");
source.setBreakpoint(firstLocation).then(function([{ actualLocation },
breakpointClient]) {
Assert.ok(!actualLocation, "Should not get an actualLocation");
first = breakpointClient;
source.setBreakpoint(secondLocation, function({ error, actualLocation },
breakpointClient) {
Assert.ok(!error, "Should not get an error setting the breakpoint");
source.setBreakpoint(secondLocation).then(function([{ actualLocation },
breakpointClient]) {
Assert.ok(!actualLocation, "Should not get an actualLocation");
second = breakpointClient;

Просмотреть файл

@ -55,8 +55,7 @@ function setBreakpoint(event, packet) {
const source = gThreadClient.source(packet.frame.where.source);
gClient.addOneTimeListener("resumed", runCode);
source.setBreakpoint({ line: 2 }, ({ error }) => {
Assert.ok(!error);
source.setBreakpoint({ line: 2 }).then(() => {
gThreadClient.resume();
});
}

Просмотреть файл

@ -51,7 +51,7 @@ const test = async function() {
line: gDebuggee.line0 + 7
};
await source.setBreakpoint(location2).then(_ => {
await source.setBreakpoint(location2).then(() => {
do_throw("no code shall not be found the specified line or below it");
}, reason => {
Assert.equal(reason.error, "noCodeAtLineColumn");

Просмотреть файл

@ -32,7 +32,7 @@ function test_simple_breakpoint() {
source.setBreakpoint({
line: 3,
condition: "a === 1"
}, function(response, bpClient) {
}).then(function([response, bpClient]) {
gThreadClient.addOneTimeListener("paused", function(event, packet) {
// Check the return value.
Assert.equal(packet.why.type, "breakpoint");

Просмотреть файл

@ -32,7 +32,7 @@ function test_simple_breakpoint() {
source.setBreakpoint({
line: 3,
condition: "a === 2"
}, function(response, bpClient) {
}).then(function([response, bpClient]) {
gThreadClient.addOneTimeListener("paused", function(event, packet) {
// Check the return value.
Assert.equal(packet.why.type, "debuggerStatement");

Просмотреть файл

@ -32,7 +32,7 @@ function test_simple_breakpoint() {
source.setBreakpoint({
line: 3,
condition: "throw new Error()"
}, function(response, bpClient) {
}).then(function([response, bpClient]) {
gThreadClient.addOneTimeListener("paused", function(event, packet) {
// Check the return value.
Assert.equal(packet.why.type, "breakpointConditionThrown");

Просмотреть файл

@ -54,9 +54,8 @@ function test_source() {
Assert.ok(!!source);
const sourceClient = gThreadClient.source(source);
sourceClient.source(function(response) {
sourceClient.source().then(function(response) {
Assert.ok(!!response);
Assert.ok(!response.error);
Assert.ok(!!response.contentType);
Assert.ok(response.contentType.includes("javascript"));

Просмотреть файл

@ -77,10 +77,7 @@ function testContents(sources, timesCalled, callback) {
const sourceClient = gThreadClient.source(sources[0]);
if (sourceClient.url) {
sourceClient.source((response) => {
Assert.ok(!response.error,
"Should not get an error loading the source from sourcesContent");
sourceClient.source().then(response => {
const expectedContent = "content for " + source.url.replace(/^.*\//, "");
Assert.equal(response.source, expectedContent,
"Should have the expected source content");

Просмотреть файл

@ -47,17 +47,13 @@ function test_cached_original_sources() {
function onNewSource(event, packet) {
const sourceClient = gThreadClient.source(packet.source);
sourceClient.source(function(response) {
Assert.ok(!response.error,
"Should not be an error grabbing the source");
sourceClient.source().then(function(response) {
Assert.equal(response.source, "initial content",
"The correct source content should be sent");
writeFile("temp.js", "new content");
sourceClient.source(function(response) {
Assert.ok(!response.error,
"Should not be an error grabbing the source");
sourceClient.source().then(function(response) {
Assert.equal(response.source, "new content",
"The correct source content should not be cached, " +
"so we should get the new content");

Просмотреть файл

@ -29,8 +29,7 @@ function run_test() {
function test_source_maps() {
gThreadClient.addOneTimeListener("newSource", function(event, packet) {
const sourceClient = gThreadClient.source(packet.source);
sourceClient.source(function({error, source}) {
Assert.ok(!error, "should be able to grab the source");
sourceClient.source().then(function({source}) {
Assert.equal(source, "foo",
"Should load the source from the sourcesContent field");
finishClient(gClient);

Просмотреть файл

@ -46,10 +46,7 @@ function test_minified() {
};
getSource(gThreadClient, "http://example.com/foo.js").then(source => {
source.setBreakpoint(location, function(response, bpClient) {
Assert.ok(!response.error);
testHitBreakpoint();
});
source.setBreakpoint(location).then(() => testHitBreakpoint());
});
});

Просмотреть файл

@ -60,9 +60,8 @@ function test_source() {
Assert.ok(!!source);
const sourceClient = gThreadClient.source(source);
sourceClient.source(function(response) {
sourceClient.source().then(function(response) {
Assert.ok(!!response);
Assert.ok(!response.error);
Assert.ok(!!response.contentType);
Assert.ok(response.contentType.includes("wasm"));

Просмотреть файл

@ -106,13 +106,9 @@ BreakpointClient.prototype = {
return;
}
this.source.setBreakpoint(info, (resp, newBreakpoint) => {
if (resp && resp.error) {
deferred.reject(resp);
} else {
deferred.resolve(newBreakpoint);
}
});
deferred.resolve(this.source.setBreakpoint(info).then(([, newBreakpoint]) => {
return newBreakpoint;
}));
});
} else {
// The property shouldn't even exist if the condition is blank

Просмотреть файл

@ -47,9 +47,6 @@ SourceClient.prototype = {
/**
* Black box this SourceClient's source.
*
* @param callback Function
* The callback function called when we receive the response from the server.
*/
blackBox: DebuggerClient.requester({
type: "blackbox"
@ -67,9 +64,6 @@ SourceClient.prototype = {
/**
* Un-black box this SourceClient's source.
*
* @param callback Function
* The callback function called when we receive the response from the server.
*/
unblackBox: DebuggerClient.requester({
type: "unblackbox"
@ -87,9 +81,6 @@ SourceClient.prototype = {
/**
* Get Executable Lines from a source
*
* @param callback Function
* The callback function called when we receive the response from the server.
*/
getExecutableLines: function(cb = noop) {
const packet = {
@ -106,61 +97,51 @@ SourceClient.prototype = {
/**
* Get a long string grip for this SourceClient's source.
*/
source: function(callback = noop) {
source: function() {
const packet = {
to: this._form.actor,
type: "source"
};
return this._client.request(packet).then(response => {
return this._onSourceResponse(response, callback);
return this._onSourceResponse(response);
});
},
/**
* Pretty print this source's text.
*/
prettyPrint: function(indent, callback = noop) {
prettyPrint: function(indent) {
const packet = {
to: this._form.actor,
type: "prettyPrint",
indent
};
return this._client.request(packet).then(response => {
if (!response.error) {
this._isPrettyPrinted = true;
this._activeThread._clearFrames();
this._activeThread.emit("prettyprintchange", this);
}
return this._onSourceResponse(response, callback);
this._isPrettyPrinted = true;
this._activeThread._clearFrames();
this._activeThread.emit("prettyprintchange", this);
return this._onSourceResponse(response);
});
},
/**
* Stop pretty printing this source's text.
*/
disablePrettyPrint: function(callback = noop) {
disablePrettyPrint: function() {
const packet = {
to: this._form.actor,
type: "disablePrettyPrint"
};
return this._client.request(packet).then(response => {
if (!response.error) {
this._isPrettyPrinted = false;
this._activeThread._clearFrames();
this._activeThread.emit("prettyprintchange", this);
}
return this._onSourceResponse(response, callback);
this._isPrettyPrinted = false;
this._activeThread._clearFrames();
this._activeThread.emit("prettyprintchange", this);
return this._onSourceResponse(response);
});
},
_onSourceResponse: function(response, callback) {
if (response.error) {
callback(response);
return response;
}
_onSourceResponse: function(response) {
if (typeof response.source === "string") {
callback(response);
return response;
}
@ -169,7 +150,6 @@ SourceClient.prototype = {
const arrayBuffer = this._activeThread.threadArrayBuffer(source);
return arrayBuffer.slice(0, arrayBuffer.length).then(function(resp) {
if (resp.error) {
callback(resp);
return resp;
}
// Keeping str as a string, ArrayBuffer/Uint8Array will not survive
@ -182,7 +162,6 @@ SourceClient.prototype = {
},
contentType,
};
callback(newResponse);
return newResponse;
});
}
@ -190,7 +169,6 @@ SourceClient.prototype = {
const longString = this._activeThread.threadLongString(source);
return longString.substring(0, longString.length).then(function(resp) {
if (resp.error) {
callback(resp);
return resp;
}
@ -198,7 +176,6 @@ SourceClient.prototype = {
source: resp.substring,
contentType: contentType
};
callback(newResponse);
return newResponse;
});
},
@ -209,10 +186,8 @@ SourceClient.prototype = {
* @param object location
* The location and condition of the breakpoint in
* the form of { line[, column, condition] }.
* @param function onResponse
* Called with the thread's response.
*/
setBreakpoint: function({ line, column, condition, noSliding }, onResponse = noop) {
setBreakpoint: function({ line, column, condition, noSliding }) {
// A helper function that sets the breakpoint.
const doSetBreakpoint = callback => {
const root = this._client.mainRoot;
@ -249,7 +224,6 @@ SourceClient.prototype = {
root.traits.conditionalBreakpoints ? condition : undefined
);
}
onResponse(response, bpClient);
if (callback) {
callback();
}
@ -265,7 +239,6 @@ SourceClient.prototype = {
return this._activeThread.interrupt().then(response => {
if (response.error) {
// Can't set the breakpoint if pausing failed.
onResponse(response);
return response;
}