Improve DeferredWrapper code
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Sep 2016 07:35:46 +0000 (07:35 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Sep 2016 07:35:46 +0000 (07:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161787

Patch by Youenn Fablet <youenn@apple.com> on 2016-09-22
Reviewed by Darin Adler.

No change of behavior.

Renaming DeferredWrapper to DeferredPromise.
Adding create method that creates the underlying JSC::JSPromiseDeferred in non-worker environments.
Updated create method to take references.
Introducing domWindow helper accessor into JSDOMObject to ease creation of promise in non-worker environments.
Doing some minor clean up (renaming of m_wrapper to m_promiseDeferred, accessor change).

* Modules/applepay/ApplePaySession.cpp:
(WebCore::ApplePaySession::canMakePaymentsWithActiveCard):
* Modules/applepay/ApplePaySession.h:
* Modules/fetch/DOMWindowFetch.cpp:
(WebCore::DOMWindowFetch::fetch):
* Modules/fetch/DOMWindowFetch.h: Updated to take a DeferredPromise to make it consistent with WorkerGlobalScopeFetch.
* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::arrayBuffer):
(WebCore::FetchBody::blob):
(WebCore::FetchBody::json):
(WebCore::FetchBody::text):
(WebCore::FetchBody::consume):
(WebCore::FetchBody::consumeArrayBuffer):
(WebCore::FetchBody::consumeArrayBufferView):
(WebCore::FetchBody::consumeText):
(WebCore::FetchBody::consumeBlob):
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::formData):
* Modules/fetch/FetchBodyConsumer.cpp:
(WebCore::FetchBodyConsumer::resolveWithData):
(WebCore::FetchBodyConsumer::resolve):
* Modules/fetch/FetchBodyConsumer.h:
* Modules/fetch/FetchBodyOwner.cpp:
(WebCore::FetchBodyOwner::arrayBuffer):
(WebCore::FetchBodyOwner::blob):
(WebCore::FetchBodyOwner::formData):
(WebCore::FetchBodyOwner::json):
(WebCore::FetchBodyOwner::text):
* Modules/fetch/FetchBodyOwner.h:
* Modules/fetch/FetchResponse.cpp:
(WebCore::FetchResponse::consume):
(WebCore::FetchResponse::finishConsumingStream):
* Modules/fetch/FetchResponse.h:
* Modules/fetch/WorkerGlobalScopeFetch.cpp:
(WebCore::WorkerGlobalScopeFetch::fetch):
* Modules/fetch/WorkerGlobalScopeFetch.h:
* bindings/js/JSCustomElementRegistryCustom.cpp:
(WebCore::whenDefinedPromise):
(WebCore::JSCustomElementRegistry::whenDefined):
* bindings/js/JSDOMGlobalObject.cpp:
(WebCore::JSDOMGlobalObject::visitChildren):
* bindings/js/JSDOMGlobalObject.h:
* bindings/js/JSDOMPromise.cpp:
(WebCore::DOMDeferredPromise::DOMDeferredPromise):
(WebCore::DOMDeferredPromise::~DOMDeferredPromise):
(WebCore::DOMDeferredPromise::clear):
(WebCore::DOMDeferredPromise::contextDestroyed):
(WebCore::DOMDeferredPromise::promise):
(WebCore::DOMDeferredPromise::callFunction):
(WebCore::DOMDeferredPromise::reject):
(WebCore::rejectPromiseWithExceptionIfAny):
(WebCore::fulfillPromiseWithJSON):
(WebCore::fulfillPromiseWithArrayBuffer):
(WebCore::DeferredWrapper::DeferredWrapper): Deleted.
(WebCore::DeferredWrapper::~DeferredWrapper): Deleted.
(WebCore::DeferredWrapper::clear): Deleted.
(WebCore::DeferredWrapper::contextDestroyed): Deleted.
(WebCore::DeferredWrapper::promise): Deleted.
(WebCore::DeferredWrapper::callFunction): Deleted.
(WebCore::DeferredWrapper::reject): Deleted.
* bindings/js/JSDOMPromise.h:
(WebCore::DOMDeferredPromise::create):
(WebCore::callPromiseFunction):
(WebCore::DOMPromise::DOMPromise):
(WebCore::DOMPromise::deferredPromise):
(WebCore::DOMDeferredPromise::resolveWithValue):
(WebCore::DOMDeferredPromise::resolveWithNewlyCreated):
(WebCore::DOMDeferredPromise::rejectWithValue):
(WebCore::DOMDeferredPromise::resolve):
(WebCore::DOMDeferredPromise::reject):
(WebCore::DeferredWrapper::create): Deleted.
(WebCore::DOMPromise::deferredWrapper): Deleted.
(WebCore::DeferredWrapper::resolveWithValue): Deleted.
(WebCore::DeferredWrapper::resolveWithNewlyCreated): Deleted.
(WebCore::DeferredWrapper::rejectWithValue): Deleted.
(WebCore::DeferredWrapper::resolve): Deleted.
(WebCore::DeferredWrapper::reject): Deleted.
* bindings/js/JSDOMWrapper.cpp: Introducing domWindow() accessor.
* bindings/js/JSDOMWrapper.h:
* bindings/js/JSFontFaceCustom.cpp:
(WebCore::JSFontFace::loaded):
* bindings/js/JSFontFaceSetCustom.cpp:
(WebCore::JSFontFaceSet::ready):
* bindings/js/JSMediaDevicesCustom.cpp:
(WebCore::JSMediaDevices::getUserMedia):
* bindings/js/JSMediaStreamTrackCustom.cpp:
(WebCore::JSMediaStreamTrack::applyConstraints):
* bindings/js/JSReadableStreamSourceCustom.cpp:
(WebCore::JSReadableStreamSource::start):
* bindings/js/JSWebKitSubtleCryptoCustom.cpp:
(WebCore::JSWebKitSubtleCrypto::encrypt):
(WebCore::JSWebKitSubtleCrypto::decrypt):
(WebCore::JSWebKitSubtleCrypto::sign):
(WebCore::JSWebKitSubtleCrypto::verify):
(WebCore::JSWebKitSubtleCrypto::digest):
(WebCore::JSWebKitSubtleCrypto::generateKey):
(WebCore::JSWebKitSubtleCrypto::importKey):
(WebCore::JSWebKitSubtleCrypto::exportKey):
(WebCore::JSWebKitSubtleCrypto::wrapKey):
(WebCore::JSWebKitSubtleCrypto::unwrapKey):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation):
(GenerateReturnParameters):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionPromise):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise):
(WebCore::jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Promise):
(WebCore::jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2Promise):
(WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunctionPromise):
(WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionPromise):
* dom/CustomElementRegistry.h:
(WebCore::CustomElementRegistry::promiseMap):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@206252 268f45cc-cd09-0410-ab3c-d52691b4dbfc

34 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/applepay/ApplePaySession.cpp
Source/WebCore/Modules/applepay/ApplePaySession.h
Source/WebCore/Modules/fetch/DOMWindowFetch.cpp
Source/WebCore/Modules/fetch/DOMWindowFetch.h
Source/WebCore/Modules/fetch/FetchBody.cpp
Source/WebCore/Modules/fetch/FetchBody.h
Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp
Source/WebCore/Modules/fetch/FetchBodyConsumer.h
Source/WebCore/Modules/fetch/FetchBodyOwner.cpp
Source/WebCore/Modules/fetch/FetchBodyOwner.h
Source/WebCore/Modules/fetch/FetchResponse.cpp
Source/WebCore/Modules/fetch/FetchResponse.h
Source/WebCore/Modules/fetch/WorkerGlobalScopeFetch.cpp
Source/WebCore/Modules/fetch/WorkerGlobalScopeFetch.h
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSCustomElementRegistryCustom.cpp
Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
Source/WebCore/bindings/js/JSDOMGlobalObject.h
Source/WebCore/bindings/js/JSDOMPromise.cpp
Source/WebCore/bindings/js/JSDOMPromise.h
Source/WebCore/bindings/js/JSDOMWrapper.cpp
Source/WebCore/bindings/js/JSDOMWrapper.h
Source/WebCore/bindings/js/JSFontFaceCustom.cpp
Source/WebCore/bindings/js/JSFontFaceSetCustom.cpp
Source/WebCore/bindings/js/JSMediaDevicesCustom.cpp
Source/WebCore/bindings/js/JSMediaStreamTrackCustom.cpp
Source/WebCore/bindings/js/JSReadableStreamSourceCustom.cpp
Source/WebCore/bindings/js/JSWebKitSubtleCryptoCustom.cpp
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSTestNode.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
Source/WebCore/dom/CustomElementRegistry.cpp
Source/WebCore/dom/CustomElementRegistry.h

