Handle IDLPromise<> properly
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 May 2017 12:17:21 +0000 (12:17 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 May 2017 12:17:21 +0000 (12:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166752

Reviewed by Youenn Fablet.

Source/JavaScriptCore:

Add JSPromise::resolve static function.
This applies `Promise.resolve()` conversion to a given value.

* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::promiseResolveFunction):
* runtime/JSPromise.cpp:
(JSC::JSPromise::resolve):
* runtime/JSPromise.h:

Source/WebCore:

This patch implements WebIDL Promise type conversion. According to the spec,
Promise takes a value and convert it to Promise by using Promise.resolve function.
We implement JSPromise::resolve in JSC and use it in JSDOMConvertPromise.

In conversion phase, we just convert the value to JSC::JSPromise* and hold it in
PromiseRejectionEvent. On the other hand, In this patch, we newly introduce a new
type DOMPromise and use it in RejectedPromiseTracker. And we also rename the previous
DOMPromise to DOMPromiseDeferred since it is corresponding to JSPromiseDeferred.
DOMPromise is DOMGuarded object. So it is strongly referenced from ScriptExecutionContext
and it is weakly referenced from the object itself. This is important since Strong<JSPromise>
reference in C++ object that has a wrapper (in this case, PromiseRejectionEvent) easily causes
cyclic reference. We hold it as DOMPromise instead of Strong<JSPromise> in RejectedPromiseTracker
to break the cyclic reference edge with weak reference.

In the meantime, we still use JSC::Strong<> in PromiseRejectionEvent. It leaks memory if promise
refers the wrapper object of PromiseRejectionEvent. CustomEvent also has the same problem.
This is a general problem that `attribute any` can create cyclic reference. And they should be
fixed in a different patch.

Currently, we do not take the following approach. e.g. There is C++ object that represents Promise.
And its wrapper object is JSPromise thing. When exposing the C++ object, it will be converted to a
wrapper object. We do not take this approach because PromiseRejectionEvent can take user-provided promise.
For example, users can create PromiseRejectionEvent in a form
`new PromiseRejectionEvent("...", { promise: promise })`. In this case, `event.promise === promise`
is required. And this is not suitable for the above C++ object model.

Large part of this patch is mechanical one to replace DOMPromise with DOMPromiseDeferred.

* CMakeLists.txt:
* Modules/applepay/ApplePaySession.cpp:
* Modules/encryptedmedia/MediaKeySession.h:
* Modules/encryptedmedia/MediaKeySystemAccess.h:
* Modules/encryptedmedia/MediaKeys.h:
* Modules/encryptedmedia/NavigatorEME.h:
* Modules/fetch/DOMWindowFetch.h:
* Modules/fetch/FetchBody.h:
* Modules/fetch/FetchBodyConsumer.h:
* Modules/fetch/FetchResponse.h:
* Modules/fetch/WorkerGlobalScopeFetch.h:
* Modules/mediastream/MediaDevices.h:
* Modules/mediastream/MediaEndpointPeerConnection.cpp:
(WebCore::MediaEndpointPeerConnection::replaceTrack):
(WebCore::MediaEndpointPeerConnection::replaceTrackTask):
* Modules/mediastream/MediaEndpointPeerConnection.h:
* Modules/mediastream/MediaStreamTrack.cpp:
(WebCore::MediaStreamTrack::applyConstraints):
* Modules/mediastream/MediaStreamTrack.h:
* Modules/mediastream/PeerConnectionBackend.cpp:
(WebCore::PeerConnectionBackend::setLocalDescription):
(WebCore::PeerConnectionBackend::setRemoteDescription):
(WebCore::PeerConnectionBackend::addIceCandidate):
* Modules/mediastream/PeerConnectionBackend.h:
(WebCore::PeerConnectionBackend::endOfIceCandidates):
* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::RTCPeerConnection::queuedSetLocalDescription):
(WebCore::RTCPeerConnection::queuedSetRemoteDescription):
(WebCore::RTCPeerConnection::queuedAddIceCandidate):
(WebCore::RTCPeerConnection::enqueueReplaceTrackTask):
(WebCore::RTCPeerConnection::replaceTrack):
* Modules/mediastream/RTCPeerConnection.h:
* Modules/mediastream/RTCRtpSender.cpp:
(WebCore::RTCRtpSender::replaceTrack):
* Modules/mediastream/RTCRtpSender.h:
* Modules/mediastream/UserMediaRequest.cpp:
(WebCore::UserMediaRequest::start):
(WebCore::UserMediaRequest::UserMediaRequest):
* Modules/mediastream/UserMediaRequest.h:
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
(WebCore::LibWebRTCPeerConnectionBackend::replaceTrack):
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:
* Modules/streams/ReadableStreamSource.h:
(WebCore::ReadableStreamSource::start):
(WebCore::ReadableStreamSource::pull):
* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::addReaction):
(WebCore::AudioContext::setState):
(WebCore::AudioContext::suspend):
(WebCore::AudioContext::resume):
(WebCore::AudioContext::close):
* Modules/webaudio/AudioContext.h:
* WebCore.xcodeproj/project.pbxproj:
* bindings/IDLTypes.h:
* bindings/js/CachedModuleScriptLoaderClient.h:
* bindings/js/JSBindingsAllInOne.cpp:
* bindings/js/JSCustomElementRegistryCustom.cpp:
* bindings/js/JSDOMConvertPromise.h:
(WebCore::Converter<IDLPromise<T>>::convert):
(WebCore::JSConverter<IDLPromise<T>>::convert):
* bindings/js/JSDOMExceptionHandling.cpp:
* bindings/js/JSDOMGlobalObject.cpp:
* bindings/js/JSDOMGuardedObject.h:
* bindings/js/JSDOMPromise.h:
(WebCore::DOMPromise::create):
(WebCore::DOMPromise::promise):
(WebCore::DOMPromise::DOMPromise):
(WebCore::DeferredPromise::create): Deleted.
(WebCore::DeferredPromise::resolve): Deleted.
(WebCore::DeferredPromise::resolveWithNewlyCreated): Deleted.
(WebCore::DeferredPromise::reject): Deleted.
(WebCore::DeferredPromise::resolveWithCallback): Deleted.
(WebCore::DeferredPromise::rejectWithCallback): Deleted.
(WebCore::DeferredPromise::DeferredPromise): Deleted.
(WebCore::DeferredPromise::deferred): Deleted.
(WebCore::DOMPromiseBase::DOMPromiseBase): Deleted.
(WebCore::DOMPromiseBase::operator=): Deleted.
(WebCore::DOMPromiseBase::reject): Deleted.
(WebCore::DOMPromiseBase::rejectType): Deleted.
(WebCore::DOMPromiseBase::promise): Deleted.
(WebCore::DOMPromise::resolve): Deleted.
(WebCore::DOMPromise<void>::resolve): Deleted.
(WebCore::callPromiseFunction): Deleted.
(WebCore::bindingPromiseFunctionAdapter): Deleted.
* bindings/js/JSDOMPromiseDeferred.cpp: Renamed from Source/WebCore/bindings/js/JSDOMPromise.cpp.
(WebCore::DeferredPromise::promise):
(WebCore::DeferredPromise::callFunction):
(WebCore::DeferredPromise::reject):
(WebCore::rejectPromiseWithExceptionIfAny):
(WebCore::createDeferredPromise):
(WebCore::createRejectedPromiseWithTypeError):
(WebCore::parseAsJSON):
(WebCore::fulfillPromiseWithJSON):
(WebCore::fulfillPromiseWithArrayBuffer):
* bindings/js/JSDOMPromiseDeferred.h: Copied from Source/WebCore/bindings/js/JSDOMPromise.h.
(WebCore::DeferredPromise::create):
(WebCore::DeferredPromise::resolve):
(WebCore::DeferredPromise::resolveWithNewlyCreated):
(WebCore::DeferredPromise::reject):
(WebCore::DeferredPromise::resolveWithCallback):
(WebCore::DeferredPromise::rejectWithCallback):
(WebCore::DeferredPromise::DeferredPromise):
(WebCore::DeferredPromise::deferred):
(WebCore::DOMPromiseDeferredBase::DOMPromiseDeferredBase):
(WebCore::DOMPromiseDeferredBase::operator=):
(WebCore::DOMPromiseDeferredBase::reject):
(WebCore::DOMPromiseDeferredBase::rejectType):
(WebCore::DOMPromiseDeferredBase::promise):
(WebCore::DOMPromiseDeferred::resolve):
(WebCore::DOMPromiseDeferred<void>::resolve):
(WebCore::callPromiseFunction):
(WebCore::bindingPromiseFunctionAdapter):
* bindings/js/JSSubtleCryptoCustom.cpp:
* bindings/js/JSWebGPUCommandBufferCustom.cpp:
* bindings/js/JSWebKitSubtleCryptoCustom.cpp:
* bindings/scripts/test/JS/JSTestPromiseRejectionEvent.cpp: Added.
(WebCore::convertDictionary<TestPromiseRejectionEvent::Init>):
(WebCore::JSTestPromiseRejectionEventPrototype::create):
(WebCore::JSTestPromiseRejectionEventPrototype::createStructure):
(WebCore::JSTestPromiseRejectionEventPrototype::JSTestPromiseRejectionEventPrototype):
(WebCore::JSTestPromiseRejectionEventConstructor::construct):
(WebCore::JSTestPromiseRejectionEventConstructor::prototypeForStructure):
(WebCore::JSTestPromiseRejectionEventConstructor::initializeProperties):
(WebCore::JSTestPromiseRejectionEventPrototype::finishCreation):
(WebCore::JSTestPromiseRejectionEvent::JSTestPromiseRejectionEvent):
(WebCore::JSTestPromiseRejectionEvent::finishCreation):
(WebCore::JSTestPromiseRejectionEvent::createPrototype):
(WebCore::JSTestPromiseRejectionEvent::prototype):
(WebCore::BindingCaller<JSTestPromiseRejectionEvent>::castForAttribute):
(WebCore::jsTestPromiseRejectionEventPromise):
(WebCore::jsTestPromiseRejectionEventPromiseGetter):
(WebCore::jsTestPromiseRejectionEventReason):
(WebCore::jsTestPromiseRejectionEventReasonGetter):
(WebCore::jsTestPromiseRejectionEventConstructor):
(WebCore::setJSTestPromiseRejectionEventConstructor):
(WebCore::JSTestPromiseRejectionEvent::getConstructor):
(WebCore::toJSNewlyCreated):
(WebCore::toJS):
* bindings/scripts/test/JS/JSTestPromiseRejectionEvent.h: Added.
(WebCore::JSTestPromiseRejectionEvent::create):
(WebCore::JSTestPromiseRejectionEvent::createStructure):
(WebCore::JSTestPromiseRejectionEvent::wrapped):
(WebCore::toJS):
(WebCore::toJSNewlyCreated):
* bindings/scripts/test/TestPromiseRejectionEvent.idl: Copied from Source/WebCore/bindings/js/CachedModuleScriptLoaderClient.h.
* css/FontFace.h:
* css/FontFaceSet.h:
* dom/CustomElementRegistry.h:
* dom/PromiseRejectionEvent.h:
* dom/RejectedPromiseTracker.cpp:
(WebCore::UnhandledPromise::UnhandledPromise):
(WebCore::UnhandledPromise::callStack):
(WebCore::UnhandledPromise::promise):
(WebCore::RejectedPromiseTracker::promiseRejected):
(WebCore::RejectedPromiseTracker::promiseHandled):
(WebCore::RejectedPromiseTracker::reportUnhandledRejections):
(WebCore::RejectedPromiseTracker::reportRejectionHandled):
(WebCore::RejectedPromise::RejectedPromise): Deleted.
(WebCore::RejectedPromise::globalObject): Deleted.
(WebCore::RejectedPromise::promise): Deleted.
* dom/RejectedPromiseTracker.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::rejectPendingPlayPromises):
(WebCore::HTMLMediaElement::resolvePendingPlayPromises):
(WebCore::HTMLMediaElement::play):
* html/HTMLMediaElement.h:
* platform/graphics/gpu/GPUCommandBuffer.h:
* testing/Internals.h:

LayoutTests:

* js/dom/promise-rejection-event-should-follow-webidl-promise-conversion-rule-expected.txt: Added.
* js/dom/promise-rejection-event-should-follow-webidl-promise-conversion-rule.html: Added.

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

66 files changed:
LayoutTests/ChangeLog
LayoutTests/js/dom/promise-rejection-event-should-follow-webidl-promise-conversion-rule-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/promise-rejection-event-should-follow-webidl-promise-conversion-rule.html [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h
Source/JavaScriptCore/runtime/JSPromise.cpp
Source/JavaScriptCore/runtime/JSPromise.h
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/applepay/ApplePaySession.cpp
Source/WebCore/Modules/encryptedmedia/MediaKeySession.h
Source/WebCore/Modules/encryptedmedia/MediaKeySystemAccess.h
Source/WebCore/Modules/encryptedmedia/MediaKeys.h
Source/WebCore/Modules/encryptedmedia/NavigatorEME.h
Source/WebCore/Modules/fetch/DOMWindowFetch.h
Source/WebCore/Modules/fetch/FetchBody.h
Source/WebCore/Modules/fetch/FetchBodyConsumer.h
Source/WebCore/Modules/fetch/FetchResponse.h
Source/WebCore/Modules/fetch/WorkerGlobalScopeFetch.h
Source/WebCore/Modules/mediastream/MediaDevices.h
Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.cpp
Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.h
Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp
Source/WebCore/Modules/mediastream/MediaStreamTrack.h
Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp
Source/WebCore/Modules/mediastream/PeerConnectionBackend.h
Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
Source/WebCore/Modules/mediastream/RTCPeerConnection.h
Source/WebCore/Modules/mediastream/RTCRtpSender.cpp
Source/WebCore/Modules/mediastream/RTCRtpSender.h
Source/WebCore/Modules/mediastream/UserMediaRequest.cpp
Source/WebCore/Modules/mediastream/UserMediaRequest.h
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h
Source/WebCore/Modules/streams/ReadableStreamSource.h
Source/WebCore/Modules/webaudio/AudioContext.cpp
Source/WebCore/Modules/webaudio/AudioContext.h
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/IDLTypes.h
Source/WebCore/bindings/js/CachedModuleScriptLoaderClient.h
Source/WebCore/bindings/js/JSBindingsAllInOne.cpp
Source/WebCore/bindings/js/JSCustomElementRegistryCustom.cpp
Source/WebCore/bindings/js/JSDOMConvertPromise.h
Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp
Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
Source/WebCore/bindings/js/JSDOMGuardedObject.h
Source/WebCore/bindings/js/JSDOMPromise.h
Source/WebCore/bindings/js/JSDOMPromiseDeferred.cpp [moved from Source/WebCore/bindings/js/JSDOMPromise.cpp with 99% similarity]
Source/WebCore/bindings/js/JSDOMPromiseDeferred.h [new file with mode: 0644]
Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
Source/WebCore/bindings/js/JSWebGPUCommandBufferCustom.cpp
Source/WebCore/bindings/js/JSWebKitSubtleCryptoCustom.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestPromiseRejectionEvent.cpp [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestPromiseRejectionEvent.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/TestPromiseRejectionEvent.idl [new file with mode: 0644]
Source/WebCore/css/FontFace.h
Source/WebCore/css/FontFaceSet.h
Source/WebCore/dom/CustomElementRegistry.h
Source/WebCore/dom/PromiseRejectionEvent.h
Source/WebCore/dom/RejectedPromiseTracker.cpp
Source/WebCore/dom/RejectedPromiseTracker.h
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.h
Source/WebCore/testing/Internals.h

index c47bf9a..a36355d 100644 (file)
@@ -1,3 +1,13 @@
+2017-05-09  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Handle IDLPromise<> properly
+        https://bugs.webkit.org/show_bug.cgi?id=166752
+
+        Reviewed by Youenn Fablet.
+
+        * js/dom/promise-rejection-event-should-follow-webidl-promise-conversion-rule-expected.txt: Added.
+        * js/dom/promise-rejection-event-should-follow-webidl-promise-conversion-rule.html: Added.
+
 2017-05-09  Zan Dobersek  <zdobersek@igalia.com>
 
         Unreviewed. Landing the WPE layout test baselines.
diff --git a/LayoutTests/js/dom/promise-rejection-event-should-follow-webidl-promise-conversion-rule-expected.txt b/LayoutTests/js/dom/promise-rejection-event-should-follow-webidl-promise-conversion-rule-expected.txt
new file mode 100644 (file)
index 0000000..34e3977
--- /dev/null
@@ -0,0 +1,14 @@
+Test PromiseRejectionEvent constructor follows WebIDL promise conversion rule.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS event.promise is an instance of Promise
+PASS event.reason is "Cappuccino"
+PASS value is 42
+PASS event.promise is an instance of Promise
+PASS event.promise is promise
+PASS event.reason is "Cocoa"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/dom/promise-rejection-event-should-follow-webidl-promise-conversion-rule.html b/LayoutTests/js/dom/promise-rejection-event-should-follow-webidl-promise-conversion-rule.html
new file mode 100644 (file)
index 0000000..cb070a3
--- /dev/null
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description('Test PromiseRejectionEvent constructor follows WebIDL promise conversion rule.');
+window.jsTestIsAsync = true;
+
+var event = null;
+var value = null;
+var promise = null;
+
+event = new PromiseRejectionEvent("rejectionhandled", {
+    promise: 42,
+    reason: `Cappuccino`
+});
+shouldBeType(`event.promise`, `Promise`);
+shouldBe(`event.reason`, `"Cappuccino"`);
+event.promise.then(function (v) {
+    value = v;
+    shouldBe(`value`, `42`);
+
+    promise = Promise.resolve(42);
+    event = new PromiseRejectionEvent("rejectionhandled", {
+        promise: promise,
+        reason: `Cocoa`
+    });
+
+    shouldBeType(`event.promise`, `Promise`);
+    shouldBe(`event.promise`, `promise`);
+    shouldBe(`event.reason`, `"Cocoa"`);
+    finishJSTest();
+});
+
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index d30e5f6..0a62eae 100644 (file)
@@ -1,3 +1,22 @@
+2017-05-09  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Handle IDLPromise<> properly
+        https://bugs.webkit.org/show_bug.cgi?id=166752
+
+        Reviewed by Youenn Fablet.
+
+        Add JSPromise::resolve static function.
+        This applies `Promise.resolve()` conversion to a given value.
+
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+        (JSC::JSGlobalObject::visitChildren):
+        * runtime/JSGlobalObject.h:
+        (JSC::JSGlobalObject::promiseResolveFunction):
+        * runtime/JSPromise.cpp:
+        (JSC::JSPromise::resolve):
+        * runtime/JSPromise.h:
+
 2017-05-09  Zan Dobersek  <zdobersek@igalia.com>
 
         Upstream the WPE port
index e3b7a8a..57f4383 100644 (file)
@@ -428,6 +428,11 @@ void JSGlobalObject::init(VM& vm)
             init.set(JSFunction::createBuiltinFunction(init.vm, iteratorHelpersPerformIterationCodeGenerator(init.vm), init.owner));
         });
 
