[ES6] Implement the latest Promise spec in JS
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Jul 2015 02:01:27 +0000 (02:01 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Jul 2015 02:01:27 +0000 (02:01 +0000)
commitc38fc7ba2c73dd5c0e67d7a66202f6930fc84320
tree851341d9a7fe7a85a968267b765c456360fa0cf7
parent6ff4764541d995f1a54a80a7c4f072999011eeec
[ES6] Implement the latest Promise spec in JS
https://bugs.webkit.org/show_bug.cgi?id=146229

Reviewed by Sam Weinig.

Source/JavaScriptCore:

Updated the Promise implementation to meet to the ES6 spec.
This patch
1. Implement ES6 Promise and related abstract operations in builtins JS
2. Expose @enqueueJob private function to JS world to post the microtask

Updated implementation has one-on-one correspondence to the ES6 spec description.
And keep the JSPromiseDeferred because it is the interface used from the WebCore.

* CMakeLists.txt:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
* JavaScriptCore.xcodeproj/project.pbxproj:
* builtins/Array.prototype.js:
(reduce):
(reduceRight):
(every):
(forEach):
(filter):
(map):
(some):
(fill):
(find):
(findIndex):
(includes):
(copyWithin):
ToInteger / ToLength are renamed to toInteger and toLength.
* builtins/ArrayConstructor.js:
(from):
ToInteger / ToLength are renamed to toInteger and toLength.
* builtins/GlobalObject.js:
(toInteger):
(toLength):
(isObject):
(ToInteger): Deleted.
(ToLength): Deleted.
ToInteger / ToLength are renamed to toInteger and toLength.
Add new abstract operation, isObject.
* builtins/Operations.Promise.js: Added.
(isPromise):
(newPromiseReaction):
(newPromiseDeferred):
(newPromiseCapability.executor):
(newPromiseCapability):
(triggerPromiseReactions):
(rejectPromise):
(fulfillPromise):
(createResolvingFunctions.resolve):
(createResolvingFunctions.reject):
(createResolvingFunctions):
(promiseReactionJob):
(promiseResolveThenableJob):
(initializePromise):
Added Promise related abstract operations.
* builtins/Promise.prototype.js:
(catch):
(.onFulfilled):
(.onRejected):
(then):
Promise#then implementation in JS.
* builtins/PromiseConstructor.js: Added.
(all.newResolveElement):
(all):
(race):
(reject):
(resolve):
Promise static functions implementations in JS.
* builtins/StringConstructor.js:
(raw):
ToInteger / ToLength are renamed to toInteger and toLength.
* inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::getInternalProperties):
* runtime/CommonIdentifiers.h:
* runtime/JSGlobalObject.cpp:
(JSC::enqueueJob):
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::initializePromiseFunction):
(JSC::JSGlobalObject::newPromiseDeferredFunction):
* runtime/JSJob.cpp: Renamed from Source/JavaScriptCore/runtime/JSPromiseReaction.h.
(JSC::createJSJob):
(JSC::JSJobMicrotask::run):
* runtime/JSJob.h: Renamed from Source/JavaScriptCore/runtime/JSPromiseFunctions.h.
* runtime/JSPromise.cpp:
(JSC::JSPromise::create):
(JSC::JSPromise::JSPromise):
(JSC::JSPromise::finishCreation):
(JSC::JSPromise::result):
(JSC::JSPromise::destroy): Deleted.
(JSC::JSPromise::visitChildren): Deleted.
(JSC::JSPromise::reject): Deleted.
(JSC::JSPromise::resolve): Deleted.
(JSC::JSPromise::appendResolveReaction): Deleted.
(JSC::JSPromise::appendRejectReaction): Deleted.
(JSC::triggerPromiseReactions): Deleted.
* runtime/JSPromise.h:
(JSC::JSPromise::status): Deleted.
(JSC::JSPromise::result): Deleted.
(JSC::JSPromise::constructor): Deleted.
* runtime/JSPromiseConstructor.cpp:
(JSC::constructPromise):
(JSC::JSPromiseConstructorFuncResolve): Deleted.
(JSC::JSPromiseConstructorFuncReject): Deleted.
(JSC::performPromiseRaceLoop): Deleted.
(JSC::JSPromiseConstructorFuncRace): Deleted.
(JSC::performPromiseAll): Deleted.
(JSC::JSPromiseConstructorFuncAll): Deleted.
* runtime/JSPromiseDeferred.cpp:
(JSC::JSPromiseDeferred::create):
(JSC::createJSPromiseDeferredFromConstructor): Deleted.
(JSC::updateDeferredFromPotentialThenable): Deleted.
(JSC::performDeferredResolve): Deleted.
(JSC::performDeferredReject): Deleted.
(JSC::abruptRejection): Deleted.
* runtime/JSPromiseDeferred.h:
* runtime/JSPromiseFunctions.cpp: Removed.
(JSC::deferredConstructionFunction): Deleted.
(JSC::createDeferredConstructionFunction): Deleted.
(JSC::identifyFunction): Deleted.
(JSC::createIdentifyFunction): Deleted.
(JSC::promiseAllCountdownFunction): Deleted.
(JSC::createPromiseAllCountdownFunction): Deleted.
(JSC::promiseResolutionHandlerFunction): Deleted.
(JSC::createPromiseResolutionHandlerFunction): Deleted.
(JSC::rejectPromiseFunction): Deleted.
(JSC::createRejectPromiseFunction): Deleted.
(JSC::resolvePromiseFunction): Deleted.
(JSC::createResolvePromiseFunction): Deleted.
(JSC::throwerFunction): Deleted.
(JSC::createThrowerFunction): Deleted.
* runtime/JSPromisePrototype.cpp:
(JSC::JSPromisePrototypeFuncThen): Deleted.
* runtime/JSPromiseReaction.cpp: Removed.
(JSC::createExecutePromiseReactionMicrotask): Deleted.
(JSC::ExecutePromiseReactionMicrotask::run): Deleted.
(JSC::JSPromiseReaction::create): Deleted.
(JSC::JSPromiseReaction::JSPromiseReaction): Deleted.
(JSC::JSPromiseReaction::finishCreation): Deleted.
(JSC::JSPromiseReaction::visitChildren): Deleted.
* runtime/VM.cpp:
(JSC::VM::VM): Deleted.
* runtime/VM.h:

LayoutTests:

Add a test to guarantee that `Promise.resolve` looks up `then` field synchronously.

* js/dom/Promise-resolve-lookup-then-expected.txt: Added.
* js/dom/Promise-resolve-lookup-then.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@186298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
31 files changed:
LayoutTests/ChangeLog
LayoutTests/js/dom/Promise-resolve-lookup-then-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/Promise-resolve-lookup-then.html [new file with mode: 0644]
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj
Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/builtins/Array.prototype.js
Source/JavaScriptCore/builtins/ArrayConstructor.js
Source/JavaScriptCore/builtins/GlobalObject.js
Source/JavaScriptCore/builtins/Operations.Promise.js [new file with mode: 0644]
Source/JavaScriptCore/builtins/Promise.prototype.js
Source/JavaScriptCore/builtins/PromiseConstructor.js [new file with mode: 0644]
Source/JavaScriptCore/builtins/StringConstructor.js
Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
Source/JavaScriptCore/runtime/CommonIdentifiers.h
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h
Source/JavaScriptCore/runtime/JSJob.cpp [moved from Source/JavaScriptCore/runtime/JSPromiseReaction.h with 54% similarity]
Source/JavaScriptCore/runtime/JSJob.h [moved from Source/JavaScriptCore/runtime/JSPromiseFunctions.h with 69% similarity]
Source/JavaScriptCore/runtime/JSPromise.cpp
Source/JavaScriptCore/runtime/JSPromise.h
Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp
Source/JavaScriptCore/runtime/JSPromiseDeferred.cpp
Source/JavaScriptCore/runtime/JSPromiseDeferred.h
Source/JavaScriptCore/runtime/JSPromiseFunctions.cpp [deleted file]
Source/JavaScriptCore/runtime/JSPromisePrototype.cpp
Source/JavaScriptCore/runtime/JSPromiseReaction.cpp [deleted file]
Source/JavaScriptCore/runtime/VM.cpp
Source/JavaScriptCore/runtime/VM.h