index aa9d81f..c0cd450 100644 (file)
@@ -1,3 +1,133 @@
+2016-09-22  Youenn Fablet  <youenn@apple.com>
+
+        Improve DeferredWrapper code
+        https://bugs.webkit.org/show_bug.cgi?id=161787
+
+        Reviewed by Darin Adler.
+
+        No change of behavior.
+
+        Renaming DeferredWrapper to DeferredPromise.
+        Adding create method that creates the underlying JSC::JSPromiseDeferred in non-worker environments.
+        Updated create method to take references.
+        Introducing domWindow helper accessor into JSDOMObject to ease creation of promise in non-worker environments.
+        Doing some minor clean up (renaming of m_wrapper to m_promiseDeferred, accessor change).
+
+        * Modules/applepay/ApplePaySession.cpp:
+        (WebCore::ApplePaySession::canMakePaymentsWithActiveCard):
+        * Modules/applepay/ApplePaySession.h:
+        * Modules/fetch/DOMWindowFetch.cpp:
+        (WebCore::DOMWindowFetch::fetch):
+        * Modules/fetch/DOMWindowFetch.h: Updated to take a DeferredPromise to make it consistent with WorkerGlobalScopeFetch.
+        * Modules/fetch/FetchBody.cpp:
+        (WebCore::FetchBody::arrayBuffer):
+        (WebCore::FetchBody::blob):
+        (WebCore::FetchBody::json):
+        (WebCore::FetchBody::text):
+        (WebCore::FetchBody::consume):
+        (WebCore::FetchBody::consumeArrayBuffer):
+        (WebCore::FetchBody::consumeArrayBufferView):
+        (WebCore::FetchBody::consumeText):
+        (WebCore::FetchBody::consumeBlob):
+        * Modules/fetch/FetchBody.h:
+        (WebCore::FetchBody::formData):
+        * Modules/fetch/FetchBodyConsumer.cpp:
+        (WebCore::FetchBodyConsumer::resolveWithData):
+        (WebCore::FetchBodyConsumer::resolve):
+        * Modules/fetch/FetchBodyConsumer.h:
+        * Modules/fetch/FetchBodyOwner.cpp:
+        (WebCore::FetchBodyOwner::arrayBuffer):
+        (WebCore::FetchBodyOwner::blob):
+        (WebCore::FetchBodyOwner::formData):
+        (WebCore::FetchBodyOwner::json):
+        (WebCore::FetchBodyOwner::text):
+        * Modules/fetch/FetchBodyOwner.h:
+        * Modules/fetch/FetchResponse.cpp:
+        (WebCore::FetchResponse::consume):
+        (WebCore::FetchResponse::finishConsumingStream):
+        * Modules/fetch/FetchResponse.h:
+        * Modules/fetch/WorkerGlobalScopeFetch.cpp:
+        (WebCore::WorkerGlobalScopeFetch::fetch):
+        * Modules/fetch/WorkerGlobalScopeFetch.h:
+        * bindings/js/JSCustomElementRegistryCustom.cpp:
+        (WebCore::whenDefinedPromise):
+        (WebCore::JSCustomElementRegistry::whenDefined):
+        * bindings/js/JSDOMGlobalObject.cpp:
+        (WebCore::JSDOMGlobalObject::visitChildren):
+        * bindings/js/JSDOMGlobalObject.h:
+        * bindings/js/JSDOMPromise.cpp:
+        (WebCore::DOMDeferredPromise::DOMDeferredPromise):
+        (WebCore::DOMDeferredPromise::~DOMDeferredPromise):
+        (WebCore::DOMDeferredPromise::clear):
+        (WebCore::DOMDeferredPromise::contextDestroyed):
+        (WebCore::DOMDeferredPromise::promise):
+        (WebCore::DOMDeferredPromise::callFunction):
+        (WebCore::DOMDeferredPromise::reject):
+        (WebCore::rejectPromiseWithExceptionIfAny):
+        (WebCore::fulfillPromiseWithJSON):
+        (WebCore::fulfillPromiseWithArrayBuffer):
+        (WebCore::DeferredWrapper::DeferredWrapper): Deleted.
+        (WebCore::DeferredWrapper::~DeferredWrapper): Deleted.
+        (WebCore::DeferredWrapper::clear): Deleted.
+        (WebCore::DeferredWrapper::contextDestroyed): Deleted.
+        (WebCore::DeferredWrapper::promise): Deleted.
+        (WebCore::DeferredWrapper::callFunction): Deleted.
+        (WebCore::DeferredWrapper::reject): Deleted.
+        * bindings/js/JSDOMPromise.h:
+        (WebCore::DOMDeferredPromise::create):
+        (WebCore::callPromiseFunction):
+        (WebCore::DOMPromise::DOMPromise):
+        (WebCore::DOMPromise::deferredPromise):
+        (WebCore::DOMDeferredPromise::resolveWithValue):
+        (WebCore::DOMDeferredPromise::resolveWithNewlyCreated):
+        (WebCore::DOMDeferredPromise::rejectWithValue):
+        (WebCore::DOMDeferredPromise::resolve):
+        (WebCore::DOMDeferredPromise::reject):
+        (WebCore::DeferredWrapper::create): Deleted.
+        (WebCore::DOMPromise::deferredWrapper): Deleted.
+        (WebCore::DeferredWrapper::resolveWithValue): Deleted.
+        (WebCore::DeferredWrapper::resolveWithNewlyCreated): Deleted.
+        (WebCore::DeferredWrapper::rejectWithValue): Deleted.
+        (WebCore::DeferredWrapper::resolve): Deleted.
+        (WebCore::DeferredWrapper::reject): Deleted.
+        * bindings/js/JSDOMWrapper.cpp: Introducing domWindow() accessor.
+        * bindings/js/JSDOMWrapper.h:
+        * bindings/js/JSFontFaceCustom.cpp:
+        (WebCore::JSFontFace::loaded):
+        * bindings/js/JSFontFaceSetCustom.cpp:
+        (WebCore::JSFontFaceSet::ready):
+        * bindings/js/JSMediaDevicesCustom.cpp:
+        (WebCore::JSMediaDevices::getUserMedia):
+        * bindings/js/JSMediaStreamTrackCustom.cpp:
+        (WebCore::JSMediaStreamTrack::applyConstraints):
+        * bindings/js/JSReadableStreamSourceCustom.cpp:
+        (WebCore::JSReadableStreamSource::start):
+        * bindings/js/JSWebKitSubtleCryptoCustom.cpp:
+        (WebCore::JSWebKitSubtleCrypto::encrypt):
+        (WebCore::JSWebKitSubtleCrypto::decrypt):
+        (WebCore::JSWebKitSubtleCrypto::sign):
+        (WebCore::JSWebKitSubtleCrypto::verify):
+        (WebCore::JSWebKitSubtleCrypto::digest):
+        (WebCore::JSWebKitSubtleCrypto::generateKey):
+        (WebCore::JSWebKitSubtleCrypto::importKey):
+        (WebCore::JSWebKitSubtleCrypto::exportKey):
+        (WebCore::JSWebKitSubtleCrypto::wrapKey):
+        (WebCore::JSWebKitSubtleCrypto::unwrapKey):
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateImplementation):
+        (GenerateReturnParameters):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionPromise):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Promise):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2Promise):
+        (WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunctionPromise):
+        (WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionPromise):
+        * dom/CustomElementRegistry.h:
+        (WebCore::CustomElementRegistry::promiseMap):
+
 2016-09-21  Alexey Proskuryakov  <ap@apple.com>
 
         Rolling out r206244, as it caused flaky crashes on tests.
index c37bf1d..2fd9391 100644 (file)
@@ -733,7 +733,7 @@ bool ApplePaySession::canMakePayments(ScriptExecutionContext& scriptExecutionCon
     return paymentCoordinator.canMakePayments();
 }
 
-void ApplePaySession::canMakePaymentsWithActiveCard(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredWrapper>&& passedPromise, ExceptionCode& ec)
+void ApplePaySession::canMakePaymentsWithActiveCard(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredPromise>&& passedPromise, ExceptionCode& ec)
 {
     auto& document = downcast<Document>(scriptExecutionContext);
     DOMWindow& window = *document.domWindow();
@@ -745,7 +745,7 @@ void ApplePaySession::canMakePaymentsWithActiveCard(ScriptExecutionContext& scri
         return;
     }
 
-    RefPtr<DeferredWrapper> promise(WTFMove(passedPromise));
+    RefPtr<DeferredPromise> promise(WTFMove(passedPromise));
     if (!shouldDiscloseApplePayCapability(document)) {
         auto& paymentCoordinator = document.frame()->mainFrame().paymentCoordinator();
         bool canMakePayments = paymentCoordinator.canMakePayments();
@@ -763,7 +763,7 @@ void ApplePaySession::canMakePaymentsWithActiveCard(ScriptExecutionContext& scri
     });
 }
 