+    m_promiseResolveFunction.initLater(
+        [] (const Initializer<JSFunction>& init) {
+            init.set(JSFunction::createBuiltinFunction(init.vm, promiseConstructorResolveCodeGenerator(init.vm), init.owner));
+        });
+
     m_newPromiseCapabilityFunction.set(vm, this, JSFunction::createBuiltinFunction(vm, promiseOperationsNewPromiseCapabilityCodeGenerator(vm), this));
     m_functionProtoHasInstanceSymbolFunction.set(vm, this, hasInstanceSymbolFunction);
     m_throwTypeErrorGetterSetter.initLater(
@@ -1187,6 +1192,7 @@ void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
     thisObject->m_arrayProtoValuesFunction.visit(visitor);
     thisObject->m_initializePromiseFunction.visit(visitor);
     thisObject->m_iteratorProtocolFunction.visit(visitor);
+    thisObject->m_promiseResolveFunction.visit(visitor);
     visitor.append(thisObject->m_objectProtoValueOfFunction);
     visitor.append(thisObject->m_newPromiseCapabilityFunction);
     visitor.append(thisObject->m_functionProtoHasInstanceSymbolFunction);
index 7e9fecb..b33d6d3 100644 (file)
@@ -265,6 +265,7 @@ public:
     LazyProperty<JSGlobalObject, JSFunction> m_arrayProtoValuesFunction;
     LazyProperty<JSGlobalObject, JSFunction> m_initializePromiseFunction;
     LazyProperty<JSGlobalObject, JSFunction> m_iteratorProtocolFunction;
+    LazyProperty<JSGlobalObject, JSFunction> m_promiseResolveFunction;
     WriteBarrier<JSFunction> m_objectProtoValueOfFunction;
     WriteBarrier<JSFunction> m_newPromiseCapabilityFunction;
     WriteBarrier<JSFunction> m_functionProtoHasInstanceSymbolFunction;
@@ -515,6 +516,7 @@ public:
     JSFunction* arrayProtoValuesFunction() const { return m_arrayProtoValuesFunction.get(this); }
     JSFunction* initializePromiseFunction() const { return m_initializePromiseFunction.get(this); }
     JSFunction* iteratorProtocolFunction() const { return m_iteratorProtocolFunction.get(this); }
+    JSFunction* promiseResolveFunction() const { return m_promiseResolveFunction.get(this); }
     JSFunction* objectProtoValueOfFunction() const { return m_objectProtoValueOfFunction.get(); }
     JSFunction* newPromiseCapabilityFunction() const { return m_newPromiseCapabilityFunction.get(); }
     JSFunction* functionProtoHasInstanceSymbolFunction() const { return m_functionProtoHasInstanceSymbolFunction.get(); }
index a83d2bf..1bff352 100644 (file)
@@ -92,4 +92,23 @@ bool JSPromise::isHandled(VM& vm) const
     return value.asBoolean();
 }
 
+JSPromise* JSPromise::resolve(JSGlobalObject& globalObject, JSValue value)
+{
+    auto* exec = globalObject.globalExec();
+    auto& vm = exec->vm();
+    auto scope = DECLARE_THROW_SCOPE(vm);
+
+    auto* promiseResolveFunction = globalObject.promiseResolveFunction();
+    CallData callData;
+    auto callType = JSC::getCallData(promiseResolveFunction, callData);
+    ASSERT(callType != CallType::None);
+
+    MarkedArgumentBuffer arguments;
+    arguments.append(value);
+    auto result = call(exec, promiseResolveFunction, callType, callData, globalObject.promiseConstructor(), arguments);
+    RETURN_IF_EXCEPTION(scope, nullptr);
+    ASSERT(result.inherits(vm, JSPromise::info()));
+    return jsCast<JSPromise*>(result);
+}
+
 } // namespace JSC
index c7d7d99..e83672c 100644 (file)
@@ -52,6 +52,8 @@ public:
     // This may raise a JS exception.
     void initialize(ExecState*, JSGlobalObject*, JSValue executor);
 
+    JS_EXPORT_PRIVATE static JSPromise* resolve(JSGlobalObject&, JSValue);
+
 protected:
     JSPromise(VM&, Structure*);
     void finishCreation(VM&);
index 459df7c..b5e8799 100644 (file)
@@ -1163,7 +1163,7 @@ set(WebCore_SOURCES
     bindings/js/JSDOMGlobalObjectTask.cpp
     bindings/js/JSDOMGuardedObject.cpp
     bindings/js/JSDOMMapLike.cpp
-    bindings/js/JSDOMPromise.cpp
+    bindings/js/JSDOMPromiseDeferred.cpp
     bindings/js/JSDOMStringMapCustom.cpp
     bindings/js/JSDOMWindowBase.cpp
     bindings/js/JSDOMWindowCustom.cpp
index 177b37d..76f1658 100644 (file)
@@ -1,3 +1,207 @@
+2017-05-09  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Handle IDLPromise<> properly
+        https://bugs.webkit.org/show_bug.cgi?id=166752
+
+        Reviewed by Youenn Fablet.
+
+        This patch implements WebIDL Promise type conversion. According to the spec,
+        Promise takes a value and convert it to Promise by using Promise.resolve function.
+        We implement JSPromise::resolve in JSC and use it in JSDOMConvertPromise.
+
+        In conversion phase, we just convert the value to JSC::JSPromise* and hold it in
+        PromiseRejectionEvent. On the other hand, In this patch, we newly introduce a new
+        type DOMPromise and use it in RejectedPromiseTracker. And we also rename the previous
+        DOMPromise to DOMPromiseDeferred since it is corresponding to JSPromiseDeferred.
+        DOMPromise is DOMGuarded object. So it is strongly referenced from ScriptExecutionContext
+        and it is weakly referenced from the object itself. This is important since Strong<JSPromise>
+        reference in C++ object that has a wrapper (in this case, PromiseRejectionEvent) easily causes
+        cyclic reference. We hold it as DOMPromise instead of Strong<JSPromise> in RejectedPromiseTracker
+        to break the cyclic reference edge with weak reference.
+
+        In the meantime, we still use JSC::Strong<> in PromiseRejectionEvent. It leaks memory if promise
+        refers the wrapper object of PromiseRejectionEvent. CustomEvent also has the same problem.
+        This is a general problem that `attribute any` can create cyclic reference. And they should be
+        fixed in a different patch.
+
+        Currently, we do not take the following approach. e.g. There is C++ object that represents Promise.
+        And its wrapper object is JSPromise thing. When exposing the C++ object, it will be converted to a
+        wrapper object. We do not take this approach because PromiseRejectionEvent can take user-provided promise.
+        For example, users can create PromiseRejectionEvent in a form
+        `new PromiseRejectionEvent("...", { promise: promise })`. In this case, `event.promise === promise`
+        is required. And this is not suitable for the above C++ object model.
+
+        Large part of this patch is mechanical one to replace DOMPromise with DOMPromiseDeferred.
+
+        * CMakeLists.txt:
+        * Modules/applepay/ApplePaySession.cpp:
+        * Modules/encryptedmedia/MediaKeySession.h:
+        * Modules/encryptedmedia/MediaKeySystemAccess.h:
+        * Modules/encryptedmedia/MediaKeys.h:
+        * Modules/encryptedmedia/NavigatorEME.h:
+        * Modules/fetch/DOMWindowFetch.h:
+        * Modules/fetch/FetchBody.h:
+        * Modules/fetch/FetchBodyConsumer.h:
+        * Modules/fetch/FetchResponse.h:
+        * Modules/fetch/WorkerGlobalScopeFetch.h:
+        * Modules/mediastream/MediaDevices.h:
+        * Modules/mediastream/MediaEndpointPeerConnection.cpp:
+        (WebCore::MediaEndpointPeerConnection::replaceTrack):
+        (WebCore::MediaEndpointPeerConnection::replaceTrackTask):
+        * Modules/mediastream/MediaEndpointPeerConnection.h:
+        * Modules/mediastream/MediaStreamTrack.cpp:
+        (WebCore::MediaStreamTrack::applyConstraints):
+        * Modules/mediastream/MediaStreamTrack.h:
+        * Modules/mediastream/PeerConnectionBackend.cpp:
+        (WebCore::PeerConnectionBackend::setLocalDescription):
+        (WebCore::PeerConnectionBackend::setRemoteDescription):
+        (WebCore::PeerConnectionBackend::addIceCandidate):
+        * Modules/mediastream/PeerConnectionBackend.h:
+        (WebCore::PeerConnectionBackend::endOfIceCandidates):
+        * Modules/mediastream/RTCPeerConnection.cpp:
+        (WebCore::RTCPeerConnection::queuedSetLocalDescription):
+        (WebCore::RTCPeerConnection::queuedSetRemoteDescription):
+        (WebCore::RTCPeerConnection::queuedAddIceCandidate):
+        (WebCore::RTCPeerConnection::enqueueReplaceTrackTask):
+        (WebCore::RTCPeerConnection::replaceTrack):
+        * Modules/mediastream/RTCPeerConnection.h:
+        * Modules/mediastream/RTCRtpSender.cpp:
+        (WebCore::RTCRtpSender::replaceTrack):
+        * Modules/mediastream/RTCRtpSender.h:
+        * Modules/mediastream/UserMediaRequest.cpp:
+        (WebCore::UserMediaRequest::start):
+        (WebCore::UserMediaRequest::UserMediaRequest):
+        * Modules/mediastream/UserMediaRequest.h:
+        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
+        (WebCore::LibWebRTCPeerConnectionBackend::replaceTrack):
+        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:
+        * Modules/streams/ReadableStreamSource.h:
+        (WebCore::ReadableStreamSource::start):
+        (WebCore::ReadableStreamSource::pull):
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::addReaction):
+        (WebCore::AudioContext::setState):
+        (WebCore::AudioContext::suspend):
+        (WebCore::AudioContext::resume):
+        (WebCore::AudioContext::close):
+        * Modules/webaudio/AudioContext.h:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/IDLTypes.h:
+        * bindings/js/CachedModuleScriptLoaderClient.h:
+        * bindings/js/JSBindingsAllInOne.cpp:
+        * bindings/js/JSCustomElementRegistryCustom.cpp:
+        * bindings/js/JSDOMConvertPromise.h:
+        (WebCore::Converter<IDLPromise<T>>::convert):
+        (WebCore::JSConverter<IDLPromise<T>>::convert):
+        * bindings/js/JSDOMExceptionHandling.cpp:
+        * bindings/js/JSDOMGlobalObject.cpp:
+        * bindings/js/JSDOMGuardedObject.h:
+        * bindings/js/JSDOMPromise.h:
+        (WebCore::DOMPromise::create):
+        (WebCore::DOMPromise::promise):
+        (WebCore::DOMPromise::DOMPromise):
+        (WebCore::DeferredPromise::create): Deleted.
+        (WebCore::DeferredPromise::resolve): Deleted.
+        (WebCore::DeferredPromise::resolveWithNewlyCreated): Deleted.
+        (WebCore::DeferredPromise::reject): Deleted.
+        (WebCore::DeferredPromise::resolveWithCallback): Deleted.
+        (WebCore::DeferredPromise::rejectWithCallback): Deleted.
+        (WebCore::DeferredPromise::DeferredPromise): Deleted.
+        (WebCore::DeferredPromise::deferred): Deleted.
+        (WebCore::DOMPromiseBase::DOMPromiseBase): Deleted.
+        (WebCore::DOMPromiseBase::operator=): Deleted.
+        (WebCore::DOMPromiseBase::reject): Deleted.
+        (WebCore::DOMPromiseBase::rejectType): Deleted.
+        (WebCore::DOMPromiseBase::promise): Deleted.
+        (WebCore::DOMPromise::resolve): Deleted.
+        (WebCore::DOMPromise<void>::resolve): Deleted.
+        (WebCore::callPromiseFunction): Deleted.
+        (WebCore::bindingPromiseFunctionAdapter): Deleted.
+        * bindings/js/JSDOMPromiseDeferred.cpp: Renamed from Source/WebCore/bindings/js/JSDOMPromise.cpp.
+        (WebCore::DeferredPromise::promise):
+        (WebCore::DeferredPromise::callFunction):
+        (WebCore::DeferredPromise::reject):
+        (WebCore::rejectPromiseWithExceptionIfAny):
+        (WebCore::createDeferredPromise):
+        (WebCore::createRejectedPromiseWithTypeError):
+        (WebCore::parseAsJSON):
+        (WebCore::fulfillPromiseWithJSON):
+        (WebCore::fulfillPromiseWithArrayBuffer):
+        * bindings/js/JSDOMPromiseDeferred.h: Copied from Source/WebCore/bindings/js/JSDOMPromise.h.
+        (WebCore::DeferredPromise::create):
+        (WebCore::DeferredPromise::resolve):
+        (WebCore::DeferredPromise::resolveWithNewlyCreated):
+        (WebCore::DeferredPromise::reject):
+        (WebCore::DeferredPromise::resolveWithCallback):
+        (WebCore::DeferredPromise::rejectWithCallback):
+        (WebCore::DeferredPromise::DeferredPromise):
+        (WebCore::DeferredPromise::deferred):
+        (WebCore::DOMPromiseDeferredBase::DOMPromiseDeferredBase):
+        (WebCore::DOMPromiseDeferredBase::operator=):
+        (WebCore::DOMPromiseDeferredBase::reject):
+        (WebCore::DOMPromiseDeferredBase::rejectType):
+        (WebCore::DOMPromiseDeferredBase::promise):
+        (WebCore::DOMPromiseDeferred::resolve):
+        (WebCore::DOMPromiseDeferred<void>::resolve):
+        (WebCore::callPromiseFunction):
+        (WebCore::bindingPromiseFunctionAdapter):
+        * bindings/js/JSSubtleCryptoCustom.cpp:
+        * bindings/js/JSWebGPUCommandBufferCustom.cpp:
+        * bindings/js/JSWebKitSubtleCryptoCustom.cpp:
+        * bindings/scripts/test/JS/JSTestPromiseRejectionEvent.cpp: Added.
+        (WebCore::convertDictionary<TestPromiseRejectionEvent::Init>):
+        (WebCore::JSTestPromiseRejectionEventPrototype::create):
+        (WebCore::JSTestPromiseRejectionEventPrototype::createStructure):
+        (WebCore::JSTestPromiseRejectionEventPrototype::JSTestPromiseRejectionEventPrototype):
+        (WebCore::JSTestPromiseRejectionEventConstructor::construct):
+        (WebCore::JSTestPromiseRejectionEventConstructor::prototypeForStructure):
+        (WebCore::JSTestPromiseRejectionEventConstructor::initializeProperties):
+        (WebCore::JSTestPromiseRejectionEventPrototype::finishCreation):
+        (WebCore::JSTestPromiseRejectionEvent::JSTestPromiseRejectionEvent):
+        (WebCore::JSTestPromiseRejectionEvent::finishCreation):
+        (WebCore::JSTestPromiseRejectionEvent::createPrototype):
+        (WebCore::JSTestPromiseRejectionEvent::prototype):
+        (WebCore::BindingCaller<JSTestPromiseRejectionEvent>::castForAttribute):
+        (WebCore::jsTestPromiseRejectionEventPromise):
+        (WebCore::jsTestPromiseRejectionEventPromiseGetter):
+        (WebCore::jsTestPromiseRejectionEventReason):
+        (WebCore::jsTestPromiseRejectionEventReasonGetter):
+        (WebCore::jsTestPromiseRejectionEventConstructor):
+        (WebCore::setJSTestPromiseRejectionEventConstructor):
+        (WebCore::JSTestPromiseRejectionEvent::getConstructor):
+        (WebCore::toJSNewlyCreated):
+        (WebCore::toJS):
+        * bindings/scripts/test/JS/JSTestPromiseRejectionEvent.h: Added.
+        (WebCore::JSTestPromiseRejectionEvent::create):
+        (WebCore::JSTestPromiseRejectionEvent::createStructure):
+        (WebCore::JSTestPromiseRejectionEvent::wrapped):
+        (WebCore::toJS):
+        (WebCore::toJSNewlyCreated):
+        * bindings/scripts/test/TestPromiseRejectionEvent.idl: Copied from Source/WebCore/bindings/js/CachedModuleScriptLoaderClient.h.
+        * css/FontFace.h:
+        * css/FontFaceSet.h:
+        * dom/CustomElementRegistry.h:
+        * dom/PromiseRejectionEvent.h:
+        * dom/RejectedPromiseTracker.cpp:
+        (WebCore::UnhandledPromise::UnhandledPromise):
+        (WebCore::UnhandledPromise::callStack):
+        (WebCore::UnhandledPromise::promise):
+        (WebCore::RejectedPromiseTracker::promiseRejected):
+        (WebCore::RejectedPromiseTracker::promiseHandled):
+        (WebCore::RejectedPromiseTracker::reportUnhandledRejections):
+        (WebCore::RejectedPromiseTracker::reportRejectionHandled):
+        (WebCore::RejectedPromise::RejectedPromise): Deleted.
+        (WebCore::RejectedPromise::globalObject): Deleted.
+        (WebCore::RejectedPromise::promise): Deleted.
+        * dom/RejectedPromiseTracker.h:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::rejectPendingPlayPromises):
+        (WebCore::HTMLMediaElement::resolvePendingPlayPromises):
+        (WebCore::HTMLMediaElement::play):
+        * html/HTMLMediaElement.h:
+        * platform/graphics/gpu/GPUCommandBuffer.h:
+        * testing/Internals.h:
+
 2017-05-09  Zan Dobersek  <zdobersek@igalia.com>
 
         Upstream the WPE port
