Commit 349af4e4 authored by weinig@apple.com's avatar weinig@apple.com

Update Promises to the https://github.com/domenic/promises-unwrapping spec

https://bugs.webkit.org/show_bug.cgi?id=120954

Reviewed by Filip Pizlo.

Source/JavaScriptCore: 

Update Promises to the revised spec. Notable changes:
- JSPromiseResolver is gone.
- TaskContext has been renamed Microtask and now has a virtual run() function.
- Instead of using custom InternalFunction subclasses, JSFunctions are used
  with PrivateName properties for internal slots.

* CMakeLists.txt:
* DerivedSources.make:
* GNUmakefile.list.am:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
* JavaScriptCore.xcodeproj/project.pbxproj:
* interpreter/CallFrame.h:
(JSC::ExecState::promiseConstructorTable):
* runtime/CommonIdentifiers.cpp:
(JSC::CommonIdentifiers::CommonIdentifiers):
* runtime/CommonIdentifiers.h:
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::reset):
(JSC::JSGlobalObject::visitChildren):
(JSC::JSGlobalObject::queueMicrotask):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::promiseConstructor):
(JSC::JSGlobalObject::promisePrototype):
(JSC::JSGlobalObject::promiseStructure):
* runtime/JSPromise.cpp:
(JSC::JSPromise::create):
(JSC::JSPromise::JSPromise):
(JSC::JSPromise::finishCreation):
(JSC::JSPromise::visitChildren):
(JSC::JSPromise::reject):
(JSC::JSPromise::resolve):
(JSC::JSPromise::appendResolveReaction):
(JSC::JSPromise::appendRejectReaction):
(JSC::triggerPromiseReactions):
* runtime/JSPromise.h:
(JSC::JSPromise::status):
(JSC::JSPromise::result):
(JSC::JSPromise::constructor):
* runtime/JSPromiseCallback.cpp: Removed.
* runtime/JSPromiseCallback.h: Removed.
* runtime/JSPromiseConstructor.cpp:
(JSC::constructPromise):
(JSC::JSPromiseConstructor::getCallData):
(JSC::JSPromiseConstructorFuncCast):
(JSC::JSPromiseConstructorFuncResolve):
(JSC::JSPromiseConstructorFuncReject):
* runtime/JSPromiseConstructor.h:
* runtime/JSPromiseDeferred.cpp: Added.
(JSC::JSPromiseDeferred::create):
(JSC::JSPromiseDeferred::JSPromiseDeferred):
(JSC::JSPromiseDeferred::finishCreation):
(JSC::JSPromiseDeferred::visitChildren):
(JSC::createJSPromiseDeferredFromConstructor):
(JSC::updateDeferredFromPotentialThenable):
* runtime/JSPromiseDeferred.h: Added.
(JSC::JSPromiseDeferred::createStructure):
(JSC::JSPromiseDeferred::promise):
(JSC::JSPromiseDeferred::resolve):
(JSC::JSPromiseDeferred::reject):
* runtime/JSPromiseFunctions.cpp: Added.
(JSC::deferredConstructionFunction):
(JSC::createDeferredConstructionFunction):
(JSC::identifyFunction):
(JSC::createIdentifyFunction):
(JSC::promiseAllCountdownFunction):
(JSC::createPromiseAllCountdownFunction):
(JSC::promiseResolutionHandlerFunction):
(JSC::createPromiseResolutionHandlerFunction):
(JSC::rejectPromiseFunction):
(JSC::createRejectPromiseFunction):
(JSC::resolvePromiseFunction):
(JSC::createResolvePromiseFunction):
(JSC::throwerFunction):
(JSC::createThrowerFunction):
* runtime/JSPromiseFunctions.h: Added.
* runtime/JSPromisePrototype.cpp:
(JSC::JSPromisePrototypeFuncThen):
(JSC::JSPromisePrototypeFuncCatch):
* runtime/JSPromiseReaction.cpp: Added.
(JSC::createExecutePromiseReactionMicroTask):
(JSC::ExecutePromiseReactionMicroTask::run):
(JSC::JSPromiseReaction::create):
(JSC::JSPromiseReaction::JSPromiseReaction):
(JSC::JSPromiseReaction::finishCreation):
(JSC::JSPromiseReaction::visitChildren):
* runtime/JSPromiseReaction.h: Added.
(JSC::JSPromiseReaction::createStructure):
(JSC::JSPromiseReaction::deferred):
(JSC::JSPromiseReaction::handler):
* runtime/JSPromiseResolver.cpp: Removed.
* runtime/JSPromiseResolver.h: Removed.
* runtime/JSPromiseResolverConstructor.cpp: Removed.
* runtime/JSPromiseResolverConstructor.h: Removed.
* runtime/JSPromiseResolverPrototype.cpp: Removed.
* runtime/JSPromiseResolverPrototype.h: Removed.
* runtime/Microtask.h: Added.
* runtime/VM.cpp:
(JSC::VM::VM):
(JSC::VM::~VM):
* runtime/VM.h:

Source/WebCore: 

* ForwardingHeaders/runtime/JSPromiseDeferred.h: Added.
* ForwardingHeaders/runtime/JSPromiseResolver.h: Removed.
* bindings/js/JSDOMGlobalObjectTask.cpp:
(WebCore::JSGlobalObjectTask::JSGlobalObjectTask):
* bindings/js/JSDOMGlobalObjectTask.h:
* bindings/js/JSDOMPromise.cpp:
(WebCore::DeferredWrapper::DeferredWrapper):
(WebCore::DeferredWrapper::promise):
(WebCore::DeferredWrapper::resolve):
(WebCore::DeferredWrapper::reject):
* bindings/js/JSDOMPromise.h:
(WebCore::DeferredWrapper::resolve):
(WebCore::DeferredWrapper::reject):
(WebCore::DeferredWrapper::resolve<String>):
(WebCore::DeferredWrapper::resolve<bool>):
(WebCore::char>>):
(WebCore::DeferredWrapper::reject<String>):
* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::queueTaskToEventLoop):
* bindings/js/JSDOMWindowBase.h:
* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::JSSubtleCrypto::encrypt):
(WebCore::JSSubtleCrypto::decrypt):
(WebCore::JSSubtleCrypto::sign):
(WebCore::JSSubtleCrypto::verify):
(WebCore::JSSubtleCrypto::digest):
(WebCore::JSSubtleCrypto::generateKey):
(WebCore::JSSubtleCrypto::importKey):
(WebCore::JSSubtleCrypto::exportKey):
(WebCore::JSSubtleCrypto::wrapKey):
(WebCore::JSSubtleCrypto::unwrapKey):
* bindings/js/JSWorkerGlobalScopeBase.cpp:
(WebCore::JSWorkerGlobalScopeBase::queueTaskToEventLoop):
* bindings/js/JSWorkerGlobalScopeBase.h:

LayoutTests: 

