Bug 1672347 - remove defer from devtools/shared/discovery/tests/xpcshell. r=Honza

Differential Revision: https://phabricator.services.mozilla.com/D94283
This commit is contained in:
Ben Delevingne 2020-10-21 10:59:32 +00:00
Родитель 79854d2dec
Коммит 2dd4dbb9c9
2 изменённых файлов: 78 добавлений и 79 удалений

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

@ -57,21 +57,20 @@ var RootActor = protocol.ActorClassWithSpec(rootSpec, {
promiseReturn: function(toWait) {
// Guarantee that this resolves after simpleReturn returns.
const deferred = defer();
const sequence = this.sequence++;
return new Promise(resolve => {
const sequence = this.sequence++;
// Wait until the number of requests specified by toWait have
// happened, to test queuing.
const check = () => {
if (this.sequence - sequence < toWait) {
executeSoon(check);
return;
}
deferred.resolve(sequence);
};
executeSoon(check);
return deferred.promise;
// Wait until the number of requests specified by toWait have
// happened, to test queuing.
const check = () => {
if (this.sequence - sequence < toWait) {
executeSoon(check);
return;
}
resolve(sequence);
};
executeSoon(check);
});
},
simpleThrow: function() {
@ -80,13 +79,13 @@ var RootActor = protocol.ActorClassWithSpec(rootSpec, {
promiseThrow: function() {
// Guarantee that this resolves after simpleReturn returns.
const deferred = defer();
let sequence = this.sequence++;
// This should be enough to force a failure if the code is broken.
do_timeout(150, () => {
deferred.reject(sequence++);
return new Promise((resolve, reject) => {
let sequence = this.sequence++;
// This should be enough to force a failure if the code is broken.
do_timeout(150, () => {
reject(sequence++);
});
});
return deferred.promise;
},
});

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

@ -206,26 +206,26 @@ function run_test() {
expectRootChildren(0);
})
.then(() => {
const deferred = defer();
rootFront.once("string-event", str => {
trace.expectSend({ type: "emitShortString", to: "<actorid>" });
trace.expectReceive({
type: "string-event",
str: "abc",
from: "<actorid>",
});
return new Promise(resolve => {
rootFront.once("string-event", str => {
trace.expectSend({ type: "emitShortString", to: "<actorid>" });
trace.expectReceive({
type: "string-event",
str: "abc",
from: "<actorid>",
});
Assert.ok(!!str);
strfront = str;
// Shouldn't generate any new references
expectRootChildren(0);
// will generate no packets.
strfront.string().then(value => {
deferred.resolve(value);
Assert.ok(!!str);
strfront = str;
// Shouldn't generate any new references
expectRootChildren(0);
// will generate no packets.
strfront.string().then(value => {
resolve(value);
});
});
rootFront.emitShortString();
});
rootFront.emitShortString();
return deferred.promise;
})
.then(value => {
Assert.equal(value, SHORT_STR);
@ -235,52 +235,52 @@ function run_test() {
return strfront.release();
})
.then(() => {
const deferred = defer();
rootFront.once("string-event", str => {
trace.expectSend({ type: "emitLongString", to: "<actorid>" });
trace.expectReceive({
type: "string-event",
str: {
type: "longString",
actor: "<actorid>",
length: 16,
initial: "abcde",
},
from: "<actorid>",
});
return new Promise(resolve => {
rootFront.once("string-event", str => {
trace.expectSend({ type: "emitLongString", to: "<actorid>" });
trace.expectReceive({
type: "string-event",
str: {
type: "longString",
actor: "<actorid>",
length: 16,
initial: "abcde",
},
from: "<actorid>",
});
Assert.ok(!!str);
// Should generate one new reference
expectRootChildren(1);
strfront = str;
strfront.string().then(value => {
trace.expectSend({
type: "substring",
start: 5,
end: 10,
to: "<actorid>",
});
trace.expectReceive({ substring: "fghij", from: "<actorid>" });
trace.expectSend({
type: "substring",
start: 10,
end: 15,
to: "<actorid>",
});
trace.expectReceive({ substring: "klmno", from: "<actorid>" });
trace.expectSend({
type: "substring",
start: 15,
end: 20,
to: "<actorid>",
});
trace.expectReceive({ substring: "p", from: "<actorid>" });
Assert.ok(!!str);
// Should generate one new reference
expectRootChildren(1);
strfront = str;
strfront.string().then(value => {
trace.expectSend({
type: "substring",
start: 5,
end: 10,
to: "<actorid>",
});
trace.expectReceive({ substring: "fghij", from: "<actorid>" });
trace.expectSend({
type: "substring",
start: 10,
end: 15,
to: "<actorid>",
});
trace.expectReceive({ substring: "klmno", from: "<actorid>" });
trace.expectSend({
type: "substring",
start: 15,
end: 20,
to: "<actorid>",
});
trace.expectReceive({ substring: "p", from: "<actorid>" });
deferred.resolve(value);
resolve(value);
});
});
rootFront.emitLongString();
});
rootFront.emitLongString();
return deferred.promise;
})
.then(value => {
Assert.equal(value, LONG_STR);