index 7449793..61a9e5c 100644 (file)
@@ -43,7 +43,7 @@
 #include "Document.h"
 #include "DocumentLoader.h"
 #include "EventNames.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "LinkIconCollector.h"
 #include "LinkIconType.h"
 #include "MainFrame.h"
index 0ce875d..0592243 100644 (file)
@@ -35,7 +35,7 @@
 #include "EventTarget.h"
 #include "GenericEventQueue.h"
 #include "GenericTaskQueue.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "MediaKeyMessageType.h"
 #include "MediaKeySessionType.h"
 #include "MediaKeyStatus.h"
@@ -70,7 +70,7 @@ public:
     void close(Ref<DeferredPromise>&&);
     void remove(Ref<DeferredPromise>&&);
 
-    using ClosedPromise = DOMPromise<void>;
+    using ClosedPromise = DOMPromiseDeferred<void>;
     void registerClosedPromise(ClosedPromise&&);
 
     const Vector<std::pair<Ref<SharedBuffer>, MediaKeyStatus>>& statuses() const { return m_statuses; }
index a113e26..0a3b6e1 100644 (file)
@@ -31,7 +31,7 @@
 #if ENABLE(ENCRYPTED_MEDIA)
 
 #include "GenericTaskQueue.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include <wtf/RefCounted.h>
 #include <wtf/text/WTFString.h>
 
index bd80bd2..9a59d17 100644 (file)
@@ -32,7 +32,7 @@
 
 #include "ExceptionOr.h"
 #include "GenericTaskQueue.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "MediaKeySessionType.h"
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
index 4c204e9..8165fae 100644 (file)
@@ -30,7 +30,7 @@
 
 #if ENABLE(ENCRYPTED_MEDIA)
 
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "MediaKeySystemConfiguration.h"
 #include "Supplementable.h"
 