* crypto/subtle/argument-conversion.html:
* crypto/subtle/resources/common.js:
* crypto/subtle/sha-1.html:
* crypto/subtle/sha-224.html:
* crypto/subtle/sha-256.html:
* crypto/subtle/sha-384.html:
* crypto/subtle/sha-512.html:
* js/dom/Promise-already-fulfilled-expected.txt: Removed.
* js/dom/Promise-already-fulfilled.html: Removed.
* js/dom/Promise-already-rejected.html:
* js/dom/Promise-already-resolved.html:
* js/dom/Promise-catch-expected.txt:
* js/dom/Promise-catch-in-workers-expected.txt:
* js/dom/Promise-catch.html:
* js/dom/Promise-chain.html:
* js/dom/Promise-exception-expected.txt:
* js/dom/Promise-exception.html:
* js/dom/Promise-expected.txt:
* js/dom/Promise-fulfill-expected.txt: Removed.
* js/dom/Promise-fulfill-in-workers-expected.txt: Removed.
* js/dom/Promise-fulfill-in-workers.html: Removed.
* js/dom/Promise-fulfill.html: Removed.
* js/dom/Promise-init-callback-receiver-expected.txt: Added.
* js/dom/Promise-init-callback-receiver.html: Added.
* js/dom/Promise-init-expected.txt:
* js/dom/Promise-init-in-workers-expected.txt:
* js/dom/Promise-init.html:
* js/dom/Promise-onFulfilled-deep-expected.txt: Added.
* js/dom/Promise-onFulfilled-deep.html: Added.
* js/dom/Promise-onRejected-deep-expected.txt: Added.
* js/dom/Promise-onRejected-deep.html: Added.
* js/dom/Promise-reject.html:
* js/dom/Promise-resolve-chain.html:
* js/dom/Promise-resolve-expected.txt:
* js/dom/Promise-resolve-in-workers-expected.txt:
* js/dom/Promise-resolve-state-expected.txt: Added.
* js/dom/Promise-resolve-state-in-workers-expected.txt: Added.
* js/dom/Promise-resolve-state-in-workers.html: Added.
* js/dom/Promise-resolve-state.html: Added.
* js/dom/Promise-resolve-with-itself-expected.txt: Added.
* js/dom/Promise-resolve-with-itself.html: Added.
* js/dom/Promise-resolve-with-then-exception.html:
* js/dom/Promise-resolve-with-then-fulfill-expected.txt:
* js/dom/Promise-resolve-with-then-fulfill.html:
* js/dom/Promise-resolve-with-then-reject-expected.txt:
* js/dom/Promise-resolve-with-then-reject.html:
* js/dom/Promise-resolve.html:
* js/dom/Promise-simple-expected.txt:
* js/dom/Promise-simple-fulfill-expected.txt: Removed.
* js/dom/Promise-simple-fulfill-inside-callback-expected.txt: Removed.
* js/dom/Promise-simple-fulfill-inside-callback.html: Removed.
* js/dom/Promise-simple-fulfill.html: Removed.
* js/dom/Promise-simple-in-workers-expected.txt:
* js/dom/Promise-simple-resolve-expected.txt: Added.
* js/dom/Promise-simple-resolve.html: Added.
* js/dom/Promise-simple.html:
* js/dom/Promise-static-all-expected.txt: Added.
* js/dom/Promise-static-all.html: Added.
* js/dom/Promise-static-cast-expected.txt: Added.
* js/dom/Promise-static-cast.html: Added.
* js/dom/Promise-static-fulfill-expected.txt: Removed.
* js/dom/Promise-static-fulfill.html: Removed.
* js/dom/Promise-static-race-expected.txt: Added.
* js/dom/Promise-static-race.html: Added.
* js/dom/Promise-static-resolve.html:
* js/dom/Promise-then-callback-receiver-expected.txt: Added.
* js/dom/Promise-then-callback-receiver.html: Added.
* js/dom/Promise-then-expected.txt:
* js/dom/Promise-then-in-workers-expected.txt:
* js/dom/Promise-then-without-callbacks.html:
* js/dom/Promise-then.html:
* js/dom/Promise-types-expected.txt:
* js/dom/Promise-types.html:
* js/dom/Promise.html:
* js/resources/Promise-catch-in-workers.js:
* js/resources/Promise-fulfill-in-workers.js: Removed.
* js/resources/Promise-init-in-workers.js:
* js/resources/Promise-reject-in-workers.js:
* js/resources/Promise-resolve-in-workers.js:
* js/resources/Promise-resolve-state-in-workers.js: Added.
* js/resources/Promise-simple-in-workers.js:
* js/resources/Promise-then-in-workers.js:
* js/resources/Promise-then-without-callbacks-in-workers.js:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@161241 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 72454da3
2014-01-02 Sam Weinig <sam@webkit.org>
Update Promises to the https://github.com/domenic/promises-unwrapping spec
https://bugs.webkit.org/show_bug.cgi?id=120954
Reviewed by Filip Pizlo.
* crypto/subtle/argument-conversion.html:
* crypto/subtle/resources/common.js:
* crypto/subtle/sha-1.html:
* crypto/subtle/sha-224.html:
* crypto/subtle/sha-256.html:
* crypto/subtle/sha-384.html:
* crypto/subtle/sha-512.html:
* js/dom/Promise-already-fulfilled-expected.txt: Removed.
* js/dom/Promise-already-fulfilled.html: Removed.
* js/dom/Promise-already-rejected.html:
* js/dom/Promise-already-resolved.html:
* js/dom/Promise-catch-expected.txt:
* js/dom/Promise-catch-in-workers-expected.txt:
* js/dom/Promise-catch.html:
* js/dom/Promise-chain.html:
* js/dom/Promise-exception-expected.txt:
* js/dom/Promise-exception.html:
* js/dom/Promise-expected.txt:
* js/dom/Promise-fulfill-expected.txt: Removed.
* js/dom/Promise-fulfill-in-workers-expected.txt: Removed.
* js/dom/Promise-fulfill-in-workers.html: Removed.
* js/dom/Promise-fulfill.html: Removed.
* js/dom/Promise-init-callback-receiver-expected.txt: Added.
* js/dom/Promise-init-callback-receiver.html: Added.
* js/dom/Promise-init-expected.txt:
* js/dom/Promise-init-in-workers-expected.txt:
* js/dom/Promise-init.html:
* js/dom/Promise-onFulfilled-deep-expected.txt: Added.
* js/dom/Promise-onFulfilled-deep.html: Added.
* js/dom/Promise-onRejected-deep-expected.txt: Added.
* js/dom/Promise-onRejected-deep.html: Added.
* js/dom/Promise-reject.html:
* js/dom/Promise-resolve-chain.html:
* js/dom/Promise-resolve-expected.txt:
* js/dom/Promise-resolve-in-workers-expected.txt:
* js/dom/Promise-resolve-state-expected.txt: Added.
* js/dom/Promise-resolve-state-in-workers-expected.txt: Added.
* js/dom/Promise-resolve-state-in-workers.html: Added.
* js/dom/Promise-resolve-state.html: Added.
* js/dom/Promise-resolve-with-itself-expected.txt: Added.
* js/dom/Promise-resolve-with-itself.html: Added.
* js/dom/Promise-resolve-with-then-exception.html:
* js/dom/Promise-resolve-with-then-fulfill-expected.txt:
* js/dom/Promise-resolve-with-then-fulfill.html:
* js/dom/Promise-resolve-with-then-reject-expected.txt:
* js/dom/Promise-resolve-with-then-reject.html:
* js/dom/Promise-resolve.html:
* js/dom/Promise-simple-expected.txt:
* js/dom/Promise-simple-fulfill-expected.txt: Removed.
* js/dom/Promise-simple-fulfill-inside-callback-expected.txt: Removed.
* js/dom/Promise-simple-fulfill-inside-callback.html: Removed.
* js/dom/Promise-simple-fulfill.html: Removed.
* js/dom/Promise-simple-in-workers-expected.txt:
* js/dom/Promise-simple-resolve-expected.txt: Added.
* js/dom/Promise-simple-resolve.html: Added.
* js/dom/Promise-simple.html:
* js/dom/Promise-static-all-expected.txt: Added.
* js/dom/Promise-static-all.html: Added.
* js/dom/Promise-static-cast-expected.txt: Added.
* js/dom/Promise-static-cast.html: Added.
* js/dom/Promise-static-fulfill-expected.txt: Removed.
* js/dom/Promise-static-fulfill.html: Removed.
* js/dom/Promise-static-race-expected.txt: Added.
* js/dom/Promise-static-race.html: Added.
* js/dom/Promise-static-resolve.html:
* js/dom/Promise-then-callback-receiver-expected.txt: Added.
* js/dom/Promise-then-callback-receiver.html: Added.
* js/dom/Promise-then-expected.txt:
* js/dom/Promise-then-in-workers-expected.txt:
* js/dom/Promise-then-without-callbacks.html:
* js/dom/Promise-then.html:
* js/dom/Promise-types-expected.txt:
* js/dom/Promise-types.html:
* js/dom/Promise.html:
* js/resources/Promise-catch-in-workers.js:
* js/resources/Promise-fulfill-in-workers.js: Removed.
* js/resources/Promise-init-in-workers.js:
* js/resources/Promise-reject-in-workers.js:
* js/resources/Promise-resolve-in-workers.js:
* js/resources/Promise-resolve-state-in-workers.js: Added.
* js/resources/Promise-simple-in-workers.js:
* js/resources/Promise-then-in-workers.js:
* js/resources/Promise-then-without-callbacks-in-workers.js:
2014-01-02 Myles C. Maxfield <mmaxfield@apple.com> 2014-01-02 Myles C. Maxfield <mmaxfield@apple.com>
Allow ImageBuffer to re-use IOSurfaces Allow ImageBuffer to re-use IOSurfaces
...@@ -13,7 +13,7 @@ description("Test crypto.subtle argument conversion"); ...@@ -13,7 +13,7 @@ description("Test crypto.subtle argument conversion");
jsTestIsAsync = true; jsTestIsAsync = true;
Promise.fulfill(null).then(function() { Promise.resolve(null).then(function() {
debug("\nPassing algorithm name as a string object..."); debug("\nPassing algorithm name as a string object...");
return crypto.subtle.digest(new String('sha-1'), new Uint8Array([])); return crypto.subtle.digest(new String('sha-1'), new Uint8Array([]));
}).then(function(result) { }).then(function(result) {
......
...@@ -107,15 +107,16 @@ if (!Promise.all) { ...@@ -107,15 +107,16 @@ if (!Promise.all) {
var results = []; var results = [];
var resultCount = 0; var resultCount = 0;
var resolver; var resolver;
var rejector;
function next(result) { function next(result) {
results[resultCount++] = result; results[resultCount++] = result;
if (resultCount < promises.length) if (resultCount < promises.length)
promises[resultCount].then(next); promises[resultCount].then(next);
else else
resolver.fulfill(results); resolver(results);
} }
promises[0].then(next, function() { resolver.reject(null) }); promises[0].then(next, function() { rejector(null) });
return new Promise(function(r) { resolver = r; }); return new Promise(function(resolve, reject) { resolver = resolve; rejector = reject; });
} }
} }
......
...@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest."); ...@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest.");
jsTestIsAsync = true; jsTestIsAsync = true;
Promise.fulfill(null).then(function() { Promise.resolve(null).then(function() {
debug("SHA1 of []"); debug("SHA1 of []");
return crypto.subtle.digest('sha-1', new Uint8Array([])); return crypto.subtle.digest('sha-1', new Uint8Array([]));
}).then(function(result) { }).then(function(result) {
......
...@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest."); ...@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest.");
jsTestIsAsync = true; jsTestIsAsync = true;
Promise.fulfill(null).then(function() { Promise.resolve(null).then(function() {
debug("SHA224 of []"); debug("SHA224 of []");
return crypto.subtle.digest('sha-224', new Uint8Array([])); return crypto.subtle.digest('sha-224', new Uint8Array([]));
}).then(function(result) { }).then(function(result) {
......
...@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest."); ...@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest.");
jsTestIsAsync = true; jsTestIsAsync = true;
Promise.fulfill(null).then(function() { Promise.resolve(null).then(function() {
debug("SHA256 of []"); debug("SHA256 of []");
return crypto.subtle.digest('sha-256', new Uint8Array([])); return crypto.subtle.digest('sha-256', new Uint8Array([]));
}).then(function(result) { }).then(function(result) {
......
...@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest."); ...@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest.");
jsTestIsAsync = true; jsTestIsAsync = true;
Promise.fulfill(null).then(function() { Promise.resolve(null).then(function() {
debug("SHA384 of []"); debug("SHA384 of []");
return crypto.subtle.digest('sha-384', new Uint8Array([])); return crypto.subtle.digest('sha-384', new Uint8Array([]));
}).then(function(result) { }).then(function(result) {
......
...@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest."); ...@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest.");
jsTestIsAsync = true; jsTestIsAsync = true;
Promise.fulfill(null).then(function() { Promise.resolve(null).then(function() {
debug("SHA512 of []"); debug("SHA512 of []");
return crypto.subtle.digest('sha-512', new Uint8Array([])); return crypto.subtle.digest('sha-512', new Uint8Array([]));
}).then(function(result) { }).then(function(result) {
......
...@@ -11,11 +11,10 @@ description('Test Promise.'); ...@@ -11,11 +11,10 @@ description('Test Promise.');
window.jsTestIsAsync = true; window.jsTestIsAsync = true;
new Promise(function(resolver) { new Promise(function(resolve, reject) {
resolver.reject('foo'); reject('foo');
resolver.fulfill('fulfill'); resolve('resolve');
resolver.resolve('resolve'); reject('reject');
resolver.reject('reject');
}).then(function() { }).then(function() {
testFailed('fulfilled'); testFailed('fulfilled');
finishJSTest(); finishJSTest();
......
...@@ -11,14 +11,13 @@ description('Test Promise.'); ...@@ -11,14 +11,13 @@ description('Test Promise.');
window.jsTestIsAsync = true; window.jsTestIsAsync = true;
new Promise(function(resolver) { new Promise(function(resolve, reject) {
var anotherResolver; var anotherResolve;
resolver.resolve(new Promise(function(r) { anotherResolver = r; })); resolve(new Promise(function(r) { anotherResolve = r; }));
resolver.fulfill('fulfill'); resolve('resolve');
resolver.resolve('resolve'); reject('reject');
resolver.reject('reject');
anotherResolver.fulfill('foo'); anotherResolve('foo');
}).then(function(result) { }).then(function(result) {
window.result = result; window.result = result;
shouldBeEqualToString('result', 'foo'); shouldBeEqualToString('result', 'foo');
......
...@@ -2,13 +2,13 @@ Test Promise. ...@@ -2,13 +2,13 @@ Test Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS thisInInit === firstPromise is true PASS thisInInit === firstPromise is false
PASS thisInInit === window is true
PASS firstPromise instanceof Promise is true PASS firstPromise instanceof Promise is true
PASS secondPromise instanceof Promise is true PASS secondPromise instanceof Promise is true
PASS firstPromise.catch(null) threw exception TypeError: Expected function or undefined as as first argument.
PASS firstPromise.catch(37) threw exception TypeError: Expected function or undefined as as first argument.
PASS thisInFulfillCallback === firstPromise is false PASS thisInFulfillCallback === firstPromise is false
PASS thisInFulfillCallback === secondPromise is true PASS thisInFulfillCallback === secondPromise is false
PASS thisInFulfillCallback === window is true
PASS result is "hello" PASS result is "hello"
PASS result is "bye" PASS result is "bye"
PASS fulfilled PASS fulfilled
......
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Starting worker: ../resources/Promise-catch-in-workers.js Starting worker: ../resources/Promise-catch-in-workers.js
PASS [Worker] thisInInit === firstPromise is true PASS [Worker] thisInInit === firstPromise is false
PASS [Worker] thisInInit === global is true
PASS [Worker] firstPromise instanceof Promise is true PASS [Worker] firstPromise instanceof Promise is true
PASS [Worker] secondPromise instanceof Promise is true PASS [Worker] secondPromise instanceof Promise is true
PASS [Worker] firstPromise.catch(null) threw exception TypeError: Expected function or undefined as as first argument.
PASS [Worker] firstPromise.catch(37) threw exception TypeError: Expected function or undefined as as first argument.
PASS [Worker] thisInFulfillCallback === firstPromise is false PASS [Worker] thisInFulfillCallback === firstPromise is false
PASS [Worker] thisInFulfillCallback === secondPromise is true PASS [Worker] thisInFulfillCallback === secondPromise is false
PASS [Worker] thisInFulfillCallback === global is true
PASS [Worker] result is "hello" PASS [Worker] result is "hello"
PASS [Worker] result is "bye" PASS [Worker] result is "bye"
PASS [Worker] fulfilled PASS [Worker] fulfilled
......
...@@ -10,17 +10,18 @@ ...@@ -10,17 +10,18 @@
description('Test Promise.'); description('Test Promise.');
window.jsTestIsAsync = true; window.jsTestIsAsync = true;
var resolver; var reject;
var firstPromise = new Promise(function(newResolver) { var firstPromise = new Promise(function(_, newReject) {
window.thisInInit = this; window.thisInInit = this;
resolver = newResolver; reject = newReject;
}); });
var secondPromise = firstPromise.catch(function(result) { var secondPromise = firstPromise.catch(function(result) {
window.thisInFulfillCallback = this; window.thisInFulfillCallback = this;
shouldBeFalse('thisInFulfillCallback === firstPromise'); shouldBeFalse('thisInFulfillCallback === firstPromise');
shouldBeTrue('thisInFulfillCallback === secondPromise'); shouldBeFalse('thisInFulfillCallback === secondPromise');
shouldBeTrue('thisInFulfillCallback === window');
window.result = result; window.result = result;
shouldBeEqualToString('result', 'hello'); shouldBeEqualToString('result', 'hello');
return 'bye'; return 'bye';
...@@ -37,14 +38,12 @@ secondPromise.then(function(result) { ...@@ -37,14 +38,12 @@ secondPromise.then(function(result) {
}, function() { }, function() {
}); });
shouldBeTrue('thisInInit === firstPromise'); shouldBeFalse('thisInInit === firstPromise');
shouldBeTrue('thisInInit === window');
shouldBeTrue('firstPromise instanceof Promise'); shouldBeTrue('firstPromise instanceof Promise');
shouldBeTrue('secondPromise instanceof Promise'); shouldBeTrue('secondPromise instanceof Promise');
shouldThrow('firstPromise.catch(null)', '"TypeError: Expected function or undefined as as first argument"'); reject('hello');
shouldThrow('firstPromise.catch(37)', '"TypeError: Expected function or undefined as as first argument"');
resolver.reject('hello');
</script> </script>
<script src="../../resources/js-test-post.js"></script> <script src="../../resources/js-test-post.js"></script>
</body> </body>
......
...@@ -11,8 +11,8 @@ description('Test Promise.'); ...@@ -11,8 +11,8 @@ description('Test Promise.');
window.jsTestIsAsync = true; window.jsTestIsAsync = true;
var resolver; var resolve;
var promise = new Promise(function (r) {resolver = r;}); var promise = new Promise(function (r) {resolve = r;});
var operation; var operation;
promise.then(function(result) { // fulfilled - continue promise.then(function(result) { // fulfilled - continue
...@@ -57,7 +57,7 @@ promise.then(function(result) { // fulfilled - continue ...@@ -57,7 +57,7 @@ promise.then(function(result) { // fulfilled - continue
}); });
operation = 'synchronous'; operation = 'synchronous';
resolver.fulfill('hello'); resolve('hello');
// The chain should be executed asynchronously. // The chain should be executed asynchronously.
operation = 'asynchronous'; operation = 'asynchronous';
......
...@@ -2,7 +2,8 @@ Test Promise. ...@@ -2,7 +2,8 @@ Test Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS thisInThenCallback === thirdPromise is true PASS thisInThenCallback === thirdPromise is false
PASS thisInThenCallback === window is true
PASS result is "foobar" PASS result is "foobar"
PASS successfullyParsed is true PASS successfullyParsed is true
......
...@@ -11,9 +11,9 @@ description('Test Promise.'); ...@@ -11,9 +11,9 @@ description('Test Promise.');
window.jsTestIsAsync = true; window.jsTestIsAsync = true;
var firstPromise = new Promise(function(resolver) { var firstPromise = new Promise(function(resolve) {
window.thisInInit = this; window.thisInInit = this;
resolver.fulfill('hello'); resolve('hello');
}); });
var secondPromise = firstPromise.then(function(result) { var secondPromise = firstPromise.then(function(result) {
...@@ -24,7 +24,8 @@ var thirdPromise = secondPromise.then(function(result) { ...@@ -24,7 +24,8 @@ var thirdPromise = secondPromise.then(function(result) {
fail('Unexpected invocation of fulfillCallback'); fail('Unexpected invocation of fulfillCallback');
}, function(result) { }, function(result) {
window.thisInThenCallback = this; window.thisInThenCallback = this;
shouldBeTrue('thisInThenCallback === thirdPromise'); shouldBeFalse('thisInThenCallback === thirdPromise');
shouldBeTrue('thisInThenCallback === window');
window.result = result; window.result = result;
shouldBeEqualToString('result', 'foobar'); shouldBeEqualToString('result', 'foobar');
finishJSTest(); finishJSTest();
......
...@@ -4,43 +4,43 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE ...@@ -4,43 +4,43 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
Test Promise resolve. About to run test - promiseResolve
PASS Then.resolve has been called PASS Promise object should exist
PASS Promise.resolve exists
PASS Promise.reject exists
PASS Then - resolveCb has been called
PASS 42 is 42 PASS 42 is 42
Test Promise reject. About to run test - promiseReject
PASS Then.reject has been called PASS Then - rejectCb has been called
PASS 42 is 42 PASS 42 is 42
Test Promise reject. About to run test - promiseException
PASS Then.reject has been called PASS Then - rejectCb has been called
PASS 42 is 42 PASS 42 is 42
Test Promise gc. About to run test - promiseGC
PASS Then - promise is still alive PASS Then - promise is still alive
Test Promise async. About to run test - promiseAsync
Global should be foo
PASS foo is foo PASS foo is foo
Global should still be foo
PASS foo is foo PASS foo is foo
Global should still be foo (2)
PASS foo is foo PASS foo is foo
Global should be bar
PASS bar is bar PASS bar is bar
Test Promise double then. About to run test - promiseDoubleThen
PASS Then.resolve has been called PASS Then.resolve has been called
PASS 42 is 42 PASS 42 is 42
PASS Then.resolve has been called PASS Then.resolve has been called
PASS 1 is 1 PASS 1 is 1
PASS 42 is 42 PASS 42 is 42
Test Promise - then / exception. About to run test - promiseThenException
PASS Then.resolve has been called PASS Then.resolve has been called
PASS Catch handler (e.g. the reject handler) called. PASS window.onerror has been called!
Test Promise - then / catch / then. About to run test - promiseThenCatchThen
PASS [object Promise] should not be [object Promise]
PASS Then.resolve has been called PASS Then.resolve has been called
PASS 42 is 42 PASS 42 is 42
PASS Then.resolve has been called PASS Then.resolve has been called
...@@ -48,7 +48,8 @@ PASS 43 is 43 ...@@ -48,7 +48,8 @@ PASS 43 is 43
PASS Then.resolve has been called PASS Then.resolve has been called
PASS 44 is 44 PASS 44 is 44
Test Promise - reject / then / catch / then. About to run test - promiseRejectThenCatchThen
PASS [object Promise] should not be [object Promise]
PASS Then.reject has been called PASS Then.reject has been called
PASS 42 is 42 PASS 42 is 42
PASS Then.resolve has been called PASS Then.resolve has been called
...@@ -56,13 +57,13 @@ PASS 43 is 43 ...@@ -56,13 +57,13 @@ PASS 43 is 43
PASS Then.resolve has been called PASS Then.resolve has been called
PASS 44 is 44 PASS 44 is 44
Test Promise - reject / then / catch / then (2). About to run test - promiseRejectThenCatchThen2
PASS Catch has been called
PASS 42 is 42 PASS 42 is 42
PASS Catch has been called
PASS Then.resolve has been called PASS Then.resolve has been called
PASS 43 is 43 PASS 43 is 43
Test Promise - reject / then / catch exception / then. About to run test - promiseRejectThenCatchExceptionThen
PASS Then.reject has been called PASS Then.reject has been called
PASS 42 is 42 PASS 42 is 42
PASS Catch has been called PASS Catch has been called
...@@ -70,47 +71,64 @@ PASS 43 is 43 ...@@ -70,47 +71,64 @@ PASS 43 is 43
PASS Then.resolve has been called PASS Then.resolve has been called
PASS 44 is 44 PASS 44 is 44
Test Promise - then / catch ordering (resolve). About to run test - promiseThenCatchOrderingResolve
Many steps... should return 2
PASS 2 is 2 PASS 2 is 2
Test Promise - then / catch ordering (reject). About to run test - promiseThenCatchOrderingReject
Many steps... should return 2
PASS 2 is 2 PASS 2 is 2
Test Promise - nested promise About to run test - promiseNestedPromise
PASS Nested promise is executed PASS Nested promise is executed
PASS Then.resolve has been called