Bug 1062323 - Chained promises should resolve asynchronously. r=bz

--HG--
extra : transplant_source : %0C%E0%D2%0FEI/%D8s%E2%D07%8B%DE%25g%96%85%22r
This commit is contained in:
Nikhil Marathe 2014-09-23 22:00:58 -07:00
parent 0d2e9d0b76
commit 9a31dbb780
2 changed files with 46 additions and 6 deletions

View File

@ -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

View File

@ -674,6 +674,46 @@ 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";
info(results);
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 +746,7 @@ var tests = [ promiseResolve, promiseReject,
promiseResolvePromise,
promiseResolveThenableCleanStack,
promiseTestAsyncThenableResolution,
promiseWrapperAsyncResolution,
];
function runTest() {