зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1062323 - Chained promises should resolve asynchronously. r=bz
This commit is contained in:
Родитель
9047e55dd0
Коммит
95c8c96ad5
|
@ -203,13 +203,13 @@ WrapperPromiseCallback::Call(JSContext* aCx,
|
|||
|
||||
ErrorResult rv;
|
||||
|
||||
// If invoking callback threw an exception, run resolver's reject with the
|
||||
// thrown exception as argument and the synchronous flag set.
|
||||
// PromiseReactionTask step 6
|
||||
JS::Rooted<JS::Value> retValue(aCx);
|
||||
mCallback->Call(value, &retValue, rv, CallbackObject::eRethrowExceptions);
|
||||
|
||||
rv.WouldReportJSException();
|
||||
|
||||
// PromiseReactionTask step 7
|
||||
if (rv.Failed() && rv.IsJSException()) {
|
||||
JS::Rooted<JS::Value> value(aCx);
|
||||
rv.StealJSException(aCx, &value);
|
||||
|
@ -219,7 +219,7 @@ WrapperPromiseCallback::Call(JSContext* aCx,
|
|||
return;
|
||||
}
|
||||
|
||||
mNextPromise->RejectInternal(aCx, value, Promise::SyncTask);
|
||||
mNextPromise->RejectInternal(aCx, value);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -284,14 +284,13 @@ WrapperPromiseCallback::Call(JSContext* aCx,
|
|||
}
|
||||
}
|
||||
|
||||
// Otherwise, run resolver's resolve with value and the synchronous flag
|
||||
// set.
|
||||
// Otherwise, run resolver's resolve with value.
|
||||
if (!JS_WrapValue(aCx, &retValue)) {
|
||||
NS_WARNING("Failed to wrap value into the right compartment.");
|
||||
return;
|
||||
}
|
||||
|
||||
mNextPromise->ResolveInternal(aCx, retValue, Promise::SyncTask);
|
||||
mNextPromise->ResolveInternal(aCx, retValue);
|
||||
}
|
||||
|
||||
// NativePromiseCallback
|
||||
|
|
|
@ -674,6 +674,45 @@ function promiseTestAsyncThenableResolution()
|
|||
});
|
||||
}
|
||||
|
||||
// Bug 1062323
|
||||
function promiseWrapperAsyncResolution()
|
||||
{
|
||||
var p = new Promise(function(resolve, reject){
|
||||
resolve();
|
||||
});
|
||||
|
||||
var results = [];
|
||||
var q = p.then(function () {
|
||||
results.push("1-1");
|
||||
}).then(function () {
|
||||
results.push("1-2");
|
||||
}).then(function () {
|
||||
results.push("1-3");
|
||||
});
|
||||
|
||||
var r = p.then(function () {
|
||||
results.push("2-1");
|
||||
}).then(function () {
|
||||
results.push("2-2");
|
||||
}).then(function () {
|
||||
results.push("2-3");
|
||||
});
|
||||
|
||||
Promise.all([q, r]).then(function() {
|
||||
var match = results[0] == "1-1" &&
|
||||
results[1] == "2-1" &&
|
||||
results[2] == "1-2" &&
|
||||
results[3] == "2-2" &&
|
||||
results[4] == "1-3" &&
|
||||
results[5] == "2-3";
|
||||
ok(match, "Chained promises should resolve asynchronously.");
|
||||
runTest();
|
||||
}, function() {
|
||||
ok(false, "promiseWrapperAsyncResolution: One of the promises failed.");
|
||||
runTest();
|
||||
});
|
||||
}
|
||||
|
||||
var tests = [ promiseResolve, promiseReject,
|
||||
promiseException, promiseGC, promiseAsync,
|
||||
promiseDoubleThen, promiseThenException,
|
||||
|
@ -706,6 +745,7 @@ var tests = [ promiseResolve, promiseReject,
|
|||
promiseResolvePromise,
|
||||
promiseResolveThenableCleanStack,
|
||||
promiseTestAsyncThenableResolution,
|
||||
promiseWrapperAsyncResolution,
|
||||
];
|
||||
|
||||
function runTest() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче