Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (158316 => 158317)
--- trunk/Source/_javascript_Core/ChangeLog 2013-10-30 21:51:42 UTC (rev 158316)
+++ trunk/Source/_javascript_Core/ChangeLog 2013-10-30 22:05:47 UTC (rev 158317)
@@ -1,3 +1,17 @@
+2013-10-30 Alexey Proskuryakov <a...@apple.com>
+
+ Add a way to fulfill promises from DOM code
+ https://bugs.webkit.org/show_bug.cgi?id=123466
+
+ Reviewed by Sam Weinig.
+
+ * _javascript_Core.xcodeproj/project.pbxproj: Make JSPromise.h and JSPromiseResolver.h
+ private headers for WebCore to use.
+
+ * runtime/JSPromise.h:
+ * runtime/JSPromiseResolver.h:
+ Export functions that JSDOMPromise will use.
+
2013-10-30 Mark Lam <mark....@apple.com>
Adjust CallFrameHeader's ReturnPC and CallFrame locations to match the native ABI .
Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (158316 => 158317)
--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2013-10-30 21:51:42 UTC (rev 158316)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2013-10-30 22:05:47 UTC (rev 158317)
@@ -735,13 +735,13 @@
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 */; };
+ 7C184E1B17BEDBD3007CB63A /* JSPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C184E1917BEDBD3007CB63A /* JSPromise.h */; settings = {ATTRIBUTES = (Private, ); }; };
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 */; };
+ 7C3BA29517C039560072DDC9 /* JSPromiseResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C3BA28F17C039560072DDC9 /* JSPromiseResolver.h */; settings = {ATTRIBUTES = (Private, ); }; };
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 */; };
Modified: trunk/Source/_javascript_Core/runtime/JSPromise.h (158316 => 158317)
--- trunk/Source/_javascript_Core/runtime/JSPromise.h 2013-10-30 21:51:42 UTC (rev 158316)
+++ trunk/Source/_javascript_Core/runtime/JSPromise.h 2013-10-30 22:05:47 UTC (rev 158317)
@@ -43,12 +43,12 @@
static JSPromise* create(VM&, Structure*);
static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
- static JSPromise* createWithResolver(VM&, JSGlobalObject*);
+ JS_EXPORT_PRIVATE static JSPromise* createWithResolver(VM&, JSGlobalObject*);
DECLARE_INFO;
void setResolver(VM&, JSPromiseResolver*);
- JSPromiseResolver* resolver() const;
+ JS_EXPORT_PRIVATE JSPromiseResolver* resolver() const;
enum State {
Pending,
Modified: trunk/Source/_javascript_Core/runtime/JSPromiseResolver.h (158316 => 158317)
--- trunk/Source/_javascript_Core/runtime/JSPromiseResolver.h 2013-10-30 21:51:42 UTC (rev 158316)
+++ trunk/Source/_javascript_Core/runtime/JSPromiseResolver.h 2013-10-30 22:05:47 UTC (rev 158317)
@@ -45,9 +45,9 @@
JSPromise* promise() const;
- void fulfillIfNotResolved(ExecState*, JSValue);
+ JS_EXPORT_PRIVATE void fulfillIfNotResolved(ExecState*, JSValue);
void resolveIfNotResolved(ExecState*, JSValue);
- void rejectIfNotResolved(ExecState*, JSValue);
+ JS_EXPORT_PRIVATE void rejectIfNotResolved(ExecState*, JSValue);
enum ResolverMode {
ResolveSynchronously,
Modified: trunk/Source/WebCore/ChangeLog (158316 => 158317)
--- trunk/Source/WebCore/ChangeLog 2013-10-30 21:51:42 UTC (rev 158316)
+++ trunk/Source/WebCore/ChangeLog 2013-10-30 22:05:47 UTC (rev 158317)
@@ -1,3 +1,28 @@
+2013-10-30 Alexey Proskuryakov <a...@apple.com>
+
+ Add a way to fulfill promises from DOM code
+ https://bugs.webkit.org/show_bug.cgi?id=123466
+
+ Reviewed by Sam Weinig.
+
+ This is not perfect, as it strongly ties DOM code to _javascript_. In the future, we
+ can make it better e.g. by subclassing, so that only a base interface would be exposed.
+
+ * GNUmakefile.list.am:
+ * WebCore.vcxproj/WebCore.vcxproj:
+ * WebCore.vcxproj/WebCore.vcxproj.filters:
+ * bindings/js/JSBindingsAllInOne.cpp:
+ * WebCore.xcodeproj/project.pbxproj:
+ Added JSDOMPromise.
+
+ * bindings/js/JSDOMPromise.cpp: Added.
+
+ * bindings/js/JSDOMPromise.h: Added.
+ (WebCore::PromiseWrapper::create):
+ (WebCore::PromiseWrapper::fulfill): A random set of specializations that I needed
+ in WebCrypto code so far.
+ (WebCore::PromiseWrapper::reject): Ditto.
+
2013-10-30 Santosh Mahto <santosh...@samsung.com>
contentEditable deleting lists when list items are block level
Modified: trunk/Source/WebCore/GNUmakefile.list.am (158316 => 158317)
--- trunk/Source/WebCore/GNUmakefile.list.am 2013-10-30 21:51:42 UTC (rev 158316)
+++ trunk/Source/WebCore/GNUmakefile.list.am 2013-10-30 22:05:47 UTC (rev 158317)
@@ -2285,6 +2285,8 @@
Source/WebCore/bindings/js/JSDOMMimeTypeArrayCustom.cpp \
Source/WebCore/bindings/js/JSDOMPluginArrayCustom.cpp \
Source/WebCore/bindings/js/JSDOMPluginCustom.cpp \
+ Source/WebCore/bindings/js/JSDOMPromise.cpp \
+ Source/WebCore/bindings/js/JSDOMPromise.h \
Source/WebCore/bindings/js/JSDOMStringListCustom.cpp \
Source/WebCore/bindings/js/JSDOMStringMapCustom.cpp \
Source/WebCore/bindings/js/JSDOMWindowBase.cpp \
Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (158316 => 158317)
--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj 2013-10-30 21:51:42 UTC (rev 158316)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj 2013-10-30 22:05:47 UTC (rev 158317)
@@ -15961,6 +15961,20 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
</ClCompile>
+ <ClCompile Include="..\bindings\js\JSDOMPromise.cpp">
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|x64'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|x64'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|x64'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
+ </ClCompile>
<ClCompile Include="..\bindings\js\JSDOMStringListCustom.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
@@ -20317,6 +20331,7 @@
<ClInclude Include="..\bindings\js\JSDOMBinding.h" />
<ClInclude Include="..\bindings\js\JSDOMGlobalObject.h" />
<ClInclude Include="..\bindings\js\JSDOMGlobalObjectTask.h" />
+ <ClInclude Include="..\bindings\js\JSDOMPromise.h" />
<ClInclude Include="..\bindings\js\JSDOMWindowBase.h" />
<ClInclude Include="..\bindings\js\JSDOMWindowCustom.h" />
<ClInclude Include="..\bindings\js\JSDOMWindowShell.h" />
Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (158316 => 158317)
--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters 2013-10-30 21:51:42 UTC (rev 158316)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters 2013-10-30 22:05:47 UTC (rev 158317)
@@ -4365,6 +4365,9 @@
<ClCompile Include="..\bindings\js\JSDOMPluginCustom.cpp">
<Filter>bindings\js</Filter>
</ClCompile>
+ <ClCompile Include="..\bindings\js\JSDOMPromise.cpp">
+ <Filter>bindings\js</Filter>
+ </ClCompile>
<ClCompile Include="..\bindings\js\JSDOMStringListCustom.cpp">
<Filter>bindings\js</Filter>
</ClCompile>
@@ -11389,6 +11392,9 @@
<ClInclude Include="..\bindings\js\JSDOMGlobalObjectTask.h">
<Filter>bindings\js</Filter>
</ClInclude>
+ <ClInclude Include="..\bindings\js\JSDOMPromise.h">
+ <Filter>bindings\js</Filter>
+ </ClInclude>
<ClInclude Include="..\bindings\js\JSErrorHandler.h">
<Filter>bindings\js</Filter>
</ClInclude>
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (158316 => 158317)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2013-10-30 21:51:42 UTC (rev 158316)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2013-10-30 22:05:47 UTC (rev 158317)
@@ -5552,6 +5552,8 @@
E16982601134636A00894115 /* ObjCRuntimeObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = E169825F1134636A00894115 /* ObjCRuntimeObject.mm */; };
E16A84F914C85CCC002977DF /* CSSBorderImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E16A84F714C85CCC002977DF /* CSSBorderImage.cpp */; };
E16A84FA14C85CCC002977DF /* CSSBorderImage.h in Headers */ = {isa = PBXBuildFile; fileRef = E16A84F814C85CCC002977DF /* CSSBorderImage.h */; };
+ E172AF8F1811BC3700FBADB9 /* JSDOMPromise.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E172AF8D1811BC3700FBADB9 /* JSDOMPromise.cpp */; };
+ E172AF901811BC3700FBADB9 /* JSDOMPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = E172AF8E1811BC3700FBADB9 /* JSDOMPromise.h */; };
E172AF70180F289500FBADB9 /* CryptoKeyUsage.h in Headers */ = {isa = PBXBuildFile; fileRef = E172AF6F180F289500FBADB9 /* CryptoKeyUsage.h */; };
E172AF77180F366C00FBADB9 /* CryptoKeyFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = E172AF76180F366C00FBADB9 /* CryptoKeyFormat.h */; };
E17B491516A9B094001C8839 /* TransitionEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E17B491316A9B093001C8839 /* TransitionEvent.cpp */; };
@@ -12548,6 +12550,8 @@
E169825F1134636A00894115 /* ObjCRuntimeObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ObjCRuntimeObject.mm; sourceTree = "<group>"; };
E16A84F714C85CCC002977DF /* CSSBorderImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSBorderImage.cpp; sourceTree = "<group>"; };
E16A84F814C85CCC002977DF /* CSSBorderImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSBorderImage.h; sourceTree = "<group>"; };
+ E172AF8D1811BC3700FBADB9 /* JSDOMPromise.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMPromise.cpp; sourceTree = "<group>"; };
+ E172AF8E1811BC3700FBADB9 /* JSDOMPromise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMPromise.h; sourceTree = "<group>"; };
E172AF6F180F289500FBADB9 /* CryptoKeyUsage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKeyUsage.h; sourceTree = "<group>"; };
E172AF76180F366C00FBADB9 /* CryptoKeyFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKeyFormat.h; sourceTree = "<group>"; };
E176580C180DF3A0005A96D1 /* OESElementIndexUint.idl */ = {isa = PBXFileReference; lastKnownFileType = text; name = OESElementIndexUint.idl; path = canvas/OESElementIndexUint.idl; sourceTree = "<group>"; };
@@ -19280,6 +19284,8 @@
E1C36C020EB076D6007410BC /* JSDOMGlobalObject.h */,
7C2BDD3B17C7F98B0038FF15 /* JSDOMGlobalObjectTask.cpp */,
7C2BDD3C17C7F98B0038FF15 /* JSDOMGlobalObjectTask.h */,
+ E172AF8D1811BC3700FBADB9 /* JSDOMPromise.cpp */,
+ E172AF8E1811BC3700FBADB9 /* JSDOMPromise.h */,
BC6932710D7E293900AE44D1 /* JSDOMWindowBase.cpp */,
BC6932720D7E293900AE44D1 /* JSDOMWindowBase.h */,
BCBFB53A0DCD29CF0019B3E5 /* JSDOMWindowShell.cpp */,
@@ -23488,6 +23494,7 @@
B562DB6017D3CD630010AF96 /* HTMLElementTypeHelpers.h in Headers */,
A5ABB78713B904BC00F197E3 /* LineBreakIteratorPoolICU.h in Headers */,
AB31C91E10AE1B8E000C7B92 /* LineClampValue.h in Headers */,
+ E172AF901811BC3700FBADB9 /* JSDOMPromise.h in Headers */,
89B5EAA211E8003D00F2367E /* LineEnding.h in Headers */,
A7AD2F880EC89D07008AB002 /* LinkHash.h in Headers */,
98CE432A129E00E5005821DC /* LinkLoader.h in Headers */,
@@ -27820,6 +27827,7 @@
E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
977E2E0E12F0FC9C00C13380 /* XSSAuditorDelegate.cpp in Sources */,
+ E172AF8F1811BC3700FBADB9 /* JSDOMPromise.cpp in Sources */,
FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
FD1762DF176686D900D836A8 /* UpSampler.cpp in Sources */,
FD1762E3176686EA00D836A8 /* DownSampler.cpp in Sources */,
Modified: trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp (158316 => 158317)
--- trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp 2013-10-30 21:51:42 UTC (rev 158316)
+++ trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp 2013-10-30 22:05:47 UTC (rev 158317)
@@ -55,6 +55,7 @@
#include "JSDOMMimeTypeArrayCustom.cpp"
#include "JSDOMPluginArrayCustom.cpp"
#include "JSDOMPluginCustom.cpp"
+#include "JSDOMPromise.cpp"
#include "JSDOMStringListCustom.cpp"
#include "JSDOMStringMapCustom.cpp"
#include "JSDOMWindowBase.cpp"
Copied: trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp (from rev 158316, trunk/Source/_javascript_Core/runtime/JSPromiseResolver.h) (0 => 158317)
--- trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp 2013-10-30 22:05:47 UTC (rev 158317)
@@ -0,0 +1,37 @@
+/*
+ * 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 "JSDOMPromise.h"
+
+namespace WebCore {
+
+PromiseWrapper::PromiseWrapper(JSDOMGlobalObject* globalObject, JSC::JSPromise* promise)
+ : m_globalObject(globalObject->vm(), globalObject)
+ , m_promise(globalObject->vm(), promise)
+{
+}
+
+}
Added: trunk/Source/WebCore/bindings/js/JSDOMPromise.h (0 => 158317)
--- trunk/Source/WebCore/bindings/js/JSDOMPromise.h (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSDOMPromise.h 2013-10-30 22:05:47 UTC (rev 158317)
@@ -0,0 +1,106 @@
+/*
+ * 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 JSDOMPromise_h
+#define JSDOMPromise_h
+
+#include "JSCryptoKey.h"
+#include "JSDOMBinding.h"
+#include <_javascript_Core/JSGlobalObject.h>
+#include <_javascript_Core/JSPromise.h>
+#include <_javascript_Core/JSPromiseResolver.h>
+#include <_javascript_Core/StrongInlines.h>
+#include <wtf/Noncopyable.h>
+
+namespace WebCore {
+
+// FIXME: Using this class in DOM code makes it dependent on JS bindings.
+class PromiseWrapper {
+ WTF_MAKE_NONCOPYABLE(PromiseWrapper)
+public:
+ static std::unique_ptr<PromiseWrapper> create(JSDOMGlobalObject* globalObject, JSC::JSPromise* promise)
+ {
+ return std::unique_ptr<PromiseWrapper>(new PromiseWrapper(globalObject, promise));
+ }
+
+ template<class FulfillResultType>
+ void fulfill(const FulfillResultType&);
+
+ template<class RejectResultType>
+ void reject(const RejectResultType&);
+
+private:
+ PromiseWrapper(JSDOMGlobalObject*, JSC::JSPromise*);
+
+ JSC::Strong<JSDOMGlobalObject> m_globalObject;
+ JSC::Strong<JSC::JSPromise> m_promise;
+};
+
+template<class FulfillResultType>
+inline void PromiseWrapper::fulfill(const FulfillResultType& result)
+{
+ JSC::ExecState* exec = m_globalObject->globalExec();
+ m_promise->resolver()->fulfillIfNotResolved(exec, toJS(exec, m_globalObject.get(), result));
+}
+
+template<class RejectResultType>
+inline void PromiseWrapper::reject(const RejectResultType& result)
+{
+ JSC::ExecState* exec = m_globalObject->globalExec();
+ m_promise->resolver()->rejectIfNotResolved(exec, toJS(exec, m_globalObject.get(), result));
+}
+
+template<>
+inline void PromiseWrapper::fulfill<String>(const String& result)
+{
+ JSC::ExecState* exec = m_globalObject->globalExec();
+ m_promise->resolver()->fulfillIfNotResolved(exec, jsString(exec, result));
+}
+
+template<>
+inline void PromiseWrapper::fulfill<bool>(const bool& result)
+{
+ JSC::ExecState* exec = m_globalObject->globalExec();
+ m_promise->resolver()->fulfillIfNotResolved(exec, JSC::jsBoolean(result));
+}
+
+template<>
+inline void PromiseWrapper::fulfill<Vector<unsigned char>>(const Vector<unsigned char>& result)
+{
+ JSC::ExecState* exec = m_globalObject->globalExec();
+ RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(result.data(), result.size());
+ m_promise->resolver()->fulfillIfNotResolved(exec, toJS(exec, m_globalObject.get(), buffer.get()));
+}
+
+template<>
+inline void PromiseWrapper::reject<String>(const String& result)
+{
+ JSC::ExecState* exec = m_globalObject->globalExec();
+ m_promise->resolver()->rejectIfNotResolved(exec, jsString(exec, result));
+}
+
+}
+
+#endif // JSDOMPromise_h