-void ApplePaySession::openPaymentSetup(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredWrapper>&& passedPromise, ExceptionCode& ec)
+void ApplePaySession::openPaymentSetup(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredPromise>&& passedPromise, ExceptionCode& ec)
 {
     auto& document = downcast<Document>(scriptExecutionContext);
     DOMWindow& window = *document.domWindow();
@@ -781,7 +781,7 @@ void ApplePaySession::openPaymentSetup(ScriptExecutionContext& scriptExecutionCo
         return;
     }
 
-    RefPtr<DeferredWrapper> promise(WTFMove(passedPromise));
+    RefPtr<DeferredPromise> promise(WTFMove(passedPromise));
     auto& paymentCoordinator = document.frame()->mainFrame().paymentCoordinator();
 
     paymentCoordinator.openPaymentSetup(merchantIdentifier, document.domain(), [promise](bool result) mutable {
index bcec069..a381c16 100644 (file)
@@ -37,7 +37,7 @@
 namespace WebCore {
 
 class ArrayValue;
-class DeferredWrapper;
+class DeferredPromise;
 class Dictionary;
 class Document;
 class Payment;
@@ -63,8 +63,8 @@ public:
 
     static bool supportsVersion(ScriptExecutionContext&, unsigned version, ExceptionCode&);
     static bool canMakePayments(ScriptExecutionContext&, ExceptionCode&);
-    static void canMakePaymentsWithActiveCard(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredWrapper>&&, ExceptionCode&);
-    static void openPaymentSetup(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredWrapper>&&, ExceptionCode&);
+    static void canMakePaymentsWithActiveCard(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&, ExceptionCode&);
+    static void openPaymentSetup(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&, ExceptionCode&);
 
     void begin(ExceptionCode&);
     void abort(ExceptionCode&);
index c480a7d..adadacd 100644 (file)
@@ -37,7 +37,7 @@
 
 namespace WebCore {
 
-void DOMWindowFetch::fetch(DOMWindow& window, FetchRequest& request, DOMPromise<FetchResponse>&& promise)
+void DOMWindowFetch::fetch(DOMWindow& window, FetchRequest& request, Ref<DeferredPromise>&& promise)
 {
     if (!window.scriptExecutionContext())
         return;
index d371f2c..8b16511 100644 (file)
 namespace WebCore {
 
 class DOMWindow;
-class DeferredWrapper;
 class Dictionary;
 class FetchRequest;
-class FetchResponse;
 
 class DOMWindowFetch {
 public:
-    static void fetch(DOMWindow&, FetchRequest&, DOMPromise<FetchResponse>&&);
+    static void fetch(DOMWindow&, FetchRequest&, Ref<DeferredPromise>&&);
 };
 
 } // namespace WebCore
index 25ed1f3..0323994 100644 (file)
@@ -124,14 +124,14 @@ void FetchBody::updateContentType(FetchHeaders& headers)
         headers.fastSet(HTTPHeaderName::ContentType, m_contentType);
 }
 
-void FetchBody::arrayBuffer(FetchBodyOwner& owner, Ref<DeferredWrapper>&& promise)
+void FetchBody::arrayBuffer(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise)
 {
     ASSERT(m_type != Type::None);
     m_consumer.setType(FetchBodyConsumer::Type::ArrayBuffer);
     consume(owner, WTFMove(promise));
 }
 
-void FetchBody::blob(FetchBodyOwner& owner, Ref<DeferredWrapper>&& promise)
+void FetchBody::blob(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise)
 {
     ASSERT(m_type != Type::None);
     m_consumer.setType(FetchBodyConsumer::Type::Blob);
@@ -139,7 +139,7 @@ void FetchBody::blob(FetchBodyOwner& owner, Ref<DeferredWrapper>&& promise)
     consume(owner, WTFMove(promise));
 }
 
-void FetchBody::json(FetchBodyOwner& owner, Ref<DeferredWrapper>&& promise)
+void FetchBody::json(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise)
 {
     ASSERT(m_type != Type::None);
 
@@ -151,7 +151,7 @@ void FetchBody::json(FetchBodyOwner& owner, Ref<DeferredWrapper>&& promise)
     consume(owner, WTFMove(promise));
 }
 
-void FetchBody::text(FetchBodyOwner& owner, Ref<DeferredWrapper>&& promise)
+void FetchBody::text(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise)
 {
     ASSERT(m_type != Type::None);
 
@@ -163,7 +163,7 @@ void FetchBody::text(FetchBodyOwner& owner, Ref<DeferredWrapper>&& promise)
     consume(owner, WTFMove(promise));
 }
 
-void FetchBody::consume(FetchBodyOwner& owner, Ref<DeferredWrapper>&& promise)
+void FetchBody::consume(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise)
 {
     // This should be handled by FetchBodyOwner
     ASSERT(m_type != Type::None);
@@ -246,28 +246,28 @@ void FetchBody::consumeAsStream(FetchBodyOwner& owner, FetchResponseSource& sour
 }
 #endif
 
-void FetchBody::consumeArrayBuffer(Ref<DeferredWrapper>&& promise)
+void FetchBody::consumeArrayBuffer(Ref<DeferredPromise>&& promise)
 {
     ASSERT(m_data);
     m_consumer.resolveWithData(WTFMove(promise), static_cast<const uint8_t*>(m_data->data()), m_data->byteLength());
     m_data = nullptr;
 }
 
-void FetchBody::consumeArrayBufferView(Ref<DeferredWrapper>&& promise)
+void FetchBody::consumeArrayBufferView(Ref<DeferredPromise>&& promise)
 {
     ASSERT(m_dataView);
     m_consumer.resolveWithData(WTFMove(promise), static_cast<const uint8_t*>(m_dataView->baseAddress()), m_dataView->byteLength());
     m_dataView = nullptr;
 }
 
-void FetchBody::consumeText(Ref<DeferredWrapper>&& promise)
+void FetchBody::consumeText(Ref<DeferredPromise>&& promise)
 {
     Vector<uint8_t> data = extractFromText();
     m_consumer.resolveWithData(WTFMove(promise), data.data(), data.size());
     m_text = { };
 }
 
-void FetchBody::consumeBlob(FetchBodyOwner& owner, Ref<DeferredWrapper>&& promise)
+void FetchBody::consumeBlob(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise)
 {
     ASSERT(m_blob);
 
index 850e664..400d22d 100644 (file)
@@ -52,11 +52,11 @@ class ScriptExecutionContext;
 
 class FetchBody {
 public:
-    void arrayBuffer(FetchBodyOwner&, Ref<DeferredWrapper>&&);
-    void blob(FetchBodyOwner&, Ref<DeferredWrapper>&&);
-    void json(FetchBodyOwner&, Ref<DeferredWrapper>&&);
-    void text(FetchBodyOwner&, Ref<DeferredWrapper>&&);
-    void formData(FetchBodyOwner&, Ref<DeferredWrapper>&& promise) { promise.get().reject(0); }
+    void arrayBuffer(FetchBodyOwner&, Ref<DeferredPromise>&&);
+    void blob(FetchBodyOwner&, Ref<DeferredPromise>&&);
+    void json(FetchBodyOwner&, Ref<DeferredPromise>&&);
+    void text(FetchBodyOwner&, Ref<DeferredPromise>&&);
+    void formData(FetchBodyOwner&, Ref<DeferredPromise>&& promise) { promise.get().reject(0); }
 
 #if ENABLE(READABLE_STREAM_API)
     void consumeAsStream(FetchBodyOwner&, FetchResponseSource&);
@@ -93,13 +93,13 @@ private:
     FetchBody(String&&);
     FetchBody(Type type) : m_type(type) { }
 
-    void consume(FetchBodyOwner&, Ref<DeferredWrapper>&&);
+    void consume(FetchBodyOwner&, Ref<DeferredPromise>&&);
 
     Vector<uint8_t> extractFromText() const;
-    void consumeArrayBuffer(Ref<DeferredWrapper>&&);
-    void consumeArrayBufferView(Ref<DeferredWrapper>&&);
-    void consumeText(Ref<DeferredWrapper>&&);
-    void consumeBlob(FetchBodyOwner&, Ref<DeferredWrapper>&&);
+    void consumeArrayBuffer(Ref<DeferredPromise>&&);
+    void consumeArrayBufferView(Ref<DeferredPromise>&&);
+    void consumeText(Ref<DeferredPromise>&&);
+    void consumeBlob(FetchBodyOwner&, Ref<DeferredPromise>&&);
 
     Type m_type { Type::None };
     String m_contentType;
@@ -112,7 +112,7 @@ private:
     String m_text;
 
     FetchBodyConsumer m_consumer { FetchBodyConsumer::Type::None };
-    RefPtr<DeferredWrapper> m_consumePromise;
+    RefPtr<DeferredPromise> m_consumePromise;
 };
 
 } // namespace WebCore
index 7264b8d..70f4991 100644 (file)
@@ -59,7 +59,7 @@ static String textFromUTF8(const unsigned char* data, unsigned length)
     return decoder->decodeAndFlush(reinterpret_cast<const char*>(data), length);
 }
 
-void FetchBodyConsumer::resolveWithData(Ref<DeferredWrapper>&& promise, const unsigned char* data, unsigned length)
+void FetchBodyConsumer::resolveWithData(Ref<DeferredPromise>&& promise, const unsigned char* data, unsigned length)
 {
     switch (m_type) {
     case Type::ArrayBuffer:
@@ -80,7 +80,7 @@ void FetchBodyConsumer::resolveWithData(Ref<DeferredWrapper>&& promise, const un
     }
 }
 
-void FetchBodyConsumer::resolve(Ref<DeferredWrapper>&& promise)
+void FetchBodyConsumer::resolve(Ref<DeferredPromise>&& promise)
 {
     ASSERT(m_type != Type::None);
     switch (m_type) {
index f949ac0..4a0fb39 100644 (file)
 
 #if ENABLE(FETCH_API)
 
+#include "JSDOMPromise.h"
 #include "SharedBuffer.h"
 
 namespace WebCore {
 
 class Blob;
-class DeferredWrapper;
 
 class FetchBodyConsumer {
 public:
@@ -57,8 +57,8 @@ public:
 
     void clean() { m_buffer = nullptr; }
 
-    void resolve(Ref<DeferredWrapper>&&);
-    void resolveWithData(Ref<DeferredWrapper>&&, const unsigned char*, unsigned);
+    void resolve(Ref<DeferredPromise>&&);
+    void resolveWithData(Ref<DeferredPromise>&&, const unsigned char*, unsigned);
 
     bool hasData() const { return !!m_buffer; }
 
index c29434f..6476094 100644 (file)
@@ -71,7 +71,7 @@ bool FetchBodyOwner::isDisturbedOrLocked() const
     return false;
 }
 
-void FetchBodyOwner::arrayBuffer(Ref<DeferredWrapper>&& promise)
+void FetchBodyOwner::arrayBuffer(Ref<DeferredPromise>&& promise)
 {
     if (m_body.isEmpty()) {
         fulfillPromiseWithArrayBuffer(WTFMove(promise), nullptr, 0);
@@ -85,7 +85,7 @@ void FetchBodyOwner::arrayBuffer(Ref<DeferredWrapper>&& promise)
     m_body.arrayBuffer(*this, WTFMove(promise));
 }
 
-void FetchBodyOwner::blob(Ref<DeferredWrapper>&& promise)
+void FetchBodyOwner::blob(Ref<DeferredPromise>&& promise)
 {
     if (m_body.isEmpty()) {
         promise->resolve(Blob::create(Vector<uint8_t>(), Blob::normalizedContentType(extractMIMETypeFromMediaType(m_body.contentType()))));
@@ -99,7 +99,7 @@ void FetchBodyOwner::blob(Ref<DeferredWrapper>&& promise)
     m_body.blob(*this, WTFMove(promise));
 }
 
-void FetchBodyOwner::formData(Ref<DeferredWrapper>&& promise)
+void FetchBodyOwner::formData(Ref<DeferredPromise>&& promise)
 {
     if (m_body.isEmpty()) {
         promise->reject(0);
@@ -113,7 +113,7 @@ void FetchBodyOwner::formData(Ref<DeferredWrapper>&& promise)
     m_body.formData(*this, WTFMove(promise));
 }
 
-void FetchBodyOwner::json(Ref<DeferredWrapper>&& promise)
+void FetchBodyOwner::json(Ref<DeferredPromise>&& promise)
 {
     if (m_body.isEmpty()) {
         promise->reject(SYNTAX_ERR);
@@ -127,7 +127,7 @@ void FetchBodyOwner::json(Ref<DeferredWrapper>&& promise)
     m_body.json(*this, WTFMove(promise));
 }
 
-void FetchBodyOwner::text(Ref<DeferredWrapper>&& promise)
+void FetchBodyOwner::text(Ref<DeferredPromise>&& promise)
 {
     if (m_body.isEmpty()) {
         promise->resolve(String());
index 0df30b7..53fd3d9 100644 (file)
@@ -46,11 +46,11 @@ public:
     // Exposed Body API
     bool isDisturbed() const { return m_isDisturbed; };
 
-    void arrayBuffer(Ref<DeferredWrapper>&&);
-    void blob(Ref<DeferredWrapper>&&);
-    void formData(Ref<DeferredWrapper>&&);
-    void json(Ref<DeferredWrapper>&&);
-    void text(Ref<DeferredWrapper>&&);
+    void arrayBuffer(Ref<DeferredPromise>&&);
+    void blob(Ref<DeferredPromise>&&);
+    void formData(Ref<DeferredPromise>&&);
+    void json(Ref<DeferredPromise>&&);
+    void text(Ref<DeferredPromise>&&);
 
     bool isDisturbedOrLocked() const;
 
index b8641d4..d93a6eb 100644 (file)
@@ -206,7 +206,7 @@ void FetchResponse::BodyLoader::stop()
         m_loader->stop();
 }
 
-void FetchResponse::consume(unsigned type, Ref<DeferredWrapper>&& wrapper)
+void FetchResponse::consume(unsigned type, Ref<DeferredPromise>&& wrapper)
 {
     ASSERT(type <= static_cast<unsigned>(FetchBodyConsumer::Type::Text));
 
@@ -241,7 +241,7 @@ void FetchResponse::consumeChunk(Ref<JSC::Uint8Array>&& chunk)
     m_consumer.append(chunk->data(), chunk->byteLength());
 }
 
-void FetchResponse::finishConsumingStream(Ref<DeferredWrapper>&& promise)
+void FetchResponse::finishConsumingStream(Ref<DeferredPromise>&& promise)
 {
     m_consumer.resolve(WTFMove(promise));
 }
index ee99368..a6fbb42 100644 (file)
@@ -60,11 +60,11 @@ public:
     using FetchPromise = DOMPromise<FetchResponse>;
     static void fetch(ScriptExecutionContext&, FetchRequest&, FetchPromise&&);
 
-    void consume(unsigned, Ref<DeferredWrapper>&&);
+    void consume(unsigned, Ref<DeferredPromise>&&);
 #if ENABLE(READABLE_STREAM_API)
     void startConsumingStream(unsigned);
     void consumeChunk(Ref<JSC::Uint8Array>&&);
-    void finishConsumingStream(Ref<DeferredWrapper>&&);
+    void finishConsumingStream(Ref<DeferredPromise>&&);
 #endif
 
     void setStatus(int, const String&, ExceptionCode&);
index 535516c..8f5c98a 100644 (file)
@@ -36,7 +36,7 @@
 
 namespace WebCore {
 
-void WorkerGlobalScopeFetch::fetch(WorkerGlobalScope& scope, FetchRequest& request, Ref<DeferredWrapper>&& promise)
+void WorkerGlobalScopeFetch::fetch(WorkerGlobalScope& scope, FetchRequest& request, Ref<DeferredPromise>&& promise)
 {
     if (!scope.scriptExecutionContext())
         return;
index 20b2625..5bbb28b 100644 (file)
 #if ENABLE(FETCH_API)
 
 #include "JSDOMPromise.h"
-#include <wtf/Forward.h>
 
 namespace WebCore {
 
-class WorkerGlobalScope;
-class DeferredWrapper;
 class FetchRequest;
+class WorkerGlobalScope;
 
 class WorkerGlobalScopeFetch {
 public:
-    static void fetch(WorkerGlobalScope&, FetchRequest&, Ref<DeferredWrapper>&&);
+    static void fetch(WorkerGlobalScope&, FetchRequest&, Ref<DeferredPromise>&&);
 };
 
 } // namespace WebCore
index 501483e..ad739dc 100644 (file)
                416E6FE81BBD12DF000A6053 /* WritableStreamInternalsBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764E9 /* WritableStreamInternalsBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
                416E6FE91BBD12E5000A6043 /* ReadableStreamBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764D8 /* ReadableStreamBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
                416E6FE91BBD12E5000A6053 /* WritableStreamBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764E8 /* WritableStreamBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               4170A2EA1D8C0CCA00318452 /* JSDOMWrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4170A2E91D8C0CC000318452 /* JSDOMWrapper.cpp */; };
                417253AA1354BBBC00360F2A /* MediaControlElements.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 417253A81354BBBC00360F2A /* MediaControlElements.cpp */; };
                417253AB1354BBBC00360F2A /* MediaControlElements.h in Headers */ = {isa = PBXBuildFile; fileRef = 417253A91354BBBC00360F2A /* MediaControlElements.h */; };
                417DA6D913734E6E007C57FB /* Internals.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 417DA4CF13734326007C57FB /* Internals.cpp */; };
                4162A4551011464700DFF3ED /* JSDedicatedWorkerGlobalScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDedicatedWorkerGlobalScope.cpp; sourceTree = "<group>"; };
                4162A4561011464700DFF3ED /* JSDedicatedWorkerGlobalScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDedicatedWorkerGlobalScope.h; sourceTree = "<group>"; };
                416E29A5102FA962007FC14E /* WorkerReportingProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerReportingProxy.h; sourceTree = "<group>"; };
+               4170A2E91D8C0CC000318452 /* JSDOMWrapper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMWrapper.cpp; sourceTree = "<group>"; };
                417253A81354BBBC00360F2A /* MediaControlElements.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaControlElements.cpp; sourceTree = "<group>"; };
                417253A91354BBBC00360F2A /* MediaControlElements.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaControlElements.h; sourceTree = "<group>"; };
                417DA4CE13734326007C57FB /* Internals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Internals.h; sourceTree = "<group>"; };
                                460CBF341D4BCCFE0092E88E /* JSDOMWindowProperties.h */,
                                BCBFB53A0DCD29CF0019B3E5 /* JSDOMWindowShell.cpp */,
                                BCBFB53B0DCD29CF0019B3E5 /* JSDOMWindowShell.h */,
+                               4170A2E91D8C0CC000318452 /* JSDOMWrapper.cpp */,
                                65E0E9431133C89F00B4CB10 /* JSDOMWrapper.h */,
                                F3D461461161D53200CA0D09 /* JSErrorHandler.cpp */,
                                F3D461471161D53200CA0D09 /* JSErrorHandler.h */,
                                314BE3A61B3103FB00141982 /* NamedImageGeneratedImage.cpp in Sources */,
                                BCF34A3711A231CD00C71804 /* NamedNodeMap.cpp in Sources */,
                                A81872240977D3C0005826D9 /* NameNodeList.cpp in Sources */,
+                               4170A2EA1D8C0CCA00318452 /* JSDOMWrapper.cpp in Sources */,
                                8306EFF11B8BCEA50031D032 /* NativeNodeFilter.cpp in Sources */,
                                E10B9B6D0B747599003ED890 /* NativeXPathNSResolver.cpp in Sources */,
                                93CCF0600AF6CA7600018E89 /* NavigationAction.cpp in Sources */,
index c97b93b..3cb80b8 100644 (file)
@@ -162,7 +162,7 @@ JSValue JSCustomElementRegistry::define(ExecState& state)
 }
 
 // https://html.spec.whatwg.org/#dom-customelementregistry-whendefined
-static JSValue whenDefinedPromise(ExecState& state, JSDOMGlobalObject& globalObject, CustomElementRegistry& registry)
+static JSValue whenDefinedPromise(ExecState& state, JSDOMGlobalObject& globalObject, CustomElementRegistry& registry, JSPromiseDeferred& promiseDeferred)
 {
     auto scope = DECLARE_THROW_SCOPE(state.vm());
 
@@ -173,17 +173,18 @@ static JSValue whenDefinedPromise(ExecState& state, JSDOMGlobalObject& globalObj
     if (UNLIKELY(scope.exception()))
         return jsUndefined();
 
-    if (!validateCustomElementNameAndThrowIfNeeded(state, localName))
+    if (!validateCustomElementNameAndThrowIfNeeded(state, localName)) {
+        ASSERT(scope.exception());
         return jsUndefined();
+    }
 
     if (registry.findInterface(localName)) {
-        auto& jsPromise = *JSPromiseDeferred::create(&state, &globalObject);
-        DeferredWrapper::create(&state, &globalObject, &jsPromise)->resolve(nullptr);
-        return jsPromise.promise();
+        DeferredPromise::create(globalObject, promiseDeferred)->resolve(nullptr);
+        return promiseDeferred.promise();
     }
 
     auto result = registry.promiseMap().ensure(localName, [&] {
-        return DeferredWrapper::create(&state, &globalObject, JSPromiseDeferred::create(&state, &globalObject));
+        return DeferredPromise::create(globalObject, promiseDeferred);
     });
 
     return result.iterator->value->promise();
@@ -193,14 +194,15 @@ JSValue JSCustomElementRegistry::whenDefined(ExecState& state)
 {
     auto scope = DECLARE_CATCH_SCOPE(state.vm());
 
-    JSDOMGlobalObject& globalObject = *jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject());
-    auto& promiseDeferred = *JSPromiseDeferred::create(&state, &globalObject);
-    JSValue promise = whenDefinedPromise(state, globalObject, wrapped());
+    ASSERT(globalObject());
+    auto promiseDeferred = JSPromiseDeferred::create(&state, globalObject());
+    ASSERT(promiseDeferred);
+    JSValue promise = whenDefinedPromise(state, *globalObject(), wrapped(), *promiseDeferred);
 
     if (UNLIKELY(scope.exception())) {
-        rejectPromiseWithExceptionIfAny(state, globalObject, promiseDeferred);
+        rejectPromiseWithExceptionIfAny(state, *globalObject(), *promiseDeferred);
         ASSERT(!scope.exception());
-        return promiseDeferred.promise();
+        return promiseDeferred->promise();
     }
 
     return promise;
index 35f895c..e870aeb 100644 (file)
@@ -178,8 +178,8 @@ void JSDOMGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
     for (auto& constructor : thisObject->constructors().values())
         visitor.append(&constructor);
 
-    for (auto& deferredWrapper : thisObject->deferredWrappers())
-        deferredWrapper->visitAggregate(visitor);
+    for (auto& deferredPromise : thisObject->deferredPromises())
+        deferredPromise->visitAggregate(visitor);
 
     thisObject->m_builtinInternalFunctions.visit(visitor);
 }
index c672e4b..d40c43f 100644 (file)
@@ -34,7 +34,7 @@
 
 namespace WebCore {
 
-    class DeferredWrapper;
+    class DeferredPromise;
     class Document;
     class Event;
     class DOMWrapperWorld;
@@ -42,7 +42,7 @@ namespace WebCore {
 
     typedef HashMap<const JSC::ClassInfo*, JSC::WriteBarrier<JSC::Structure>> JSDOMStructureMap;
     typedef HashMap<const JSC::ClassInfo*, JSC::WriteBarrier<JSC::JSObject>> JSDOMConstructorMap;
-    typedef HashSet<DeferredWrapper*> DeferredWrapperSet;
+    typedef HashSet<DeferredPromise*> DeferredPromiseSet;
 
     class WEBCORE_EXPORT JSDOMGlobalObject : public JSC::JSGlobalObject {
         typedef JSC::JSGlobalObject Base;
@@ -58,7 +58,7 @@ namespace WebCore {
         JSDOMStructureMap& structures() { return m_structures; }
         JSDOMConstructorMap& constructors() { return m_constructors; }
 
-        DeferredWrapperSet& deferredWrappers() { return m_deferredWrappers; }
+        DeferredPromiseSet& deferredPromises() { return m_deferredPromises; }
 
         ScriptExecutionContext* scriptExecutionContext() const;
 
@@ -91,7 +91,7 @@ namespace WebCore {
     protected:
         JSDOMStructureMap m_structures;
         JSDOMConstructorMap m_constructors;
-        DeferredWrapperSet m_deferredWrappers;
+        DeferredPromiseSet m_deferredPromises;
 
         Event* m_currentEvent;
         Ref<DOMWrapperWorld> m_world;
index bea7ee0..afe920d 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "ExceptionCode.h"
 #include "JSDOMError.h"
+#include "JSDOMWindow.h"
 #include <builtins/BuiltinNames.h>
 #include <runtime/Exception.h>
 #include <runtime/JSONObject.h>
@@ -37,41 +38,41 @@ using namespace JSC;
 
 namespace WebCore {
 
-DeferredWrapper::DeferredWrapper(ExecState*, JSDOMGlobalObject* globalObject, JSPromiseDeferred* promiseDeferred)
-    : ActiveDOMCallback(globalObject->scriptExecutionContext())
-    , m_deferred(promiseDeferred)
-    , m_globalObject(globalObject)
+DeferredPromise::DeferredPromise(JSDOMGlobalObject& globalObject, JSPromiseDeferred& promiseDeferred)
+    : ActiveDOMCallback(globalObject.scriptExecutionContext())
+    , m_deferred(&promiseDeferred)
+    , m_globalObject(&globalObject)
 {
-    globalObject->vm().heap.writeBarrier(globalObject, promiseDeferred);
-    m_globalObject->deferredWrappers().add(this);
+    globalObject.vm().heap.writeBarrier(&globalObject, &promiseDeferred);
+    globalObject.deferredPromises().add(this);
 }
 
-DeferredWrapper::~DeferredWrapper()
+DeferredPromise::~DeferredPromise()
 {
     clear();
 }
 
-void DeferredWrapper::clear()
+void DeferredPromise::clear()
 {
     ASSERT(!m_deferred || m_globalObject);
     if (m_deferred && m_globalObject)
-        m_globalObject->deferredWrappers().remove(this);
+        m_globalObject->deferredPromises().remove(this);
     m_deferred.clear();
 }
 
-void DeferredWrapper::contextDestroyed()
+void DeferredPromise::contextDestroyed()
 {
     ActiveDOMCallback::contextDestroyed();
     clear();
 }
 
-JSC::JSValue DeferredWrapper::promise() const
+JSC::JSValue DeferredPromise::promise() const
 {
     ASSERT(m_deferred);
     return m_deferred->promise();
 }
 
-void DeferredWrapper::callFunction(ExecState& exec, JSValue function, JSValue resolution)
+void DeferredPromise::callFunction(ExecState& exec, JSValue function, JSValue resolution)
 {
     if (!canInvokeCallback())
         return;
@@ -88,7 +89,7 @@ void DeferredWrapper::callFunction(ExecState& exec, JSValue function, JSValue re
     clear();
 }
 
-void DeferredWrapper::reject(ExceptionCode ec, const String& message)
+void DeferredPromise::reject(ExceptionCode ec, const String& message)
 {
     if (isSuspended())
         return;
@@ -111,7 +112,15 @@ void rejectPromiseWithExceptionIfAny(JSC::ExecState& state, JSDOMGlobalObject& g
     JSValue error = scope.exception()->value();
     scope.clearException();
 
-    DeferredWrapper::create(&state, &globalObject, &promiseDeferred)->reject(error);
+    DeferredPromise::create(globalObject, promiseDeferred)->reject(error);
+}
+
+Ref<DeferredPromise> createDeferredPromise(JSC::ExecState& state, JSDOMWindow& domWindow)
+{
+    JSC::JSPromiseDeferred* deferred = JSC::JSPromiseDeferred::create(&state, &domWindow);
+    // deferred can only be null in workers.
+    ASSERT(deferred);
+    return DeferredPromise::create(domWindow, *deferred);
 }
 
 JSC::EncodedJSValue createRejectedPromiseWithTypeError(JSC::ExecState& state, const String& errorMessage)
@@ -139,7 +148,7 @@ static inline JSC::JSValue parseAsJSON(JSC::ExecState* state, const String& data
     return JSC::JSONParse(state, data);
 }
 
-void fulfillPromiseWithJSON(Ref<DeferredWrapper>&& promise, const String& data)
+void fulfillPromiseWithJSON(Ref<DeferredPromise>&& promise, const String& data)
 {
     JSC::JSValue value = parseAsJSON(promise->globalObject()->globalExec(), data);
     if (!value)
@@ -148,7 +157,7 @@ void fulfillPromiseWithJSON(Ref<DeferredWrapper>&& promise, const String& data)
         promise->resolve(value);
 }
 
-void fulfillPromiseWithArrayBuffer(Ref<DeferredWrapper>&& promise, ArrayBuffer* arrayBuffer)
+void fulfillPromiseWithArrayBuffer(Ref<DeferredPromise>&& promise, ArrayBuffer* arrayBuffer)
 {
     if (!arrayBuffer) {
         promise->reject<JSValue>(createOutOfMemoryError(promise->globalObject()->globalExec()));
@@ -157,7 +166,7 @@ void fulfillPromiseWithArrayBuffer(Ref<DeferredWrapper>&& promise, ArrayBuffer*
     promise->resolve(arrayBuffer);
 }
 
-void fulfillPromiseWithArrayBuffer(Ref<DeferredWrapper>&& promise, const void* data, size_t length)
+void fulfillPromiseWithArrayBuffer(Ref<DeferredPromise>&& promise, const void* data, size_t length)
 {
     fulfillPromiseWithArrayBuffer(WTFMove(promise), ArrayBuffer::tryCreate(data, length).get());
 }
index 4d49ed9..f587cb3 100644 (file)
@@ -96,15 +96,14 @@ struct PromiseResultInspector<DOMClass, typename std::enable_if<TypeInspector<DO
     static constexpr bool passByConstRef = false;
 };
 
-class DeferredWrapper : public RefCounted<DeferredWrapper>, public ActiveDOMCallback {
+class DeferredPromise : public RefCounted<DeferredPromise>, public ActiveDOMCallback {
 public:
-    // FIXME: We should pass references here, not pointers, see bug 161787
-    static Ref<DeferredWrapper> create(JSC::ExecState* state, JSDOMGlobalObject* globalObject, JSC::JSPromiseDeferred* deferred)
+    static Ref<DeferredPromise> create(JSDOMGlobalObject& globalObject, JSC::JSPromiseDeferred& deferred)
     {
-        return adoptRef(*new DeferredWrapper(state, globalObject, deferred));
+        return adoptRef(*new DeferredPromise(globalObject, deferred));
     }
 
-    ~DeferredWrapper();
+    ~DeferredPromise();
 
     template<class ResolveResultType> typename std::enable_if<PromiseResultInspector<ResolveResultType>::passByValue, void>::type
     resolve(ResolveResultType result) { resolveWithValue(result); }
@@ -136,7 +135,7 @@ public:
     void visitAggregate(JSC::SlotVisitor& visitor) { visitor.appendUnbarrieredWeak(&m_deferred); }
 
 private:
-    DeferredWrapper(JSC::ExecState*, JSDOMGlobalObject*, JSC::JSPromiseDeferred*);
+    DeferredPromise(JSDOMGlobalObject&, JSC::JSPromiseDeferred&);
 
     void clear();
     void contextDestroyed() override;
@@ -152,13 +151,15 @@ private:
     JSC::Weak<JSDOMGlobalObject> m_globalObject;
 };
 
-void fulfillPromiseWithJSON(Ref<DeferredWrapper>&&, const String&);
-void fulfillPromiseWithArrayBuffer(Ref<DeferredWrapper>&&, ArrayBuffer*);
-void fulfillPromiseWithArrayBuffer(Ref<DeferredWrapper>&&, const void*, size_t);
+Ref<DeferredPromise> createDeferredPromise(JSC::ExecState&, JSDOMWindow&);
+
+void fulfillPromiseWithJSON(Ref<DeferredPromise>&&, const String&);
+void fulfillPromiseWithArrayBuffer(Ref<DeferredPromise>&&, ArrayBuffer*);
+void fulfillPromiseWithArrayBuffer(Ref<DeferredPromise>&&, const void*, size_t);
 void rejectPromiseWithExceptionIfAny(JSC::ExecState&, JSDOMGlobalObject&, JSC::JSPromiseDeferred&);
 JSC::EncodedJSValue createRejectedPromiseWithTypeError(JSC::ExecState&, const String&);
 
-using PromiseFunction = void(JSC::ExecState&, Ref<DeferredWrapper>&&);
+using PromiseFunction = void(JSC::ExecState&, Ref<DeferredPromise>&&);
 
 enum class PromiseExecutionScope { WindowOnly, WindowOrWorker };
 
@@ -175,16 +176,16 @@ inline JSC::JSValue callPromiseFunction(JSC::ExecState& state)
     if (executionScope == PromiseExecutionScope::WindowOrWorker && !promiseDeferred)
         return JSC::jsUndefined();
 
-    promiseFunction(state, DeferredWrapper::create(&state, &globalObject, promiseDeferred));
+    promiseFunction(state, DeferredPromise::create(globalObject, *promiseDeferred));
 
     rejectPromiseWithExceptionIfAny(state, globalObject, *promiseDeferred);
     ASSERT_UNUSED(scope, !scope.exception());
     return promiseDeferred->promise();
 }
 
-using BindingPromiseFunction = JSC::EncodedJSValue(JSC::ExecState*, Ref<DeferredWrapper>&&);
+using BindingPromiseFunction = JSC::EncodedJSValue(JSC::ExecState*, Ref<DeferredPromise>&&);
 template<BindingPromiseFunction bindingFunction>
-inline void bindingPromiseFunctionAdapter(JSC::ExecState& state, Ref<DeferredWrapper>&& promise)
+inline void bindingPromiseFunctionAdapter(JSC::ExecState& state, Ref<DeferredPromise>&& promise)
 {
     bindingFunction(&state, WTFMove(promise));
 }
@@ -199,28 +200,25 @@ inline JSC::JSValue callPromiseFunction(JSC::ExecState& state)
 template <typename Value>
 class DOMPromise {
 public:
-    DOMPromise(Ref<DeferredWrapper>&& wrapper)
-        : m_wrapper(WTFMove(wrapper))
-    {
-    }
+    DOMPromise(Ref<DeferredPromise>&& genericPromise) : m_promiseDeferred(WTFMove(genericPromise)) { }
 
-    DOMPromise(DOMPromise&& promise) : m_wrapper(WTFMove(promise.m_wrapper)) { }
+    DOMPromise(DOMPromise&& promise) : m_promiseDeferred(WTFMove(promise.m_promiseDeferred)) { }
 
     DOMPromise(const DOMPromise&) = default;
     DOMPromise& operator=(DOMPromise const&) = default;
 
-    void resolve(typename PromiseResultInspector<Value>::Type value) { m_wrapper->resolve(value); }
+    void resolve(typename PromiseResultInspector<Value>::Type value) { m_promiseDeferred->resolve(value); }
 
-    template<typename... ErrorType> void reject(ErrorType&&... error) { m_wrapper->reject(std::forward<ErrorType>(error)...); }
+    template<typename... ErrorType> void reject(ErrorType&&... error) { m_promiseDeferred->reject(std::forward<ErrorType>(error)...); }
 
-    DeferredWrapper& deferredWrapper() { return m_wrapper; }
+    JSC::JSValue promise() const { return m_promiseDeferred->promise(); };
 
 private:
-    Ref<DeferredWrapper> m_wrapper;
+    Ref<DeferredPromise> m_promiseDeferred;
 };
 
 template<class ResolveResultType>
-inline void DeferredWrapper::resolveWithValue(ResolveResultType&& result)
+inline void DeferredPromise::resolveWithValue(ResolveResultType&& result)
 {
     if (isSuspended())
         return;
@@ -231,7 +229,7 @@ inline void DeferredWrapper::resolveWithValue(ResolveResultType&& result)
 }
 
 template<class ResolveResultType>
-inline void DeferredWrapper::resolveWithNewlyCreated(Ref<ResolveResultType>&& result)
+inline void DeferredPromise::resolveWithNewlyCreated(Ref<ResolveResultType>&& result)
 {
     if (isSuspended())
         return;
@@ -243,7 +241,7 @@ inline void DeferredWrapper::resolveWithNewlyCreated(Ref<ResolveResultType>&& re
 }
 
 template<class RejectResultType>
-inline void DeferredWrapper::rejectWithValue(RejectResultType&& result)
+inline void DeferredPromise::rejectWithValue(RejectResultType&& result)
 {
     if (isSuspended())
         return;
@@ -255,7 +253,7 @@ inline void DeferredWrapper::rejectWithValue(RejectResultType&& result)
 }
 
 template<>
-inline void DeferredWrapper::resolve(bool result)
+inline void DeferredPromise::resolve(bool result)
 {
     if (isSuspended())
         return;
@@ -267,7 +265,7 @@ inline void DeferredWrapper::resolve(bool result)
 }
 
 template<>
-inline void DeferredWrapper::resolve(JSC::JSValue value)
+inline void DeferredPromise::resolve(JSC::JSValue value)
 {
     if (isSuspended())
         return;
@@ -279,7 +277,7 @@ inline void DeferredWrapper::resolve(JSC::JSValue value)
 }
 
 template<>
-inline void DeferredWrapper::reject(JSC::JSValue value)
+inline void DeferredPromise::reject(JSC::JSValue value)
 {
     if (isSuspended())
         return;
@@ -291,7 +289,7 @@ inline void DeferredWrapper::reject(JSC::JSValue value)
 }
 
 template<>
-inline void DeferredWrapper::resolve(std::nullptr_t)
+inline void DeferredPromise::resolve(std::nullptr_t)
 {
     if (isSuspended())
         return;
@@ -303,7 +301,7 @@ inline void DeferredWrapper::resolve(std::nullptr_t)
 }
 
 template<>
-inline void DeferredWrapper::reject(std::nullptr_t)
+inline void DeferredPromise::reject(std::nullptr_t)
 {
     if (isSuspended())
         return;
@@ -315,7 +313,7 @@ inline void DeferredWrapper::reject(std::nullptr_t)
 }
 
 template<>
-inline void DeferredWrapper::resolve(const String& result)
+inline void DeferredPromise::resolve(const String& result)
 {
     if (isSuspended())
         return;
@@ -327,7 +325,7 @@ inline void DeferredWrapper::resolve(const String& result)
 }
 
 template<>
-inline void DeferredWrapper::reject(const String& result)
+inline void DeferredPromise::reject(const String& result)
 {
     if (isSuspended())
         return;
index 45ac21d..325e72b 100644 (file)
@@ -27,6 +27,7 @@
 #include "JSDOMWrapper.h"
 
 #include "DOMWrapperWorld.h"
+#include "JSDOMWindow.h"
 #include <runtime/Error.h>
 
 using namespace JSC;
@@ -35,4 +36,11 @@ namespace WebCore {
 
 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSDOMObject);
 
+JSDOMWindow& JSDOMObject::domWindow() const
+{
+    auto* domWindow = JSC::jsCast<JSDOMWindow*>(JSC::JSNonFinalObject::globalObject());
+    ASSERT(domWindow);
+    return *domWindow;
+}
+
 } // namespace WebCore
index 22a2a2c..cd50aef 100644 (file)
@@ -27,6 +27,7 @@
 
 namespace WebCore {
 
+class JSDOMWindow;
 class ScriptExecutionContext;
 
 static const uint8_t JSNodeType = JSC::LastJSCObjectType + 1;
@@ -41,8 +42,10 @@ public:
     JSDOMGlobalObject* globalObject() const { return JSC::jsCast<JSDOMGlobalObject*>(JSC::JSNonFinalObject::globalObject()); }
     ScriptExecutionContext* scriptExecutionContext() const { return globalObject()->scriptExecutionContext(); }
 
+    JSDOMWindow& domWindow() const;
+
 protected:
-    JSDOMObject(JSC::Structure* structure, JSC::JSGlobalObject& globalObject) 
+    JSDOMObject(JSC::Structure* structure, JSC::JSGlobalObject& globalObject)
         : Base(globalObject.vm(), structure)
     {
         ASSERT(scriptExecutionContext());
index b741e53..29bdef2 100644 (file)
@@ -39,11 +39,11 @@ JSC::JSValue JSFontFace::loaded(JSC::ExecState& state) const
 {
     if (!m_loaded) {
         if (!wrapped().promise()) {
-            Ref<DeferredWrapper> promise = DeferredWrapper::create(&state, globalObject(), JSC::JSPromiseDeferred::create(&state, globalObject()));
+            auto promise = createDeferredPromise(state, domWindow());
             m_loaded.set(state.vm(), this, promise->promise());
             wrapped().registerLoaded(WTFMove(promise));
         } else
-            m_loaded.set(state.vm(), this, wrapped().promise().value().deferredWrapper().promise());
+            m_loaded.set(state.vm(), this, wrapped().promise().value().promise());
     }
     return m_loaded.get();
 }
index 2870b48..22560d4 100644 (file)
@@ -34,7 +34,7 @@ namespace WebCore {
 JSC::JSValue JSFontFaceSet::ready(JSC::ExecState& state) const
 {
     if (!m_ready) {
-        Ref<DeferredWrapper> promise = DeferredWrapper::create(&state, globalObject(), JSC::JSPromiseDeferred::create(&state, globalObject()));
+        auto promise = createDeferredPromise(state, domWindow());
         m_ready.set(state.vm(), this, promise->promise());
         wrapped().registerReady(WTFMove(promise));
     }
index c31e94e..ed523ab 100644 (file)
@@ -340,7 +340,7 @@ void parseMediaConstraintsDictionary(const Dictionary& mediaTrackConstraints, Me
     }
 }
 
-static void JSMediaDevicesGetUserMediaPromiseFunction(ExecState& state, Ref<DeferredWrapper>&& promise)
+static void JSMediaDevicesGetUserMediaPromiseFunction(ExecState& state, Ref<DeferredPromise>&& promise)
 {
     VM& vm = state.vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
index fdf66a7..b22b282 100644 (file)
@@ -184,11 +184,13 @@ JSValue JSMediaStreamTrack::applyConstraints(ExecState& state)
         valid = !advancedConstraints.isEmpty() || !mandatoryConstraints.isEmpty();
     }
 
-    JSC::JSPromiseDeferred* promiseDeferred = JSC::JSPromiseDeferred::create(&state, globalObject());
+    auto deferredPromise = createDeferredPromise(state, domWindow());
+    auto promise = deferredPromise->promise();
+
     auto constraints = MediaConstraintsImpl::create(WTFMove(mandatoryConstraints), WTFMove(advancedConstraints), valid);
-    wrapped().applyConstraints(WTFMove(constraints), DeferredWrapper::create(&state, globalObject(), promiseDeferred));
+    wrapped().applyConstraints(WTFMove(constraints), WTFMove(deferredPromise));
 
-    return promiseDeferred->promise();
+    return promise;
 }
 
 JSValue JSMediaStreamTrack::getConstraints(ExecState& state)
index 39a73f5..7751410 100644 (file)
@@ -43,8 +43,11 @@ JSValue JSReadableStreamSource::start(ExecState& state)
     JSReadableStreamSource* jsSource = const_cast<JSReadableStreamSource*>(this);
     m_controller.set(state.vm(), jsSource, state.argument(0));
 
+    ASSERT(globalObject());
     JSC::JSPromiseDeferred* promiseDeferred = JSC::JSPromiseDeferred::create(&state, globalObject());
-    wrapped().start(ReadableStreamDefaultController(controller), DeferredWrapper::create(&state, globalObject(), promiseDeferred));
+    if (!promiseDeferred)
+        return jsUndefined();
+    wrapped().start(ReadableStreamDefaultController(controller), DeferredPromise::create(*globalObject(), *promiseDeferred));
     return promiseDeferred->promise();
 }
 
index ca9e14b..5859b79 100644 (file)
@@ -173,9 +173,8 @@ JSValue JSWebKitSubtleCrypto::encrypt(ExecState& state)
     if (!success)
         return jsUndefined();
 
-    
-    JSPromiseDeferred* promiseDeferred = JSPromiseDeferred::create(&state, globalObject());
-    RefPtr<DeferredWrapper> wrapper = DeferredWrapper::create(&state, globalObject(), promiseDeferred);
+    RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
+    auto promise = wrapper->promise();
     auto successCallback = [wrapper](const Vector<uint8_t>& result) mutable {
         fulfillPromiseWithArrayBuffer(wrapper.releaseNonNull(), result.data(), result.size());
     };
@@ -190,7 +189,7 @@ JSValue JSWebKitSubtleCrypto::encrypt(ExecState& state)
         return jsUndefined();
     }
 
-    return promiseDeferred->promise();
+    return promise;
 }
 
 JSValue JSWebKitSubtleCrypto::decrypt(ExecState& state)
@@ -227,8 +226,8 @@ JSValue JSWebKitSubtleCrypto::decrypt(ExecState& state)
     if (!success)
         return jsUndefined();
 
-    JSPromiseDeferred* promiseDeferred = JSPromiseDeferred::create(&state, globalObject());
-    RefPtr<DeferredWrapper> wrapper = DeferredWrapper::create(&state, globalObject(), promiseDeferred);
+    RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
+    auto promise = wrapper->promise();
     auto successCallback = [wrapper](const Vector<uint8_t>& result) mutable {
         fulfillPromiseWithArrayBuffer(wrapper.releaseNonNull(), result.data(), result.size());
     };
@@ -243,7 +242,7 @@ JSValue JSWebKitSubtleCrypto::decrypt(ExecState& state)
         return jsUndefined();
     }
 
-    return promiseDeferred->promise();
+    return promise;
 }
 
 JSValue JSWebKitSubtleCrypto::sign(ExecState& state)
@@ -280,8 +279,8 @@ JSValue JSWebKitSubtleCrypto::sign(ExecState& state)
     if (!success)
         return jsUndefined();
 
-    JSPromiseDeferred* promiseDeferred = JSPromiseDeferred::create(&state, globalObject());
-    RefPtr<DeferredWrapper> wrapper = DeferredWrapper::create(&state, globalObject(), promiseDeferred);
+    RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
+    auto promise = wrapper->promise();
     auto successCallback = [wrapper](const Vector<uint8_t>& result) mutable {
         fulfillPromiseWithArrayBuffer(wrapper.releaseNonNull(), result.data(), result.size());
     };
@@ -296,7 +295,7 @@ JSValue JSWebKitSubtleCrypto::sign(ExecState& state)
         return jsUndefined();
     }
 
-    return promiseDeferred->promise();
+    return promise;
 }
 
 JSValue JSWebKitSubtleCrypto::verify(ExecState& state)
@@ -339,8 +338,8 @@ JSValue JSWebKitSubtleCrypto::verify(ExecState& state)
     if (!success)
         return jsUndefined();
 
-    JSPromiseDeferred* promiseDeferred = JSPromiseDeferred::create(&state, globalObject());
-    RefPtr<DeferredWrapper> wrapper = DeferredWrapper::create(&state, globalObject(), promiseDeferred);
+    RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
+    auto promise = wrapper->promise();
     auto successCallback = [wrapper](bool result) mutable {
         wrapper->resolve(result);
     };
@@ -355,7 +354,7 @@ JSValue JSWebKitSubtleCrypto::verify(ExecState& state)
         return jsUndefined();
     }
 
-    return promiseDeferred->promise();
+    return promise;
 }
 
 JSValue JSWebKitSubtleCrypto::digest(ExecState& state)
@@ -382,8 +381,8 @@ JSValue JSWebKitSubtleCrypto::digest(ExecState& state)
     if (!success)
         return jsUndefined();
 
-    JSPromiseDeferred* promiseDeferred = JSPromiseDeferred::create(&state, globalObject());
-    RefPtr<DeferredWrapper> wrapper = DeferredWrapper::create(&state, globalObject(), promiseDeferred);
+    RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
+    auto promise = wrapper->promise();
     auto successCallback = [wrapper](const Vector<uint8_t>& result) mutable {
         fulfillPromiseWithArrayBuffer(wrapper.releaseNonNull(), result.data(), result.size());
     };
@@ -398,7 +397,7 @@ JSValue JSWebKitSubtleCrypto::digest(ExecState& state)
         return jsUndefined();
     }
 
-    return promiseDeferred->promise();
+    return promise;
 }
 
 JSValue JSWebKitSubtleCrypto::generateKey(ExecState& state)
@@ -434,8 +433,8 @@ JSValue JSWebKitSubtleCrypto::generateKey(ExecState& state)
             return jsUndefined();
     }
 
-    JSPromiseDeferred* promiseDeferred = JSPromiseDeferred::create(&state, globalObject());
-    RefPtr<DeferredWrapper> wrapper = DeferredWrapper::create(&state, globalObject(), promiseDeferred);
+    RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
+    auto promise = wrapper->promise();
     auto successCallback = [wrapper](CryptoKey* key, CryptoKeyPair* keyPair) mutable {
         ASSERT(key || keyPair);
         ASSERT(!key || !keyPair);
@@ -455,7 +454,7 @@ JSValue JSWebKitSubtleCrypto::generateKey(ExecState& state)
         return jsUndefined();
     }
 
-    return promiseDeferred->promise();
+    return promise;
 }
 
 static void importKey(ExecState& state, CryptoKeyFormat keyFormat, CryptoOperationData data, RefPtr<CryptoAlgorithm> algorithm, RefPtr<CryptoAlgorithmParameters> parameters, bool extractable, CryptoKeyUsage keyUsages, CryptoAlgorithm::KeyCallback callback, CryptoAlgorithm::VoidCallback failureCallback)
@@ -570,8 +569,8 @@ JSValue JSWebKitSubtleCrypto::importKey(ExecState& state)
             return jsUndefined();
     }
 
-    JSPromiseDeferred* promiseDeferred = JSPromiseDeferred::create(&state, globalObject());
-    RefPtr<DeferredWrapper> wrapper = DeferredWrapper::create(&state, globalObject(), promiseDeferred);
+    RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
+    auto promise = wrapper->promise();
     auto successCallback = [wrapper](CryptoKey& result) mutable {
         wrapper->resolve(result);
     };
@@ -583,7 +582,7 @@ JSValue JSWebKitSubtleCrypto::importKey(ExecState& state)
     if (UNLIKELY(scope.exception()))
         return jsUndefined();
 
-    return promiseDeferred->promise();
+    return promise;
 }
 
 static void exportKey(ExecState& state, CryptoKeyFormat keyFormat, const CryptoKey& key, CryptoAlgorithm::VectorCallback callback, CryptoAlgorithm::VoidCallback failureCallback)
@@ -639,8 +638,8 @@ JSValue JSWebKitSubtleCrypto::exportKey(ExecState& state)
     if (!key)
         return throwTypeError(&state, scope);
 
-    JSPromiseDeferred* promiseDeferred = JSPromiseDeferred::create(&state, globalObject());
-    RefPtr<DeferredWrapper> wrapper = DeferredWrapper::create(&state, globalObject(), promiseDeferred);
+    RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
+    auto promise = wrapper->promise();
     auto successCallback = [wrapper](const Vector<uint8_t>& result) mutable {
         fulfillPromiseWithArrayBuffer(wrapper.releaseNonNull(), result.data(), result.size());
     };
@@ -652,7 +651,7 @@ JSValue JSWebKitSubtleCrypto::exportKey(ExecState& state)
     if (UNLIKELY(scope.exception()))
         return jsUndefined();
 
-    return promiseDeferred->promise();
+    return promise;
 }
 
 JSValue JSWebKitSubtleCrypto::wrapKey(ExecState& state)
@@ -693,8 +692,8 @@ JSValue JSWebKitSubtleCrypto::wrapKey(ExecState& state)
     if (!parameters)
         return jsUndefined();
 
-    JSPromiseDeferred* promiseDeferred = JSPromiseDeferred::create(&state, globalObject());
-    RefPtr<DeferredWrapper> wrapper = DeferredWrapper::create(&state, globalObject(), promiseDeferred);
+    RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
+    auto promise = wrapper->promise();
 
     auto exportSuccessCallback = [keyFormat, algorithm, parameters, wrappingKey, wrapper](const Vector<uint8_t>& exportedKeyData) mutable {
         auto encryptSuccessCallback = [wrapper](const Vector<uint8_t>& encryptedData) mutable {
@@ -722,7 +721,7 @@ JSValue JSWebKitSubtleCrypto::wrapKey(ExecState& state)
         return jsUndefined();
     }
 
-    return promiseDeferred->promise();
+    return promise;
 }
 
 JSValue JSWebKitSubtleCrypto::unwrapKey(ExecState& state)
@@ -793,8 +792,8 @@ JSValue JSWebKitSubtleCrypto::unwrapKey(ExecState& state)
             return jsUndefined();
     }
 
-    JSPromiseDeferred* promiseDeferred = JSPromiseDeferred::create(&state, globalObject());
-    RefPtr<DeferredWrapper> wrapper = DeferredWrapper::create(&state, globalObject(), promiseDeferred);
+    RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
+    auto promise = wrapper->promise();
     Strong<JSDOMGlobalObject> domGlobalObject(state.vm(), globalObject());
 
     auto decryptSuccessCallback = [domGlobalObject, keyFormat, unwrappedKeyAlgorithm, unwrappedKeyAlgorithmParameters, extractable, keyUsages, wrapper](const Vector<uint8_t>& result) mutable {
@@ -828,7 +827,7 @@ JSValue JSWebKitSubtleCrypto::unwrapKey(ExecState& state)
         return jsUndefined();
     }
 
-    return promiseDeferred->promise();
+    return promise;
 }
 
 } // namespace WebCore
index d9ce054..afb9030 100644 (file)
@@ -3425,7 +3425,7 @@ sub GenerateImplementation
 
                 my $scope = $interface->extendedAttributes->{"Exposed"} ? "WindowOrWorker" : "WindowOnly";
                 push(@implContent, <<END);
-static EncodedJSValue ${functionName}Promise(ExecState*, Ref<DeferredWrapper>&&);
+static EncodedJSValue ${functionName}Promise(ExecState*, Ref<DeferredPromise>&&);
 
 ${functionReturn} ${functionName}(ExecState* state)
 {
@@ -3433,7 +3433,7 @@ ${functionReturn} ${functionName}(ExecState* state)
     return JSValue::encode(callPromiseFunction<${functionName}Promise, PromiseExecutionScope::${scope}>(*state));
 }
 
-static inline EncodedJSValue ${functionName}Promise(ExecState* state, Ref<DeferredWrapper>&& deferredWrapper)
+static inline EncodedJSValue ${functionName}Promise(ExecState* state, Ref<DeferredPromise>&& promise)
 END
             }
             else {
@@ -4146,7 +4146,7 @@ sub GenerateReturnParameters
     my @arguments;
 
     if (IsReturningPromise($function)) {
-        push(@arguments, "WTFMove(deferredWrapper)");
+        push(@arguments, "WTFMove(promise)");
     }
     push(@arguments, "ec") if $function->signature->extendedAttributes->{"RaisesException"} || $function->signature->extendedAttributes->{"RaisesExceptionWithMessage"};
     return @arguments;
index cd77115..550437a 100644 (file)
@@ -231,7 +231,7 @@ JSValue JSTestNode::getConstructor(VM& vm, const JSGlobalObject* globalObject)
     return getDOMConstructor<JSTestNodeConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
 }
 
-static EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState*, Ref<DeferredWrapper>&&);
+static EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState*, Ref<DeferredPromise>&&);
 
 EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionTestWorkerPromise(ExecState* state)
 {
@@ -239,7 +239,7 @@ EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionTestWorkerPromise(ExecSt
     return JSValue::encode(callPromiseFunction<jsTestNodePrototypeFunctionTestWorkerPromisePromise, PromiseExecutionScope::WindowOrWorker>(*state));
 }
 
-static inline EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState* state, Ref<DeferredWrapper>&& deferredWrapper)
+static inline EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState* state, Ref<DeferredPromise>&& promise)
 {
     VM& vm = state->vm();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
@@ -250,7 +250,7 @@ static inline EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise
         return throwThisTypeError(*state, throwScope, "TestNode", "testWorkerPromise");
     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestNode::info());
     auto& impl = castedThis->wrapped();
-    impl.testWorkerPromise(WTFMove(deferredWrapper));
+    impl.testWorkerPromise(WTFMove(promise));
     return JSValue::encode(jsUndefined());
 }
 
index eda82ba..30db87c 100644 (file)
@@ -7160,7 +7160,7 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionAny(ExecState* state)
     return JSValue::encode(jsUndefined());
 }
 
