Add InternalPromise to use Promises safely in the internals
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Aug 2015 04:43:24 +0000 (04:43 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Aug 2015 04:43:24 +0000 (04:43 +0000)
commit5582b800b1d7c0dbcaaf0f4d8d18b277faf7cbe8
tree650568c363f3fe6912df4964ee4da7deedd72bb8
parent7309755256ba1dac8bcae74405bf4898cbd02baa
Add InternalPromise to use Promises safely in the internals
https://bugs.webkit.org/show_bug.cgi?id=148136

Reviewed by Saam Barati.

This patch implements InternalPromise.
It is completely different instance set (constructor, prototype, instance)
but it has the same feature to the Promise.

In the Promise operations, when resolving the promise with the returned promise
from the fulfill handler, we need to look up "then" method.

e.g.
    var p3 = p1.then(function handler(...) {
        return p2;
    });

When handler is executed, we retrieve the returned `p2` promise. And to resolve
the returned promise by "then" method (that is `p3`), we construct the chain by executing
`p2.then(resolving function for p3)`. So if the user modify the Promise.prototype.then,
we can observe the internal operations.

By using InternalPromise, we completely hide InternalPromise.prototype from the users.
It allows JSC to use Promises internally; even if the user modify / override
the Promise.prototype.then function, it does not effect on InternalPromise.

One limitation is that the implementation need to take care not to leak the InternalPromise instance
to the user space.

* CMakeLists.txt:
* DerivedSources.make:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
* JavaScriptCore.xcodeproj/project.pbxproj:
* builtins/InternalPromiseConstructor.js: Added.
(internalAll.newResolveElement):
(internalAll):
* builtins/Operations.Promise.js:
(newPromiseDeferred): Deleted.
* builtins/PromiseConstructor.js:
(privateAll.newResolveElement): Deleted.
(privateAll): Deleted.
* runtime/CommonIdentifiers.h:
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::promiseConstructor):
(JSC::JSGlobalObject::internalPromiseConstructor):
(JSC::JSGlobalObject::newPromiseCapabilityFunction):
(JSC::JSGlobalObject::newPromiseDeferredFunction): Deleted.
* runtime/JSInternalPromise.cpp: Copied from Source/JavaScriptCore/runtime/JSPromisePrototype.h.
(JSC::JSInternalPromise::create):
(JSC::JSInternalPromise::createStructure):
(JSC::JSInternalPromise::JSInternalPromise):
* runtime/JSInternalPromise.h: Copied from Source/JavaScriptCore/runtime/JSPromise.h.
* runtime/JSInternalPromiseConstructor.cpp: Added.
(JSC::JSInternalPromiseConstructor::create):
(JSC::JSInternalPromiseConstructor::createStructure):
(JSC::JSInternalPromiseConstructor::JSInternalPromiseConstructor):
(JSC::constructPromise):
(JSC::JSInternalPromiseConstructor::getConstructData):
(JSC::JSInternalPromiseConstructor::getCallData):
(JSC::JSInternalPromiseConstructor::getOwnPropertySlot):
* runtime/JSInternalPromiseConstructor.h: Copied from Source/JavaScriptCore/runtime/JSPromiseConstructor.h.
* runtime/JSInternalPromiseDeferred.cpp: Added.
(JSC::JSInternalPromiseDeferred::create):
(JSC::JSInternalPromiseDeferred::JSInternalPromiseDeferred):
(JSC::JSInternalPromiseDeferred::promise):
* runtime/JSInternalPromiseDeferred.h: Copied from Source/JavaScriptCore/runtime/JSPromisePrototype.h.
* runtime/JSInternalPromisePrototype.cpp: Copied from Source/JavaScriptCore/runtime/JSPromisePrototype.cpp.
(JSC::JSInternalPromisePrototype::create):
(JSC::JSInternalPromisePrototype::createStructure):
(JSC::JSInternalPromisePrototype::JSInternalPromisePrototype):
* runtime/JSInternalPromisePrototype.h: Copied from Source/JavaScriptCore/runtime/JSPromise.h.
* runtime/JSPromise.cpp:
(JSC::JSPromise::create):
(JSC::JSPromise::JSPromise):
(JSC::JSPromise::initialize):
* runtime/JSPromise.h:
* runtime/JSPromiseConstructor.cpp:
(JSC::JSPromiseConstructor::JSPromiseConstructor):
(JSC::constructPromise):
(JSC::JSPromiseConstructor::getOwnPropertySlot):
(JSC::JSPromiseConstructor::finishCreation): Deleted.
* runtime/JSPromiseConstructor.h:
* runtime/JSPromiseDeferred.cpp:
(JSC::newPromiseCapability):
(JSC::JSPromiseDeferred::create):
(JSC::JSPromiseDeferred::JSPromiseDeferred):
* runtime/JSPromiseDeferred.h:
* runtime/JSPromisePrototype.cpp:
(JSC::JSPromisePrototype::getOwnPropertySlot):
* runtime/JSPromisePrototype.h:
* runtime/VM.cpp:
(JSC::VM::VM):
* runtime/VM.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@188681 268f45cc-cd09-0410-ab3c-d52691b4dbfc
30 files changed:
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/DerivedSources.make
Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj
Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/builtins/InternalPromiseConstructor.js [new file with mode: 0644]
Source/JavaScriptCore/builtins/Operations.Promise.js
Source/JavaScriptCore/builtins/PromiseConstructor.js
Source/JavaScriptCore/runtime/CommonIdentifiers.h
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h
Source/JavaScriptCore/runtime/JSInternalPromise.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSInternalPromise.h [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSInternalPromiseConstructor.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSInternalPromiseConstructor.h [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSInternalPromiseDeferred.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSInternalPromiseDeferred.h [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSInternalPromisePrototype.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSInternalPromisePrototype.h [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSPromise.cpp
Source/JavaScriptCore/runtime/JSPromise.h
Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp
Source/JavaScriptCore/runtime/JSPromiseConstructor.h
Source/JavaScriptCore/runtime/JSPromiseDeferred.cpp
Source/JavaScriptCore/runtime/JSPromiseDeferred.h
Source/JavaScriptCore/runtime/JSPromisePrototype.cpp
Source/JavaScriptCore/runtime/JSPromisePrototype.h
Source/JavaScriptCore/runtime/VM.cpp
Source/JavaScriptCore/runtime/VM.h