Commit bd760697 authored by weinig@apple.com's avatar weinig@apple.com

Add support for Promises

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

Reviewed by Darin Adler.

Source/JavaScriptCore: 

Add an initial implementation of Promises - http://dom.spec.whatwg.org/#promises.
- Despite Promises being defined in the DOM, the implementation is being put in JSC
  in preparation for the Promises eventually being defined in ECMAScript.

* CMakeLists.txt:
* DerivedSources.make:
* DerivedSources.pri:
* GNUmakefile.list.am:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
* JavaScriptCore.xcodeproj/project.pbxproj:
* Target.pri:
Add new files.

* jsc.cpp:
Update jsc's GlobalObjectMethodTable to stub out the new QueueTaskToEventLoop callback. This mean's
you can't quite use Promises with with the command line tool yet.
    
* interpreter/CallFrame.h:
(JSC::ExecState::promisePrototypeTable):
(JSC::ExecState::promiseConstructorTable):
(JSC::ExecState::promiseResolverPrototypeTable):
* runtime/VM.cpp:
(JSC::VM::VM):
(JSC::VM::~VM):
* runtime/VM.h:
Add supporting code for the new static lookup tables.

* runtime/CommonIdentifiers.h:
Add 3 new identifiers, "Promise", "PromiseResolver", and "then".

* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::reset):
(JSC::JSGlobalObject::visitChildren):
Add supporting code Promise and PromiseResolver's constructors and structures.

* runtime/JSGlobalObject.h:
(JSC::TaskContext::~TaskContext):
Add a new callback to the GlobalObjectMethodTable to post a task on the embedder's runloop.

(JSC::JSGlobalObject::promisePrototype):
(JSC::JSGlobalObject::promiseResolverPrototype):
(JSC::JSGlobalObject::promiseStructure):
(JSC::JSGlobalObject::promiseResolverStructure):
(JSC::JSGlobalObject::promiseCallbackStructure):
(JSC::JSGlobalObject::promiseWrapperCallbackStructure):
Add supporting code Promise and PromiseResolver's constructors and structures.

* runtime/JSPromise.cpp: Added.
* runtime/JSPromise.h: Added.
* runtime/JSPromiseCallback.cpp: Added.
* runtime/JSPromiseCallback.h: Added.
* runtime/JSPromiseConstructor.cpp: Added.
* runtime/JSPromiseConstructor.h: Added.
* runtime/JSPromisePrototype.cpp: Added.
* runtime/JSPromisePrototype.h: Added.
* runtime/JSPromiseResolver.cpp: Added.
* runtime/JSPromiseResolver.h: Added.
* runtime/JSPromiseResolverConstructor.cpp: Added.
* runtime/JSPromiseResolverConstructor.h: Added.
* runtime/JSPromiseResolverPrototype.cpp: Added.
* runtime/JSPromiseResolverPrototype.h: Added.
Add Promise implementation.

Source/WebCore: 

Add an initial implementation of Promises - http://dom.spec.whatwg.org/#promises.
- Despite Promises being defined in the DOM, the implementation is being put in JSC
  in preparation for the Promises eventually being defined in ECMAScript.

Tests: fast/js/Promise-already-fulfilled.html
       fast/js/Promise-already-rejected.html
       fast/js/Promise-already-resolved.html
       fast/js/Promise-catch-in-workers.html
       fast/js/Promise-catch.html
       fast/js/Promise-chain.html
       fast/js/Promise-exception.html
       fast/js/Promise-fulfill-in-workers.html
       fast/js/Promise-fulfill.html
       fast/js/Promise-init-in-workers.html
       fast/js/Promise-init.html
       fast/js/Promise-reject-in-workers.html
       fast/js/Promise-reject.html
       fast/js/Promise-resolve-chain.html
       fast/js/Promise-resolve-in-workers.html
       fast/js/Promise-resolve-with-then-exception.html
       fast/js/Promise-resolve-with-then-fulfill.html
       fast/js/Promise-resolve-with-then-reject.html
       fast/js/Promise-resolve.html
       fast/js/Promise-simple-fulfill-inside-callback.html
       fast/js/Promise-simple-fulfill.html
       fast/js/Promise-simple-in-workers.html
       fast/js/Promise-simple.html
       fast/js/Promise-static-fulfill.html
       fast/js/Promise-static-reject.html
       fast/js/Promise-static-resolve.html
       fast/js/Promise-then-in-workers.html
       fast/js/Promise-then-without-callbacks-in-workers.html
       fast/js/Promise-then-without-callbacks.html
       fast/js/Promise-then.html
       fast/js/Promise-types.html
       fast/js/Promise.html

