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

--HG--
extra : amend_source : cf7f71cbacb12d96cfdd08ddc7d9cfdd8d93eaa8
extra : transplant_source : d%D3%96%16%26%A0%ED%89%DF%1E%AC%C9%1B%97%CC%B9h8%D2D
This commit is contained in:
Nikhil Marathe 2014-09-22 16:37:40 -07:00
parent 5089ddfa18
commit 712d37a30f
2 changed files with 45 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,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() {