index b3d1575..13bf75a 100644 (file)
@@ -30,7 +30,7 @@
 
 #if ENABLE(FETCH_API)
 
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include <wtf/Forward.h>
 
 namespace WebCore {
index 2e60af8..4f75ca1 100644 (file)
@@ -34,7 +34,7 @@
 #include "FetchBodyConsumer.h"
 #include "FetchLoader.h"
 #include "FormData.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "URLSearchParams.h"
 #include <wtf/Optional.h>
 #include <wtf/Variant.h>
index 4a0fb39..38b7689 100644 (file)
@@ -30,7 +30,7 @@
 
 #if ENABLE(FETCH_API)
 
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "SharedBuffer.h"
 
 namespace WebCore {
index f5a9e27..a90637f 100644 (file)
@@ -52,7 +52,7 @@ public:
     static Ref<FetchResponse> error(ScriptExecutionContext&);
     static ExceptionOr<Ref<FetchResponse>> redirect(ScriptExecutionContext&, const String& url, int status);
 
-    using FetchPromise = DOMPromise<IDLInterface<FetchResponse>>;
+    using FetchPromise = DOMPromiseDeferred<IDLInterface<FetchResponse>>;
     static void fetch(ScriptExecutionContext&, FetchRequest&, FetchPromise&&);
 
     void consume(unsigned, Ref<DeferredPromise>&&);
index 5bbb28b..477069f 100644 (file)
@@ -30,7 +30,7 @@
 
 #if ENABLE(FETCH_API)
 
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 
 namespace WebCore {
 
index 2855ea5..93f9380 100644 (file)
@@ -35,7 +35,7 @@
 
 #include "EventTarget.h"
 #include "ExceptionOr.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "MediaTrackConstraints.h"
 #include "RealtimeMediaSourceCenter.h"
 #include "Timer.h"
@@ -56,8 +56,8 @@ public:
 
     Document* document() const;
 
-    using Promise = DOMPromise<IDLInterface<MediaStream>>;
-    using EnumerateDevicesPromise = DOMPromise<IDLSequence<IDLInterface<MediaDeviceInfo>>>;
+    using Promise = DOMPromiseDeferred<IDLInterface<MediaStream>>;
+    using EnumerateDevicesPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<MediaDeviceInfo>>>;
 
     struct StreamConstraints {
         Variant<bool, MediaTrackConstraints> video;
index 6dfec93..1dd039b 100644 (file)
@@ -696,7 +696,7 @@ std::unique_ptr<RTCDataChannelHandler> MediaEndpointPeerConnection::createDataCh
     return m_mediaEndpoint->createDataChannelHandler(label, options);
 }
 
-void MediaEndpointPeerConnection::replaceTrack(RTCRtpSender& sender, Ref<MediaStreamTrack>&& withTrack, DOMPromise<void>&& promise)
+void MediaEndpointPeerConnection::replaceTrack(RTCRtpSender& sender, Ref<MediaStreamTrack>&& withTrack, DOMPromiseDeferred<void>&& promise)
 {
     RTCRtpTransceiver* transceiver = matchTransceiver(m_peerConnection.getTransceivers(), [&sender] (RTCRtpTransceiver& current) {
         return &current.sender() == &sender;
@@ -716,7 +716,7 @@ void MediaEndpointPeerConnection::replaceTrack(RTCRtpSender& sender, Ref<MediaSt
     });
 }
 
-void MediaEndpointPeerConnection::replaceTrackTask(RTCRtpSender& sender, const String& mid, Ref<MediaStreamTrack>&& withTrack, DOMPromise<void>& promise)
+void MediaEndpointPeerConnection::replaceTrackTask(RTCRtpSender& sender, const String& mid, Ref<MediaStreamTrack>&& withTrack, DOMPromiseDeferred<void>& promise)
 {
     if (m_peerConnection.isClosed())
         return;
index ce7ec3e..1e31cd4 100644 (file)
@@ -63,7 +63,7 @@ private:
     Vector<RefPtr<MediaStream>> getRemoteStreams() const final;
 
     Ref<RTCRtpReceiver> createReceiver(const String& transceiverMid, const String& trackKind, const String& trackId) final;
-    void replaceTrack(RTCRtpSender&, Ref<MediaStreamTrack>&&, DOMPromise<void>&&) final;
+    void replaceTrack(RTCRtpSender&, Ref<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&) final;
 
     void emulatePlatformEvent(const String& action) final;
 
@@ -85,7 +85,7 @@ private:
 
     void addIceCandidateTask(RTCIceCandidate&);
 
-    void replaceTrackTask(RTCRtpSender&, const String& mid, Ref<MediaStreamTrack>&&, DOMPromise<void>&);
+    void replaceTrackTask(RTCRtpSender&, const String& mid, Ref<MediaStreamTrack>&&, DOMPromiseDeferred<void>&);
 
     bool localDescriptionTypeValidForState(RTCSdpType) const;
     bool remoteDescriptionTypeValidForState(RTCSdpType) const;
index e554bc4..177ef72 100644 (file)
@@ -253,7 +253,7 @@ static Ref<MediaConstraintsImpl> createMediaConstraintsImpl(const std::optional<
     return createMediaConstraintsImpl(constraints.value());
 }
 
-void MediaStreamTrack::applyConstraints(const std::optional<MediaTrackConstraints>& constraints, DOMPromise<void>&& promise)
+void MediaStreamTrack::applyConstraints(const std::optional<MediaTrackConstraints>& constraints, DOMPromiseDeferred<void>&& promise)
 {
     m_promise = WTFMove(promise);
 
index 1016d63..facea1a 100644 (file)
@@ -32,7 +32,7 @@
 #include "ActiveDOMObject.h"
 #include "DoubleRange.h"
 #include "EventTarget.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "LongRange.h"
 #include "MediaStreamTrackPrivate.h"
 #include "MediaTrackConstraints.h"
@@ -108,7 +108,7 @@ public:
     TrackCapabilities getCapabilities() const;
 
     const MediaTrackConstraints& getConstraints() const { return m_constraints; }
-    void applyConstraints(const std::optional<MediaTrackConstraints>&, DOMPromise<void>&&);
+    void applyConstraints(const std::optional<MediaTrackConstraints>&, DOMPromiseDeferred<void>&&);
 
     RealtimeMediaSource& source() { return m_private->source(); }
     MediaStreamTrackPrivate& privateTrack() { return m_private.get(); }
@@ -152,7 +152,7 @@ private:
     Ref<MediaStreamTrackPrivate> m_private;
 
     MediaTrackConstraints m_constraints;
-    std::optional<DOMPromise<void>> m_promise;
+    std::optional<DOMPromiseDeferred<void>> m_promise;
     WeakPtrFactory<MediaStreamTrack> m_weakPtrFactory;
 
     bool m_ended { false };
index 22854ea..2200616 100644 (file)
@@ -133,7 +133,7 @@ static inline bool isLocalDescriptionTypeValidForState(RTCSdpType type, RTCSigna
     return false;
 }
 
-void PeerConnectionBackend::setLocalDescription(RTCSessionDescription& sessionDescription, DOMPromise<void>&& promise)
+void PeerConnectionBackend::setLocalDescription(RTCSessionDescription& sessionDescription, DOMPromiseDeferred<void>&& promise)
 {
     ASSERT(!m_peerConnection.isClosed());
 
@@ -193,7 +193,7 @@ static inline bool isRemoteDescriptionTypeValidForState(RTCSdpType type, RTCSign
     return false;
 }
 
-void PeerConnectionBackend::setRemoteDescription(RTCSessionDescription& sessionDescription, DOMPromise<void>&& promise)
+void PeerConnectionBackend::setRemoteDescription(RTCSessionDescription& sessionDescription, DOMPromiseDeferred<void>&& promise)
 {
     ASSERT(!m_peerConnection.isClosed());
 
@@ -234,7 +234,7 @@ void PeerConnectionBackend::setRemoteDescriptionFailed(Exception&& exception)
     m_setDescriptionPromise = std::nullopt;
 }
 
-void PeerConnectionBackend::addIceCandidate(RTCIceCandidate* iceCandidate, DOMPromise<void>&& promise)
+void PeerConnectionBackend::addIceCandidate(RTCIceCandidate* iceCandidate, DOMPromiseDeferred<void>&& promise)
 {
     ASSERT(!m_peerConnection.isClosed());
 
index 555bfb8..1b85f08 100644 (file)
@@ -33,7 +33,7 @@
 
 #if ENABLE(WEB_RTC)
 
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "RTCRtpParameters.h"
 #include "RTCSignalingState.h"
 
@@ -56,8 +56,8 @@ struct RTCDataChannelInit;
 struct RTCOfferOptions;
 
 namespace PeerConnection {
-using SessionDescriptionPromise = DOMPromise<IDLInterface<RTCSessionDescription>>;
-using StatsPromise = DOMPromise<IDLInterface<RTCStatsReport>>;
+using SessionDescriptionPromise = DOMPromiseDeferred<IDLInterface<RTCSessionDescription>>;
+using StatsPromise = DOMPromiseDeferred<IDLInterface<RTCStatsReport>>;
 }
 
 using CreatePeerConnectionBackend = std::unique_ptr<PeerConnectionBackend> (*)(RTCPeerConnection&);
@@ -71,9 +71,9 @@ public:
 
     void createOffer(RTCOfferOptions&&, PeerConnection::SessionDescriptionPromise&&);
     void createAnswer(RTCAnswerOptions&&, PeerConnection::SessionDescriptionPromise&&);
-    void setLocalDescription(RTCSessionDescription&, DOMPromise<void>&&);
-    void setRemoteDescription(RTCSessionDescription&, DOMPromise<void>&&);
-    void addIceCandidate(RTCIceCandidate*, DOMPromise<void>&&);
+    void setLocalDescription(RTCSessionDescription&, DOMPromiseDeferred<void>&&);
+    void setRemoteDescription(RTCSessionDescription&, DOMPromiseDeferred<void>&&);
+    void addIceCandidate(RTCIceCandidate*, DOMPromiseDeferred<void>&&);
 
     virtual std::unique_ptr<RTCDataChannelHandler> createDataChannelHandler(const String&, const RTCDataChannelInit&) = 0;
 
@@ -94,7 +94,7 @@ public:
     virtual Vector<RefPtr<MediaStream>> getRemoteStreams() const = 0;
 
     virtual Ref<RTCRtpReceiver> createReceiver(const String& transceiverMid, const String& trackKind, const String& trackId) = 0;
-    virtual void replaceTrack(RTCRtpSender&, Ref<MediaStreamTrack>&&, DOMPromise<void>&&) = 0;
+    virtual void replaceTrack(RTCRtpSender&, Ref<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&) = 0;
     virtual void notifyAddedTrack(RTCRtpSender&) { }
     virtual void notifyRemovedTrack(RTCRtpSender&) { }
 
@@ -137,7 +137,7 @@ private:
     virtual void doSetLocalDescription(RTCSessionDescription&) = 0;
     virtual void doSetRemoteDescription(RTCSessionDescription&) = 0;
     virtual void doAddIceCandidate(RTCIceCandidate&) = 0;
-    virtual void endOfIceCandidates(DOMPromise<void>&& promise) { promise.resolve(); }
+    virtual void endOfIceCandidates(DOMPromiseDeferred<void>&& promise) { promise.resolve(); }
     virtual void doStop() = 0;
 
 protected:
@@ -145,8 +145,8 @@ protected:
 
 private:
     std::optional<PeerConnection::SessionDescriptionPromise> m_offerAnswerPromise;
-    std::optional<DOMPromise<void>> m_setDescriptionPromise;
-    std::optional<DOMPromise<void>> m_addIceCandidatePromise;
+    std::optional<DOMPromiseDeferred<void>> m_setDescriptionPromise;
+    std::optional<DOMPromiseDeferred<void>> m_addIceCandidatePromise;
 
     bool m_shouldFilterICECandidates { true };
     struct PendingICECandidate {
index 503646c..9131603 100644 (file)
@@ -234,7 +234,7 @@ void RTCPeerConnection::queuedCreateAnswer(RTCAnswerOptions&& options, SessionDe
     m_backend->createAnswer(WTFMove(options), WTFMove(promise));
 }
 
-void RTCPeerConnection::queuedSetLocalDescription(RTCSessionDescription& description, DOMPromise<void>&& promise)
+void RTCPeerConnection::queuedSetLocalDescription(RTCSessionDescription& description, DOMPromiseDeferred<void>&& promise)
 {
     LOG(WebRTC, "Setting local description:\n%s\n", description.sdp().utf8().data());
     if (isClosed()) {
@@ -260,7 +260,7 @@ RefPtr<RTCSessionDescription> RTCPeerConnection::pendingLocalDescription() const
     return m_backend->pendingLocalDescription();
 }
 
-void RTCPeerConnection::queuedSetRemoteDescription(RTCSessionDescription& description, DOMPromise<void>&& promise)
+void RTCPeerConnection::queuedSetRemoteDescription(RTCSessionDescription& description, DOMPromiseDeferred<void>&& promise)
 {
     LOG(WebRTC, "Setting remote description:\n%s\n", description.sdp().utf8().data());
 
@@ -286,7 +286,7 @@ RefPtr<RTCSessionDescription> RTCPeerConnection::pendingRemoteDescription() cons
     return m_backend->pendingRemoteDescription();
 }
 
-void RTCPeerConnection::queuedAddIceCandidate(RTCIceCandidate* rtcCandidate, DOMPromise<void>&& promise)
+void RTCPeerConnection::queuedAddIceCandidate(RTCIceCandidate* rtcCandidate, DOMPromiseDeferred<void>&& promise)
 {
     LOG(WebRTC, "Received ice candidate:\n%s\n", rtcCandidate ? rtcCandidate->candidate().utf8().data() : "null");
 
@@ -512,7 +512,7 @@ void RTCPeerConnection::fireEvent(Event& event)
     dispatchEvent(event);
 }
 
-void RTCPeerConnection::enqueueReplaceTrackTask(RTCRtpSender& sender, Ref<MediaStreamTrack>&& withTrack, DOMPromise<void>&& promise)
+void RTCPeerConnection::enqueueReplaceTrackTask(RTCRtpSender& sender, Ref<MediaStreamTrack>&& withTrack, DOMPromiseDeferred<void>&& promise)
 {
     scriptExecutionContext()->postTask([protectedSender = makeRef(sender), promise = WTFMove(promise), withTrack = WTFMove(withTrack)](ScriptExecutionContext&) mutable {
         protectedSender->setTrack(WTFMove(withTrack));
@@ -520,7 +520,7 @@ void RTCPeerConnection::enqueueReplaceTrackTask(RTCRtpSender& sender, Ref<MediaS
     });
 }
 
-void RTCPeerConnection::replaceTrack(RTCRtpSender& sender, RefPtr<MediaStreamTrack>&& withTrack, DOMPromise<void>&& promise)
+void RTCPeerConnection::replaceTrack(RTCRtpSender& sender, RefPtr<MediaStreamTrack>&& withTrack, DOMPromiseDeferred<void>&& promise)
 {
     if (!withTrack) {
         scriptExecutionContext()->postTask([protectedSender = makeRef(sender), promise = WTFMove(promise)](ScriptExecutionContext&) mutable {
index 047426c..f5e5fc3 100644 (file)
@@ -76,17 +76,17 @@ public:
     void queuedCreateOffer(RTCOfferOptions&&, PeerConnection::SessionDescriptionPromise&&);
     void queuedCreateAnswer(RTCAnswerOptions&&, PeerConnection::SessionDescriptionPromise&&);
 
-    void queuedSetLocalDescription(RTCSessionDescription&, DOMPromise<void>&&);
+    void queuedSetLocalDescription(RTCSessionDescription&, DOMPromiseDeferred<void>&&);
     RefPtr<RTCSessionDescription> localDescription() const;
     RefPtr<RTCSessionDescription> currentLocalDescription() const;
     RefPtr<RTCSessionDescription> pendingLocalDescription() const;
 
-    void queuedSetRemoteDescription(RTCSessionDescription&, DOMPromise<void>&&);
+    void queuedSetRemoteDescription(RTCSessionDescription&, DOMPromiseDeferred<void>&&);
     RefPtr<RTCSessionDescription> remoteDescription() const;
     RefPtr<RTCSessionDescription> currentRemoteDescription() const;
     RefPtr<RTCSessionDescription> pendingRemoteDescription() const;
 
-    void queuedAddIceCandidate(RTCIceCandidate*, DOMPromise<void>&&);
+    void queuedAddIceCandidate(RTCIceCandidate*, DOMPromiseDeferred<void>&&);
 
     RTCSignalingState signalingState() const { return m_signalingState; }
     RTCIceGatheringState iceGatheringState() const { return m_iceGatheringState; }
@@ -143,7 +143,7 @@ public:
     void disableICECandidateFiltering() { m_backend->disableICECandidateFiltering(); }
     void enableICECandidateFiltering() { m_backend->enableICECandidateFiltering(); }
 
-    void enqueueReplaceTrackTask(RTCRtpSender&, Ref<MediaStreamTrack>&&, DOMPromise<void>&&);
+    void enqueueReplaceTrackTask(RTCRtpSender&, Ref<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&);
 
     void clearController() { m_controller = nullptr; }
 
@@ -166,7 +166,7 @@ private:
 
     // FIXME: We might want PeerConnectionBackend to be the Backend
     // RTCRtpSender::Backend
-    void replaceTrack(RTCRtpSender&, RefPtr<MediaStreamTrack>&&, DOMPromise<void>&&) final;
+    void replaceTrack(RTCRtpSender&, RefPtr<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&) final;
     RTCRtpParameters getParameters(RTCRtpSender&) const final;
 
     void updateConnectionState();
index 02f29b2..0d46641 100644 (file)
@@ -72,7 +72,7 @@ void RTCRtpSender::setTrack(Ref<MediaStreamTrack>&& track)
     m_track = WTFMove(track);
 }
 
-void RTCRtpSender::replaceTrack(RefPtr<MediaStreamTrack>&& withTrack, DOMPromise<void>&& promise)
+void RTCRtpSender::replaceTrack(RefPtr<MediaStreamTrack>&& withTrack, DOMPromiseDeferred<void>&& promise)
 {
     if (isStopped()) {
         promise.reject(INVALID_STATE_ERR);
index 3c507a6..30a515b 100644 (file)
@@ -41,7 +41,7 @@ class RTCRtpSender : public RTCRtpSenderReceiverBase {
 public:
     class Backend {
     public:
-        virtual void replaceTrack(RTCRtpSender&, RefPtr<MediaStreamTrack>&&, DOMPromise<void>&&) = 0;
+        virtual void replaceTrack(RTCRtpSender&, RefPtr<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&) = 0;
         virtual RTCRtpParameters getParameters(RTCRtpSender&) const = 0;
         virtual ~Backend() { }
     };
@@ -60,7 +60,7 @@ public:
     void setTrack(Ref<MediaStreamTrack>&&);
     void setTrackToNull();
 
-    void replaceTrack(RefPtr<MediaStreamTrack>&&, DOMPromise<void>&&);
+    void replaceTrack(RefPtr<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&);
 
     RTCRtpParameters getParameters();
 
index 4d2bfbc..96125fd 100644 (file)
@@ -49,7 +49,7 @@
 
 namespace WebCore {
 
-ExceptionOr<void> UserMediaRequest::start(Document& document, Ref<MediaConstraintsImpl>&& audioConstraints, Ref<MediaConstraintsImpl>&& videoConstraints, DOMPromise<IDLInterface<MediaStream>>&& promise)
+ExceptionOr<void> UserMediaRequest::start(Document& document, Ref<MediaConstraintsImpl>&& audioConstraints, Ref<MediaConstraintsImpl>&& videoConstraints, DOMPromiseDeferred<IDLInterface<MediaStream>>&& promise)
 {
     auto* userMedia = UserMediaController::from(document.page());
     if (!userMedia)
@@ -64,7 +64,7 @@ ExceptionOr<void> UserMediaRequest::start(Document& document, Ref<MediaConstrain
     return { };
 }
 
-UserMediaRequest::UserMediaRequest(Document& document, UserMediaController& controller, Ref<MediaConstraintsImpl>&& audioConstraints, Ref<MediaConstraintsImpl>&& videoConstraints, DOMPromise<IDLInterface<MediaStream>>&& promise)
+UserMediaRequest::UserMediaRequest(Document& document, UserMediaController& controller, Ref<MediaConstraintsImpl>&& audioConstraints, Ref<MediaConstraintsImpl>&& videoConstraints, DOMPromiseDeferred<IDLInterface<MediaStream>>&& promise)
     : ContextDestructionObserver(&document)
     , m_audioConstraints(WTFMove(audioConstraints))
     , m_videoConstraints(WTFMove(videoConstraints))
index 316fee1..a3e9690 100644 (file)
@@ -35,7 +35,7 @@
 #if ENABLE(MEDIA_STREAM)
 
 #include "ActiveDOMObject.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 
 namespace WebCore {
 
@@ -46,7 +46,7 @@ class UserMediaController;
 
 class UserMediaRequest : public RefCounted<UserMediaRequest>, private ContextDestructionObserver {
 public:
-    static ExceptionOr<void> start(Document&, Ref<MediaConstraintsImpl>&& audioConstraints, Ref<MediaConstraintsImpl>&& videoConstraints, DOMPromise<IDLInterface<MediaStream>>&&);
+    static ExceptionOr<void> start(Document&, Ref<MediaConstraintsImpl>&& audioConstraints, Ref<MediaConstraintsImpl>&& videoConstraints, DOMPromiseDeferred<IDLInterface<MediaStream>>&&);
 
     virtual ~UserMediaRequest();
 
@@ -72,7 +72,7 @@ public:
     WEBCORE_EXPORT Document* document() const;
 
 private:
-    UserMediaRequest(Document&, UserMediaController&, Ref<MediaConstraintsImpl>&& audioConstraints, Ref<MediaConstraintsImpl>&& videoConstraints, DOMPromise<IDLInterface<MediaStream>>&&);
+    UserMediaRequest(Document&, UserMediaController&, Ref<MediaConstraintsImpl>&& audioConstraints, Ref<MediaConstraintsImpl>&& videoConstraints, DOMPromiseDeferred<IDLInterface<MediaStream>>&&);
 
     void contextDestroyed() final;
     
@@ -86,7 +86,7 @@ private:
     String m_allowedAudioDeviceUID;
 
     UserMediaController* m_controller;
-    DOMPromise<IDLInterface<MediaStream>> m_promise;
+    DOMPromiseDeferred<IDLInterface<MediaStream>> m_promise;
     RefPtr<UserMediaRequest> m_protector;
 };
 
index 310204b..1817e65 100644 (file)
@@ -328,7 +328,7 @@ void LibWebRTCPeerConnectionBackend::addRemoteStream(Ref<MediaStream>&& mediaStr
     m_remoteStreams.append(WTFMove(mediaStream));
 }
 
-void LibWebRTCPeerConnectionBackend::replaceTrack(RTCRtpSender& sender, Ref<MediaStreamTrack>&& track, DOMPromise<void>&& promise)
+void LibWebRTCPeerConnectionBackend::replaceTrack(RTCRtpSender& sender, Ref<MediaStreamTrack>&& track, DOMPromiseDeferred<void>&& promise)
 {
     ASSERT(sender.track());
     auto* currentTrack = sender.track();
index 92e68a6..5436f8f 100644 (file)
@@ -69,7 +69,7 @@ private:
     RefPtr<RTCSessionDescription> currentRemoteDescription() const final;
     RefPtr<RTCSessionDescription> pendingRemoteDescription() const final;
 
-    void replaceTrack(RTCRtpSender&, Ref<MediaStreamTrack>&&, DOMPromise<void>&&) final;
+    void replaceTrack(RTCRtpSender&, Ref<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&) final;
     RTCRtpParameters getParameters(RTCRtpSender&) const final;
 
     void emulatePlatformEvent(const String&) final { }
index 9c16ca8..4103ac8 100644 (file)
@@ -30,7 +30,7 @@
 
 #if ENABLE(STREAMS_API)
 
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "ReadableStreamDefaultController.h"
 #include <wtf/Optional.h>
 
@@ -40,8 +40,8 @@ class ReadableStreamSource : public RefCounted<ReadableStreamSource> {
 public:
     virtual ~ReadableStreamSource() { }
 
-    void start(ReadableStreamDefaultController&&, DOMPromise<void>&&);
-    void pull(DOMPromise<void>&&);
+    void start(ReadableStreamDefaultController&&, DOMPromiseDeferred<void>&&);
+    void pull(DOMPromiseDeferred<void>&&);
     void cancel(JSC::JSValue);
 
     bool isPulling() const { return !!m_promise; }
@@ -63,11 +63,11 @@ protected:
     virtual void doCancel() = 0;
 
 private:
-    std::optional<DOMPromise<void>> m_promise;
+    std::optional<DOMPromiseDeferred<void>> m_promise;
     std::optional<ReadableStreamDefaultController> m_controller;
 };
 
-inline void ReadableStreamSource::start(ReadableStreamDefaultController&& controller, DOMPromise<void>&& promise)
+inline void ReadableStreamSource::start(ReadableStreamDefaultController&& controller, DOMPromiseDeferred<void>&& promise)
 {
     ASSERT(!m_promise);
     m_promise = WTFMove(promise);
@@ -77,7 +77,7 @@ inline void ReadableStreamSource::start(ReadableStreamDefaultController&& contro
     doStart();
 }
 
-inline void ReadableStreamSource::pull(DOMPromise<void>&& promise)
+inline void ReadableStreamSource::pull(DOMPromiseDeferred<void>&& promise)
 {
     ASSERT(!m_promise);
     ASSERT(m_controller);
index 11de04a..235299c 100644 (file)
@@ -53,7 +53,7 @@
 #include "GenericEventQueue.h"
 #include "HRTFDatabaseLoader.h"
 #include "HRTFPanner.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "Logging.h"
 #include "NetworkingContext.h"
 #include "OfflineAudioCompletionEvent.h"
@@ -283,7 +283,7 @@ bool AudioContext::isInitialized() const
     return m_isInitialized;
 }
 
-void AudioContext::addReaction(State state, DOMPromise<void>&& promise)
+void AudioContext::addReaction(State state, DOMPromiseDeferred<void>&& promise)
 {
     size_t stateIndex = static_cast<size_t>(state);
     if (stateIndex >= m_stateReactions.size())
@@ -304,7 +304,7 @@ void AudioContext::setState(State state)
     if (stateIndex >= m_stateReactions.size())
         return;
 
-    Vector<DOMPromise<void>> reactions;
+    Vector<DOMPromiseDeferred<void>> reactions;
     m_stateReactions[stateIndex].swap(reactions);
 
     for (auto& promise : reactions)
@@ -1040,7 +1040,7 @@ void AudioContext::decrementActiveSourceCount()
     --m_activeSourceCount;
 }
 
-void AudioContext::suspend(DOMPromise<void>&& promise)
+void AudioContext::suspend(DOMPromiseDeferred<void>&& promise)
 {
     if (isOfflineContext()) {
         promise.reject(INVALID_STATE_ERR);
@@ -1069,7 +1069,7 @@ void AudioContext::suspend(DOMPromise<void>&& promise)
     });
 }
 
-void AudioContext::resume(DOMPromise<void>&& promise)
+void AudioContext::resume(DOMPromiseDeferred<void>&& promise)
 {
     if (isOfflineContext()) {
         promise.reject(INVALID_STATE_ERR);
@@ -1098,7 +1098,7 @@ void AudioContext::resume(DOMPromise<void>&& promise)
     });
 }
 
-void AudioContext::close(DOMPromise<void>&& promise)
+void AudioContext::close(DOMPromiseDeferred<void>&& promise)
 {
     if (isOfflineContext()) {
         promise.reject(INVALID_STATE_ERR);
index e41168e..49bb137 100644 (file)
@@ -31,7 +31,7 @@
 #include "AudioDestinationNode.h"
 #include "EventListener.h"
 #include "EventTarget.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "MediaCanStartListener.h"
 #include "MediaProducer.h"
 #include "PlatformMediaSession.h"
@@ -111,9 +111,9 @@ public:
     using ActiveDOMObject::suspend;
     using ActiveDOMObject::resume;
 
-    void suspend(DOMPromise<void>&&);
-    void resume(DOMPromise<void>&&);
-    void close(DOMPromise<void>&&);
+    void suspend(DOMPromiseDeferred<void>&&);
+    void resume(DOMPromiseDeferred<void>&&);
+    void close(DOMPromiseDeferred<void>&&);
 
     enum class State { Suspended, Running, Interrupted, Closed };
     State state() const;
@@ -329,7 +329,7 @@ private:
     void handleDirtyAudioSummingJunctions();
     void handleDirtyAudioNodeOutputs();
 
-    void addReaction(State, DOMPromise<void>&&);
+    void addReaction(State, DOMPromiseDeferred<void>&&);
     void updateAutomaticPullNodes();
 
     // Only accessed in the audio thread.
@@ -366,7 +366,7 @@ private:
     Vector<AudioNode*> m_renderingAutomaticPullNodes;
     // Only accessed in the audio thread.
     Vector<AudioNode*> m_deferredFinishDerefList;
-    Vector<Vector<DOMPromise<void>>> m_stateReactions;
+    Vector<Vector<DOMPromiseDeferred<void>>> m_stateReactions;
 
     std::unique_ptr<PlatformMediaSession> m_mediaSession;
     std::unique_ptr<GenericEventQueue> m_eventQueue;
index 4e64ed1..30df954 100644 (file)
                E172AF6D180F24C600FBADB9 /* CryptoAlgorithm.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E172AF6B180F24C600FBADB9 /* CryptoAlgorithm.cpp */; };
                E172AF6E180F24C600FBADB9 /* CryptoAlgorithm.h in Headers */ = {isa = PBXBuildFile; fileRef = E172AF6C180F24C600FBADB9 /* CryptoAlgorithm.h */; };
                E172AF70180F289500FBADB9 /* CryptoKeyUsage.h in Headers */ = {isa = PBXBuildFile; fileRef = E172AF6F180F289500FBADB9 /* CryptoKeyUsage.h */; };
-               E172AF8F1811BC3700FBADB9 /* JSDOMPromise.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E172AF8D1811BC3700FBADB9 /* JSDOMPromise.cpp */; };
-               E172AF901811BC3700FBADB9 /* JSDOMPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = E172AF8E1811BC3700FBADB9 /* JSDOMPromise.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               E172AF8F1811BC3700FBADB9 /* JSDOMPromiseDeferred.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E172AF8D1811BC3700FBADB9 /* JSDOMPromiseDeferred.cpp */; };
+               E172AF901811BC3700FBADB9 /* JSDOMPromiseDeferred.h in Headers */ = {isa = PBXBuildFile; fileRef = E172AF8E1811BC3700FBADB9 /* JSDOMPromiseDeferred.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E175BA991E8AE3380071454F /* GridPosition.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1F817451E897A5200F22CD0 /* GridPosition.cpp */; };
                E179F0DA1B9774FE00ED0A27 /* Internals.mm in Sources */ = {isa = PBXBuildFile; fileRef = E179F0D91B9774FE00ED0A27 /* Internals.mm */; };
                E17B491516A9B094001C8839 /* TransitionEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E17B491316A9B093001C8839 /* TransitionEvent.cpp */; };
                E3565B7B1DC2D6C900217DBD /* JSEventCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = E34EE49F1DC2D57500EAA9D3 /* JSEventCustom.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E35802B61DC8435D00A9773C /* DOMJITIDLTypeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = E35802B51DC8435800A9773C /* DOMJITIDLTypeFilter.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E377FE4D1DADE16500CDD025 /* NodeConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = E3D049931DADC04500718F3C /* NodeConstants.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               E37C86501EB63E3F0087C6CA /* JSDOMPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = E37C864F1EB63E2D0087C6CA /* JSDOMPromise.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E38838981BAD145F00D62EE3 /* ScriptModuleLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38838941BAD145F00D62EE3 /* ScriptModuleLoader.cpp */; };
                E38838991BAD145F00D62EE3 /* ScriptModuleLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = E38838951BAD145F00D62EE3 /* ScriptModuleLoader.h */; };
                E398FC241DC32A20003C4684 /* DOMJITHelpers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E398FC231DC32A1B003C4684 /* DOMJITHelpers.cpp */; };
                E172AF6B180F24C600FBADB9 /* CryptoAlgorithm.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithm.cpp; sourceTree = "<group>"; };
                E172AF6C180F24C600FBADB9 /* CryptoAlgorithm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithm.h; sourceTree = "<group>"; };
                E172AF6F180F289500FBADB9 /* CryptoKeyUsage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKeyUsage.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>"; };
+               E172AF8D1811BC3700FBADB9 /* JSDOMPromiseDeferred.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMPromiseDeferred.cpp; sourceTree = "<group>"; };
+               E172AF8E1811BC3700FBADB9 /* JSDOMPromiseDeferred.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMPromiseDeferred.h; sourceTree = "<group>"; };
                E176580C180DF3A0005A96D1 /* OESElementIndexUint.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = OESElementIndexUint.idl; sourceTree = "<group>"; };
                E179F0D91B9774FE00ED0A27 /* Internals.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Internals.mm; sourceTree = "<group>"; };
                E17B490B16A97269001C8839 /* TransitionEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TransitionEvent.idl; sourceTree = "<group>"; };
                E334825E1DC93AA0009C9544 /* DOMJITAbstractHeapRepository.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMJITAbstractHeapRepository.h; sourceTree = "<group>"; };
                E34EE49F1DC2D57500EAA9D3 /* JSEventCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSEventCustom.h; sourceTree = "<group>"; };
                E35802B51DC8435800A9773C /* DOMJITIDLTypeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMJITIDLTypeFilter.h; sourceTree = "<group>"; };
+               E37C864F1EB63E2D0087C6CA /* JSDOMPromise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMPromise.h; sourceTree = "<group>"; };
                E38838941BAD145F00D62EE3 /* ScriptModuleLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptModuleLoader.cpp; sourceTree = "<group>"; };
                E38838951BAD145F00D62EE3 /* ScriptModuleLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptModuleLoader.h; sourceTree = "<group>"; };
                E398FC231DC32A1B003C4684 /* DOMJITHelpers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMJITHelpers.cpp; sourceTree = "<group>"; };
                                4138F8561D253EEE001CB61E /* JSDOMIterator.h */,
                                41DEFCB31E56C1B9000D9E5F /* JSDOMMapLike.cpp */,
                                41DEFCB41E56C1B9000D9E5F /* JSDOMMapLike.h */,
-                               E172AF8D1811BC3700FBADB9 /* JSDOMPromise.cpp */,
-                               E172AF8E1811BC3700FBADB9 /* JSDOMPromise.h */,
+                               E37C864F1EB63E2D0087C6CA /* JSDOMPromise.h */,
+                               E172AF8D1811BC3700FBADB9 /* JSDOMPromiseDeferred.cpp */,
+                               E172AF8E1811BC3700FBADB9 /* JSDOMPromiseDeferred.h */,
                                BC6932710D7E293900AE44D1 /* JSDOMWindowBase.cpp */,
                                BC6932720D7E293900AE44D1 /* JSDOMWindowBase.h */,
                                460CBF331D4BCCFE0092E88E /* JSDOMWindowProperties.cpp */,
                                C0C054CC1118C8E400CE2636 /* generate-bindings.pl in Headers */,
                                BC23F0DB0DAFF4A4009FDC91 /* GeneratedImage.h in Headers */,
                                830030F61B7D33B500ED3AAC /* GenericCachedHTMLCollection.h in Headers */,
+                               E37C86501EB63E3F0087C6CA /* JSDOMPromise.h in Headers */,
                                0720B0A114D3323500642955 /* GenericEventQueue.h in Headers */,
                                CD62FB961AF018E70012ED7D /* GenericTaskQueue.h in Headers */,
                                9746AF2414F4DDE6003E7A70 /* Geolocation.h in Headers */,
                                0F4966AB1DB40C4300A274BB /* JSDOMPoint.h in Headers */,
                                0F4966AD1DB40C4300A274BB /* JSDOMPointInit.h in Headers */,
                                0F4966AF1DB40C4300A274BB /* JSDOMPointReadOnly.h in Headers */,
-                               E172AF901811BC3700FBADB9 /* JSDOMPromise.h in Headers */,
+                               E172AF901811BC3700FBADB9 /* JSDOMPromiseDeferred.h in Headers */,
                                0F4710BC1DB56BE8002DCEC3 /* JSDOMRect.h in Headers */,
                                0F4710BE1DB56BE8002DCEC3 /* JSDOMRectInit.h in Headers */,
                                0F4710C01DB56BE8002DCEC3 /* JSDOMRectReadOnly.h in Headers */,
                                0F4966AA1DB40C4300A274BB /* JSDOMPoint.cpp in Sources */,
                                0F4966AC1DB40C4300A274BB /* JSDOMPointInit.cpp in Sources */,
                                0F4966AE1DB40C4300A274BB /* JSDOMPointReadOnly.cpp in Sources */,
-                               E172AF8F1811BC3700FBADB9 /* JSDOMPromise.cpp in Sources */,
+                               E172AF8F1811BC3700FBADB9 /* JSDOMPromiseDeferred.cpp in Sources */,
                                0F4710BB1DB56BE8002DCEC3 /* JSDOMRect.cpp in Sources */,
                                0F4710BD1DB56BE8002DCEC3 /* JSDOMRectInit.cpp in Sources */,
                                0F4710BF1DB56BE8002DCEC3 /* JSDOMRectReadOnly.cpp in Sources */,
index 2812050..b5b142c 100644 (file)
@@ -48,7 +48,7 @@ namespace WebCore {
 class IDBKey;
 class IDBKeyData;
 class IDBValue;
-template<typename> class DOMPromise;
+class DOMPromise;
 
 template<typename T>
 struct IDLType {
@@ -185,7 +185,7 @@ template<typename K, typename V> struct IDLRecord : IDLType<Vector<WTF::KeyValue
     using ParameterType = const Vector<WTF::KeyValuePair<typename K::ImplementationType, typename V::ImplementationType>>&;
 };
 
-template<typename T> struct IDLPromise : IDLType<DOMPromise<T>> {
+template<typename T> struct IDLPromise : IDLType<DOMPromise> {
     using InnerType = T;
 };
 
index a6d3c18..2dc841d 100644 (file)
@@ -51,7 +51,7 @@
 #include "JSDOMExceptionHandling.cpp"
 #include "JSDOMGlobalObject.cpp"
 #include "JSDOMGlobalObjectTask.cpp"
-#include "JSDOMPromise.cpp"
+#include "JSDOMPromiseDeferred.cpp"
 #include "JSDOMStringMapCustom.cpp"
 #include "JSDOMWindowBase.cpp"
 #include "JSDOMWindowCustom.cpp"
index c661abf..876f6ca 100644 (file)
@@ -32,7 +32,7 @@
 #include "JSCustomElementInterface.h"
 #include "JSDOMBinding.h"
 #include "JSDOMConvert.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 
 using namespace JSC;
 
index c22370e..055834b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Yusuke Suzuki <utatane.tea@gmail.com>
+ * Copyright (C) 2017 Yusuke Suzuki <utatane.tea@gmail.com>.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #include "IDLTypes.h"
 #include "JSDOMConvertBase.h"
+#include "JSDOMPromise.h"
 
 namespace WebCore {
 
-// FIXME: Implement IDLPromise<> conversions.
-// https://bugs.webkit.org/show_bug.cgi?id=166752
-template<typename T>
-struct Converter<IDLPromise<T>> : DefaultConverter<IDLPromise<T>> {
-    using ReturnType = JSC::JSValue;
+template<typename T> struct Converter<IDLPromise<T>> : DefaultConverter<IDLPromise<T>> {
+    using ReturnType = JSC::JSPromise*;
 
-    static JSC::JSValue convert(JSC::ExecState&, JSC::JSValue value)
+    // https://heycam.github.io/webidl/#es-promise
+    template<typename ExceptionThrower = DefaultExceptionThrower>
+    static ReturnType convert(JSC::ExecState& state, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
     {
-        return value;
+        JSC::VM& vm = state.vm();
+        auto scope = DECLARE_THROW_SCOPE(vm);
+        auto* globalObject = jsDynamicDowncast<JSDOMGlobalObject*>(vm, state.lexicalGlobalObject());
+        if (!globalObject)
+            return nullptr;
+
+        // 1. Let resolve be the original value of %Promise%.resolve.
+        // 2. Let promise be the result of calling resolve with %Promise% as the this value and V as the single argument value.
+        auto* promise = JSC::JSPromise::resolve(*globalObject, value);
+        if (scope.exception()) {
+            exceptionThrower(state, scope);
+            return nullptr;
+        }
+        ASSERT(promise);
+
+        // 3. Return the IDL promise type value that is a reference to the same object as promise.
+        return promise;
     }
 };
 
-template<typename T>
-struct JSConverter<IDLPromise<T>> {
-    using Type = JSC::JSValue;
+template<typename T> struct JSConverter<IDLPromise<T>> {
     static constexpr bool needsState = false;
     static constexpr bool needsGlobalObject = false;
 
-    static JSC::JSValue convert(JSC::JSValue value)
+    static JSC::JSValue convert(JSC::JSPromise& promise)
     {
-        return value;
+        // The result of converting an IDL promise type value to an ECMAScript value is the Promise value
+        // that represents a reference to the same object that the IDL promise type represents.
+        return &promise;
     }
 };
 
index daf0f01..38d68a7 100644 (file)
@@ -27,7 +27,7 @@
 #include "ExceptionCodeDescription.h"
 #include "ExceptionHeaders.h"
 #include "ExceptionInterfaces.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "JSDOMWindow.h"
 #include "JSDynamicDowncast.h"
 #include "JSExceptionBase.h"
index a5f4ec9..7240ad0 100644 (file)
@@ -28,7 +28,7 @@
 #include "JSDOMGlobalObject.h"
 
 #include "Document.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "JSDOMWindow.h"
 #include "JSEventListener.h"
 #include "JSMediaStream.h"
index f74ae2a..be1faf9 100644 (file)
@@ -38,7 +38,7 @@ class WEBCORE_EXPORT DOMGuardedObject : public RefCounted<DOMGuardedObject>, pub
 public:
     ~DOMGuardedObject();
 
-    bool isSuspended() { return !m_guarded || !canInvokeCallback(); } // The wrapper world has gone away or active DOM objects have been suspended.
+    bool isSuspended() const { return !m_guarded || !canInvokeCallback(); } // The wrapper world has gone away or active DOM objects have been suspended.
 
     void visitAggregate(JSC::SlotVisitor& visitor) { visitor.append(m_guarded); }
 
index 890d6e6..85d614d 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017 Yusuke Suzuki <utatane.tea@gmail.com>.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #pragma once
 
-#include "JSDOMConvert.h"
 #include "JSDOMGuardedObject.h"
-#include <runtime/JSPromiseDeferred.h>
+#include <runtime/JSPromise.h>
 
 namespace WebCore {
 
-class DeferredPromise : public DOMGuarded<JSC::JSPromiseDeferred> {
+class DOMPromise : public DOMGuarded<JSC::JSPromise> {
 public:
-    static Ref<DeferredPromise> create(JSDOMGlobalObject& globalObject, JSC::JSPromiseDeferred& deferred)
+    static Ref<DOMPromise> create(JSDOMGlobalObject& globalObject, JSC::JSPromise& promise)
     {
-        return adoptRef(*new DeferredPromise(globalObject, deferred));
+        return adoptRef(*new DOMPromise(globalObject, promise));
     }
 
-    template<class IDLType>
-    void resolve(typename IDLType::ParameterType value)
+    JSC::JSPromise* promise() const
     {
-        if (isSuspended())
-            return;
-        ASSERT(deferred());
-        ASSERT(globalObject());
-        JSC::ExecState* exec = globalObject()->globalExec();
-        JSC::JSLockHolder locker(exec);
-        resolve(*exec, toJS<IDLType>(*exec, *globalObject(), std::forward<typename IDLType::ParameterType>(value)));
+        ASSERT(!isSuspended());
+        return guarded();
     }
 
-    void resolve()
-    {
-        if (isSuspended())
-            return;
-        ASSERT(deferred());
-        ASSERT(globalObject());
-        JSC::ExecState* exec = globalObject()->globalExec();
-        JSC::JSLockHolder locker(exec);
-        resolve(*exec, JSC::jsUndefined());
-    }
-
-    template<class IDLType>
-    void resolveWithNewlyCreated(typename IDLType::ParameterType value)
-    {
-        if (isSuspended())
-            return;
-        ASSERT(deferred());
-        ASSERT(globalObject());
-        JSC::ExecState* exec = globalObject()->globalExec();
-        JSC::JSLockHolder locker(exec);
-        resolve(*exec, toJSNewlyCreated<IDLType>(*exec, *globalObject(), std::forward<typename IDLType::ParameterType>(value)));
-    }
-
-    template<class IDLType>
-    void reject(typename IDLType::ParameterType value)
-    {
-        if (isSuspended())
-            return;
-        ASSERT(deferred());
-        ASSERT(globalObject());
-        JSC::ExecState* exec = globalObject()->globalExec();
-        JSC::JSLockHolder locker(exec);
-        reject(*exec, toJS<IDLType>(*exec, *globalObject(), std::forward<typename IDLType::ParameterType>(value)));
-    }
-
-    void reject();
-    void reject(std::nullptr_t);
-    void reject(Exception&&);
-    WEBCORE_EXPORT void reject(ExceptionCode, const String& = { });
-    void reject(const JSC::PrivateName&);
-
-    template<typename Callback>
-    void resolveWithCallback(Callback callback)
-    {
-        if (isSuspended())
-            return;
-        ASSERT(deferred());
-        ASSERT(globalObject());
-        JSC::ExecState* exec = globalObject()->globalExec();
-        JSC::JSLockHolder locker(exec);
-        resolve(*exec, callback(*exec, *globalObject()));
-    }
-
-    template<typename Callback>
-    void rejectWithCallback(Callback callback)
-    {
-        if (isSuspended())
-            return;
-        ASSERT(deferred());
-        ASSERT(globalObject());
-        JSC::ExecState* exec = globalObject()->globalExec();
-        JSC::JSLockHolder locker(exec);
-        reject(*exec, callback(*exec, *globalObject()));
-    }
-
-    JSC::JSValue promise() const;
-
 private:
-    DeferredPromise(JSDOMGlobalObject& globalObject, JSC::JSPromiseDeferred& deferred) : DOMGuarded<JSC::JSPromiseDeferred>(globalObject, deferred) { }
-
-    JSC::JSPromiseDeferred* deferred() const { return guarded(); }
-
-    WEBCORE_EXPORT void callFunction(JSC::ExecState&, JSC::JSValue function, JSC::JSValue resolution);
-    void resolve(JSC::ExecState& state, JSC::JSValue resolution) { callFunction(state, deferred()->resolve(), resolution); }
-    void reject(JSC::ExecState& state, JSC::JSValue resolution) { callFunction(state, deferred()->reject(), resolution); }
-};
-
-class DOMPromiseBase {
-public:
-    DOMPromiseBase(Ref<DeferredPromise>&& genericPromise)
-        : m_promiseDeferred(WTFMove(genericPromise))
-    {
-    }
-
-    DOMPromiseBase(DOMPromiseBase&& promise)
-        : m_promiseDeferred(WTFMove(promise.m_promiseDeferred))
-    {
-    }
-
-    DOMPromiseBase(const DOMPromiseBase& other)
-        : m_promiseDeferred(other.m_promiseDeferred.copyRef())
-    {
-    }
-
-    DOMPromiseBase& operator=(const DOMPromiseBase& other)
-    {
-        m_promiseDeferred = other.m_promiseDeferred.copyRef();
-        return *this;
-    }
-
-    DOMPromiseBase& operator=(DOMPromiseBase&& other)
+    DOMPromise(JSDOMGlobalObject& globalObject, JSC::JSPromise& promise)
+        : DOMGuarded<JSC::JSPromise>(globalObject, promise)
     {
-        m_promiseDeferred = WTFMove(other.m_promiseDeferred);
-        return *this;
-    }
-
-    void reject()
-    {
-        m_promiseDeferred->reject();
-    }
-
-    template<typename... ErrorType> 
-    void reject(ErrorType&&... error)
-    {
-        m_promiseDeferred->reject(std::forward<ErrorType>(error)...);
-    }
-
-    template<typename IDLType>
-    void rejectType(typename IDLType::ParameterType value)
-    {
-        m_promiseDeferred->reject<IDLType>(std::forward<typename IDLType::ParameterType>(value));
-    }
-
-    JSC::JSValue promise() const { return m_promiseDeferred->promise(); };
-
-protected:
-    Ref<DeferredPromise> m_promiseDeferred;
-};
-
-template<typename IDLType> 
-class DOMPromise : public DOMPromiseBase {
-public:
-    using DOMPromiseBase::DOMPromiseBase;
-    using DOMPromiseBase::operator=;
-    using DOMPromiseBase::promise;
-    using DOMPromiseBase::reject;
-
-    void resolve(typename IDLType::ParameterType value)
-    { 
-        m_promiseDeferred->resolve<IDLType>(std::forward<typename IDLType::ParameterType>(value));
     }
 };
 
-template<> class DOMPromise<void> : public DOMPromiseBase {
-public:
-    using DOMPromiseBase::DOMPromiseBase;
-    using DOMPromiseBase::operator=;
-    using DOMPromiseBase::promise;
-    using DOMPromiseBase::reject;
-
-    void resolve()
-    { 
-        m_promiseDeferred->resolve();
-    }
-};
-
-
-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);
-WEBCORE_EXPORT void rejectPromiseWithExceptionIfAny(JSC::ExecState&, JSDOMGlobalObject&, JSC::JSPromiseDeferred&);
-JSC::EncodedJSValue createRejectedPromiseWithTypeError(JSC::ExecState&, const String&);
-
-using PromiseFunction = void(JSC::ExecState&, Ref<DeferredPromise>&&);
-
-enum class PromiseExecutionScope { WindowOnly, WindowOrWorker };
-
-template<PromiseFunction promiseFunction, PromiseExecutionScope executionScope>
-inline JSC::JSValue callPromiseFunction(JSC::ExecState& state)
-{
-    JSC::VM& vm = state.vm();
-    auto scope = DECLARE_CATCH_SCOPE(vm);
-
-    JSDOMGlobalObject& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject());
-    JSC::JSPromiseDeferred* promiseDeferred = JSC::JSPromiseDeferred::create(&state, &globalObject);
-
-    // promiseDeferred can be null when terminating a Worker abruptly.
-    if (executionScope == PromiseExecutionScope::WindowOrWorker && !promiseDeferred)
-        return JSC::jsUndefined();
-
-    promiseFunction(state, DeferredPromise::create(globalObject, *promiseDeferred));
-
-    rejectPromiseWithExceptionIfAny(state, globalObject, *promiseDeferred);
-    scope.assertNoException();
-    return promiseDeferred->promise();
-}
-
-using BindingPromiseFunction = JSC::EncodedJSValue(JSC::ExecState*, Ref<DeferredPromise>&&);
-template<BindingPromiseFunction bindingFunction>
-inline void bindingPromiseFunctionAdapter(JSC::ExecState& state, Ref<DeferredPromise>&& promise)
-{
-    bindingFunction(&state, WTFMove(promise));
-}
-
-template<BindingPromiseFunction bindingPromiseFunction, PromiseExecutionScope executionScope>
-inline JSC::JSValue callPromiseFunction(JSC::ExecState& state)
-{
-    return callPromiseFunction<bindingPromiseFunctionAdapter<bindingPromiseFunction>, executionScope>(state);
-}
-
 } // namespace WebCore
@@ -24,7 +24,7 @@
  */
 
 #include "config.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 
 #include "ExceptionCode.h"
 #include "JSDOMError.h"
diff --git a/Source/WebCore/bindings/js/JSDOMPromiseDeferred.h b/Source/WebCore/bindings/js/JSDOMPromiseDeferred.h
new file mode 100644 (file)
index 0000000..f613cac
--- /dev/null
@@ -0,0 +1,258 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "JSDOMConvert.h"
+#include "JSDOMGuardedObject.h"
+#include <runtime/JSPromiseDeferred.h>
+
+namespace WebCore {
+
+class DeferredPromise : public DOMGuarded<JSC::JSPromiseDeferred> {
+public:
+    static Ref<DeferredPromise> create(JSDOMGlobalObject& globalObject, JSC::JSPromiseDeferred& deferred)
+    {
+        return adoptRef(*new DeferredPromise(globalObject, deferred));
+    }
+
+    template<class IDLType>
+    void resolve(typename IDLType::ParameterType value)
+    {
+        if (isSuspended())
+            return;
+        ASSERT(deferred());
+        ASSERT(globalObject());
+        JSC::ExecState* exec = globalObject()->globalExec();
+        JSC::JSLockHolder locker(exec);
+        resolve(*exec, toJS<IDLType>(*exec, *globalObject(), std::forward<typename IDLType::ParameterType>(value)));
+    }
+
+    void resolve()
+    {
+        if (isSuspended())
+            return;
+        ASSERT(deferred());
+        ASSERT(globalObject());
+        JSC::ExecState* exec = globalObject()->globalExec();
+        JSC::JSLockHolder locker(exec);
+        resolve(*exec, JSC::jsUndefined());
+    }
+
+    template<class IDLType>
+    void resolveWithNewlyCreated(typename IDLType::ParameterType value)
+    {
+        if (isSuspended())
+            return;
+        ASSERT(deferred());
+        ASSERT(globalObject());
+        JSC::ExecState* exec = globalObject()->globalExec();
+        JSC::JSLockHolder locker(exec);
+        resolve(*exec, toJSNewlyCreated<IDLType>(*exec, *globalObject(), std::forward<typename IDLType::ParameterType>(value)));
+    }
+
+    template<class IDLType>
+    void reject(typename IDLType::ParameterType value)
+    {
+        if (isSuspended())
+            return;
+        ASSERT(deferred());
+        ASSERT(globalObject());
+        JSC::ExecState* exec = globalObject()->globalExec();
+        JSC::JSLockHolder locker(exec);
+        reject(*exec, toJS<IDLType>(*exec, *globalObject(), std::forward<typename IDLType::ParameterType>(value)));
+    }
+
+    void reject();
+    void reject(std::nullptr_t);
+    void reject(Exception&&);
+    WEBCORE_EXPORT void reject(ExceptionCode, const String& = { });
+    void reject(const JSC::PrivateName&);
+
+    template<typename Callback>
+    void resolveWithCallback(Callback callback)
+    {
+        if (isSuspended())
+            return;
+        ASSERT(deferred());
+        ASSERT(globalObject());
+        JSC::ExecState* exec = globalObject()->globalExec();
+        JSC::JSLockHolder locker(exec);
+        resolve(*exec, callback(*exec, *globalObject()));
+    }
+
+    template<typename Callback>
+    void rejectWithCallback(Callback callback)
+    {
+        if (isSuspended())
+            return;
+        ASSERT(deferred());
+        ASSERT(globalObject());
+        JSC::ExecState* exec = globalObject()->globalExec();
+        JSC::JSLockHolder locker(exec);
+        reject(*exec, callback(*exec, *globalObject()));
+    }
+
+    JSC::JSValue promise() const;
+
+private:
+    DeferredPromise(JSDOMGlobalObject& globalObject, JSC::JSPromiseDeferred& deferred)
+        : DOMGuarded<JSC::JSPromiseDeferred>(globalObject, deferred)
+    {
+    }
+
+    JSC::JSPromiseDeferred* deferred() const { return guarded(); }
+
+    WEBCORE_EXPORT void callFunction(JSC::ExecState&, JSC::JSValue function, JSC::JSValue resolution);
+    void resolve(JSC::ExecState& state, JSC::JSValue resolution) { callFunction(state, deferred()->resolve(), resolution); }
+    void reject(JSC::ExecState& state, JSC::JSValue resolution) { callFunction(state, deferred()->reject(), resolution); }
+};
+
+class DOMPromiseDeferredBase {
+public:
+    DOMPromiseDeferredBase(Ref<DeferredPromise>&& genericPromise)
+        : m_promiseDeferred(WTFMove(genericPromise))
+    {
+    }
+
+    DOMPromiseDeferredBase(DOMPromiseDeferredBase&& promise)
+        : m_promiseDeferred(WTFMove(promise.m_promiseDeferred))
+    {
+    }
+
+    DOMPromiseDeferredBase(const DOMPromiseDeferredBase& other)
+        : m_promiseDeferred(other.m_promiseDeferred.copyRef())
+    {
+    }
+
+    DOMPromiseDeferredBase& operator=(const DOMPromiseDeferredBase& other)
+    {
+        m_promiseDeferred = other.m_promiseDeferred.copyRef();
+        return *this;
+    }
+
+    DOMPromiseDeferredBase& operator=(DOMPromiseDeferredBase&& other)
+    {
+        m_promiseDeferred = WTFMove(other.m_promiseDeferred);
+        return *this;
+    }
+
+    void reject()
+    {
+        m_promiseDeferred->reject();
+    }
+
+    template<typename... ErrorType> 
+    void reject(ErrorType&&... error)
+    {
+        m_promiseDeferred->reject(std::forward<ErrorType>(error)...);
+    }
+
+    template<typename IDLType>
+    void rejectType(typename IDLType::ParameterType value)
+    {
+        m_promiseDeferred->reject<IDLType>(std::forward<typename IDLType::ParameterType>(value));
+    }
+
+    JSC::JSValue promise() const { return m_promiseDeferred->promise(); };
+
+protected:
+    Ref<DeferredPromise> m_promiseDeferred;
+};
+
+template<typename IDLType> 
+class DOMPromiseDeferred : public DOMPromiseDeferredBase {
+public:
+    using DOMPromiseDeferredBase::DOMPromiseDeferredBase;
+    using DOMPromiseDeferredBase::operator=;
+    using DOMPromiseDeferredBase::promise;
+    using DOMPromiseDeferredBase::reject;
+
+    void resolve(typename IDLType::ParameterType value)
+    { 
+        m_promiseDeferred->resolve<IDLType>(std::forward<typename IDLType::ParameterType>(value));
+    }
+};
+
+template<> class DOMPromiseDeferred<void> : public DOMPromiseDeferredBase {
+public:
+    using DOMPromiseDeferredBase::DOMPromiseDeferredBase;
+    using DOMPromiseDeferredBase::operator=;
+    using DOMPromiseDeferredBase::promise;
+    using DOMPromiseDeferredBase::reject;
+
+    void resolve()
+    { 
+        m_promiseDeferred->resolve();
+    }
+};
+
+
+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);
+WEBCORE_EXPORT void rejectPromiseWithExceptionIfAny(JSC::ExecState&, JSDOMGlobalObject&, JSC::JSPromiseDeferred&);
+JSC::EncodedJSValue createRejectedPromiseWithTypeError(JSC::ExecState&, const String&);
+
+using PromiseFunction = void(JSC::ExecState&, Ref<DeferredPromise>&&);
+
+enum class PromiseExecutionScope { WindowOnly, WindowOrWorker };
+
+template<PromiseFunction promiseFunction, PromiseExecutionScope executionScope>
+inline JSC::JSValue callPromiseFunction(JSC::ExecState& state)
+{
+    JSC::VM& vm = state.vm();
+    auto scope = DECLARE_CATCH_SCOPE(vm);
+
+    JSDOMGlobalObject& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject());
+    JSC::JSPromiseDeferred* promiseDeferred = JSC::JSPromiseDeferred::create(&state, &globalObject);
+
+    // promiseDeferred can be null when terminating a Worker abruptly.
+    if (executionScope == PromiseExecutionScope::WindowOrWorker && !promiseDeferred)
+        return JSC::jsUndefined();
+
+    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<DeferredPromise>&&);
+template<BindingPromiseFunction bindingFunction>
+inline void bindingPromiseFunctionAdapter(JSC::ExecState& state, Ref<DeferredPromise>&& promise)
+{
+    bindingFunction(&state, WTFMove(promise));
+}
+
+template<BindingPromiseFunction bindingPromiseFunction, PromiseExecutionScope executionScope>
+inline JSC::JSValue callPromiseFunction(JSC::ExecState& state)
+{
+    return callPromiseFunction<bindingPromiseFunctionAdapter<bindingPromiseFunction>, executionScope>(state);
+}
+
+} // namespace WebCore
index ef37aea..410de76 100644 (file)
@@ -37,7 +37,7 @@
 #include "JSCryptoAlgorithmParameters.h"
 #include "JSCryptoKey.h"
 #include "JSCryptoKeyPair.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "JSDOMWrapper.h"
 #include "JSEcKeyParams.h"
 #include "JSEcdhKeyDeriveParams.h"
index 2fb3f0b..930c4fd 100644 (file)
@@ -29,7 +29,7 @@
 #if ENABLE(WEBGPU)
 
 #include "GPUCommandBuffer.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "JSDOMWrapper.h"
 #include <runtime/JSCJSValue.h>
 
index 638b37e..4cb3e2c 100644 (file)
@@ -40,7 +40,7 @@
 #include "JSCryptoKeyPair.h"
 #include "JSCryptoKeySerializationJWK.h"
 #include "JSCryptoOperationData.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "ScriptState.h"
 #include <runtime/Error.h>
 
diff --git a/Source/WebCore/bindings/scripts/test/JS/JSTestPromiseRejectionEvent.cpp b/Source/WebCore/bindings/scripts/test/JS/JSTestPromiseRejectionEvent.cpp
new file mode 100644 (file)
index 0000000..adbb47b
--- /dev/null
@@ -0,0 +1,299 @@
+/*
+    This file is part of the WebKit open source project.
+    This file has been generated by generate-bindings.pl. DO NOT MODIFY!
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#include "JSTestPromiseRejectionEvent.h"
+
+#include "JSDOMBinding.h"
+#include "JSDOMBindingCaller.h"
+#include "JSDOMConstructor.h"
+#include "JSDOMExceptionHandling.h"
+#include "JSDOMPromise.h"
+#include "JSDOMWrapperCache.h"
+#include <runtime/Error.h>
+#include <wtf/GetPtr.h>
+
+using namespace JSC;
+
+namespace WebCore {
+
+template<> TestPromiseRejectionEvent::Init convertDictionary<TestPromiseRejectionEvent::Init>(ExecState& state, JSValue value)
+{
+    VM& vm = state.vm();
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+    bool isNullOrUndefined = value.isUndefinedOrNull();
+    auto* object = isNullOrUndefined ? nullptr : value.getObject();
+    if (UNLIKELY(!isNullOrUndefined && !object)) {
+        throwTypeError(&state, throwScope);
+        return { };
+    }
+    if (UNLIKELY(object && object->type() == RegExpObjectType)) {
+        throwTypeError(&state, throwScope);
+        return { };
+    }
+    TestPromiseRejectionEvent::Init result;
+    JSValue bubblesValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "bubbles"));
+    if (!bubblesValue.isUndefined()) {
+        result.bubbles = convert<IDLBoolean>(state, bubblesValue);
+        RETURN_IF_EXCEPTION(throwScope, { });
+    } else
+        result.bubbles = false;
+    JSValue cancelableValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "cancelable"));
+    if (!cancelableValue.isUndefined()) {
+        result.cancelable = convert<IDLBoolean>(state, cancelableValue);
+        RETURN_IF_EXCEPTION(throwScope, { });
+    } else
+        result.cancelable = false;
+    JSValue composedValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "composed"));
+    if (!composedValue.isUndefined()) {
+        result.composed = convert<IDLBoolean>(state, composedValue);
+        RETURN_IF_EXCEPTION(throwScope, { });
+    } else
+        result.composed = false;
+    JSValue promiseValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "promise"));
+    if (!promiseValue.isUndefined()) {
+        result.promise = convert<IDLPromise<IDLAny>>(state, promiseValue);
+        RETURN_IF_EXCEPTION(throwScope, { });
+    } else {
+        throwRequiredMemberTypeError(state, throwScope, "promise", "TestPromiseRejectionEventInit", "Promise");
+        return { };
+    }
+    JSValue reasonValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "reason"));
+    if (!reasonValue.isUndefined()) {
+        result.reason = convert<IDLAny>(state, reasonValue);
+        RETURN_IF_EXCEPTION(throwScope, { });
+    } else
+        result.reason = jsUndefined();
+    return result;
+}
+
+// Attributes
+
+JSC::EncodedJSValue jsTestPromiseRejectionEventPromise(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
+JSC::EncodedJSValue jsTestPromiseRejectionEventReason(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
+JSC::EncodedJSValue jsTestPromiseRejectionEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
+bool setJSTestPromiseRejectionEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
+
+class JSTestPromiseRejectionEventPrototype : public JSC::JSNonFinalObject {
+public:
+    using Base = JSC::JSNonFinalObject;
+    static JSTestPromiseRejectionEventPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
+    {
+        JSTestPromiseRejectionEventPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestPromiseRejectionEventPrototype>(vm.heap)) JSTestPromiseRejectionEventPrototype(vm, globalObject, structure);
+        ptr->finishCreation(vm);
+        return ptr;
+    }
+
+    DECLARE_INFO;
+    static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+    {
+        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+    }
+
+private:
+    JSTestPromiseRejectionEventPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
+        : JSC::JSNonFinalObject(vm, structure)
+    {
+    }
+
+    void finishCreation(JSC::VM&);
+};
+
+using JSTestPromiseRejectionEventConstructor = JSDOMConstructor<JSTestPromiseRejectionEvent>;
+
+template<> EncodedJSValue JSC_HOST_CALL JSTestPromiseRejectionEventConstructor::construct(ExecState* state)
+{
+    VM& vm = state->vm();
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+    UNUSED_PARAM(throwScope);
+    auto* castedThis = jsCast<JSTestPromiseRejectionEventConstructor*>(state->jsCallee());
+    ASSERT(castedThis);
+    if (UNLIKELY(state->argumentCount() < 2))
+        return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
+    auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+    auto eventInitDict = convert<IDLDictionary<TestPromiseRejectionEvent::Init>>(*state, state->uncheckedArgument(1));
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+    auto object = TestPromiseRejectionEvent::create(*state, WTFMove(type), WTFMove(eventInitDict));
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+    return JSValue::encode(toJSNewlyCreated<IDLInterface<TestPromiseRejectionEvent>>(*state, *castedThis->globalObject(), WTFMove(object)));
+}
+
+template<> JSValue JSTestPromiseRejectionEventConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
+{
+    return JSEvent::getConstructor(vm, &globalObject);
+}
+
+template<> void JSTestPromiseRejectionEventConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
+{
+    putDirect(vm, vm.propertyNames->prototype, JSTestPromiseRejectionEvent::prototype(vm, globalObject), DontDelete | ReadOnly | DontEnum);
+    putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestPromiseRejectionEvent"))), ReadOnly | DontEnum);
+    putDirect(vm, vm.propertyNames->length, jsNumber(2), ReadOnly | DontEnum);
+}
+
+template<> const ClassInfo JSTestPromiseRejectionEventConstructor::s_info = { "TestPromiseRejectionEvent", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestPromiseRejectionEventConstructor) };
+
+/* Hash table for prototype */
+
+static const HashTableValue JSTestPromiseRejectionEventPrototypeTableValues[] =
+{
+    { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestPromiseRejectionEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestPromiseRejectionEventConstructor) } },
+    { "promise", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestPromiseRejectionEventPromise), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
+    { "reason", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestPromiseRejectionEventReason), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
+};
+
+const ClassInfo JSTestPromiseRejectionEventPrototype::s_info = { "TestPromiseRejectionEventPrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestPromiseRejectionEventPrototype) };
+
+void JSTestPromiseRejectionEventPrototype::finishCreation(VM& vm)
+{
+    Base::finishCreation(vm);
+    reifyStaticProperties(vm, JSTestPromiseRejectionEventPrototypeTableValues, *this);
+}
+
+const ClassInfo JSTestPromiseRejectionEvent::s_info = { "TestPromiseRejectionEvent", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestPromiseRejectionEvent) };
+
+JSTestPromiseRejectionEvent::JSTestPromiseRejectionEvent(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestPromiseRejectionEvent>&& impl)
+    : JSEvent(structure, globalObject, WTFMove(impl))
+{
+}
+
+void JSTestPromiseRejectionEvent::finishCreation(VM& vm)
+{
+    Base::finishCreation(vm);
+    ASSERT(inherits(vm, info()));
+
+}
+
+JSObject* JSTestPromiseRejectionEvent::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
+{
+    return JSTestPromiseRejectionEventPrototype::create(vm, &globalObject, JSTestPromiseRejectionEventPrototype::createStructure(vm, &globalObject, JSEvent::prototype(vm, globalObject)));
+}
+
+JSObject* JSTestPromiseRejectionEvent::prototype(VM& vm, JSDOMGlobalObject& globalObject)
+{
+    return getDOMPrototype<JSTestPromiseRejectionEvent>(vm, globalObject);
+}
+
+template<> inline JSTestPromiseRejectionEvent* BindingCaller<JSTestPromiseRejectionEvent>::castForAttribute(ExecState& state, EncodedJSValue thisValue)
+{
+    return jsDynamicDowncast<JSTestPromiseRejectionEvent*>(state.vm(), JSValue::decode(thisValue));
+}
+
+static inline JSValue jsTestPromiseRejectionEventPromiseGetter(ExecState&, JSTestPromiseRejectionEvent&, ThrowScope& throwScope);
+
+EncodedJSValue jsTestPromiseRejectionEventPromise(ExecState* state, EncodedJSValue thisValue, PropertyName)
+{
+    return BindingCaller<JSTestPromiseRejectionEvent>::attribute<jsTestPromiseRejectionEventPromiseGetter, CastedThisErrorBehavior::RejectPromise>(state, thisValue, "promise");
+}
+
+static inline JSValue jsTestPromiseRejectionEventPromiseGetter(ExecState& state, JSTestPromiseRejectionEvent& thisObject, ThrowScope& throwScope)
+{
+    UNUSED_PARAM(throwScope);
+    UNUSED_PARAM(state);
+    auto& impl = thisObject.wrapped();
+    JSValue result = toJS<IDLPromise<IDLAny>>(impl.promise());
+    return result;
+}
+
+static inline JSValue jsTestPromiseRejectionEventReasonGetter(ExecState&, JSTestPromiseRejectionEvent&, ThrowScope& throwScope);
+
+EncodedJSValue jsTestPromiseRejectionEventReason(ExecState* state, EncodedJSValue thisValue, PropertyName)
+{
+    return BindingCaller<JSTestPromiseRejectionEvent>::attribute<jsTestPromiseRejectionEventReasonGetter>(state, thisValue, "reason");
+}
+
+static inline JSValue jsTestPromiseRejectionEventReasonGetter(ExecState& state, JSTestPromiseRejectionEvent& thisObject, ThrowScope& throwScope)
+{
+    UNUSED_PARAM(throwScope);
+    UNUSED_PARAM(state);
+    auto& impl = thisObject.wrapped();
+    JSValue result = toJS<IDLAny>(impl.reason());
+    return result;
+}
+
+EncodedJSValue jsTestPromiseRejectionEventConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
+{
+    VM& vm = state->vm();
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+    JSTestPromiseRejectionEventPrototype* domObject = jsDynamicDowncast<JSTestPromiseRejectionEventPrototype*>(vm, JSValue::decode(thisValue));
+    if (UNLIKELY(!domObject))
+        return throwVMTypeError(state, throwScope);
+    return JSValue::encode(JSTestPromiseRejectionEvent::getConstructor(state->vm(), domObject->globalObject()));
+}
+
+bool setJSTestPromiseRejectionEventConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
+{
+    VM& vm = state->vm();
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+    JSValue value = JSValue::decode(encodedValue);
+    JSTestPromiseRejectionEventPrototype* domObject = jsDynamicDowncast<JSTestPromiseRejectionEventPrototype*>(vm, JSValue::decode(thisValue));
+    if (UNLIKELY(!domObject)) {
+        throwVMTypeError(state, throwScope);
+        return false;
+    }
+    // Shadowing a built-in constructor
+    return domObject->putDirect(state->vm(), state->propertyNames().constructor, value);
+}
+
+JSValue JSTestPromiseRejectionEvent::getConstructor(VM& vm, const JSGlobalObject* globalObject)
+{
+    return getDOMConstructor<JSTestPromiseRejectionEventConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
+}
+
+#if ENABLE(BINDING_INTEGRITY)
+#if PLATFORM(WIN)
+#pragma warning(disable: 4483)
+extern "C" { extern void (*const __identifier("??_7TestPromiseRejectionEvent@WebCore@@6B@")[])(); }
+#else
+extern "C" { extern void* _ZTVN7WebCore25TestPromiseRejectionEventE[]; }
+#endif
+#endif
+
+JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestPromiseRejectionEvent>&& impl)
+{
+
+#if ENABLE(BINDING_INTEGRITY)
+    void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
+#if PLATFORM(WIN)
+    void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestPromiseRejectionEvent@WebCore@@6B@"));
+#else
+    void* expectedVTablePointer = &_ZTVN7WebCore25TestPromiseRejectionEventE[2];
+#if COMPILER(CLANG)
+    // If this fails TestPromiseRejectionEvent does not have a vtable, so you need to add the
+    // ImplementationLacksVTable attribute to the interface definition
+    static_assert(__is_polymorphic(TestPromiseRejectionEvent), "TestPromiseRejectionEvent is not polymorphic");
+#endif
+#endif
+    // If you hit this assertion you either have a use after free bug, or
+    // TestPromiseRejectionEvent has subclasses. If TestPromiseRejectionEvent has subclasses that get passed
+    // to toJS() we currently require TestPromiseRejectionEvent you to opt out of binding hardening
+    // by adding the SkipVTableValidation attribute to the interface IDL definition
+    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
+#endif
+    return createWrapper<TestPromiseRejectionEvent>(globalObject, WTFMove(impl));
+}
+
+JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestPromiseRejectionEvent& impl)
+{
+    return wrap(state, globalObject, impl);
+}
+
+
+}
diff --git a/Source/WebCore/bindings/scripts/test/JS/JSTestPromiseRejectionEvent.h b/Source/WebCore/bindings/scripts/test/JS/JSTestPromiseRejectionEvent.h
new file mode 100644 (file)
index 0000000..071094a
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+    This file is part of the WebKit open source project.
+    This file has been generated by generate-bindings.pl. DO NOT MODIFY!
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#pragma once
+
+#include "JSDOMConvert.h"
+#include "JSEvent.h"
+#include "TestPromiseRejectionEvent.h"
+
+namespace WebCore {
+
+class JSTestPromiseRejectionEvent : public JSEvent {
+public:
+    using Base = JSEvent;
+    using DOMWrapped = TestPromiseRejectionEvent;
+    static JSTestPromiseRejectionEvent* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject, Ref<TestPromiseRejectionEvent>&& impl)
+    {
+        JSTestPromiseRejectionEvent* ptr = new (NotNull, JSC::allocateCell<JSTestPromiseRejectionEvent>(globalObject->vm().heap)) JSTestPromiseRejectionEvent(structure, *globalObject, WTFMove(impl));
+        ptr->finishCreation(globalObject->vm());
+        return ptr;
+    }
+
+    static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&);
+    static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&);
+
+    DECLARE_INFO;
+
+    static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+    {
+        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::JSType(JSEventType), StructureFlags), info());
+    }
+
+    static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*);
+    TestPromiseRejectionEvent& wrapped() const
+    {
+        return static_cast<TestPromiseRejectionEvent&>(Base::wrapped());
+    }
+protected:
+    JSTestPromiseRejectionEvent(JSC::Structure*, JSDOMGlobalObject&, Ref<TestPromiseRejectionEvent>&&);
+
+    void finishCreation(JSC::VM&);
+};
+
+JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject*, TestPromiseRejectionEvent&);
+inline JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestPromiseRejectionEvent* impl) { return impl ? toJS(state, globalObject, *impl) : JSC::jsNull(); }
+JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject*, Ref<TestPromiseRejectionEvent>&&);
+inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* globalObject, RefPtr<TestPromiseRejectionEvent>&& impl) { return impl ? toJSNewlyCreated(state, globalObject, impl.releaseNonNull()) : JSC::jsNull(); }
+
+template<> struct JSDOMWrapperConverterTraits<TestPromiseRejectionEvent> {
+    using WrapperClass = JSTestPromiseRejectionEvent;
+    using ToWrappedReturnType = TestPromiseRejectionEvent*;
+};
+template<> TestPromiseRejectionEvent::Init convertDictionary<TestPromiseRejectionEvent::Init>(JSC::ExecState&, JSC::JSValue);
+
+
+} // namespace WebCore
diff --git a/Source/WebCore/bindings/scripts/test/TestPromiseRejectionEvent.idl b/Source/WebCore/bindings/scripts/test/TestPromiseRejectionEvent.idl
new file mode 100644 (file)
index 0000000..056a949
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2017 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. ``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
+ * 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.
+ */
+
+[
+    Constructor(DOMString type, TestPromiseRejectionEventInit eventInitDict),
+    ConstructorCallWith=ScriptState,
+    Exposed=(Window,Worker),
+] interface TestPromiseRejectionEvent : Event {
+    readonly attribute Promise<any> promise;
+    readonly attribute any reason;
+};
+
+dictionary TestPromiseRejectionEventInit : EventInit {
+    required Promise<any> promise;
+    any reason;
+};
index 0b06ce9..813403a 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "CSSFontFace.h"
 #include "CSSPropertyNames.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include <wtf/Variant.h>
 #include <wtf/WeakPtr.h>
 
@@ -73,7 +73,7 @@ public:
     enum class LoadStatus { Unloaded, Loading, Loaded, Error };
     LoadStatus status() const;
 
-    using Promise = DOMPromise<IDLInterface<FontFace>>;
+    using Promise = DOMPromiseDeferred<IDLInterface<FontFace>>;
     std::optional<Promise>& promise() { return m_promise; }
     void registerLoaded(Promise&&);
 
index fa8fe2a..e84d095 100644 (file)
@@ -28,7 +28,7 @@
 #include "ActiveDOMObject.h"
 #include "CSSFontFaceSet.h"
 #include "EventTarget.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 
 namespace WebCore {
 
@@ -46,14 +46,14 @@ public:
     bool remove(FontFace&);
     void clear();
 
-    using LoadPromise = DOMPromise<IDLSequence<IDLInterface<FontFace>>>;
+    using LoadPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<FontFace>>>;
     void load(const String& font, const String& text, LoadPromise&&);
     ExceptionOr<bool> check(const String& font, const String& text);
 
     enum class LoadStatus { Loading, Loaded };
     LoadStatus status() const;
 
-    using ReadyPromise = DOMPromise<IDLInterface<FontFaceSet>>;
+    using ReadyPromise = DOMPromiseDeferred<IDLInterface<FontFaceSet>>;
     void registerReady(ReadyPromise&&);
 
     CSSFontFaceSet& backing() { return m_backing; }
index 112097b..efdfc24 100644 (file)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "QualifiedName.h"
 #include <wtf/HashMap.h>
 #include <wtf/SetForScope.h>
index 0fb1a4c..1642757 100644 (file)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "Event.h"
+#include "JSDOMPromise.h"
 #include <heap/Strong.h>
 
 namespace WebCore {
@@ -33,7 +34,7 @@ namespace WebCore {
 class PromiseRejectionEvent final : public Event {
 public:
     struct Init : EventInit {
-        JSC::JSValue promise;
+        JSC::JSPromise* promise;
         JSC::JSValue reason;
     };
 
@@ -44,7 +45,7 @@ public:
 
     virtual ~PromiseRejectionEvent();
 
-    JSC::JSValue promise() const { return m_promise.get(); }
+    JSC::JSPromise& promise() const { return *m_promise.get(); }
     JSC::JSValue reason() const { return m_reason.get(); }
 
     EventInterface eventInterface() const override { return PromiseRejectionEventInterfaceType; }
@@ -52,7 +53,7 @@ public:
 private:
     PromiseRejectionEvent(JSC::ExecState&, const AtomicString&, const Init&, IsTrusted);
 
-    JSC::Strong<JSC::Unknown> m_promise;
+    JSC::Strong<JSC::JSPromise> m_promise;
     JSC::Strong<JSC::Unknown> m_reason;
 };
 
index 232abb8..63e50e1 100644 (file)
@@ -50,46 +50,29 @@ using namespace Inspector;
 
 namespace WebCore {
 
-class RejectedPromise {
-    WTF_MAKE_NONCOPYABLE(RejectedPromise);
+class UnhandledPromise {
+    WTF_MAKE_NONCOPYABLE(UnhandledPromise);
 public:
-    RejectedPromise(VM& vm, JSDOMGlobalObject& globalObject, JSPromise& promise)
-        : m_globalObject(vm, &globalObject)
-        , m_promise(vm, &promise)
-    {
-    }
-
-    RejectedPromise(RejectedPromise&&) = default;
-
-    JSDOMGlobalObject& globalObject()
-    {
-        return *m_globalObject.get();
-    }
-
-    JSPromise& promise()
+    UnhandledPromise(JSDOMGlobalObject& globalObject, JSPromise& promise, RefPtr<ScriptCallStack>&& stack)
+        : m_promise(DOMPromise::create(globalObject, promise))
+        , m_stack(WTFMove(stack))
     {
-        return *m_promise.get();
     }
 
-private:
-    Strong<JSDOMGlobalObject> m_globalObject;
-    Strong<JSPromise> m_promise;
-};
+    UnhandledPromise(UnhandledPromise&&) = default;
 
-class UnhandledPromise : public RejectedPromise {
-public:
-    UnhandledPromise(VM& vm, JSDOMGlobalObject& globalObject, JSPromise& promise, RefPtr<ScriptCallStack>&& stack)
-        : RejectedPromise(vm, globalObject, promise)
-        , m_stack(WTFMove(stack))
+    ScriptCallStack* callStack()
     {
+        return m_stack.get();
     }
 
-    ScriptCallStack* callStack()
+    DOMPromise& promise()
     {
-        return m_stack.get();
+        return m_promise.get();
     }
 
 private:
+    Ref<DOMPromise> m_promise;
     RefPtr<ScriptCallStack> m_stack;
 };
 
@@ -125,17 +108,19 @@ void RejectedPromiseTracker::promiseRejected(ExecState& state, JSDOMGlobalObject
 {
     // https://html.spec.whatwg.org/multipage/webappapis.html#the-hostpromiserejectiontracker-implementation
 
-    VM& vm = state.vm();
-    JSValue reason = promise.result(vm);
-    m_aboutToBeNotifiedRejectedPromises.append(UnhandledPromise { vm, globalObject, promise, createScriptCallStackFromReason(state, reason) });
+    JSValue reason = promise.result(state.vm());
+    m_aboutToBeNotifiedRejectedPromises.append(UnhandledPromise { globalObject, promise, createScriptCallStackFromReason(state, reason) });
 }
 
-void RejectedPromiseTracker::promiseHandled(ExecState& state, JSDOMGlobalObject& globalObject, JSPromise& promise)
+void RejectedPromiseTracker::promiseHandled(ExecState&, JSDOMGlobalObject& globalObject, JSPromise& promise)
 {
     // https://html.spec.whatwg.org/multipage/webappapis.html#the-hostpromiserejectiontracker-implementation
 
     bool removed = m_aboutToBeNotifiedRejectedPromises.removeFirstMatching([&] (UnhandledPromise& unhandledPromise) {
-        return &unhandledPromise.promise() == &promise;
+        auto& domPromise = unhandledPromise.promise();
+        if (domPromise.isSuspended())
+            return false;
+        return domPromise.promise() == &promise;
     });
     if (removed)
         return;
@@ -143,9 +128,7 @@ void RejectedPromiseTracker::promiseHandled(ExecState& state, JSDOMGlobalObject&
     if (!m_outstandingRejectedPromises.remove(&promise))
         return;
 
-    VM& vm = state.vm();
-
-    m_context.postTask([this, rejectedPromise = RejectedPromise { vm, globalObject, promise }] (ScriptExecutionContext&) mutable {
+    m_context.postTask([this, rejectedPromise = DOMPromise::create(globalObject, promise)] (ScriptExecutionContext&) mutable {
         reportRejectionHandled(WTFMove(rejectedPromise));
     });
 }
@@ -171,8 +154,11 @@ void RejectedPromiseTracker::reportUnhandledRejections(Vector<UnhandledPromise>&
     JSC::JSLockHolder lock(vm);
 
     for (auto& unhandledPromise : unhandledPromises) {
-        ExecState& state = *unhandledPromise.globalObject().globalExec();
-        auto& promise = unhandledPromise.promise();
+        auto& domPromise = unhandledPromise.promise();
+        if (domPromise.isSuspended())
+            continue;
+        auto& state = *domPromise.globalObject()->globalExec();
+        auto& promise = *domPromise.promise();
 
         if (promise.isHandled(vm))
             continue;
@@ -187,25 +173,29 @@ void RejectedPromiseTracker::reportUnhandledRejections(Vector<UnhandledPromise>&
         bool needsDefaultAction = target->dispatchEvent(event);
 
         if (needsDefaultAction)
-            m_context.reportUnhandledPromiseRejection(state, unhandledPromise.promise(), unhandledPromise.callStack());
+            m_context.reportUnhandledPromiseRejection(state, promise, unhandledPromise.callStack());
 
         if (!promise.isHandled(vm))
             m_outstandingRejectedPromises.set(&promise, &promise);
     }
 }
 
-void RejectedPromiseTracker::reportRejectionHandled(RejectedPromise&& rejectedPromise)
+void RejectedPromiseTracker::reportRejectionHandled(Ref<DOMPromise>&& rejectedPromise)
 {
     // https://html.spec.whatwg.org/multipage/webappapis.html#the-hostpromiserejectiontracker-implementation
 
     VM& vm = m_context.vm();
     JSC::JSLockHolder lock(vm);
 
-    ExecState& state = *rejectedPromise.globalObject().globalExec();
+    if (rejectedPromise->isSuspended())
+        return;
+
+    auto& state = *rejectedPromise->globalObject()->globalExec();
+    auto& promise = *rejectedPromise->promise();
 
     PromiseRejectionEvent::Init initializer;
-    initializer.promise = &rejectedPromise.promise();
-    initializer.reason = rejectedPromise.promise().result(state.vm());
+    initializer.promise = &promise;
+    initializer.reason = promise.result(vm);
 
     auto event = PromiseRejectionEvent::create(state, eventNames().rejectionhandledEvent, initializer);
     auto target = m_context.errorEventTarget();
index d58ff5f..ac7c164 100644 (file)
@@ -38,8 +38,8 @@ class VM;
 
 namespace WebCore {
 
+class DOMPromise;
 class JSDOMGlobalObject;
-class RejectedPromise;
 class ScriptExecutionContext;
 class UnhandledPromise;
 
@@ -56,7 +56,7 @@ public:
 
 private:
     void reportUnhandledRejections(Vector<UnhandledPromise>&&);
-    void reportRejectionHandled(RejectedPromise&&);
+    void reportRejectionHandled(Ref<DOMPromise>&&);
 
     ScriptExecutionContext& m_context;
     Vector<UnhandledPromise> m_aboutToBeNotifiedRejectedPromises;
index aa2bf97..6a198af 100644 (file)
@@ -53,7 +53,7 @@
 #include "HTMLSourceElement.h"
 #include "HTMLVideoElement.h"
 #include "JSDOMError.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "JSHTMLMediaElement.h"
 #include "Language.h"
 #include "Logging.h"
@@ -1012,7 +1012,7 @@ void HTMLMediaElement::scheduleResolvePendingPlayPromises()
 
 void HTMLMediaElement::rejectPendingPlayPromises(DOMError& error)
 {
-    Vector<DOMPromise<void>> pendingPlayPromises = WTFMove(m_pendingPlayPromises);
+    Vector<DOMPromiseDeferred<void>> pendingPlayPromises = WTFMove(m_pendingPlayPromises);
 
     for (auto& promise : pendingPlayPromises)
         promise.rejectType<IDLInterface<DOMError>>(error);
@@ -1020,7 +1020,7 @@ void HTMLMediaElement::rejectPendingPlayPromises(DOMError& error)
 
 void HTMLMediaElement::resolvePendingPlayPromises()
 {
-    Vector<DOMPromise<void>> pendingPlayPromises = WTFMove(m_pendingPlayPromises);
+    Vector<DOMPromiseDeferred<void>> pendingPlayPromises = WTFMove(m_pendingPlayPromises);
 
     for (auto& promise : pendingPlayPromises)
         promise.resolve();
@@ -3136,7 +3136,7 @@ void HTMLMediaElement::setPreload(const String& preload)
     setAttributeWithoutSynchronization(preloadAttr, preload);
 }
 
-void HTMLMediaElement::play(DOMPromise<void>&& promise)
+void HTMLMediaElement::play(DOMPromiseDeferred<void>&& promise)
 {
     LOG(Media, "HTMLMediaElement::play(%p)", this);
 
index 96e0a95..18d6fbf 100644 (file)
@@ -93,7 +93,7 @@ class VideoTrackList;
 class VideoTrackPrivate;
 class WebKitMediaKeys;
 
-template<typename> class DOMPromise;
+template<typename> class DOMPromiseDeferred;
 
 #if ENABLE(VIDEO_TRACK)
 using CueIntervalTree = PODIntervalTree<MediaTime, TextTrackCue*>;
@@ -238,7 +238,7 @@ public:
     bool loop() const;
     void setLoop(bool b);
 
-    void play(DOMPromise<void>&&);
+    void play(DOMPromiseDeferred<void>&&);
 
     WEBCORE_EXPORT void play() override;
     WEBCORE_EXPORT void pause() override;
@@ -871,7 +871,7 @@ private:
     RefPtr<TimeRanges> m_playedTimeRanges;
     GenericEventQueue m_asyncEventQueue;
 
-    Vector<DOMPromise<void>> m_pendingPlayPromises;
+    Vector<DOMPromiseDeferred<void>> m_pendingPlayPromises;
 
     double m_requestedPlaybackRate { 1 };
     double m_reportedPlaybackRate { 1 };
index bf11c3f..e83d60f 100644 (file)
@@ -28,7 +28,7 @@
 
 #if ENABLE(WEBGPU)
 
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
index ba8a215..837a542 100644 (file)
@@ -29,7 +29,7 @@
 #include "CSSComputedStyleDeclaration.h"
 #include "ContextDestructionObserver.h"
 #include "ExceptionOr.h"
-#include "JSDOMPromise.h"
+#include "JSDOMPromiseDeferred.h"
 #include "PageConsoleClient.h"
 #include "RealtimeMediaSource.h"
 #include <runtime/Float32Array.h>
@@ -573,7 +573,7 @@ public:
     unsigned long trackAudioSampleCount() const { return m_trackAudioSampleCount; }
     unsigned long trackVideoSampleCount() const { return m_trackVideoSampleCount; }
     void observeMediaStreamTrack(MediaStreamTrack&);
-    using TrackFramePromise = DOMPromise<IDLInterface<ImageData>>;
+    using TrackFramePromise = DOMPromiseDeferred<IDLInterface<ImageData>>;
     void grabNextMediaStreamTrackFrame(TrackFramePromise&&);
 #endif