* GNUmakefile.list.am:
* Target.pri:
* UseJSC.cmake:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSBindingsAllInOne.cpp:
Add new files.

* bindings/js/JSDOMGlobalObjectTask.cpp: Added.
(WebCore::JSGlobalObjectCallback::create):
(WebCore::JSGlobalObjectCallback::~JSGlobalObjectCallback):
(WebCore::JSGlobalObjectCallback::call):
(WebCore::JSGlobalObjectCallback::JSGlobalObjectCallback):
(WebCore::JSGlobalObjectTask::JSGlobalObjectTask):
(WebCore::JSGlobalObjectTask::~JSGlobalObjectTask):
(WebCore::JSGlobalObjectTask::performTask):
* bindings/js/JSDOMGlobalObjectTask.h: Added.
(WebCore::JSGlobalObjectTask::create):
Add a new task type to be used with the GlobalObjectMethodTable's new QueueTaskToEventLoop callback.

* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::queueTaskToEventLoop):
* bindings/js/JSDOMWindowBase.h:
Implement the GlobalObjectMethodTable callback, QueueTaskToEventLoop. 

* bindings/js/JSMainThreadExecState.h:
All using JSMainThreadExecState as a simple RAII object.

* bindings/js/JSWorkerGlobalScopeBase.cpp:
(WebCore::JSWorkerGlobalScopeBase::JSWorkerGlobalScopeBase):
(WebCore::JSWorkerGlobalScopeBase::allowsAccessFrom):
(WebCore::JSWorkerGlobalScopeBase::supportsProfiling):
(WebCore::JSWorkerGlobalScopeBase::supportsRichSourceInfo):
(WebCore::JSWorkerGlobalScopeBase::shouldInterruptScript):
(WebCore::JSWorkerGlobalScopeBase::javaScriptExperimentsEnabled):
(WebCore::JSWorkerGlobalScopeBase::queueTaskToEventLoop):
* bindings/js/JSWorkerGlobalScopeBase.h:
Add a GlobalObjectMethodTable and implement QueueTaskToEventLoop. Forward the other callbacks
to JSGlobalObject so they retain their existing behavior.

LayoutTests: 

Add tests adapted from the Mozilla and Blink projects.

