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
diff --git a/Source/JavaScriptCore/CMakeLists.txt b/Source/JavaScriptCore/CMakeLists.txt
index 501d2a5..9979c17 100644
--- a/Source/JavaScriptCore/CMakeLists.txt
+++ b/Source/JavaScriptCore/CMakeLists.txt
@@ -334,6 +334,13 @@
runtime/JSNotAnObject.cpp
runtime/JSONObject.cpp
runtime/JSObject.cpp
+ runtime/JSPromise.cpp
+ runtime/JSPromiseCallback.cpp
+ runtime/JSPromiseConstructor.cpp
+ runtime/JSPromisePrototype.cpp
+ runtime/JSPromiseResolver.cpp
+ runtime/JSPromiseResolverConstructor.cpp
+ runtime/JSPromiseResolverPrototype.cpp
runtime/JSPropertyNameIterator.cpp
runtime/JSProxy.cpp
runtime/JSScope.cpp
@@ -415,6 +422,9 @@
runtime/JSDataViewPrototype.cpp
runtime/JSGlobalObject.cpp
runtime/JSONObject.cpp
+ runtime/JSPromiseConstructor.cpp
+ runtime/JSPromisePrototype.cpp
+ runtime/JSPromiseResolverPrototype.cpp
runtime/NamePrototype.cpp
runtime/NumberConstructor.cpp
runtime/NumberPrototype.cpp
diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog
index 55afd46..6736d53 100644
--- a/Source/JavaScriptCore/ChangeLog
+++ b/Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,73 @@
+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 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.
+
2013-08-26 Zan Dobersek <zdobersek@igalia.com>
Plenty of -Wcast-align warnings in KeywordLookup.h
diff --git a/Source/JavaScriptCore/DerivedSources.make b/Source/JavaScriptCore/DerivedSources.make
index a2fe0cc..b66fbcb 100644
--- a/Source/JavaScriptCore/DerivedSources.make
+++ b/Source/JavaScriptCore/DerivedSources.make
@@ -44,6 +44,9 @@
JSDataViewPrototype.lut.h \
JSONObject.lut.h \
JSGlobalObject.lut.h \
+ JSPromisePrototype.lut.h \
+ JSPromiseConstructor.lut.h \
+ JSPromiseResolverPrototype.lut.h \
KeywordLookup.h \
Lexer.lut.h \
NamePrototype.lut.h \
diff --git a/Source/JavaScriptCore/DerivedSources.pri b/Source/JavaScriptCore/DerivedSources.pri
index 7b15e73..e154251 100644
--- a/Source/JavaScriptCore/DerivedSources.pri
+++ b/Source/JavaScriptCore/DerivedSources.pri
@@ -16,6 +16,9 @@
runtime/JSDataViewPrototype.cpp \
runtime/JSGlobalObject.cpp \
runtime/JSONObject.cpp \
+ runtime/JSPromiseConstructor.cpp \
+ runtime/JSPromisePrototype.cpp \
+ runtime/JSPromiseResolverPrototype.cpp \
runtime/MathObject.cpp \
runtime/NamePrototype.cpp \
runtime/NumberConstructor.cpp \
diff --git a/Source/JavaScriptCore/GNUmakefile.list.am b/Source/JavaScriptCore/GNUmakefile.list.am
index 2ad431fd..4f70ab3 100644
--- a/Source/JavaScriptCore/GNUmakefile.list.am
+++ b/Source/JavaScriptCore/GNUmakefile.list.am
@@ -20,6 +20,9 @@
DerivedSources/JavaScriptCore/JSDataViewPrototype.lut.h \
DerivedSources/JavaScriptCore/JSGlobalObject.lut.h \
DerivedSources/JavaScriptCore/JSONObject.lut.h \
+ DerivedSources/JavaScriptCore/JSPromiseConstructor.lut.h \
+ DerivedSources/JavaScriptCore/JSPromisePrototype.lut.h \
+ DerivedSources/JavaScriptCore/JSPromiseResolverPrototype.lut.h \
DerivedSources/JavaScriptCore/MathObject.lut.h \
DerivedSources/JavaScriptCore/NamePrototype.lut.h \
DerivedSources/JavaScriptCore/NumberConstructor.lut.h \
@@ -811,6 +814,20 @@
Source/JavaScriptCore/runtime/JSObject.h \
Source/JavaScriptCore/runtime/JSONObject.cpp \
Source/JavaScriptCore/runtime/JSONObject.h \
+ Source/JavaScriptCore/runtime/JSPromise.cpp \
+ Source/JavaScriptCore/runtime/JSPromise.h \
+ Source/JavaScriptCore/runtime/JSPromiseCallback.cpp \
+ Source/JavaScriptCore/runtime/JSPromiseCallback.h \
+ Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp \
+ Source/JavaScriptCore/runtime/JSPromiseConstructor.h \
+ Source/JavaScriptCore/runtime/JSPromisePrototype.cpp \
+ Source/JavaScriptCore/runtime/JSPromisePrototype.h \
+ Source/JavaScriptCore/runtime/JSPromiseResolver.cpp \
+ Source/JavaScriptCore/runtime/JSPromiseResolver.h \
+ Source/JavaScriptCore/runtime/JSPromiseResolverConstructor.cpp \
+ Source/JavaScriptCore/runtime/JSPromiseResolverConstructor.h \
+ Source/JavaScriptCore/runtime/JSPromiseResolverPrototype.cpp \
+ Source/JavaScriptCore/runtime/JSPromiseResolverPrototype.h \
Source/JavaScriptCore/runtime/JSPropertyNameIterator.cpp \
Source/JavaScriptCore/runtime/JSPropertyNameIterator.h \
Source/JavaScriptCore/runtime/JSSegmentedVariableObject.cpp \
diff --git a/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj b/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj
index f0fb39c..a60c112 100644
--- a/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj
+++ b/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj
@@ -468,6 +468,13 @@
<ClCompile Include="..\runtime\JSNotAnObject.cpp" />
<ClCompile Include="..\runtime\JSONObject.cpp" />
<ClCompile Include="..\runtime\JSObject.cpp" />
+ <ClInclude Include="..\runtime\JSPromise.cpp" />
+ <ClInclude Include="..\runtime\JSPromiseCallback.cpp" />
+ <ClInclude Include="..\runtime\JSPromiseConstructor.cpp" />
+ <ClInclude Include="..\runtime\JSPromisePrototype.cpp" />
+ <ClInclude Include="..\runtime\JSPromiseResolver.cpp" />
+ <ClInclude Include="..\runtime\JSPromiseResolverConstructor.cpp" />
+ <ClInclude Include="..\runtime\JSPromiseResolverPrototype.cpp" />
<ClCompile Include="..\runtime\JSPropertyNameIterator.cpp" />
<ClCompile Include="..\runtime\JSProxy.cpp" />
<ClCompile Include="..\runtime\JSScope.cpp" />
@@ -543,6 +550,9 @@
<ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSDataViewPrototype.lut.h" />
<ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSGlobalObject.lut.h" />
<ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSONObject.lut.h" />
+ <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSPromiseConstructor.lut.h" />
+ <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSPromisePrototype.lut.h" />
+ <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSPromiseResolverPrototype.lut.h" />
<ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\Lexer.lut.h" />
<ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\LLIntAssembly.h" />
<ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\NumberConstructor.lut.h" />
@@ -880,6 +890,13 @@
<ClInclude Include="..\runtime\JSNotAnObject.h" />
<ClInclude Include="..\runtime\JSONObject.h" />
<ClInclude Include="..\runtime\JSObject.h" />
+ <ClInclude Include="..\runtime\JSPromise.h" />
+ <ClInclude Include="..\runtime\JSPromiseCallback.h" />
+ <ClInclude Include="..\runtime\JSPromiseConstructor.h" />
+ <ClInclude Include="..\runtime\JSPromisePrototype.h" />
+ <ClInclude Include="..\runtime\JSPromiseResolver.h" />
+ <ClInclude Include="..\runtime\JSPromiseResolverConstructor.h" />
+ <ClInclude Include="..\runtime\JSPromiseResolverPrototype.h" />
<ClInclude Include="..\runtime\JSPropertyNameIterator.h" />
<ClInclude Include="..\runtime\JSProxy.h" />
<ClInclude Include="..\runtime\JSScope.h" />
diff --git a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj b/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
index f99a5d8..2b6ea3e 100644
--- a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
+++ b/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
@@ -649,6 +649,20 @@
65C02850171795E200351E35 /* ARMv7Disassembler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65C0284F171795E200351E35 /* ARMv7Disassembler.cpp */; };
65C0285C1717966800351E35 /* ARMv7DOpcode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65C0285A1717966800351E35 /* ARMv7DOpcode.cpp */; };
65C0285D1717966800351E35 /* ARMv7DOpcode.h in Headers */ = {isa = PBXBuildFile; fileRef = 65C0285B1717966800351E35 /* ARMv7DOpcode.h */; };
+ 7C15F65D17C199CE00794D40 /* JSPromiseCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C15F65B17C199CE00794D40 /* JSPromiseCallback.cpp */; };
+ 7C15F65E17C199CE00794D40 /* JSPromiseCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C15F65C17C199CE00794D40 /* JSPromiseCallback.h */; };
+ 7C184E1A17BEDBD3007CB63A /* JSPromise.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C184E1817BEDBD3007CB63A /* JSPromise.cpp */; };
+ 7C184E1B17BEDBD3007CB63A /* JSPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C184E1917BEDBD3007CB63A /* JSPromise.h */; };
+ 7C184E1E17BEE22E007CB63A /* JSPromisePrototype.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C184E1C17BEE22E007CB63A /* JSPromisePrototype.cpp */; };
+ 7C184E1F17BEE22E007CB63A /* JSPromisePrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C184E1D17BEE22E007CB63A /* JSPromisePrototype.h */; };
+ 7C184E2217BEE240007CB63A /* JSPromiseConstructor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C184E2017BEE240007CB63A /* JSPromiseConstructor.cpp */; };
+ 7C184E2317BEE240007CB63A /* JSPromiseConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C184E2117BEE240007CB63A /* JSPromiseConstructor.h */; };
+ 7C3BA29417C039560072DDC9 /* JSPromiseResolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C3BA28E17C039560072DDC9 /* JSPromiseResolver.cpp */; };
+ 7C3BA29517C039560072DDC9 /* JSPromiseResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C3BA28F17C039560072DDC9 /* JSPromiseResolver.h */; };
+ 7C3BA29617C039560072DDC9 /* JSPromiseResolverConstructor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C3BA29017C039560072DDC9 /* JSPromiseResolverConstructor.cpp */; };
+ 7C3BA29717C039560072DDC9 /* JSPromiseResolverConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C3BA29117C039560072DDC9 /* JSPromiseResolverConstructor.h */; };
+ 7C3BA29817C039560072DDC9 /* JSPromiseResolverPrototype.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C3BA29217C039560072DDC9 /* JSPromiseResolverPrototype.cpp */; };
+ 7C3BA29917C039560072DDC9 /* JSPromiseResolverPrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C3BA29317C039560072DDC9 /* JSPromiseResolverPrototype.h */; };
7E4EE7090EBB7963005934AA /* StructureChain.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E4EE7080EBB7963005934AA /* StructureChain.h */; settings = {ATTRIBUTES = (Private, ); }; };
7E4EE70F0EBB7A5B005934AA /* StructureChain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E4EE70E0EBB7A5B005934AA /* StructureChain.cpp */; };
7EFF00640EC05A9A00AA7C93 /* NodeInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EFF00630EC05A9A00AA7C93 /* NodeInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1012,8 +1026,6 @@
BC18C46B0E16F5CD00B34460 /* SymbolTable.h in Headers */ = {isa = PBXBuildFile; fileRef = 14A396A60CD2933100B5B4FF /* SymbolTable.h */; settings = {ATTRIBUTES = (Private, ); }; };
BC18C47A0E16F5CD00B34460 /* WebKitAvailability.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DE3D0F40DD8DDFB00468714 /* WebKitAvailability.h */; settings = {ATTRIBUTES = (Public, ); }; };
BC18C5240E16FC8A00B34460 /* ArrayPrototype.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = BC18C5230E16FC8A00B34460 /* ArrayPrototype.lut.h */; };
- BC18C5260E16FCA700B34460 /* StringPrototype.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = BC18C5250E16FCA700B34460 /* StringPrototype.lut.h */; };
- BC18C52A0E16FCC200B34460 /* MathObject.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = BC18C5290E16FCC200B34460 /* MathObject.lut.h */; };
BC18C52C0E16FCD200B34460 /* RegExpObject.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = BC18C52B0E16FCD200B34460 /* RegExpObject.lut.h */; };
BC18C52E0E16FCE100B34460 /* Lexer.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = BC18C52D0E16FCE100B34460 /* Lexer.lut.h */; };
BC257DE80E1F51C50016B6C9 /* Arguments.h in Headers */ = {isa = PBXBuildFile; fileRef = BC257DE60E1F51C50016B6C9 /* Arguments.h */; };
@@ -1779,6 +1791,23 @@
65EA73620BAE35D1001BB560 /* CommonIdentifiers.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = CommonIdentifiers.cpp; sourceTree = "<group>"; };
65EA73630BAE35D1001BB560 /* CommonIdentifiers.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CommonIdentifiers.h; sourceTree = "<group>"; };
704FD35305697E6D003DBED9 /* BooleanObject.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = BooleanObject.h; sourceTree = "<group>"; tabWidth = 8; };
+ 7C15F65B17C199CE00794D40 /* JSPromiseCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPromiseCallback.cpp; sourceTree = "<group>"; };
+ 7C15F65C17C199CE00794D40 /* JSPromiseCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPromiseCallback.h; sourceTree = "<group>"; };
+ 7C184E1817BEDBD3007CB63A /* JSPromise.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPromise.cpp; sourceTree = "<group>"; };
+ 7C184E1917BEDBD3007CB63A /* JSPromise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPromise.h; sourceTree = "<group>"; };
+ 7C184E1C17BEE22E007CB63A /* JSPromisePrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPromisePrototype.cpp; sourceTree = "<group>"; };
+ 7C184E1D17BEE22E007CB63A /* JSPromisePrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPromisePrototype.h; sourceTree = "<group>"; };
+ 7C184E2017BEE240007CB63A /* JSPromiseConstructor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPromiseConstructor.cpp; sourceTree = "<group>"; };
+ 7C184E2117BEE240007CB63A /* JSPromiseConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPromiseConstructor.h; sourceTree = "<group>"; };
+ 7C184E2417BFFA36007CB63A /* JSPromiseConstructor.lut.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSPromiseConstructor.lut.h; sourceTree = "<group>"; };
+ 7C184E2517BFFA36007CB63A /* JSPromisePrototype.lut.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSPromisePrototype.lut.h; sourceTree = "<group>"; };
+ 7C3BA28E17C039560072DDC9 /* JSPromiseResolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPromiseResolver.cpp; sourceTree = "<group>"; };
+ 7C3BA28F17C039560072DDC9 /* JSPromiseResolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPromiseResolver.h; sourceTree = "<group>"; };
+ 7C3BA29017C039560072DDC9 /* JSPromiseResolverConstructor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPromiseResolverConstructor.cpp; sourceTree = "<group>"; };
+ 7C3BA29117C039560072DDC9 /* JSPromiseResolverConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPromiseResolverConstructor.h; sourceTree = "<group>"; };
+ 7C3BA29217C039560072DDC9 /* JSPromiseResolverPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPromiseResolverPrototype.cpp; sourceTree = "<group>"; };
+ 7C3BA29317C039560072DDC9 /* JSPromiseResolverPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPromiseResolverPrototype.h; sourceTree = "<group>"; };
+ 7C3BA29A17C03BE10072DDC9 /* JSPromiseResolverPrototype.lut.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSPromiseResolverPrototype.lut.h; sourceTree = "<group>"; };
7E4EE7080EBB7963005934AA /* StructureChain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StructureChain.h; sourceTree = "<group>"; };
7E4EE70E0EBB7A5B005934AA /* StructureChain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StructureChain.cpp; sourceTree = "<group>"; };
7EFF00630EC05A9A00AA7C93 /* NodeInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeInfo.h; sourceTree = "<group>"; };
@@ -2121,8 +2150,6 @@
BC18C3C50E16EE3300B34460 /* StringPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringPrototype.cpp; sourceTree = "<group>"; };
BC18C3C60E16EE3300B34460 /* StringPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringPrototype.h; sourceTree = "<group>"; };
BC18C5230E16FC8A00B34460 /* ArrayPrototype.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArrayPrototype.lut.h; sourceTree = "<group>"; };
- BC18C5250E16FCA700B34460 /* StringPrototype.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringPrototype.lut.h; sourceTree = "<group>"; };
- BC18C5290E16FCC200B34460 /* MathObject.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathObject.lut.h; sourceTree = "<group>"; };
BC18C52B0E16FCD200B34460 /* RegExpObject.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RegExpObject.lut.h; sourceTree = "<group>"; };
BC18C52D0E16FCE100B34460 /* Lexer.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Lexer.lut.h; sourceTree = "<group>"; };
BC22A3980E16E14800AF21C8 /* JSObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSObject.cpp; sourceTree = "<group>"; };
@@ -2156,7 +2183,6 @@
BC7952340E15EB5600A898AB /* BooleanPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BooleanPrototype.cpp; sourceTree = "<group>"; };
BC7952350E15EB5600A898AB /* BooleanPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BooleanPrototype.h; sourceTree = "<group>"; };
BC7F8FBA0E19D1EF008632C0 /* JSCell.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCell.cpp; sourceTree = "<group>"; };
- BC8149AF12F89F53007B2C32 /* HeaderDetection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HeaderDetection.h; sourceTree = "<group>"; };
BC87CDB810712ACA000614CF /* JSONObject.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSONObject.lut.h; sourceTree = "<group>"; };
BC8F3CCF0DAF17BA00577A80 /* ConstructData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConstructData.h; sourceTree = "<group>"; };
BC9041470EB9250900FE26FA /* StructureTransitionTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StructureTransitionTable.h; sourceTree = "<group>"; };
@@ -2865,18 +2891,18 @@
650FDF8D09D0FCA700769E54 /* Derived Sources */ = {
isa = PBXGroup;
children = (
+ 7C3BA29A17C03BE10072DDC9 /* JSPromiseResolverPrototype.lut.h */,
BC18C5230E16FC8A00B34460 /* ArrayPrototype.lut.h */,
BCD203E70E1718F4002C7E82 /* DatePrototype.lut.h */,
- BC8149AF12F89F53007B2C32 /* HeaderDetection.h */,
BC87CDB810712ACA000614CF /* JSONObject.lut.h */,
+ 7C184E2417BFFA36007CB63A /* JSPromiseConstructor.lut.h */,
+ 7C184E2517BFFA36007CB63A /* JSPromisePrototype.lut.h */,
A7C225CD1399849C00FF1662 /* KeywordLookup.h */,
BC18C52D0E16FCE100B34460 /* Lexer.lut.h */,
- BC18C5290E16FCC200B34460 /* MathObject.lut.h */,
BC2680E60E16D52300A06E92 /* NumberConstructor.lut.h */,
BCD202D50E170708002C7E82 /* RegExpConstructor.lut.h */,
A718F61A11754A21002465A7 /* RegExpJitTables.h */,
BC18C52B0E16FCD200B34460 /* RegExpObject.lut.h */,
- BC18C5250E16FCA700B34460 /* StringPrototype.lut.h */,
5D53727D0E1C55EC0021E549 /* TracingDtrace.h */,
);
name = "Derived Sources";
@@ -3102,6 +3128,20 @@
BC22A3990E16E14800AF21C8 /* JSObject.h */,
A7F9935E0FD7325100A0B2D0 /* JSONObject.cpp */,
A7F9935D0FD7325100A0B2D0 /* JSONObject.h */,
+ 7C184E1817BEDBD3007CB63A /* JSPromise.cpp */,
+ 7C184E1917BEDBD3007CB63A /* JSPromise.h */,
+ 7C15F65B17C199CE00794D40 /* JSPromiseCallback.cpp */,
+ 7C15F65C17C199CE00794D40 /* JSPromiseCallback.h */,
+ 7C184E2017BEE240007CB63A /* JSPromiseConstructor.cpp */,
+ 7C184E2117BEE240007CB63A /* JSPromiseConstructor.h */,
+ 7C184E1C17BEE22E007CB63A /* JSPromisePrototype.cpp */,
+ 7C184E1D17BEE22E007CB63A /* JSPromisePrototype.h */,
+ 7C3BA28E17C039560072DDC9 /* JSPromiseResolver.cpp */,
+ 7C3BA28F17C039560072DDC9 /* JSPromiseResolver.h */,
+ 7C3BA29017C039560072DDC9 /* JSPromiseResolverConstructor.cpp */,
+ 7C3BA29117C039560072DDC9 /* JSPromiseResolverConstructor.h */,
+ 7C3BA29217C039560072DDC9 /* JSPromiseResolverPrototype.cpp */,
+ 7C3BA29317C039560072DDC9 /* JSPromiseResolverPrototype.h */,
A727FF660DA3053B00E548D7 /* JSPropertyNameIterator.cpp */,
A727FF650DA3053B00E548D7 /* JSPropertyNameIterator.h */,
862553CE16136AA5009F17D0 /* JSProxy.cpp */,
@@ -3767,6 +3807,7 @@
BC18C3FB0E16F5CD00B34460 /* DebuggerCallFrame.h in Headers */,
0F136D4D174AD69E0075B354 /* DeferGC.h in Headers */,
A77A423E17A0BBFD00A8DB81 /* DFGAbstractHeap.h in Headers */,
+ 7C15F65E17C199CE00794D40 /* JSPromiseCallback.h in Headers */,
A704D90317A0BAA8006BA554 /* DFGAbstractInterpreter.h in Headers */,
A704D90417A0BAA8006BA554 /* DFGAbstractInterpreterInlines.h in Headers */,
0F620177143FCD3F0068B77C /* DFGAbstractValue.h in Headers */,
@@ -3834,6 +3875,7 @@
A7D9A29817A0BC7400EE2618 /* DFGLICMPhase.h in Headers */,
A7D89CFC17A0B8CC00773AD8 /* DFGLivenessAnalysisPhase.h in Headers */,
0FF0F19B16B729FA005DF95B /* DFGLongLivedState.h in Headers */,
+ 7C184E1F17BEE22E007CB63A /* JSPromisePrototype.h in Headers */,
A767B5B617A0B9650063D940 /* DFGLoopPreHeaderCreationPhase.h in Headers */,
A704D90717A0BAA8006BA554 /* DFGMergeMode.h in Headers */,
0F2BDC451522801B00CD8910 /* DFGMinifiedGraph.h in Headers */,
@@ -3911,6 +3953,7 @@
0F235BD417178E1C00690C7F /* FTLExitArgument.h in Headers */,
0F235BD617178E1C00690C7F /* FTLExitArgumentForOperand.h in Headers */,
0F235BD717178E1C00690C7F /* FTLExitArgumentList.h in Headers */,
+ 7C3BA29917C039560072DDC9 /* JSPromiseResolverPrototype.h in Headers */,
0F235BD917178E1C00690C7F /* FTLExitThunkGenerator.h in Headers */,
0F235BDB17178E1C00690C7F /* FTLExitValue.h in Headers */,
A7F2996C17A0BB670010417A /* FTLFail.h in Headers */,
@@ -3975,6 +4018,7 @@
BC11667B0E199C05008066DD /* InternalFunction.h in Headers */,
1429D77C0ED20D7300B89619 /* Interpreter.h in Headers */,
860BD801148EA6F200112B2F /* Intrinsic.h in Headers */,
+ 7C3BA29517C039560072DDC9 /* JSPromiseResolver.h in Headers */,
BC18C4130E16F5CD00B34460 /* JavaScript.h in Headers */,
BC18C4140E16F5CD00B34460 /* JavaScriptCore.h in Headers */,
BC18C4150E16F5CD00B34460 /* JavaScriptCorePrefix.h in Headers */,
@@ -4135,7 +4179,6 @@
C21122E315DD9AB300790E3A /* MarkStackInlines.h in Headers */,
8612E4CD152389EC00C836BE /* MatchResult.h in Headers */,
BC18C43C0E16F5CD00B34460 /* MathObject.h in Headers */,
- BC18C52A0E16FCC200B34460 /* MathObject.lut.h in Headers */,
90213E3E123A40C200D422F3 /* MemoryStatistics.h in Headers */,
0FB5467B14F5C7E1002C2989 /* MethodOfGettingAValueProfile.h in Headers */,
86C568E211A213EE0007F7F0 /* MIPSAssembler.h in Headers */,
@@ -4200,11 +4243,14 @@
1474C33B16AA2D950062F01D /* PrototypeMap.h in Headers */,
0F9332A414CA7DD90085F3C6 /* PutByIdStatus.h in Headers */,
0F0CD4C215F1A6070032F1C0 /* PutDirectIndexMode.h in Headers */,
+ 7C184E1B17BEDBD3007CB63A /* JSPromise.h in Headers */,
+ 0F2B66F217B6B5AB00A7AE3F /* JSGenericTypedArrayViewConstructor.h in Headers */,
0F9FC8C514E1B60400D52AE0 /* PutKind.h in Headers */,
147B84630E6DE6B1004775A4 /* PutPropertySlot.h in Headers */,
0FF60AC216740F8300029779 /* ReduceWhitespace.h in Headers */,
BC18C45A0E16F5CD00B34460 /* RegExp.h in Headers */,
A1712B3F11C7B228007A5315 /* RegExpCache.h in Headers */,
+ 7C3BA29717C039560072DDC9 /* JSPromiseResolverConstructor.h in Headers */,
BCD202C20E1706A7002C7E82 /* RegExpConstructor.h in Headers */,
BCD202D60E170708002C7E82 /* RegExpConstructor.lut.h in Headers */,
A1712B4111C7B235007A5315 /* RegExpKey.h in Headers */,
@@ -4215,6 +4261,7 @@
BC18C45D0E16F5CD00B34460 /* Register.h in Headers */,
969A072B0ED1CE6900F1F681 /* RegisterID.h in Headers */,
0FB7F39D15ED8E4600F167B2 /* Reject.h in Headers */,
+ 7C184E2317BEE240007CB63A /* JSPromiseConstructor.h in Headers */,
86D3B3C410159D7F002865E7 /* RepatchBuffer.h in Headers */,
869EBCB70E8C6D4A008722CC /* ResultType.h in Headers */,
C22B31B9140577D700DB475A /* SamplingCounter.h in Headers */,
@@ -4241,7 +4288,6 @@
BC18C4660E16F5CD00B34460 /* StringConstructor.h in Headers */,
BC18C4680E16F5CD00B34460 /* StringObject.h in Headers */,
BC18C46A0E16F5CD00B34460 /* StringPrototype.h in Headers */,
- BC18C5260E16FCA700B34460 /* StringPrototype.lut.h in Headers */,
142E313B134FF0A600AFADB5 /* Strong.h in Headers */,
145722861437E140005FDE26 /* StrongInlines.h in Headers */,
BCDE3AB80E6C82F5001453A7 /* Structure.h in Headers */,
@@ -4728,6 +4774,7 @@
C2981FD817BAEE4B00A3BC98 /* DFGDesiredWeakReferences.cpp in Sources */,
C2981FDC17BAFF4400A3BC98 /* DFGDesiredWriteBarriers.cpp in Sources */,
0FF427641591A1CC004CB9FF /* DFGDisassembler.cpp in Sources */,
+ 7C3BA29817C039560072DDC9 /* JSPromiseResolverPrototype.cpp in Sources */,
0FD81AD2154FB4EE00983E72 /* DFGDominators.cpp in Sources */,
0FD3C82614115D4000FD81CB /* DFGDriver.cpp in Sources */,
0FF0F19E16B72A0B005DF95B /* DFGEdge.cpp in Sources */,
@@ -4749,6 +4796,7 @@
A767B5B517A0B9650063D940 /* DFGLoopPreHeaderCreationPhase.cpp in Sources */,
0F2BDC4D1522818600CD8910 /* DFGMinifiedNode.cpp in Sources */,
A737810D1799EA2E00817533 /* DFGNaturalLoops.cpp in Sources */,
+ 7C15F65D17C199CE00794D40 /* JSPromiseCallback.cpp in Sources */,
0FF0F19C16B72A03005DF95B /* DFGNode.cpp in Sources */,
0FA581BA150E952C00B9A2D9 /* DFGNodeFlags.cpp in Sources */,
86EC9DCF1328DF82002B2AD7 /* DFGOperations.cpp in Sources */,
@@ -4768,6 +4816,7 @@
0FFFC95D14EF90B300C72532 /* DFGPredictionPropagationPhase.cpp in Sources */,
86BB09C0138E381B0056702F /* DFGRepatch.cpp in Sources */,
86EC9DD21328DF82002B2AD7 /* DFGSpeculativeJIT.cpp in Sources */,
+ 7C3BA29617C039560072DDC9 /* JSPromiseResolverConstructor.cpp in Sources */,
86880F1F14328BB900B08D42 /* DFGSpeculativeJIT32_64.cpp in Sources */,
86880F4D14353B2100B08D42 /* DFGSpeculativeJIT64.cpp in Sources */,
A7D89CFF17A0B8CC00773AD8 /* DFGSSAConversionPhase.cpp in Sources */,
@@ -4797,6 +4846,7 @@
0FEA0A1C1708B00700BB722C /* FTLAbstractHeap.cpp in Sources */,
0FEA0A1E1708B00700BB722C /* FTLAbstractHeapRepository.cpp in Sources */,
0FEA0A09170513DB00BB722C /* FTLCapabilities.cpp in Sources */,
+ 7C184E1E17BEE22E007CB63A /* JSPromisePrototype.cpp in Sources */,
0F235BD117178E1C00690C7F /* FTLCArgumentGetter.cpp in Sources */,
0FEA0A271709623B00BB722C /* FTLCommonValues.cpp in Sources */,
0FEA0A0B170513DB00BB722C /* FTLCompile.cpp in Sources */,
@@ -4858,6 +4908,7 @@
140B7D1D0DC69AF7009C42B8 /* JSActivation.cpp in Sources */,
140566C4107EC255005DBC8D /* JSAPIValueWrapper.cpp in Sources */,
C2CF39C116E15A8100DD69BE /* JSAPIWrapperObject.mm in Sources */,
+ 7C3BA29417C039560072DDC9 /* JSPromiseResolver.cpp in Sources */,
147F39D0107EC37600427A48 /* JSArray.cpp in Sources */,
0F2B66E217B6B5AB00A7AE3F /* JSArrayBuffer.cpp in Sources */,
0F2B66E417B6B5AB00A7AE3F /* JSArrayBufferConstructor.cpp in Sources */,
@@ -4927,6 +4978,7 @@
14469DDE107EC7E700650446 /* Lookup.cpp in Sources */,
0F4680CC14BBB17A00BFE272 /* LowLevelInterpreter.cpp in Sources */,
14B723B212D7DA46003BD5ED /* MachineStackMarker.cpp in Sources */,
+ 7C184E1A17BEDBD3007CB63A /* JSPromise.cpp in Sources */,
0FEB3ECF16237F6C00AB67AD /* MacroAssembler.cpp in Sources */,
86C568E011A213EE0007F7F0 /* MacroAssemblerARM.cpp in Sources */,
A729009C17976C6000317298 /* MacroAssemblerARMv7.cpp in Sources */,
@@ -4981,6 +5033,7 @@
1474C33C16AA2D9B0062F01D /* PrototypeMap.cpp in Sources */,
0F9332A314CA7DD70085F3C6 /* PutByIdStatus.cpp in Sources */,
0FF60AC316740F8800029779 /* ReduceWhitespace.cpp in Sources */,
+ 7C184E2217BEE240007CB63A /* JSPromiseConstructor.cpp in Sources */,
14280841107EC0930013E7B2 /* RegExp.cpp in Sources */,
A1712B3B11C7B212007A5315 /* RegExpCache.cpp in Sources */,
8642C510151C06A90046D4EF /* RegExpCachedResult.cpp in Sources */,
diff --git a/Source/JavaScriptCore/Target.pri b/Source/JavaScriptCore/Target.pri
index 849d74b..71a2f9e 100644
--- a/Source/JavaScriptCore/Target.pri
+++ b/Source/JavaScriptCore/Target.pri
@@ -323,6 +323,13 @@
runtime/JSNotAnObject.cpp \
runtime/JSONObject.cpp \
runtime/JSObject.cpp \
+ runtime/JSPromise.cpp \
+ runtime/JSPromiseCallback.cpp \
+ runtime/JSPromiseConstructor.cpp \
+ runtime/JSPromisePrototype.cpp \
+ runtime/JSPromiseResolver.cpp \
+ runtime/JSPromiseResolverConstructor.cpp \
+ runtime/JSPromiseResolverPrototype.cpp \
runtime/JSPropertyNameIterator.cpp \
runtime/JSProxy.cpp \
runtime/JSScope.cpp \
diff --git a/Source/JavaScriptCore/interpreter/CallFrame.h b/Source/JavaScriptCore/interpreter/CallFrame.h
index 965d187..b27bcbe 100644
--- a/Source/JavaScriptCore/interpreter/CallFrame.h
+++ b/Source/JavaScriptCore/interpreter/CallFrame.h
@@ -101,6 +101,9 @@
static const HashTable* regExpConstructorTable(CallFrame* callFrame) { return callFrame->vm().regExpConstructorTable; }
static const HashTable* regExpPrototypeTable(CallFrame* callFrame) { return callFrame->vm().regExpPrototypeTable; }
static const HashTable* stringConstructorTable(CallFrame* callFrame) { return callFrame->vm().stringConstructorTable; }
+ static const HashTable* promisePrototypeTable(CallFrame* callFrame) { return callFrame->vm().promisePrototypeTable; }
+ static const HashTable* promiseConstructorTable(CallFrame* callFrame) { return callFrame->vm().promiseConstructorTable; }
+ static const HashTable* promiseResolverPrototypeTable(CallFrame* callFrame) { return callFrame->vm().promiseResolverPrototypeTable; }
static CallFrame* create(Register* callFrameBase) { return static_cast<CallFrame*>(callFrameBase); }
Register* registers() { return this; }
diff --git a/Source/JavaScriptCore/jsc.cpp b/Source/JavaScriptCore/jsc.cpp
index 07a1dd0..403eda7 100644
--- a/Source/JavaScriptCore/jsc.cpp
+++ b/Source/JavaScriptCore/jsc.cpp
@@ -259,7 +259,7 @@
COMPILE_ASSERT(!IsInteger<GlobalObject>::value, WTF_IsInteger_GlobalObject_false);
const ClassInfo GlobalObject::s_info = { "global", &JSGlobalObject::s_info, 0, ExecState::globalObjectTable, CREATE_METHOD_TABLE(GlobalObject) };
-const GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled };
+const GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled, 0 };
GlobalObject::GlobalObject(VM& vm, Structure* structure)
diff --git a/Source/JavaScriptCore/runtime/CommonIdentifiers.h b/Source/JavaScriptCore/runtime/CommonIdentifiers.h
index ef0de3e..6ff9877 100644
--- a/Source/JavaScriptCore/runtime/CommonIdentifiers.h
+++ b/Source/JavaScriptCore/runtime/CommonIdentifiers.h
@@ -41,6 +41,8 @@
macro(NaN) \
macro(Number) \
macro(Object) \
+ macro(Promise) \
+ macro(PromiseResolver) \
macro(RangeError) \
macro(ReferenceError) \
macro(RegExp) \
@@ -123,6 +125,7 @@
macro(stack) \
macro(subarray) \
macro(test) \
+ macro(then) \
macro(toExponential) \
macro(toFixed) \
macro(toISOString) \
diff --git a/Source/JavaScriptCore/runtime/JSGlobalObject.cpp b/Source/JavaScriptCore/runtime/JSGlobalObject.cpp
index effddfd..e2bdfdc 100644
--- a/Source/JavaScriptCore/runtime/JSGlobalObject.cpp
+++ b/Source/JavaScriptCore/runtime/JSGlobalObject.cpp
@@ -66,6 +66,13 @@
#include "JSLock.h"
#include "JSNameScope.h"
#include "JSONObject.h"
+#include "JSPromise.h"
+#include "JSPromiseCallback.h"
+#include "JSPromiseConstructor.h"
+#include "JSPromisePrototype.h"
+#include "JSPromiseResolver.h"
+#include "JSPromiseResolverConstructor.h"
+#include "JSPromiseResolverPrototype.h"
#include "JSTypedArrayConstructors.h"
#include "JSTypedArrayPrototypes.h"
#include "JSTypedArrays.h"
@@ -99,7 +106,7 @@
const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, 0, ExecState::globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
-const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled };
+const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled, 0 };
/* Source for JSGlobalObject.lut.h
@begin globalObjectTable
@@ -297,6 +304,14 @@
m_errorPrototype.set(exec->vm(), this, ErrorPrototype::create(exec, this, ErrorPrototype::createStructure(exec->vm(), this, m_objectPrototype.get())));
m_errorStructure.set(exec->vm(), this, ErrorInstance::createStructure(exec->vm(), this, m_errorPrototype.get()));
+ m_promisePrototype.set(exec->vm(), this, JSPromisePrototype::create(exec, this, JSPromisePrototype::createStructure(exec->vm(), this, m_objectPrototype.get())));
+ m_promiseStructure.set(exec->vm(), this, JSPromise::createStructure(exec->vm(), this, m_promisePrototype.get()));
+
+ m_promiseResolverPrototype.set(exec->vm(), this, JSPromiseResolverPrototype::create(exec, this, JSPromiseResolverPrototype::createStructure(exec->vm(), this, m_objectPrototype.get())));
+ m_promiseResolverStructure.set(exec->vm(), this, JSPromiseResolver::createStructure(exec->vm(), this, m_promiseResolverPrototype.get()));
+ m_promiseCallbackStructure.set(exec->vm(), this, JSPromiseCallback::createStructure(exec->vm(), this, m_functionPrototype.get()));
+ m_promiseWrapperCallbackStructure.set(exec->vm(), this, JSPromiseWrapperCallback::createStructure(exec->vm(), this, m_functionPrototype.get()));
+
// Constructors
JSCell* objectConstructor = ObjectConstructor::create(exec, this, ObjectConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_objectPrototype.get());
@@ -306,6 +321,8 @@
JSCell* booleanConstructor = BooleanConstructor::create(exec, this, BooleanConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_booleanPrototype.get());
JSCell* numberConstructor = NumberConstructor::create(exec, this, NumberConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_numberPrototype.get());
JSCell* dateConstructor = DateConstructor::create(exec, this, DateConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_datePrototype.get());
+ JSCell* promiseConstructor = JSPromiseConstructor::create(exec, this, JSPromiseConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_promisePrototype.get());
+ JSCell* promiseResolverConstructor = JSPromiseResolverConstructor::create(exec, this, JSPromiseResolverConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_promiseResolverPrototype.get());
m_regExpConstructor.set(exec->vm(), this, RegExpConstructor::create(exec, this, RegExpConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_regExpPrototype.get()));
@@ -329,6 +346,8 @@
m_datePrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, dateConstructor, DontEnum);
m_regExpPrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, m_regExpConstructor.get(), DontEnum);
m_errorPrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, m_errorConstructor.get(), DontEnum);
+ m_promisePrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, promiseConstructor, DontEnum);
+ m_promiseResolverPrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, promiseResolverConstructor, DontEnum);
putDirectWithoutTransition(exec->vm(), exec->propertyNames().Object, objectConstructor, DontEnum);
putDirectWithoutTransition(exec->vm(), exec->propertyNames().Function, functionConstructor, DontEnum);
@@ -345,6 +364,8 @@
putDirectWithoutTransition(exec->vm(), exec->propertyNames().SyntaxError, m_syntaxErrorConstructor.get(), DontEnum);
putDirectWithoutTransition(exec->vm(), exec->propertyNames().TypeError, m_typeErrorConstructor.get(), DontEnum);
putDirectWithoutTransition(exec->vm(), exec->propertyNames().URIError, m_URIErrorConstructor.get(), DontEnum);
+ putDirectWithoutTransition(exec->vm(), exec->propertyNames().Promise, promiseConstructor, DontEnum);
+ putDirectWithoutTransition(exec->vm(), exec->propertyNames().PromiseResolver, promiseResolverConstructor, DontEnum);
m_evalFunction.set(exec->vm(), this, JSFunction::create(exec, this, 1, exec->propertyNames().eval.string(), globalFuncEval));
putDirectWithoutTransition(exec->vm(), exec->propertyNames().eval, m_evalFunction.get(), DontEnum);
@@ -564,6 +585,8 @@
visitor.append(&thisObject->m_datePrototype);
visitor.append(&thisObject->m_regExpPrototype);
visitor.append(&thisObject->m_errorPrototype);
+ visitor.append(&thisObject->m_promisePrototype);
+ visitor.append(&thisObject->m_promiseResolverPrototype);
visitor.append(&thisObject->m_withScopeStructure);
visitor.append(&thisObject->m_strictEvalActivationStructure);
@@ -594,7 +617,11 @@
visitor.append(&thisObject->m_regExpStructure);
visitor.append(&thisObject->m_stringObjectStructure);
visitor.append(&thisObject->m_internalFunctionStructure);
-
+ visitor.append(&thisObject->m_promiseStructure);
+ visitor.append(&thisObject->m_promiseResolverStructure);
+ visitor.append(&thisObject->m_promiseCallbackStructure);
+ visitor.append(&thisObject->m_promiseWrapperCallbackStructure);
+
visitor.append(&thisObject->m_arrayBufferPrototype);
visitor.append(&thisObject->m_arrayBufferStructure);
diff --git a/Source/JavaScriptCore/runtime/JSGlobalObject.h b/Source/JavaScriptCore/runtime/JSGlobalObject.h
index fee8fe44..f2d6738 100644
--- a/Source/JavaScriptCore/runtime/JSGlobalObject.h
+++ b/Source/JavaScriptCore/runtime/JSGlobalObject.h
@@ -24,8 +24,8 @@
#include "ArrayAllocationProfile.h"
#include "JSArray.h"
-#include "JSClassRef.h"
#include "JSArrayBufferPrototype.h"
+#include "JSClassRef.h"
#include "JSSegmentedVariableObject.h"
#include "JSWeakObjectMapRefInternal.h"
#include "NumberPrototype.h"
@@ -38,6 +38,7 @@
#include <JavaScriptCore/JSBase.h>
#include <wtf/HashSet.h>
#include <wtf/OwnPtr.h>
+#include <wtf/PassRefPtr.h>
#include <wtf/RandomNumber.h>
struct OpaqueJSClass;
@@ -58,6 +59,8 @@
class FunctionPrototype;
class GetterSetter;
class GlobalCodeBlock;
+class JSPromisePrototype;
+class JSPromiseResolverPrototype;
class JSStack;
class LLIntOffsetsExtractor;
class NativeErrorConstructor;
@@ -70,7 +73,14 @@
struct HashTable;
typedef Vector<ExecState*, 16> ExecStateStack;
-
+
+class TaskContext : public RefCounted<TaskContext> {
+public:
+ virtual ~TaskContext()
+ {
+ }
+};
+
struct GlobalObjectMethodTable {
typedef bool (*AllowsAccessFromFunctionPtr)(const JSGlobalObject*, ExecState*);
AllowsAccessFromFunctionPtr allowsAccessFrom;
@@ -86,6 +96,10 @@
typedef bool (*JavaScriptExperimentsEnabledFunctionPtr)(const JSGlobalObject*);
JavaScriptExperimentsEnabledFunctionPtr javaScriptExperimentsEnabled;
+
+ typedef void (*QueueTaskToEventLoopCallbackFunctionPtr)(ExecState*, TaskContext*);
+ typedef void (*QueueTaskToEventLoopFunctionPtr)(const JSGlobalObject*, QueueTaskToEventLoopCallbackFunctionPtr, PassRefPtr<TaskContext>);
+ QueueTaskToEventLoopFunctionPtr queueTaskToEventLoop;
};
class JSGlobalObject : public JSSegmentedVariableObject {
@@ -134,6 +148,8 @@
WriteBarrier<DatePrototype> m_datePrototype;
WriteBarrier<RegExpPrototype> m_regExpPrototype;
WriteBarrier<ErrorPrototype> m_errorPrototype;
+ WriteBarrier<JSPromisePrototype> m_promisePrototype;
+ WriteBarrier<JSPromiseResolverPrototype> m_promiseResolverPrototype;
WriteBarrier<Structure> m_withScopeStructure;
WriteBarrier<Structure> m_strictEvalActivationStructure;
@@ -167,7 +183,11 @@
WriteBarrier<Structure> m_regExpStructure;
WriteBarrier<Structure> m_stringObjectStructure;
WriteBarrier<Structure> m_internalFunctionStructure;
-
+ WriteBarrier<Structure> m_promiseStructure;
+ WriteBarrier<Structure> m_promiseResolverStructure;
+ WriteBarrier<Structure> m_promiseCallbackStructure;
+ WriteBarrier<Structure> m_promiseWrapperCallbackStructure;
+
WriteBarrier<JSArrayBufferPrototype> m_arrayBufferPrototype;
WriteBarrier<Structure> m_arrayBufferStructure;
@@ -312,6 +332,8 @@
DatePrototype* datePrototype() const { return m_datePrototype.get(); }
RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); }
ErrorPrototype* errorPrototype() const { return m_errorPrototype.get(); }
+ JSPromisePrototype* promisePrototype() const { return m_promisePrototype.get(); }
+ JSPromiseResolverPrototype* promiseResolverPrototype() const { return m_promiseResolverPrototype.get(); }
Structure* withScopeStructure() const { return m_withScopeStructure.get(); }
Structure* strictEvalActivationStructure() const { return m_strictEvalActivationStructure.get(); }
@@ -359,7 +381,11 @@
Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
Structure* regExpStructure() const { return m_regExpStructure.get(); }
Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); }
-
+ Structure* promiseStructure() const { return m_promiseStructure.get(); }
+ Structure* promiseResolverStructure() const { return m_promiseResolverStructure.get(); }
+ Structure* promiseCallbackStructure() const { return m_promiseCallbackStructure.get(); }
+ Structure* promiseWrapperCallbackStructure() const { return m_promiseWrapperCallbackStructure.get(); }
+
JSArrayBufferPrototype* arrayBufferPrototype() const { return m_arrayBufferPrototype.get(); }
Structure* arrayBufferStructure() const { return m_arrayBufferStructure.get(); }
diff --git a/Source/JavaScriptCore/runtime/JSPromise.cpp b/Source/JavaScriptCore/runtime/JSPromise.cpp
new file mode 100644
index 0000000..20481cc
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromise.cpp
@@ -0,0 +1,241 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSPromise.h"
+
+#include "Error.h"
+#include "JSCJSValueInlines.h"
+#include "JSCellInlines.h"
+#include "JSPromiseResolver.h"
+#include "SlotVisitorInlines.h"
+#include "StrongInlines.h"
+#include "StructureInlines.h"
+
+namespace JSC {
+
+class JSPromiseTaskContext : public TaskContext {
+public:
+ static PassRefPtr<JSPromiseTaskContext> create(VM& vm, JSPromise* promise)
+ {
+ return adoptRef(new JSPromiseTaskContext(vm, promise));
+ }
+
+ JSPromise& promise() const { return *m_promise.get(); }
+
+private:
+ JSPromiseTaskContext(VM& vm, JSPromise* promise)
+ {
+ m_promise.set(vm, promise);
+ }
+
+ Strong<JSPromise> m_promise;
+};
+
+const ClassInfo JSPromise::s_info = { "Promise", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSPromise) };
+
+JSPromise* JSPromise::create(VM& vm, Structure* structure)
+{
+ JSPromise* promise = new (NotNull, allocateCell<JSPromise>(vm.heap)) JSPromise(vm, structure);
+ promise->finishCreation(vm);
+ return promise;
+}
+
+JSPromise* JSPromise::createWithResolver(VM& vm, JSGlobalObject* globalObject)
+{
+ JSPromise* promise = new (NotNull, allocateCell<JSPromise>(vm.heap)) JSPromise(vm, globalObject->promiseStructure());
+ promise->finishCreation(vm);
+
+ JSPromiseResolver* resolver = JSPromiseResolver::create(vm, globalObject->promiseResolverStructure(), promise);
+ promise->setResolver(vm, resolver);
+
+ return promise;
+}
+
+Structure* JSPromise::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+JSPromise::JSPromise(VM& vm, Structure* structure)
+ : JSDestructibleObject(vm, structure)
+ , m_state(Pending)
+{
+}
+
+void JSPromise::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+}
+
+void JSPromise::destroy(JSCell* cell)
+{
+ static_cast<JSPromise*>(cell)->JSPromise::~JSPromise();
+}
+
+void JSPromise::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ JSPromise* thisObject = jsCast<JSPromise*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
+ ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
+
+ Base::visitChildren(thisObject, visitor);
+
+ visitor.append(&thisObject->m_resolver);
+ visitor.append(&thisObject->m_result);
+
+ for (size_t i = 0; i < thisObject->m_fulfillCallbacks.size(); ++i)
+ visitor.append(&thisObject->m_fulfillCallbacks[i]);
+ for (size_t i = 0; i < thisObject->m_rejectCallbacks.size(); ++i)
+ visitor.append(&thisObject->m_rejectCallbacks[i]);
+}
+
+void JSPromise::setResolver(VM& vm, JSPromiseResolver* resolver)
+{
+ m_resolver.set(vm, this, resolver);
+}
+
+JSPromiseResolver* JSPromise::resolver() const
+{
+ return m_resolver.get();
+}
+
+void JSPromise::setResult(VM& vm, JSValue result)
+{
+ m_result.set(vm, this, result);
+}
+
+JSValue JSPromise::result() const
+{
+ return m_result.get();
+}
+
+void JSPromise::setState(JSPromise::State state)
+{
+ ASSERT(m_state == Pending);
+ m_state = state;
+}
+
+JSPromise::State JSPromise::state() const
+{
+ return m_state;
+}
+
+void JSPromise::appendCallbacks(ExecState* exec, InternalFunction* fulfillCallback, InternalFunction* rejectCallback)
+{
+ // 1. Append fulfillCallback to promise's fulfill callbacks.
+ m_fulfillCallbacks.append(WriteBarrier<InternalFunction>(exec->vm(), this, fulfillCallback));
+
+ // 2. Append rejectCallback to promise' reject callbacks.
+ m_rejectCallbacks.append(WriteBarrier<InternalFunction>(exec->vm(), this, rejectCallback));
+
+ // 3. If promise's state is fulfilled, queue a task to process promise's fulfill callbacks with promise's result.
+ if (m_state == Fulfilled) {
+ queueTaskToProcessFulfillCallbacks(exec);
+ return;
+ }
+
+ // 4. If promise's state is rejected, queue a task to process promise's reject callbacks with promise's result.
+ if (m_state == Rejected) {
+ queueTaskToProcessRejectCallbacks(exec);
+ return;
+ }
+}
+
+void JSPromise::queueTaskToProcessFulfillCallbacks(ExecState* exec)
+{
+ JSGlobalObject* globalObject = this->globalObject();
+ if (globalObject->globalObjectMethodTable()->queueTaskToEventLoop)
+ globalObject->globalObjectMethodTable()->queueTaskToEventLoop(globalObject, processFulfillCallbacksForTask, JSPromiseTaskContext::create(exec->vm(), this));
+ else
+ WTFLogAlways("ERROR: Event loop not supported.");
+}
+
+void JSPromise::queueTaskToProcessRejectCallbacks(ExecState* exec)
+{
+ JSGlobalObject* globalObject = this->globalObject();
+ if (globalObject->globalObjectMethodTable()->queueTaskToEventLoop)
+ globalObject->globalObjectMethodTable()->queueTaskToEventLoop(globalObject, processRejectCallbacksForTask, JSPromiseTaskContext::create(exec->vm(), this));
+ else
+ WTFLogAlways("ERROR: Event loop not supported.");
+}
+
+void JSPromise::processFulfillCallbacksForTask(ExecState* exec, TaskContext* taskContext)
+{
+ JSPromiseTaskContext* promiseTaskContext = static_cast<JSPromiseTaskContext*>(taskContext);
+ JSPromise& promise = promiseTaskContext->promise();
+
+ promise.processFulfillCallbacksWithValue(exec, promise.result());
+}
+
+void JSPromise::processRejectCallbacksForTask(ExecState* exec, TaskContext* taskContext)
+{
+ JSPromiseTaskContext* promiseTaskContext = static_cast<JSPromiseTaskContext*>(taskContext);
+ JSPromise& promise = promiseTaskContext->promise();
+
+ promise.processRejectCallbacksWithValue(exec, promise.result());
+}
+
+void JSPromise::processFulfillCallbacksWithValue(ExecState* exec, JSValue value)
+{
+ ASSERT(m_state == Fulfilled);
+
+ for (size_t i = 0; i < m_fulfillCallbacks.size(); ++i) {
+ JSValue callback = m_fulfillCallbacks[i].get();
+
+ CallData callData;
+ CallType callType = JSC::getCallData(callback, callData);
+ ASSERT(callType != CallTypeNone);
+
+ MarkedArgumentBuffer arguments;
+ arguments.append(value);
+ call(exec, callback, callType, callData, this, arguments);
+ }
+
+ m_fulfillCallbacks.clear();
+}
+
+void JSPromise::processRejectCallbacksWithValue(ExecState* exec, JSValue value)
+{
+ ASSERT(m_state == Rejected);
+
+ for (size_t i = 0; i < m_rejectCallbacks.size(); ++i) {
+ JSValue callback = m_rejectCallbacks[i].get();
+
+ CallData callData;
+ CallType callType = JSC::getCallData(callback, callData);
+ ASSERT(callType != CallTypeNone);
+
+ MarkedArgumentBuffer arguments;
+ arguments.append(value);
+ call(exec, callback, callType, callData, this, arguments);
+ }
+
+ m_rejectCallbacks.clear();
+}
+
+} // namespace JSC
diff --git a/Source/JavaScriptCore/runtime/JSPromise.h b/Source/JavaScriptCore/runtime/JSPromise.h
new file mode 100644
index 0000000..06e4812
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromise.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSPromise_h
+#define JSPromise_h
+
+#include "JSDestructibleObject.h"
+
+namespace JSC {
+
+class JSPromiseResolver;
+class InternalFunction;
+class TaskContext;
+
+class JSPromise : public JSDestructibleObject {
+public:
+ typedef JSDestructibleObject Base;
+
+ static JSPromise* create(VM&, Structure*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ static JSPromise* createWithResolver(VM&, JSGlobalObject*);
+
+ DECLARE_INFO;
+
+ void setResolver(VM&, JSPromiseResolver*);
+ JSPromiseResolver* resolver() const;
+
+ enum State {
+ Pending,
+ Fulfilled,
+ Rejected,
+ };
+
+ void setState(State);
+ State state() const;
+
+ void setResult(VM&, JSValue);
+ JSValue result() const;
+
+ void appendCallbacks(ExecState*, InternalFunction* fulfillCallback, InternalFunction* rejectCallback);
+
+ void queueTaskToProcessFulfillCallbacks(ExecState*);
+ void queueTaskToProcessRejectCallbacks(ExecState*);
+ void processFulfillCallbacksWithValue(ExecState*, JSValue);
+ void processRejectCallbacksWithValue(ExecState*, JSValue);
+
+protected:
+ void finishCreation(VM&);
+ static const unsigned StructureFlags = OverridesVisitChildren | JSObject::StructureFlags;
+
+private:
+ JSPromise(VM&, Structure*);
+
+ static void processFulfillCallbacksForTask(ExecState*, TaskContext*);
+ static void processRejectCallbacksForTask(ExecState*, TaskContext*);
+
+ static void destroy(JSCell*);
+ static void visitChildren(JSCell*, SlotVisitor&);
+
+ WriteBarrier<JSPromiseResolver> m_resolver;
+ WriteBarrier<Unknown> m_result;
+ Vector<WriteBarrier<InternalFunction> > m_fulfillCallbacks;
+ Vector<WriteBarrier<InternalFunction> > m_rejectCallbacks;
+ State m_state;
+};
+
+} // namespace JSC
+
+#endif // JSPromise_h
diff --git a/Source/JavaScriptCore/runtime/JSPromiseCallback.cpp b/Source/JavaScriptCore/runtime/JSPromiseCallback.cpp
new file mode 100644
index 0000000..115991b
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromiseCallback.cpp
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSPromiseCallback.h"
+
+#include "JSCJSValueInlines.h"
+#include "JSCellInlines.h"
+#include "JSPromise.h"
+#include "JSPromiseResolver.h"
+#include "SlotVisitorInlines.h"
+#include "StructureInlines.h"
+
+namespace JSC {
+
+const ClassInfo JSPromiseCallback::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSPromiseCallback) };
+
+JSPromiseCallback* JSPromiseCallback::create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, JSPromiseResolver* resolver, Algorithm algorithm)
+{
+ JSPromiseCallback* constructor = new (NotNull, allocateCell<JSPromiseCallback>(*exec->heap())) JSPromiseCallback(globalObject, structure, algorithm);
+ constructor->finishCreation(exec, resolver);
+ return constructor;
+}
+
+Structure* JSPromiseCallback::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+JSPromiseCallback::JSPromiseCallback(JSGlobalObject* globalObject, Structure* structure, Algorithm algorithm)
+ : InternalFunction(globalObject, structure)
+ , m_algorithm(algorithm)
+{
+}
+
+void JSPromiseCallback::finishCreation(ExecState* exec, JSPromiseResolver* resolver)
+{
+ Base::finishCreation(exec->vm(), "PromiseCallback");
+ m_resolver.set(exec->vm(), this, resolver);
+}
+
+void JSPromiseCallback::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ JSPromiseCallback* thisObject = jsCast<JSPromiseCallback*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
+ ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
+
+ Base::visitChildren(thisObject, visitor);
+
+ visitor.append(&thisObject->m_resolver);
+}
+
+EncodedJSValue JSC_HOST_CALL JSPromiseCallback::callPromiseCallback(ExecState* exec)
+{
+ JSPromiseCallback* promiseCallback = jsCast<JSPromiseCallback*>(exec->callee());
+ JSPromiseResolver* resolver = promiseCallback->m_resolver.get();
+
+ // 1. Let value be the first argument that is passed, and undefined otherwise.
+ JSValue value = exec->argument(0);
+
+ // 2. Run resolver's algorithm with value and the synchronous flag set.
+ switch (promiseCallback->m_algorithm) {
+ case JSPromiseCallback::Fulfill:
+ resolver->fulfill(exec, value, JSPromiseResolver::ResolveSynchronously);
+ break;
+
+ case JSPromiseCallback::Resolve:
+ resolver->resolve(exec, value, JSPromiseResolver::ResolveSynchronously);
+ break;
+
+ case JSPromiseCallback::Reject:
+ resolver->reject(exec, value, JSPromiseResolver::ResolveSynchronously);
+ break;
+ }
+
+ return JSValue::encode(jsUndefined());
+}
+
+CallType JSPromiseCallback::getCallData(JSCell*, CallData& callData)
+{
+ callData.native.function = callPromiseCallback;
+ return CallTypeHost;
+}
+
+
+
+
+const ClassInfo JSPromiseWrapperCallback::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSPromiseWrapperCallback) };
+
+JSPromiseWrapperCallback* JSPromiseWrapperCallback::create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, JSPromiseResolver* resolver, JSValue callback)
+{
+ JSPromiseWrapperCallback* constructor = new (NotNull, allocateCell<JSPromiseWrapperCallback>(*exec->heap())) JSPromiseWrapperCallback(globalObject, structure);
+ constructor->finishCreation(exec, resolver, callback);
+ return constructor;
+}
+
+Structure* JSPromiseWrapperCallback::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+JSPromiseWrapperCallback::JSPromiseWrapperCallback(JSGlobalObject* globalObject, Structure* structure)
+ : InternalFunction(globalObject, structure)
+{
+}
+
+void JSPromiseWrapperCallback::finishCreation(ExecState* exec, JSPromiseResolver* resolver, JSValue callback)
+{
+ Base::finishCreation(exec->vm(), "PromiseWrapperCallback");
+ m_resolver.set(exec->vm(), this, resolver);
+ m_callback.set(exec->vm(), this, callback);
+}
+
+void JSPromiseWrapperCallback::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ JSPromiseWrapperCallback* thisObject = jsCast<JSPromiseWrapperCallback*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
+ ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
+
+ Base::visitChildren(thisObject, visitor);
+
+ visitor.append(&thisObject->m_resolver);
+ visitor.append(&thisObject->m_callback);
+}
+
+EncodedJSValue JSC_HOST_CALL JSPromiseWrapperCallback::callPromiseWrapperCallback(ExecState* exec)
+{
+ JSPromiseWrapperCallback* promiseWrapperCallback = jsCast<JSPromiseWrapperCallback*>(exec->callee());
+
+ JSPromiseResolver* resolver = promiseWrapperCallback->m_resolver.get();
+ JSValue callback = promiseWrapperCallback->m_callback.get();
+
+ // 1. Let argument be the first argument that is passed, and undefined otherwise.
+ JSValue argument = exec->argument(0);
+
+ // 2. Set callback's callback this value to resolver's associated promise.
+ // 3. Let value be the result of invoking callback with argument as argument.
+ CallData callData;
+ CallType callType = JSC::getCallData(callback, callData);
+ ASSERT(callType != CallTypeNone);
+
+ MarkedArgumentBuffer callbackArguments;
+ callbackArguments.append(argument);
+ JSValue value = JSC::call(exec, callback, callType, callData, resolver->promise(), callbackArguments);
+
+ // 4. If invoking callback threw an exception, catch it and run resolver's reject
+ // with the thrown exception as argument and the synchronous flag set.
+ if (exec->hadException()) {
+ JSValue exception = exec->exception();
+ exec->clearException();
+
+ resolver->reject(exec, exception, JSPromiseResolver::ResolveSynchronously);
+ return JSValue::encode(jsUndefined());
+ }
+
+ // 5. Otherwise, run resolver's resolve with value and the synchronous flag set.
+ resolver->resolve(exec, value, JSPromiseResolver::ResolveSynchronously);
+
+ return JSValue::encode(jsUndefined());
+}
+
+CallType JSPromiseWrapperCallback::getCallData(JSCell*, CallData& callData)
+{
+ callData.native.function = callPromiseWrapperCallback;
+ return CallTypeHost;
+}
+
+} // namespace JSC
diff --git a/Source/JavaScriptCore/runtime/JSPromiseCallback.h b/Source/JavaScriptCore/runtime/JSPromiseCallback.h
new file mode 100644
index 0000000..2f5510d
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromiseCallback.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSPromiseCallback_h
+#define JSPromiseCallback_h
+
+#include "InternalFunction.h"
+
+namespace JSC {
+
+class JSPromiseResolver;
+
+class JSPromiseCallback : public InternalFunction {
+public:
+ typedef InternalFunction Base;
+
+ enum Algorithm {
+ Fulfill,
+ Resolve,
+ Reject,
+ };
+
+ static JSPromiseCallback* create(ExecState*, JSGlobalObject*, Structure*, JSPromiseResolver*, Algorithm);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+private:
+ JSPromiseCallback(JSGlobalObject*, Structure*, Algorithm);
+ void finishCreation(ExecState*, JSPromiseResolver*);
+ static const unsigned StructureFlags = OverridesVisitChildren | JSObject::StructureFlags;
+
+ static EncodedJSValue JSC_HOST_CALL callPromiseCallback(ExecState*);
+ static CallType getCallData(JSCell*, CallData&);
+
+ static void visitChildren(JSCell*, SlotVisitor&);
+
+ WriteBarrier<JSPromiseResolver> m_resolver;
+ Algorithm m_algorithm;
+};
+
+class JSPromiseWrapperCallback : public InternalFunction {
+public:
+ typedef InternalFunction Base;
+
+ static JSPromiseWrapperCallback* create(ExecState*, JSGlobalObject*, Structure*, JSPromiseResolver*, JSValue callback);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+private:
+ JSPromiseWrapperCallback(JSGlobalObject*, Structure*);
+ void finishCreation(ExecState*, JSPromiseResolver*, JSValue callback);
+ static const unsigned StructureFlags = OverridesVisitChildren | JSObject::StructureFlags;
+
+ static EncodedJSValue JSC_HOST_CALL callPromiseWrapperCallback(ExecState*);
+ static CallType getCallData(JSCell*, CallData&);
+
+ static void visitChildren(JSCell*, SlotVisitor&);
+
+ WriteBarrier<JSPromiseResolver> m_resolver;
+ WriteBarrier<Unknown> m_callback;
+};
+
+} // namespace JSC
+
+#endif // JSPromiseCallback_h
diff --git a/Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp b/Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp
new file mode 100644
index 0000000..a30dae1
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSPromiseConstructor.h"
+
+#include "Error.h"
+#include "JSCJSValueInlines.h"
+#include "JSCellInlines.h"
+#include "JSPromise.h"
+#include "JSPromiseCallback.h"
+#include "JSPromisePrototype.h"
+#include "JSPromiseResolver.h"
+#include "Lookup.h"
+#include "StructureInlines.h"
+
+namespace JSC {
+
+ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSPromiseConstructor);
+
+// static Promise fulfill(any value);
+static EncodedJSValue JSC_HOST_CALL JSPromiseConstructorFuncFulfill(ExecState*);
+// static Promise resolve(any value); // same as any(value)
+static EncodedJSValue JSC_HOST_CALL JSPromiseConstructorFuncResolve(ExecState*);
+// static Promise reject(any value);
+static EncodedJSValue JSC_HOST_CALL JSPromiseConstructorFuncReject(ExecState*);
+
+}
+
+#include "JSPromiseConstructor.lut.h"
+
+namespace JSC {
+
+const ClassInfo JSPromiseConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::promiseConstructorTable, CREATE_METHOD_TABLE(JSPromiseConstructor) };
+
+/* Source for JSPromiseConstructor.lut.h
+@begin promiseConstructorTable
+ fulfill JSPromiseConstructorFuncFulfill DontEnum|Function 1
+ resolve JSPromiseConstructorFuncResolve DontEnum|Function 1
+ reject JSPromiseConstructorFuncReject DontEnum|Function 1
+@end
+*/
+
+JSPromiseConstructor* JSPromiseConstructor::create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, JSPromisePrototype* promisePrototype)
+{
+ JSPromiseConstructor* constructor = new (NotNull, allocateCell<JSPromiseConstructor>(*exec->heap())) JSPromiseConstructor(globalObject, structure);
+ constructor->finishCreation(exec, promisePrototype);
+ return constructor;
+}
+
+Structure* JSPromiseConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+JSPromiseConstructor::JSPromiseConstructor(JSGlobalObject* globalObject, Structure* structure)
+ : InternalFunction(globalObject, structure)
+{
+}
+
+void JSPromiseConstructor::finishCreation(ExecState* exec, JSPromisePrototype* promisePrototype)
+{
+ Base::finishCreation(exec->vm(), "Promise");
+ putDirectWithoutTransition(exec->vm(), exec->propertyNames().prototype, promisePrototype, DontEnum | DontDelete | ReadOnly);
+ putDirectWithoutTransition(exec->vm(), exec->propertyNames().length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
+}
+
+static EncodedJSValue JSC_HOST_CALL constructPromise(ExecState* exec)
+{
+ if (!exec->argumentCount())
+ return throwVMError(exec, createTypeError(exec, "Expected at least one argument"));
+
+ JSValue function = exec->argument(0);
+
+ CallData callData;
+ CallType callType = getCallData(function, callData);
+ if (callType == CallTypeNone)
+ return throwVMError(exec, createTypeError(exec, "Expected function as as first argument"));
+
+ JSGlobalObject* globalObject = asInternalFunction(exec->callee())->globalObject();
+
+ // 1. Let promise be a new promise.
+ JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject);
+
+ // 2. Let resolver be promise's associated resolver.
+ JSPromiseResolver* resolver = promise->resolver();
+
+ // 3. Set init's callback this value to promise.
+ // 4. Invoke init with resolver passed as parameter.
+ MarkedArgumentBuffer initArguments;
+ initArguments.append(resolver);
+ call(exec, function, callType, callData, promise, initArguments);
+
+ // 5. If init threw an exception, catch it, and then, if resolver's resolved flag
+ // is unset, run resolver's reject with the thrown exception as argument.
+ if (exec->hadException()) {
+ JSValue exception = exec->exception();
+ exec->clearException();
+
+ resolver->rejectIfNotResolved(exec, exception);
+ }
+
+ return JSValue::encode(promise);
+}
+
+ConstructType JSPromiseConstructor::getConstructData(JSCell*, ConstructData& constructData)
+{
+ constructData.native.function = constructPromise;
+ return ConstructTypeHost;
+}
+
+CallType JSPromiseConstructor::getCallData(JSCell*, CallData&)
+{
+ return CallTypeNone;
+}
+
+bool JSPromiseConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
+{
+ return getStaticFunctionSlot<InternalFunction>(exec, ExecState::promiseConstructorTable(exec), jsCast<JSPromiseConstructor*>(object), propertyName, slot);
+}
+
+EncodedJSValue JSC_HOST_CALL JSPromiseConstructorFuncFulfill(ExecState* exec)
+{
+ if (!exec->argumentCount())
+ return throwVMError(exec, createTypeError(exec, "Expected at least one argument"));
+
+ JSGlobalObject* globalObject = exec->callee()->globalObject();
+
+ JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject);
+ promise->resolver()->fulfill(exec, exec->argument(0));
+
+ return JSValue::encode(promise);
+}
+
+EncodedJSValue JSC_HOST_CALL JSPromiseConstructorFuncResolve(ExecState* exec)
+{
+ if (!exec->argumentCount())
+ return throwVMError(exec, createTypeError(exec, "Expected at least one argument"));
+
+ JSGlobalObject* globalObject = exec->callee()->globalObject();
+
+ JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject);
+ promise->resolver()->resolve(exec, exec->argument(0));
+
+ return JSValue::encode(promise);
+}
+
+EncodedJSValue JSC_HOST_CALL JSPromiseConstructorFuncReject(ExecState* exec)
+{
+ if (!exec->argumentCount())
+ return throwVMError(exec, createTypeError(exec, "Expected at least one argument"));
+
+ JSGlobalObject* globalObject = exec->callee()->globalObject();
+
+ JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject);
+ promise->resolver()->reject(exec, exec->argument(0));
+
+ return JSValue::encode(promise);
+}
+
+} // namespace JSC
diff --git a/Source/JavaScriptCore/runtime/JSPromiseConstructor.h b/Source/JavaScriptCore/runtime/JSPromiseConstructor.h
new file mode 100644
index 0000000..dd71efc
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromiseConstructor.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSPromiseConstructor_h
+#define JSPromiseConstructor_h
+
+#include "InternalFunction.h"
+
+namespace JSC {
+
+class JSPromisePrototype;
+
+class JSPromiseConstructor : public InternalFunction {
+public:
+ typedef InternalFunction Base;
+
+ static JSPromiseConstructor* create(ExecState*, JSGlobalObject*, Structure*, JSPromisePrototype*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(ExecState*, JSPromisePrototype*);
+ static const unsigned StructureFlags = OverridesGetOwnPropertySlot | InternalFunction::StructureFlags;
+
+private:
+ JSPromiseConstructor(JSGlobalObject*, Structure*);
+ static ConstructType getConstructData(JSCell*, ConstructData&);
+ static CallType getCallData(JSCell*, CallData&);
+ static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
+};
+
+} // namespace JSC
+
+#endif // JSPromiseConstructor_h
diff --git a/Source/JavaScriptCore/runtime/JSPromisePrototype.cpp b/Source/JavaScriptCore/runtime/JSPromisePrototype.cpp
new file mode 100644
index 0000000..faae9a5
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromisePrototype.cpp
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSPromisePrototype.h"
+
+#include "Error.h"
+#include "JSCJSValueInlines.h"
+#include "JSCellInlines.h"
+#include "JSGlobalObject.h"
+#include "JSPromise.h"
+#include "JSPromiseCallback.h"
+#include "JSPromiseResolver.h"
+#include "StructureInlines.h"
+
+namespace JSC {
+
+ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSPromisePrototype);
+
+// Promise then([TreatUndefinedAs=Missing] optional AnyCallback fulfillCallback, [TreatUndefinedAs=Missing] optional AnyCallback rejectCallback);
+static EncodedJSValue JSC_HOST_CALL JSPromisePrototypeFuncThen(ExecState*);
+// Promise catch([TreatUndefinedAs=Missing] optional AnyCallback rejectCallback);
+static EncodedJSValue JSC_HOST_CALL JSPromisePrototypeFuncCatch(ExecState*);
+
+}
+
+#include "JSPromisePrototype.lut.h"
+
+namespace JSC {
+
+const ClassInfo JSPromisePrototype::s_info = { "PromisePrototype", &JSNonFinalObject::s_info, 0, ExecState::promisePrototypeTable, CREATE_METHOD_TABLE(JSPromisePrototype) };
+
+/* Source for JSPromisePrototype.lut.h
+@begin promisePrototypeTable
+ then JSPromisePrototypeFuncThen DontEnum|Function 0
+ catch JSPromisePrototypeFuncCatch DontEnum|Function 0
+@end
+*/
+
+JSPromisePrototype* JSPromisePrototype::create(ExecState* exec, JSGlobalObject*, Structure* structure)
+{
+ JSPromisePrototype* object = new (NotNull, allocateCell<JSPromisePrototype>(*exec->heap())) JSPromisePrototype(exec, structure);
+ object->finishCreation(exec, structure);
+ return object;
+}
+
+Structure* JSPromisePrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+JSPromisePrototype::JSPromisePrototype(ExecState* exec, Structure* structure)
+ : JSNonFinalObject(exec->vm(), structure)
+{
+}
+
+void JSPromisePrototype::finishCreation(ExecState* exec, Structure*)
+{
+ Base::finishCreation(exec->vm());
+}
+
+bool JSPromisePrototype::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
+{
+ return getStaticFunctionSlot<JSObject>(exec, ExecState::promisePrototypeTable(exec), jsCast<JSPromisePrototype*>(object), propertyName, slot);
+}
+
+static InternalFunction* wrapCallback(ExecState* exec, JSGlobalObject* globalObject, JSValue callback, JSPromiseResolver* resolver, JSPromiseCallback::Algorithm algorithm)
+{
+ if (!callback.isUndefined())
+ return JSPromiseWrapperCallback::create(exec, globalObject, globalObject->promiseWrapperCallbackStructure(), resolver, callback);
+ return JSPromiseCallback::create(exec, globalObject, globalObject->promiseCallbackStructure(), resolver, algorithm);
+}
+
+EncodedJSValue JSC_HOST_CALL JSPromisePrototypeFuncThen(ExecState* exec)
+{
+ JSPromise* thisObject = jsDynamicCast<JSPromise*>(exec->thisValue());
+ if (!thisObject)
+ return throwVMError(exec, createTypeError(exec, "Receiver of then must be a Promise"));
+
+ JSValue fulfillCallback = exec->argument(0);
+ if (!fulfillCallback.isUndefined()) {
+ CallData callData;
+ CallType callType = getCallData(fulfillCallback, callData);
+ if (callType == CallTypeNone)
+ return throwVMError(exec, createTypeError(exec, "Expected function or undefined as as first argument"));
+ }
+
+ JSValue rejectCallback = exec->argument(1);
+ if (!rejectCallback.isUndefined()) {
+ CallData callData;
+ CallType callType = getCallData(rejectCallback, callData);
+ if (callType == CallTypeNone)
+ return throwVMError(exec, createTypeError(exec, "Expected function or undefined as as second argument"));
+ }
+
+ JSFunction* callee = jsCast<JSFunction*>(exec->callee());
+ JSGlobalObject* globalObject = callee->globalObject();
+
+ // 1. Let promise be a new promise.
+ JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject);
+
+ // 2. Let resolver be promise's associated resolver.
+ JSPromiseResolver* resolver = promise->resolver();
+
+ // 3. Let fulfillWrapper be a promise wrapper callback for resolver and fulfillCallback if fulfillCallback is
+ // not omitted and a promise callback for resolver and its fulfill algorithm otherwise.
+ InternalFunction* fulfillWrapper = wrapCallback(exec, globalObject, fulfillCallback, resolver, JSPromiseCallback::Fulfill);
+
+ // 4. Let rejectWrapper be a promise wrapper callback for resolver and rejectCallback if rejectCallback is
+ // not omitted and a promise callback for resolver and its reject algorithm otherwise.
+ InternalFunction* rejectWrapper = wrapCallback(exec, globalObject, rejectCallback, resolver, JSPromiseCallback::Reject);
+
+ // 5. Append fulfillWrapper and rejectWrapper to the context object.
+ thisObject->appendCallbacks(exec, fulfillWrapper, rejectWrapper);
+
+ // 6. Return promise.
+ return JSValue::encode(promise);
+}
+
+EncodedJSValue JSC_HOST_CALL JSPromisePrototypeFuncCatch(ExecState* exec)
+{
+ JSPromise* thisObject = jsDynamicCast<JSPromise*>(exec->thisValue());
+ if (!thisObject)
+ return throwVMError(exec, createTypeError(exec, "Receiver of catch must be a Promise"));
+
+ JSValue rejectCallback = exec->argument(0);
+ if (!rejectCallback.isUndefined()) {
+ CallData callData;
+ CallType callType = getCallData(rejectCallback, callData);
+ if (callType == CallTypeNone)
+ return throwVMError(exec, createTypeError(exec, "Expected function or undefined as as first argument"));
+ }
+
+ JSFunction* callee = jsCast<JSFunction*>(exec->callee());
+ JSGlobalObject* globalObject = callee->globalObject();
+
+ // 1. Let promise be a new promise.
+ JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject);
+
+ // 2. Let resolver be promise's associated resolver.
+ JSPromiseResolver* resolver = promise->resolver();
+
+ // 3. Let fulfillCallback be a new promise callback for resolver and its fulfill algorithm.
+ InternalFunction* fulfillWrapper = JSPromiseCallback::create(exec, globalObject, globalObject->promiseCallbackStructure(), resolver, JSPromiseCallback::Fulfill);
+
+ // 4. Let rejectWrapper be a promise wrapper callback for resolver and rejectCallback if rejectCallback is
+ // not omitted and a promise callback for resolver and its reject algorithm otherwise.
+ InternalFunction* rejectWrapper = wrapCallback(exec, globalObject, rejectCallback, resolver, JSPromiseCallback::Reject);
+
+ // 5. Append fulfillWrapper and rejectWrapper to the context object.
+ thisObject->appendCallbacks(exec, fulfillWrapper, rejectWrapper);
+
+ // 6. Return promise.
+ return JSValue::encode(promise);
+}
+
+} // namespace JSC
diff --git a/Source/JavaScriptCore/runtime/JSPromisePrototype.h b/Source/JavaScriptCore/runtime/JSPromisePrototype.h
new file mode 100644
index 0000000..c979beb
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromisePrototype.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSPromisePrototype_h
+#define JSPromisePrototype_h
+
+#include "JSObject.h"
+
+namespace JSC {
+
+class JSPromisePrototype : public JSNonFinalObject {
+public:
+ typedef JSNonFinalObject Base;
+
+ static JSPromisePrototype* create(ExecState*, JSGlobalObject*, Structure*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(ExecState*, Structure*);
+ static const unsigned StructureFlags = OverridesGetOwnPropertySlot | JSObject::StructureFlags;
+
+private:
+ JSPromisePrototype(ExecState*, Structure*);
+ static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
+};
+
+} // namespace JSC
+
+#endif // JSPromisePrototype_h
diff --git a/Source/JavaScriptCore/runtime/JSPromiseResolver.cpp b/Source/JavaScriptCore/runtime/JSPromiseResolver.cpp
new file mode 100644
index 0000000..9427b66
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromiseResolver.cpp
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSPromiseResolver.h"
+
+#include "JSCJSValueInlines.h"
+#include "JSCellInlines.h"
+#include "JSGlobalObject.h"
+#include "JSPromise.h"
+#include "JSPromiseCallback.h"
+#include "SlotVisitorInlines.h"
+#include "StructureInlines.h"
+
+namespace JSC {
+
+const ClassInfo JSPromiseResolver::s_info = { "PromiseResolver", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSPromiseResolver) };
+
+JSPromiseResolver* JSPromiseResolver::create(VM& vm, Structure* structure, JSPromise* promise)
+{
+ JSPromiseResolver* object = new (NotNull, allocateCell<JSPromiseResolver>(vm.heap)) JSPromiseResolver(vm, structure);
+ object->finishCreation(vm, promise);
+ return object;
+}
+
+Structure* JSPromiseResolver::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+JSPromiseResolver::JSPromiseResolver(VM& vm, Structure* structure)
+ : JSNonFinalObject(vm, structure)
+ , m_isResolved(false)
+{
+}
+
+void JSPromiseResolver::finishCreation(VM& vm, JSPromise* promise)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+ m_promise.set(vm, this, promise);
+}
+
+void JSPromiseResolver::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ JSPromiseResolver* thisObject = jsCast<JSPromiseResolver*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
+ ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
+
+ Base::visitChildren(thisObject, visitor);
+ visitor.append(&thisObject->m_promise);
+}
+
+JSPromise* JSPromiseResolver::promise() const
+{
+ return m_promise.get();
+}
+
+void JSPromiseResolver::fulfillIfNotResolved(ExecState* exec, JSValue value)
+{
+ if (!m_isResolved) {
+ m_isResolved = true;
+ fulfill(exec, value);
+ }
+}
+
+void JSPromiseResolver::resolveIfNotResolved(ExecState* exec, JSValue value)
+{
+ if (!m_isResolved) {
+ m_isResolved = true;
+ resolve(exec, value);
+ }
+}
+
+void JSPromiseResolver::rejectIfNotResolved(ExecState* exec, JSValue value)
+{
+ if (!m_isResolved) {
+ m_isResolved = true;
+ reject(exec, value);
+ }
+}
+
+void JSPromiseResolver::fulfill(ExecState* exec, JSValue value, ResolverMode mode)
+{
+ // 1. Let promise be the context object's associated promise.
+ // 2. Set promise's state to fulfilled.
+ m_promise->setState(JSPromise::Fulfilled);
+
+ // 3. Set promise's result to value.
+ m_promise->setResult(exec->vm(), value);
+
+ // 4. If the synchronous flag is set, process promise's fulfill callbacks with value.
+ if (mode == ResolveSynchronously) {
+ m_promise->processFulfillCallbacksWithValue(exec, value);
+ return;
+ }
+
+ // 5. Otherwise, the synchronous flag is unset, queue a task to process promise's fulfill callbacks with value.
+ m_promise->queueTaskToProcessFulfillCallbacks(exec);
+}
+
+void JSPromiseResolver::resolve(ExecState* exec, JSValue value, ResolverMode mode)
+{
+ // 1. Let then be null.
+ JSValue then = jsNull();
+
+ // 2. If value is a JavaScript Object, set then to the result of calling the JavaScript [[Get]] internal
+ // method of value with property name then.
+ if (value.isObject()) {
+ then = value.get(exec, exec->propertyNames().then);
+
+ // 3. If calling the [[Get]] internal method threw an exception, catch it and run reject with the thrown
+ // exception and the synchronous flag if set, and then terminate these steps.
+ if (exec->hadException()) {
+ JSValue exception = exec->exception();
+ exec->clearException();
+
+ reject(exec, exception, mode);
+ return;
+ }
+
+ // 4. If JavaScript IsCallable(then) is true, run these substeps and then terminate these steps:
+ CallData callData;
+ CallType callType = JSC::getCallData(then, callData);
+ if (callType != CallTypeNone) {
+ // 4.1. Let fulfillCallback be a promise callback for the context object and its resolve algorithm.
+ JSPromiseCallback* fulfillCallback = JSPromiseCallback::create(exec, globalObject(), globalObject()->promiseCallbackStructure(), this, JSPromiseCallback::Resolve);
+
+ // 4.2. Let rejectCallback be a promise callback for the context object and its reject algorithm.
+ JSPromiseCallback* rejectCallback = JSPromiseCallback::create(exec, globalObject(), globalObject()->promiseCallbackStructure(), this, JSPromiseCallback::Reject);
+
+ // 4.3. Call the JavaScript [[Call]] internal method of then with this value value and fulfillCallback
+ // and rejectCallback as arguments.
+ MarkedArgumentBuffer thenArguments;
+ thenArguments.append(fulfillCallback);
+ thenArguments.append(rejectCallback);
+ call(exec, then, callType, callData, value, thenArguments);
+
+ // 4.4 If calling the [[Call]] internal method threw an exception, catch it and run context object's
+ // reject with the thrown exception and the synchronous flag if set.
+ if (exec->hadException()) {
+ JSValue exception = exec->exception();
+ exec->clearException();
+
+ reject(exec, exception, mode);
+ return;
+ }
+ return;
+ }
+ }
+
+ // 5. Run context object's fulfill with value and the synchronous flag if set.
+ fulfill(exec, value, mode);
+}
+
+void JSPromiseResolver::reject(ExecState* exec, JSValue value, ResolverMode mode)
+{
+ // 1. Let promise be the context object's associated promise.
+ // 2. Set promise's state to rejected.
+ m_promise->setState(JSPromise::Rejected);
+
+ // 3. Set promise's result to value.
+ m_promise->setResult(exec->vm(), value);
+
+ // 4. If the synchronous flag is set, process promise's reject callbacks with value.
+ if (mode == ResolveSynchronously) {
+ m_promise->processRejectCallbacksWithValue(exec, value);
+ return;
+ }
+
+ // 5. Otherwise, the synchronous flag is unset, queue a task to process promise's reject callbacks with value.
+ m_promise->queueTaskToProcessRejectCallbacks(exec);
+}
+
+} // namespace JSC
diff --git a/Source/JavaScriptCore/runtime/JSPromiseResolver.h b/Source/JavaScriptCore/runtime/JSPromiseResolver.h
new file mode 100644
index 0000000..06f3286
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromiseResolver.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSPromiseResolver_h
+#define JSPromiseResolver_h
+
+#include "JSObject.h"
+
+namespace JSC {
+
+class JSPromise;
+
+class JSPromiseResolver : public JSNonFinalObject {
+public:
+ typedef JSNonFinalObject Base;
+
+ static JSPromiseResolver* create(VM&, Structure*, JSPromise*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+ JSPromise* promise() const;
+
+ void fulfillIfNotResolved(ExecState*, JSValue);
+ void resolveIfNotResolved(ExecState*, JSValue);
+ void rejectIfNotResolved(ExecState*, JSValue);
+
+ enum ResolverMode {
+ ResolveSynchronously,
+ ResolveAsynchronously,
+ };
+
+ void fulfill(ExecState*, JSValue, ResolverMode = ResolveAsynchronously);
+ void resolve(ExecState*, JSValue, ResolverMode = ResolveAsynchronously);
+ void reject(ExecState*, JSValue, ResolverMode = ResolveAsynchronously);
+
+protected:
+ void finishCreation(VM&, JSPromise*);
+ static const unsigned StructureFlags = OverridesVisitChildren | JSObject::StructureFlags;
+
+private:
+ JSPromiseResolver(VM&, Structure*);
+
+ static void visitChildren(JSCell*, SlotVisitor&);
+
+ WriteBarrier<JSPromise> m_promise;
+ bool m_isResolved;
+};
+
+} // namespace JSC
+
+#endif // JSPromiseResolver_h
diff --git a/Source/JavaScriptCore/runtime/JSPromiseResolverConstructor.cpp b/Source/JavaScriptCore/runtime/JSPromiseResolverConstructor.cpp
new file mode 100644
index 0000000..adb65ab
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromiseResolverConstructor.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSPromiseResolverConstructor.h"
+
+#include "JSCJSValueInlines.h"
+#include "JSCellInlines.h"
+#include "JSPromiseResolverPrototype.h"
+#include "Lookup.h"
+#include "StructureInlines.h"
+
+namespace JSC {
+
+ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSPromiseResolverConstructor);
+
+const ClassInfo JSPromiseResolverConstructor::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSPromiseResolverConstructor) };
+
+JSPromiseResolverConstructor* JSPromiseResolverConstructor::create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, JSPromiseResolverPrototype* promisePrototype)
+{
+ JSPromiseResolverConstructor* constructor = new (NotNull, allocateCell<JSPromiseResolverConstructor>(*exec->heap())) JSPromiseResolverConstructor(globalObject, structure);
+ constructor->finishCreation(exec, promisePrototype);
+ return constructor;
+}
+
+Structure* JSPromiseResolverConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+JSPromiseResolverConstructor::JSPromiseResolverConstructor(JSGlobalObject* globalObject, Structure* structure)
+ : InternalFunction(globalObject, structure)
+{
+}
+
+void JSPromiseResolverConstructor::finishCreation(ExecState* exec, JSPromiseResolverPrototype* promiseResolverPrototype)
+{
+ Base::finishCreation(exec->vm(), "PromiseResolver");
+ putDirectWithoutTransition(exec->vm(), exec->propertyNames().prototype, promiseResolverPrototype, DontEnum | DontDelete | ReadOnly);
+}
+
+ConstructType JSPromiseResolverConstructor::getConstructData(JSCell*, ConstructData&)
+{
+ return ConstructTypeNone;
+}
+
+CallType JSPromiseResolverConstructor::getCallData(JSCell*, CallData&)
+{
+ return CallTypeNone;
+}
+
+} // namespace JSC
diff --git a/Source/JavaScriptCore/runtime/JSPromiseResolverConstructor.h b/Source/JavaScriptCore/runtime/JSPromiseResolverConstructor.h
new file mode 100644
index 0000000..191b5a1
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromiseResolverConstructor.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSPromiseResolverConstructor_h
+#define JSPromiseResolverConstructor_h
+
+#include "InternalFunction.h"
+
+namespace JSC {
+
+class JSPromiseResolverPrototype;
+
+class JSPromiseResolverConstructor : public InternalFunction {
+public:
+ typedef InternalFunction Base;
+
+ static JSPromiseResolverConstructor* create(ExecState*, JSGlobalObject*, Structure*, JSPromiseResolverPrototype*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(ExecState*, JSPromiseResolverPrototype*);
+ static const unsigned StructureFlags = InternalFunction::StructureFlags;
+
+private:
+ JSPromiseResolverConstructor(JSGlobalObject*, Structure*);
+ static ConstructType getConstructData(JSCell*, ConstructData&);
+ static CallType getCallData(JSCell*, CallData&);
+};
+
+} // namespace JSC
+
+#endif // JSPromiseResolverConstructor_h
diff --git a/Source/JavaScriptCore/runtime/JSPromiseResolverPrototype.cpp b/Source/JavaScriptCore/runtime/JSPromiseResolverPrototype.cpp
new file mode 100644
index 0000000..103627a
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromiseResolverPrototype.cpp
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSPromiseResolverPrototype.h"
+
+#include "Error.h"
+#include "JSCJSValueInlines.h"
+#include "JSCellInlines.h"
+#include "JSPromiseResolver.h"
+#include "StructureInlines.h"
+
+namespace JSC {
+
+ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSPromiseResolverPrototype);
+
+// void fulfill(optional any value);
+static EncodedJSValue JSC_HOST_CALL JSPromiseResolverPrototypeFuncFulfill(ExecState*);
+// void resolve(optional any value);
+static EncodedJSValue JSC_HOST_CALL JSPromiseResolverPrototypeFuncResolve(ExecState*);
+// void reject(optional any value);
+static EncodedJSValue JSC_HOST_CALL JSPromiseResolverPrototypeFuncReject(ExecState*);
+
+}
+
+#include "JSPromiseResolverPrototype.lut.h"
+
+namespace JSC {
+
+const ClassInfo JSPromiseResolverPrototype::s_info = { "PromiseResolverPrototype", &Base::s_info, 0, ExecState::promiseResolverPrototypeTable, CREATE_METHOD_TABLE(JSPromiseResolverPrototype) };
+
+/* Source for JSPromiseResolverPrototype.lut.h
+@begin promiseResolverPrototypeTable
+ fulfill JSPromiseResolverPrototypeFuncFulfill DontEnum|Function 1
+ resolve JSPromiseResolverPrototypeFuncResolve DontEnum|Function 1
+ reject JSPromiseResolverPrototypeFuncReject DontEnum|Function 1
+@end
+*/
+
+JSPromiseResolverPrototype* JSPromiseResolverPrototype::create(ExecState* exec, JSGlobalObject*, Structure* structure)
+{
+ JSPromiseResolverPrototype* object = new (NotNull, allocateCell<JSPromiseResolverPrototype>(*exec->heap())) JSPromiseResolverPrototype(exec, structure);
+ object->finishCreation(exec, structure);
+ return object;
+}
+
+Structure* JSPromiseResolverPrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+JSPromiseResolverPrototype::JSPromiseResolverPrototype(ExecState* exec, Structure* structure)
+ : JSNonFinalObject(exec->vm(), structure)
+{
+}
+
+void JSPromiseResolverPrototype::finishCreation(ExecState* exec, Structure*)
+{
+ Base::finishCreation(exec->vm());
+}
+
+bool JSPromiseResolverPrototype::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
+{
+ return getStaticFunctionSlot<JSObject>(exec, ExecState::promiseResolverPrototypeTable(exec), jsCast<JSPromiseResolverPrototype*>(object), propertyName, slot);
+}
+
+EncodedJSValue JSC_HOST_CALL JSPromiseResolverPrototypeFuncFulfill(ExecState* exec)
+{
+ JSPromiseResolver* thisObject = jsDynamicCast<JSPromiseResolver*>(exec->thisValue());
+ if (!thisObject)
+ return throwVMError(exec, createTypeError(exec, "Receiver of fulfill must be a PromiseResolver"));
+
+ thisObject->fulfillIfNotResolved(exec, exec->argument(0));
+ return JSValue::encode(jsUndefined());
+}
+
+EncodedJSValue JSC_HOST_CALL JSPromiseResolverPrototypeFuncResolve(ExecState* exec)
+{
+ JSPromiseResolver* thisObject = jsDynamicCast<JSPromiseResolver*>(exec->thisValue());
+ if (!thisObject)
+ return throwVMError(exec, createTypeError(exec, "Receiver of resolve must be a PromiseResolver"));
+
+ thisObject->resolveIfNotResolved(exec, exec->argument(0));
+ return JSValue::encode(jsUndefined());
+}
+
+EncodedJSValue JSC_HOST_CALL JSPromiseResolverPrototypeFuncReject(ExecState* exec)
+{
+ JSPromiseResolver* thisObject = jsDynamicCast<JSPromiseResolver*>(exec->thisValue());
+ if (!thisObject)
+ return throwVMError(exec, createTypeError(exec, "Receiver of reject must be a PromiseResolver"));
+
+ thisObject->rejectIfNotResolved(exec, exec->argument(0));
+ return JSValue::encode(jsUndefined());
+}
+
+} // namespace JSC
diff --git a/Source/JavaScriptCore/runtime/JSPromiseResolverPrototype.h b/Source/JavaScriptCore/runtime/JSPromiseResolverPrototype.h
new file mode 100644
index 0000000..e61e67d
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/JSPromiseResolverPrototype.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSPromiseResolverPrototype_h
+#define JSPromiseResolverPrototype_h
+
+#include "JSObject.h"
+
+namespace JSC {
+
+class JSPromiseResolverPrototype : public JSNonFinalObject {
+public:
+ typedef JSNonFinalObject Base;
+
+ static JSPromiseResolverPrototype* create(ExecState*, JSGlobalObject*, Structure*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(ExecState*, Structure*);
+ static const unsigned StructureFlags = OverridesGetOwnPropertySlot | JSObject::StructureFlags;
+
+private:
+ JSPromiseResolverPrototype(ExecState*, Structure*);
+ static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
+};
+
+} // namespace JSC
+
+#endif // JSPromiseResolverPrototype_h
diff --git a/Source/JavaScriptCore/runtime/VM.cpp b/Source/JavaScriptCore/runtime/VM.cpp
index 9beeb05..9bb0d4c 100644
--- a/Source/JavaScriptCore/runtime/VM.cpp
+++ b/Source/JavaScriptCore/runtime/VM.cpp
@@ -101,6 +101,9 @@
extern const HashTable regExpConstructorTable;
extern const HashTable regExpPrototypeTable;
extern const HashTable stringConstructorTable;
+extern const HashTable promisePrototypeTable;
+extern const HashTable promiseConstructorTable;
+extern const HashTable promiseResolverPrototypeTable;
// Note: Platform.h will enforce that ENABLE(ASSEMBLER) is true if either
// ENABLE(JIT) or ENABLE(YARR_JIT) or both are enabled. The code below
@@ -161,6 +164,9 @@
, regExpConstructorTable(fastNew<HashTable>(JSC::regExpConstructorTable))
, regExpPrototypeTable(fastNew<HashTable>(JSC::regExpPrototypeTable))
, stringConstructorTable(fastNew<HashTable>(JSC::stringConstructorTable))
+ , promisePrototypeTable(fastNew<HashTable>(JSC::promisePrototypeTable))
+ , promiseConstructorTable(fastNew<HashTable>(JSC::promiseConstructorTable))
+ , promiseResolverPrototypeTable(fastNew<HashTable>(JSC::promiseResolverPrototypeTable))
, identifierTable(vmType == Default ? wtfThreadData().currentIdentifierTable() : createIdentifierTable())
, propertyNames(new CommonIdentifiers(this))
, emptyList(new MarkedArgumentBuffer)
@@ -310,6 +316,9 @@
regExpConstructorTable->deleteTable();
regExpPrototypeTable->deleteTable();
stringConstructorTable->deleteTable();
+ promisePrototypeTable->deleteTable();
+ promiseConstructorTable->deleteTable();
+ promiseResolverPrototypeTable->deleteTable();
fastDelete(const_cast<HashTable*>(arrayConstructorTable));
fastDelete(const_cast<HashTable*>(arrayPrototypeTable));
@@ -328,6 +337,9 @@
fastDelete(const_cast<HashTable*>(regExpConstructorTable));
fastDelete(const_cast<HashTable*>(regExpPrototypeTable));
fastDelete(const_cast<HashTable*>(stringConstructorTable));
+ fastDelete(const_cast<HashTable*>(promisePrototypeTable));
+ fastDelete(const_cast<HashTable*>(promiseConstructorTable));
+ fastDelete(const_cast<HashTable*>(promiseResolverPrototypeTable));
delete emptyList;
diff --git a/Source/JavaScriptCore/runtime/VM.h b/Source/JavaScriptCore/runtime/VM.h
index fbf8acc..843db3a 100644
--- a/Source/JavaScriptCore/runtime/VM.h
+++ b/Source/JavaScriptCore/runtime/VM.h
@@ -235,6 +235,9 @@
const HashTable* regExpConstructorTable;
const HashTable* regExpPrototypeTable;
const HashTable* stringConstructorTable;
+ const HashTable* promisePrototypeTable;
+ const HashTable* promiseConstructorTable;
+ const HashTable* promiseResolverPrototypeTable;
Strong<Structure> structureStructure;
Strong<Structure> structureRareDataStructure;