-static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionPromise(ExecState*, Ref<DeferredWrapper>&&);
+static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionPromise(ExecState*, Ref<DeferredPromise>&&);
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunction(ExecState* state)
 {
@@ -7168,7 +7168,7 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunction(ExecS
     return JSValue::encode(callPromiseFunction<jsTestObjPrototypeFunctionTestPromiseFunctionPromise, PromiseExecutionScope::WindowOnly>(*state));
 }
 
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionPromise(ExecState* state, Ref<DeferredWrapper>&& deferredWrapper)
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionPromise(ExecState* state, Ref<DeferredPromise>&& promise)
 {
     VM& vm = state->vm();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
@@ -7179,11 +7179,11 @@ static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionPromis
         return throwThisTypeError(*state, throwScope, "TestObject", "testPromiseFunction");
     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
     auto& impl = castedThis->wrapped();
-    impl.testPromiseFunction(WTFMove(deferredWrapper));
+    impl.testPromiseFunction(WTFMove(promise));
     return JSValue::encode(jsUndefined());
 }
 
-static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise(ExecState*, Ref<DeferredWrapper>&&);
+static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise(ExecState*, Ref<DeferredPromise>&&);
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgument(ExecState* state)
 {
@@ -7191,7 +7191,7 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithFl
     return JSValue::encode(callPromiseFunction<jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise, PromiseExecutionScope::WindowOnly>(*state));
 }
 
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise(ExecState* state, Ref<DeferredWrapper>&& deferredWrapper)
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise(ExecState* state, Ref<DeferredPromise>&& promise)
 {
     VM& vm = state->vm();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
@@ -7207,11 +7207,11 @@ static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithFl
     auto a = convert<float>(*state, state->argument(0), ShouldAllowNonFinite::No);
     if (UNLIKELY(throwScope.exception()))
         return JSValue::encode(jsUndefined());
-    impl.testPromiseFunctionWithFloatArgument(WTFMove(a), WTFMove(deferredWrapper));
+    impl.testPromiseFunctionWithFloatArgument(WTFMove(a), WTFMove(promise));
     return JSValue::encode(jsUndefined());
 }
 
-static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise(ExecState*, Ref<DeferredWrapper>&&);
+static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise(ExecState*, Ref<DeferredPromise>&&);
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithException(ExecState* state)
 {
@@ -7219,7 +7219,7 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithEx
     return JSValue::encode(callPromiseFunction<jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise, PromiseExecutionScope::WindowOnly>(*state));
 }
 
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise(ExecState* state, Ref<DeferredWrapper>&& deferredWrapper)
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise(ExecState* state, Ref<DeferredPromise>&& promise)
 {
     VM& vm = state->vm();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
@@ -7231,12 +7231,12 @@ static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithEx
     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
     auto& impl = castedThis->wrapped();
     ExceptionCode ec = 0;
-    impl.testPromiseFunctionWithException(WTFMove(deferredWrapper), ec);
+    impl.testPromiseFunctionWithException(WTFMove(promise), ec);
     setDOMException(state, ec);
     return JSValue::encode(jsUndefined());
 }
 
-static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise(ExecState*, Ref<DeferredWrapper>&&);
+static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise(ExecState*, Ref<DeferredPromise>&&);
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgument(ExecState* state)
 {
@@ -7244,7 +7244,7 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithOp
     return JSValue::encode(callPromiseFunction<jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise, PromiseExecutionScope::WindowOnly>(*state));
 }
 
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise(ExecState* state, Ref<DeferredWrapper>&& deferredWrapper)
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise(ExecState* state, Ref<DeferredPromise>&& promise)
 {
     VM& vm = state->vm();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
@@ -7258,11 +7258,11 @@ static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithOp
     auto a = state->argument(0).isUndefined() ? Optional<int32_t>() : convert<int32_t>(*state, state->uncheckedArgument(0), NormalConversion);
     if (UNLIKELY(throwScope.exception()))
         return JSValue::encode(jsUndefined());
-    impl.testPromiseFunctionWithOptionalIntArgument(WTFMove(a), WTFMove(deferredWrapper));
+    impl.testPromiseFunctionWithOptionalIntArgument(WTFMove(a), WTFMove(promise));
     return JSValue::encode(jsUndefined());
 }
 
-static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Promise(ExecState*, Ref<DeferredWrapper>&&);
+static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Promise(ExecState*, Ref<DeferredPromise>&&);
 
 static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1(ExecState* state)
 {
@@ -7270,7 +7270,7 @@ static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunc
     return JSValue::encode(callPromiseFunction<jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Promise, PromiseExecutionScope::WindowOnly>(*state));
 }
 
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Promise(ExecState* state, Ref<DeferredWrapper>&& deferredWrapper)
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Promise(ExecState* state, Ref<DeferredPromise>&& promise)
 {
     VM& vm = state->vm();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
@@ -7286,11 +7286,11 @@ static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunc
     auto a = convert<float>(*state, state->argument(0), ShouldAllowNonFinite::No);
     if (UNLIKELY(throwScope.exception()))
         return JSValue::encode(jsUndefined());
-    impl.testPromiseOverloadedFunction(WTFMove(a), WTFMove(deferredWrapper));
+    impl.testPromiseOverloadedFunction(WTFMove(a), WTFMove(promise));
     return JSValue::encode(jsUndefined());
 }
 
-static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2Promise(ExecState*, Ref<DeferredWrapper>&&);
+static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2Promise(ExecState*, Ref<DeferredPromise>&&);
 
 static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2(ExecState* state)
 {
@@ -7298,7 +7298,7 @@ static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunc
     return JSValue::encode(callPromiseFunction<jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2Promise, PromiseExecutionScope::WindowOnly>(*state));
 }
 
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2Promise(ExecState* state, Ref<DeferredWrapper>&& deferredWrapper)
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2Promise(ExecState* state, Ref<DeferredPromise>&& promise)
 {
     VM& vm = state->vm();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
@@ -7314,7 +7314,7 @@ static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunc
     auto request = JSFetchRequest::toWrapped(state->argument(0));
     if (UNLIKELY(!request))
         return throwArgumentTypeError(*state, throwScope, 0, "request", "TestObject", "testPromiseOverloadedFunction", "FetchRequest");
-    impl.testPromiseOverloadedFunction(*request, WTFMove(deferredWrapper));
+    impl.testPromiseOverloadedFunction(*request, WTFMove(promise));
     return JSValue::encode(jsUndefined());
 }
 
@@ -7335,7 +7335,7 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseOverloadedFunc
     return argsCount < 1 ? throwVMError(state, throwScope, createNotEnoughArgumentsError(state)) : throwVMTypeError(state, throwScope);
 }
 