* fast/js/Promise-already-fulfilled-expected.txt: Added.
* fast/js/Promise-already-fulfilled.html: Added.
* fast/js/Promise-already-rejected-expected.txt: Added.
* fast/js/Promise-already-rejected.html: Added.
* fast/js/Promise-already-resolved-expected.txt: Added.
* fast/js/Promise-already-resolved.html: Added.
* fast/js/Promise-catch-expected.txt: Added.
* fast/js/Promise-catch-in-workers-expected.txt: Added.
* fast/js/Promise-catch-in-workers.html: Added.
* fast/js/Promise-catch.html: Added.
* fast/js/Promise-chain-expected.txt: Added.
* fast/js/Promise-chain.html: Added.
* fast/js/Promise-exception-expected.txt: Added.
* fast/js/Promise-exception.html: Added.
* fast/js/Promise-expected.txt: Added.
* fast/js/Promise-fulfill-expected.txt: Added.
* fast/js/Promise-fulfill-in-workers-expected.txt: Added.
* fast/js/Promise-fulfill-in-workers.html: Added.
* fast/js/Promise-fulfill.html: Added.
* fast/js/Promise-init-expected.txt: Added.
* fast/js/Promise-init-in-workers-expected.txt: Added.
* fast/js/Promise-init-in-workers.html: Added.
* fast/js/Promise-init.html: Added.
* fast/js/Promise-reject-expected.txt: Added.
* fast/js/Promise-reject-in-workers-expected.txt: Added.
* fast/js/Promise-reject-in-workers.html: Added.
* fast/js/Promise-reject.html: Added.
* fast/js/Promise-resolve-chain-expected.txt: Added.
* fast/js/Promise-resolve-chain.html: Added.
* fast/js/Promise-resolve-expected.txt: Added.
* fast/js/Promise-resolve-in-workers-expected.txt: Added.
* fast/js/Promise-resolve-in-workers.html: Added.
* fast/js/Promise-resolve-with-then-exception-expected.txt: Added.
* fast/js/Promise-resolve-with-then-exception.html: Added.
* fast/js/Promise-resolve-with-then-fulfill-expected.txt: Added.
* fast/js/Promise-resolve-with-then-fulfill.html: Added.
* fast/js/Promise-resolve-with-then-reject-expected.txt: Added.
* fast/js/Promise-resolve-with-then-reject.html: Added.
* fast/js/Promise-resolve.html: Added.
* fast/js/Promise-simple-expected.txt: Added.
* fast/js/Promise-simple-fulfill-expected.txt: Added.
* fast/js/Promise-simple-fulfill-inside-callback-expected.txt: Added.
* fast/js/Promise-simple-fulfill-inside-callback.html: Added.
* fast/js/Promise-simple-fulfill.html: Added.
* fast/js/Promise-simple-in-workers-expected.txt: Added.
* fast/js/Promise-simple-in-workers.html: Added.
* fast/js/Promise-simple.html: Added.
* fast/js/Promise-static-fulfill-expected.txt: Added.
* fast/js/Promise-static-fulfill.html: Added.
* fast/js/Promise-static-reject-expected.txt: Added.
* fast/js/Promise-static-reject.html: Added.
* fast/js/Promise-static-resolve-expected.txt: Added.
* fast/js/Promise-static-resolve.html: Added.
* fast/js/Promise-then-expected.txt: Added.
* fast/js/Promise-then-in-workers-expected.txt: Added.
* fast/js/Promise-then-in-workers.html: Added.
* fast/js/Promise-then-without-callbacks-expected.txt: Added.
* fast/js/Promise-then-without-callbacks-in-workers-expected.txt: Added.
* fast/js/Promise-then-without-callbacks-in-workers.html: Added.
* fast/js/Promise-then-without-callbacks.html: Added.
* fast/js/Promise-then.html: Added.
* fast/js/Promise-types-expected.txt: Added.
* fast/js/Promise-types.html: Added.
* fast/js/Promise.html: Added.
* fast/js/resources/Promise-catch-in-workers.js: Added.
* fast/js/resources/Promise-fulfill-in-workers.js: Added.
* fast/js/resources/Promise-init-in-workers.js: Added.
* fast/js/resources/Promise-reject-in-workers.js: Added.
* fast/js/resources/Promise-resolve-in-workers.js: Added.
* fast/js/resources/Promise-simple-in-workers.js: Added.
* fast/js/resources/Promise-then-in-workers.js: Added.
* fast/js/resources/Promise-then-without-callbacks-in-workers.js: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154629 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 50fbb5b1
2013-08-24 Sam Weinig <sam@webkit.org>
Add support for Promises
https://bugs.webkit.org/show_bug.cgi?id=120260
Reviewed by Darin Adler.
Add tests adapted from the Mozilla and Blink projects.
* fast/js/Promise-already-fulfilled-expected.txt: Added.
* fast/js/Promise-already-fulfilled.html: Added.
* fast/js/Promise-already-rejected-expected.txt: Added.
* fast/js/Promise-already-rejected.html: Added.
* fast/js/Promise-already-resolved-expected.txt: Added.
* fast/js/Promise-already-resolved.html: Added.
* fast/js/Promise-catch-expected.txt: Added.
* fast/js/Promise-catch-in-workers-expected.txt: Added.
* fast/js/Promise-catch-in-workers.html: Added.
* fast/js/Promise-catch.html: Added.
* fast/js/Promise-chain-expected.txt: Added.
* fast/js/Promise-chain.html: Added.
* fast/js/Promise-exception-expected.txt: Added.
* fast/js/Promise-exception.html: Added.
* fast/js/Promise-expected.txt: Added.
* fast/js/Promise-fulfill-expected.txt: Added.
* fast/js/Promise-fulfill-in-workers-expected.txt: Added.
* fast/js/Promise-fulfill-in-workers.html: Added.
* fast/js/Promise-fulfill.html: Added.
* fast/js/Promise-init-expected.txt: Added.
* fast/js/Promise-init-in-workers-expected.txt: Added.
* fast/js/Promise-init-in-workers.html: Added.
* fast/js/Promise-init.html: Added.
* fast/js/Promise-reject-expected.txt: Added.
* fast/js/Promise-reject-in-workers-expected.txt: Added.
* fast/js/Promise-reject-in-workers.html: Added.
* fast/js/Promise-reject.html: Added.
* fast/js/Promise-resolve-chain-expected.txt: Added.
* fast/js/Promise-resolve-chain.html: Added.
* fast/js/Promise-resolve-expected.txt: Added.
* fast/js/Promise-resolve-in-workers-expected.txt: Added.
* fast/js/Promise-resolve-in-workers.html: Added.
* fast/js/Promise-resolve-with-then-exception-expected.txt: Added.
* fast/js/Promise-resolve-with-then-exception.html: Added.
* fast/js/Promise-resolve-with-then-fulfill-expected.txt: Added.
* fast/js/Promise-resolve-with-then-fulfill.html: Added.
* fast/js/Promise-resolve-with-then-reject-expected.txt: Added.
* fast/js/Promise-resolve-with-then-reject.html: Added.
* fast/js/Promise-resolve.html: Added.
* fast/js/Promise-simple-expected.txt: Added.
* fast/js/Promise-simple-fulfill-expected.txt: Added.
* fast/js/Promise-simple-fulfill-inside-callback-expected.txt: Added.
* fast/js/Promise-simple-fulfill-inside-callback.html: Added.
* fast/js/Promise-simple-fulfill.html: Added.
* fast/js/Promise-simple-in-workers-expected.txt: Added.
* fast/js/Promise-simple-in-workers.html: Added.
* fast/js/Promise-simple.html: Added.
* fast/js/Promise-static-fulfill-expected.txt: Added.
* fast/js/Promise-static-fulfill.html: Added.
* fast/js/Promise-static-reject-expected.txt: Added.
* fast/js/Promise-static-reject.html: Added.
* fast/js/Promise-static-resolve-expected.txt: Added.
* fast/js/Promise-static-resolve.html: Added.
* fast/js/Promise-then-expected.txt: Added.
* fast/js/Promise-then-in-workers-expected.txt: Added.
* fast/js/Promise-then-in-workers.html: Added.
* fast/js/Promise-then-without-callbacks-expected.txt: Added.
* fast/js/Promise-then-without-callbacks-in-workers-expected.txt: Added.
* fast/js/Promise-then-without-callbacks-in-workers.html: Added.
* fast/js/Promise-then-without-callbacks.html: Added.
* fast/js/Promise-then.html: Added.
* fast/js/Promise-types-expected.txt: Added.
* fast/js/Promise-types.html: Added.
* fast/js/Promise.html: Added.
* fast/js/resources/Promise-catch-in-workers.js: Added.
* fast/js/resources/Promise-fulfill-in-workers.js: Added.
* fast/js/resources/Promise-init-in-workers.js: Added.
* fast/js/resources/Promise-reject-in-workers.js: Added.
* fast/js/resources/Promise-resolve-in-workers.js: Added.
* fast/js/resources/Promise-simple-in-workers.js: Added.
* fast/js/resources/Promise-then-in-workers.js: Added.
* fast/js/resources/Promise-then-without-callbacks-in-workers.js: Added.
2013-08-26 Rob Buis <rwlbuis@webkit.org>
Computed style of fill/stroke properties incorrect on references
Test Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS result is "foo"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description('Test Promise.');
window.jsTestIsAsync = true;
new Promise(function(resolver) {
resolver.fulfill('foo');
resolver.fulfill('fulfill');
resolver.resolve('resolve');
resolver.reject('reject');
}).then(function(result) {
window.result = result;
shouldBeEqualToString('result', 'foo');
finishJSTest();
}, function() {
testFailed('rejected');
finishJSTest();
});
</script>
<script src="resources/js-test-post.js"></script>
</body>
</html>
Test Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS result is "foo"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description('Test Promise.');
window.jsTestIsAsync = true;
new Promise(function(resolver) {
resolver.reject('foo');
resolver.fulfill('fulfill');
resolver.resolve('resolve');
resolver.reject('reject');
}).then(function() {
testFailed('fulfilled');
finishJSTest();
}, function(result) {
window.result = result;
shouldBeEqualToString('result', 'foo');
finishJSTest();
});
</script>
<script src="resources/js-test-post.js"></script>
</body>
</html>
Test Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS result is "foo"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
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');
anotherResolver.fulfill('foo');
}).then(function(result) {
window.result = result;
shouldBeEqualToString('result', 'foo');
finishJSTest();
}, function() {
testFailed('rejected');
finishJSTest();
});
</script>
<script src="resources/js-test-post.js"></script>
</body>
</html>
Test Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS thisInInit === firstPromise 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 result is "hello"
PASS result is "bye"
PASS fulfilled
PASS successfullyParsed is true
TEST COMPLETE
[Worker] Test Promise.
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] 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] result is "hello"
PASS [Worker] result is "bye"
PASS [Worker] fulfilled
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
worker = startWorker('resources/Promise-catch-in-workers.js');
</script>
<script src="resources/js-test-post.js"></script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src="resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description('Test Promise.');
window.jsTestIsAsync = true;
var resolver;
var firstPromise = new Promise(function(newResolver) {
window.thisInInit = this;
resolver = newResolver;
});
var secondPromise = firstPromise.catch(function(result) {
window.thisInFulfillCallback = this;
shouldBeFalse('thisInFulfillCallback === firstPromise');
shouldBeTrue('thisInFulfillCallback === secondPromise');
window.result = result;
shouldBeEqualToString('result', 'hello');
return 'bye';
});
secondPromise.then(function(result) {
window.result = result;
shouldBeEqualToString('result', 'bye');
testPassed('fulfilled');
finishJSTest();
}, function() {
testFailed('rejected');
finishJSTest();
}, function() {
});
shouldBeTrue('thisInInit === firstPromise');
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');
</script>
<script src="resources/js-test-post.js"></script>
</body>
</html>
Test Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS fulfilled
PASS result is "hello"
PASS fulfilled
PASS result is "hello2"
PASS rejected
PASS result is "error"
PASS rejected
PASS result is "error2"
PASS fulfilled
PASS result is "recovered"
PASS operation is "asynchronous"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description('Test Promise.');
window.jsTestIsAsync = true;
var resolver;
var promise = new Promise(function (r) {resolver = r;});
var operation;
promise.then(function(result) { // fulfilled - continue
testPassed('fulfilled');
window.result = result;
shouldBeEqualToString('result', 'hello');
return 'hello2';
}, function() {
testFailed('rrejected');
}).then() // pass through
.then(function(result) { // fulfilled - throw an exception
testPassed('fulfilled');
window.result = result;
shouldBeEqualToString('result', 'hello2');
throw 'error';
}, function() {
testFailed('rejected');
}).then(function() { // rejected - throw an exception
testFailed('fulfilled');
}, function(result) {
testPassed('rejected');
window.result = result;
shouldBeEqualToString('result', 'error');
throw 'error2';
}).then() // pass through
.then(function() { // rejected - recover
testFailed('fulfilled');
}, function(result) {
testPassed('rejected');
window.result = result;
shouldBeEqualToString('result', 'error2');
return 'recovered';
}).then(function(result) { // fulfilled - the last
testPassed('fulfilled');
window.result = result;
shouldBeEqualToString('result', 'recovered');
shouldBeEqualToString('operation', 'asynchronous');
finishJSTest();
}, function() {
testFailed('rejected');
finishJSTest();
});
operation = 'synchronous';
resolver.fulfill('hello');
// The chain should be executed asynchronously.
operation = 'asynchronous';
</script>
<script src="resources/js-test-post.js"></script>
</body>
</html>
Test Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS thisInThenCallback === thirdPromise is true
PASS result is "foobar"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description('Test Promise.');
window.jsTestIsAsync = true;
var firstPromise = new Promise(function(resolver) {
window.thisInInit = this;
resolver.fulfill('hello');
});
var secondPromise = firstPromise.then(function(result) {
throw 'foobar';
});
var thirdPromise = secondPromise.then(function(result) {
fail('Unexpected invocation of fulfillCallback');
}, function(result) {
window.thisInThenCallback = this;
shouldBeTrue('thisInThenCallback === thirdPromise');
window.result = result;
shouldBeEqualToString('result', 'foobar');
finishJSTest();
});
</script>
<script src="resources/js-test-post.js"></script>
</body>
</html>
Promises - Adapted from http://dxr.mozilla.org/mozilla-central/source/dom/promise/tests/test_promise.html.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Test Promise resolve.
PASS Then.resolve has been called
PASS 42 is 42
Test Promise reject.
PASS Then.reject has been called
PASS 42 is 42
Test Promise reject.
PASS Then.reject has been called
PASS 42 is 42
Test Promise gc.
PASS Then - promise is still alive
Test Promise async.
Global should be foo
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.
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.
PASS Then.resolve has been called
PASS Catch handler (e.g. the reject handler) called.
Test Promise - then / catch / then.
PASS Then.resolve has been called
PASS 42 is 42
PASS Then.resolve has been called
PASS 43 is 43
PASS Then.resolve has been called
PASS 44 is 44
Test Promise - reject / then / catch / then.
PASS Then.reject has been called
PASS 42 is 42
PASS Then.resolve has been called
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
PASS 42 is 42
PASS Then.resolve has been called
PASS 43 is 43
Test Promise - reject / then / catch exception / then.
PASS Then.reject has been called
PASS 42 is 42
PASS Catch has been called
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
PASS 2 is 2
Test Promise - then / catch ordering (reject).
Many steps... should return 2
PASS 2 is 2
Test Promise - nested promise
PASS Nested promise is executed
PASS Then.resolve has been called
PASS 42 is 42
Test Promise - nested-nested promise.
PASS Nested promise is executed
PASS Then.resolve has been called
PASS 43 is 43
Test Promise - wrong nested promise.
PASS Nested promise is executed
PASS Then.resolve has been called
PASS 42 is 42
Test Promise - promise loop.
PASS Nested promise is executed
PASS Nested-nested promise is executed
PASS Then.resolve has been called
PASS 42 is 42
Test Promise - Promise.reject().
PASS Then.reject has been called
PASS 42 is 42
Test Promise - Promise.resolve().
PASS Then.resolve has been called
PASS 42 is 42
Test Promise - Promise.resolve() with nested promise.
PASS Nested promise is executed
PASS Then.resolve has been called
PASS 42 is 42
PASS successfullyParsed is true
TEST COMPLETE
Test Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS promiseState is "pending"
PASS promiseState is "pending"
PASS promiseState is "fu