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>
Allow ImageBuffer to re-use IOSurfaces
......@@ -13,7 +13,7 @@ description("Test crypto.subtle argument conversion");
jsTestIsAsync = true;
Promise.fulfill(null).then(function() {
Promise.resolve(null).then(function() {
debug("\nPassing algorithm name as a string object...");
return crypto.subtle.digest(new String('sha-1'), new Uint8Array([]));
}).then(function(result) {
......
......@@ -107,15 +107,16 @@ if (!Promise.all) {
var results = [];
var resultCount = 0;
var resolver;
var rejector;
function next(result) {
results[resultCount++] = result;
if (resultCount < promises.length)
promises[resultCount].then(next);
else
resolver.fulfill(results);
resolver(results);
}
promises[0].then(next, function() { resolver.reject(null) });
return new Promise(function(r) { resolver = r; });
promises[0].then(next, function() { rejector(null) });
return new Promise(function(resolve, reject) { resolver = resolve; rejector = reject; });
}
}
......
......@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest.");
jsTestIsAsync = true;
Promise.fulfill(null).then(function() {
Promise.resolve(null).then(function() {
debug("SHA1 of []");
return crypto.subtle.digest('sha-1', new Uint8Array([]));
}).then(function(result) {
......
......@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest.");
jsTestIsAsync = true;
Promise.fulfill(null).then(function() {
Promise.resolve(null).then(function() {
debug("SHA224 of []");
return crypto.subtle.digest('sha-224', new Uint8Array([]));
}).then(function(result) {
......
......@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest.");
jsTestIsAsync = true;
Promise.fulfill(null).then(function() {
Promise.resolve(null).then(function() {
debug("SHA256 of []");
return crypto.subtle.digest('sha-256', new Uint8Array([]));
}).then(function(result) {
......
......@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest.");
jsTestIsAsync = true;
Promise.fulfill(null).then(function() {
Promise.resolve(null).then(function() {
debug("SHA384 of []");
return crypto.subtle.digest('sha-384', new Uint8Array([]));
}).then(function(result) {
......
......@@ -13,7 +13,7 @@ description("Test crypto.subtle.digest.");
jsTestIsAsync = true;
Promise.fulfill(null).then(function() {
Promise.resolve(null).then(function() {
debug("SHA512 of []");
return crypto.subtle.digest('sha-512', new Uint8Array([]));
}).then(function(result) {
......
......@@ -11,11 +11,10 @@ description('Test Promise.');
window.jsTestIsAsync = true;
new Promise(function(resolver) {
resolver.reject('foo');
resolver.fulfill('fulfill');
resolver.resolve('resolve');
resolver.reject('reject');
new Promise(function(resolve, reject) {
reject('foo');
resolve('resolve');
reject('reject');
}).then(function() {
testFailed('fulfilled');
finishJSTest();
......
......@@ -11,14 +11,13 @@ description('Test Promise.');
window.jsTestIsAsync = true;
new Promise(function(resolver) {
var anotherResolver;
resolver.resolve(new Promise(function(r) { anotherResolver = r; }));
resolver.fulfill('fulfill');
resolver.resolve('resolve');
resolver.reject('reject');
new Promise(function(resolve, reject) {
var anotherResolve;
resolve(new Promise(function(r) { anotherResolve = r; }));
resolve('resolve');
reject('reject');
anotherResolver.fulfill('foo');
anotherResolve('foo');
}).then(function(result) {
window.result = result;
shouldBeEqualToString('result', 'foo');
......
......@@ -2,13 +2,13 @@ Test Promise.
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 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 === secondPromise is true
PASS thisInFulfillCallback === secondPromise is false
PASS thisInFulfillCallback === window is true
PASS result is "hello"
PASS result is "bye"
PASS fulfilled
......
......@@ -3,13 +3,13 @@
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
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] 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 === secondPromise is true
PASS [Worker] thisInFulfillCallback === secondPromise is false
PASS [Worker] thisInFulfillCallback === global is true
PASS [Worker] result is "hello"
PASS [Worker] result is "bye"
PASS [Worker] fulfilled
......
......@@ -10,17 +10,18 @@
description('Test Promise.');
window.jsTestIsAsync = true;
var resolver;
var reject;
var firstPromise = new Promise(function(newResolver) {
var firstPromise = new Promise(function(_, newReject) {
window.thisInInit = this;
resolver = newResolver;
reject = newReject;
});
var secondPromise = firstPromise.catch(function(result) {
window.thisInFulfillCallback = this;
shouldBeFalse('thisInFulfillCallback === firstPromise');
shouldBeTrue('thisInFulfillCallback === secondPromise');
shouldBeFalse('thisInFulfillCallback === secondPromise');
shouldBeTrue('thisInFulfillCallback === window');
window.result = result;
shouldBeEqualToString('result', 'hello');
return 'bye';
......@@ -37,14 +38,12 @@ secondPromise.then(function(result) {
}, function() {
});
shouldBeTrue('thisInInit === firstPromise');
shouldBeFalse('thisInInit === firstPromise');
shouldBeTrue('thisInInit === window');
shouldBeTrue('firstPromise instanceof Promise');
shouldBeTrue('secondPromise instanceof Promise');
shouldThrow('firstPromise.catch(null)', '"TypeError: Expected function or undefined as as first argument"');
shouldThrow('firstPromise.catch(37)', '"TypeError: Expected function or undefined as as first argument"');
resolver.reject('hello');
reject('hello');
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
......
......@@ -11,8 +11,8 @@ description('Test Promise.');
window.jsTestIsAsync = true;
var resolver;
var promise = new Promise(function (r) {resolver = r;});
var resolve;
var promise = new Promise(function (r) {resolve = r;});
var operation;
promise.then(function(result) { // fulfilled - continue
......@@ -57,7 +57,7 @@ promise.then(function(result) { // fulfilled - continue
});
operation = 'synchronous';
resolver.fulfill('hello');
resolve('hello');
// The chain should be executed asynchronously.
operation = 'asynchronous';
......
......@@ -2,7 +2,8 @@ Test Promise.
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 successfullyParsed is true
......
......@@ -11,9 +11,9 @@ description('Test Promise.');
window.jsTestIsAsync = true;
var firstPromise = new Promise(function(resolver) {
var firstPromise = new Promise(function(resolve) {
window.thisInInit = this;
resolver.fulfill('hello');
resolve('hello');
});
var secondPromise = firstPromise.then(function(result) {
......@@ -24,7 +24,8 @@ var thirdPromise = secondPromise.then(function(result) {
fail('Unexpected invocation of fulfillCallback');
}, function(result) {
window.thisInThenCallback = this;
shouldBeTrue('thisInThenCallback === thirdPromise');
shouldBeFalse('thisInThenCallback === thirdPromise');
shouldBeTrue('thisInThenCallback === window');
window.result = result;
shouldBeEqualToString('result', 'foobar');
finishJSTest();
......
......@@ -4,43 +4,43 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
Test Promise resolve.
PASS Then.resolve has been called
About to run test - promiseResolve
PASS Promise object should exist
PASS Promise.resolve exists
PASS Promise.reject exists
PASS Then - resolveCb has been called
PASS 42 is 42
Test Promise reject.
PASS Then.reject has been called
About to run test - promiseReject
PASS Then - rejectCb has been called
PASS 42 is 42
Test Promise reject.
PASS Then.reject has been called
About to run test - promiseException
PASS Then - rejectCb has been called
PASS 42 is 42
Test Promise gc.
About to run test - promiseGC
PASS Then - promise is still alive
Test Promise async.
Global should be foo
About to run test - promiseAsync
PASS foo is foo
Global should still be foo
PASS foo is foo
Global should still be foo (2)
PASS foo is foo
Global should be bar
PASS bar is bar
Test Promise double then.
About to run test - promiseDoubleThen
PASS Then.resolve has been called
PASS 42 is 42
PASS Then.resolve has been called
PASS 1 is 1
PASS 42 is 42
Test Promise - then / exception.
About to run test - promiseThenException
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 42 is 42
PASS Then.resolve has been called
......@@ -48,7 +48,8 @@ PASS 43 is 43
PASS Then.resolve has been called
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 42 is 42
PASS Then.resolve has been called
......@@ -56,13 +57,13 @@ PASS 43 is 43
PASS Then.resolve has been called
PASS 44 is 44
Test Promise - reject / then / catch / then (2).
PASS Catch has been called
About to run test - promiseRejectThenCatchThen2
PASS 42 is 42
PASS Catch has been called
PASS Then.resolve has been called
PASS 43 is 43
Test Promise - reject / then / catch exception / then.
About to run test - promiseRejectThenCatchExceptionThen
PASS Then.reject has been called
PASS 42 is 42
PASS Catch has been called
......@@ -70,47 +71,64 @@ PASS 43 is 43
PASS Then.resolve has been called
PASS 44 is 44
Test Promise - then / catch ordering (resolve).
Many steps... should return 2
About to run test - promiseThenCatchOrderingResolve
PASS 2 is 2
Test Promise - then / catch ordering (reject).
Many steps... should return 2
About to run test - promiseThenCatchOrderingReject
PASS 2 is 2
Test Promise - nested promise
About to run test - promiseNestedPromise
PASS Nested promise is executed
PASS Then.resolve has been called
PASS 42 is 42
Test Promise - nested-nested promise.
About to run test - promiseNestedNestedPromise
PASS Nested promise is executed
PASS Then.resolve has been called
PASS 43 is 43
Test Promise - wrong nested promise.
About to run test - promiseWrongNestedPromise
PASS Nested promise is executed
PASS Then.resolve has been called
PASS 42 is 42
Test Promise - promise loop.
About to run test - promiseLoop
PASS Nested promise is executed
PASS Nested-nested promise is executed
PASS Then.resolve has been called
PASS Nested nested promise is executed
PASS 42 is 42
Test Promise - Promise.reject().
PASS Then.reject has been called
About to run test - promiseStaticReject
PASS 42 is 42
Test Promise - Promise.resolve().
PASS Then.resolve has been called
About to run test - promiseStaticResolve
PASS 42 is 42
Test Promise - Promise.resolve() with nested promise.
About to run test - promiseResolveNestedPromise
PASS Nested promise is executed
PASS Then.resolve has been called
PASS 42 is 42
About to run test - promiseResolveNoArg
PASS Promise.resolve exists
PASS Promise.reject exists
PASS Then - resolveCb has been called
PASS undefined is undefined
About to run test - promiseRejectNoArg
PASS Then - rejectCb has been called
PASS undefined is undefined
About to run test - promiseThenNoArg
PASS [object Promise] should not be [object Promise]
PASS 42 is 42
About to run test - promiseThenUndefinedResolveFunction
PASS 42 is 42
About to run test - promiseThenNullResolveFunction
PASS 42 is 42
About to run test - promiseCatchNoArg
PASS [object Promise] should not be [object Promise]
PASS 42 is 42
About to run test - promiseRejectNoHandler
PASS successfullyParsed is true
TEST COMPLETE
......
Test Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS receiverInSloppy is window
PASS receiverInStrict is undefined
PASS successfullyParsed is true
TEST COMPLETE
......@@ -9,14 +9,17 @@
<script>
description('Test Promise.');
window.jsTestIsAsync = true;
var receiverInSloppy;
new Promise(function () {
window.receiverInSloppy = this;
shouldBe('receiverInSloppy', 'window');
});
var future = new Promise(function(resolver) {
resolver.fulfill('hello');
}).then(function(result) {
window.result = result;
shouldBeEqualToString('result', 'hello');
finishJSTest();
var receiverInStrict;
new Promise(function () {
'use strict';
window.receiverInStrict = this;
shouldBe('receiverInStrict', 'undefined');
});
</script>
......
......@@ -4,11 +4,12 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS promise instanceof Promise is true
PASS promise.constructor is Promise
PASS thisInInit is promise
PASS resolver instanceof PromiseResolver is true
PASS resolver.constructor is PromiseResolver
PASS new Promise() threw exception TypeError: Expected at least one argument.
PASS new Promise(37) threw exception TypeError: Expected function as as first argument.
PASS thisInInit === promise is false
PASS thisInInit === window is true
PASS resolve instanceof Function is true
PASS reject instanceof Function is true
PASS new Promise() threw exception TypeError: Promise constructor takes a function argument.
PASS new Promise(37) threw exception TypeError: Promise constructor takes a function argument.
PASS promise = new Promise(function() { throw Error("foo"); }) did not throw exception.
PASS result.message is "foo"
PASS fulfilled
......
......@@ -5,11 +5,12 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
Starting worker: ../resources/Promise-init-in-workers.js
PASS [Worker] promise instanceof Promise is true
PASS [Worker] promise.constructor is Promise
PASS [Worker] thisInInit is promise
PASS [Worker] resolver instanceof PromiseResolver is true
PASS [Worker] resolver.constructor is PromiseResolver
PASS [Worker] new Promise() threw exception TypeError: Expected at least one argument.
PASS [Worker] new Promise(37) threw exception TypeError: Expected function as as first argument.
PASS [Worker] thisInInit === promise is false
PASS [Worker] thisInInit === global is true
PASS [Worker] resolve instanceof Function is true
PASS [Worker] reject instanceof Function is true
PASS [Worker] new Promise() threw exception TypeError: Promise constructor takes a function argument.
PASS [Worker] new Promise(37) threw exception TypeError: Promise constructor takes a function argument.
PASS [Worker] promise = new Promise(function() { throw Error("foo"); }) did not throw exception.
PASS [Worker] result.message is "foo"
PASS [Worker] fulfilled
......
......@@ -12,20 +12,22 @@ window.jsTestIsAsync = true;
description('Test Promise.');