-static EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionPromise(ExecState*, Ref<DeferredWrapper>&&);
+static EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionPromise(ExecState*, Ref<DeferredPromise>&&);
 
 EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionTestStaticPromiseFunction(ExecState* state)
 {
@@ -7343,16 +7343,16 @@ EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionTestStaticPromiseFuncti
     return JSValue::encode(callPromiseFunction<jsTestObjConstructorFunctionTestStaticPromiseFunctionPromise, PromiseExecutionScope::WindowOnly>(*state));
 }
 
-static inline EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionPromise(ExecState* state, Ref<DeferredWrapper>&& deferredWrapper)
+static inline EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionPromise(ExecState* state, Ref<DeferredPromise>&& promise)
 {
     VM& vm = state->vm();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
     UNUSED_PARAM(throwScope);
-    TestObj::testStaticPromiseFunction(WTFMove(deferredWrapper));
+    TestObj::testStaticPromiseFunction(WTFMove(promise));
     return JSValue::encode(jsUndefined());
 }
 
-static EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionPromise(ExecState*, Ref<DeferredWrapper>&&);
+static EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionPromise(ExecState*, Ref<DeferredPromise>&&);
 
 EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionTestStaticPromiseFunctionWithException(ExecState* state)
 {
@@ -7360,13 +7360,13 @@ EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionTestStaticPromiseFuncti
     return JSValue::encode(callPromiseFunction<jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionPromise, PromiseExecutionScope::WindowOnly>(*state));
 }
 
-static inline EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionPromise(ExecState* state, Ref<DeferredWrapper>&& deferredWrapper)
+static inline EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionPromise(ExecState* state, Ref<DeferredPromise>&& promise)
 {
     VM& vm = state->vm();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
     UNUSED_PARAM(throwScope);
     ExceptionCode ec = 0;
-    TestObj::testStaticPromiseFunctionWithException(WTFMove(deferredWrapper), ec);
+    TestObj::testStaticPromiseFunctionWithException(WTFMove(promise), ec);
     setDOMException(state, ec);
     return JSValue::encode(jsUndefined());
 }
index e0dd103..81f7ca1 100644 (file)
@@ -34,7 +34,6 @@
 #include "Element.h"
 #include "ElementTraversal.h"
 #include "JSCustomElementInterface.h"
-#include "JSDOMPromise.h"
 #include "MathMLNames.h"
 #include "QualifiedName.h"
 #include "SVGNames.h"
index 5761a47..18e4bee 100644 (file)
@@ -27,6 +27,7 @@
 
 #if ENABLE(CUSTOM_ELEMENTS)
 
+#include "JSDOMPromise.h"
 #include "QualifiedName.h"
 #include <wtf/HashMap.h>
 #include <wtf/TemporaryChange.h>
@@ -44,7 +45,6 @@ namespace WebCore {
 
 class CustomElementRegistry;
 class DOMWindow;
-class DeferredWrapper;
 class Element;
 class JSCustomElementInterface;
 class QualifiedName;
@@ -66,7 +66,7 @@ public:
 
     JSC::JSValue get(const AtomicString&);
 
-    HashMap<AtomicString, Ref<DeferredWrapper>>& promiseMap() { return m_promiseMap; }
+    HashMap<AtomicString, Ref<DeferredPromise>>& promiseMap() { return m_promiseMap; }
 
 private:
     CustomElementRegistry(DOMWindow&);
@@ -74,7 +74,7 @@ private:
     DOMWindow& m_window;
     HashMap<AtomicString, Ref<JSCustomElementInterface>> m_nameMap;
     HashMap<const JSC::JSObject*, JSCustomElementInterface*> m_constructorMap;
-    HashMap<AtomicString, Ref<DeferredWrapper>> m_promiseMap;
+    HashMap<AtomicString, Ref<DeferredPromise>> m_promiseMap;
 
     bool m_elementDefinitionIsRunning { false };