Changeset 223725 in webkit
- Timestamp:
- Oct 19, 2017 4:31:03 PM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r223720 r223725 1 2017-10-19 Sam Weinig <sam@webkit.org> 2 3 [Bindings] Standardize on DOMPromise as the way to store passed in promises 4 https://bugs.webkit.org/show_bug.cgi?id=178533 5 6 Reviewed by Youenn Fablet. 7 8 This standardizes on RefPtr<DOMPromise> as the canonical way to store a promise 9 that has been passed in from JS. This does not change promises that start off in 10 WebCore and are passed to JS; they remain using DOMPromiseDeferred and DOMPromiseProxy. 11 12 * Modules/paymentrequest/PaymentRequestUpdateEvent.cpp: 13 * Modules/paymentrequest/PaymentRequestUpdateEvent.h: 14 * dom/PromiseRejectionEvent.cpp: 15 * dom/PromiseRejectionEvent.h: 16 * dom/RejectedPromiseTracker.cpp: 17 18 Use a RefPtr<DOMPromise> rather than a JSPromise* to hold onto the promise. 19 20 * bindings/IDLTypes.h: 21 22 Use IDLWrapper to get better defaults, since DOMPromise is refcounted. 23 24 * bindings/js/JSDOMConvertPromise.h: 25 (WebCore::Converter<IDLPromise<T>>::convert): 26 27 Switch default conversion to return a RefPtr<DOMPromise> rather than a JSPromise* 28 29 (WebCore::JSConverter<IDLPromise<T>>::convert): 30 31 Add support for converting from a DOMPromise to a JSValue. 32 33 * bindings/js/JSDOMPromise.cpp: 34 * bindings/js/JSDOMPromise.h: 35 (WebCore::DOMPromise::create): Deleted. 36 37 Remove now unused constructor. 38 39 * workers/service/ExtendableEvent.cpp: 40 (WebCore::ExtendableEvent::waitUntil): 41 * workers/service/ExtendableEvent.h: 42 * workers/service/ExtendableEvent.idl: 43 * workers/service/FetchEvent.cpp: 44 (WebCore::FetchEvent::respondWith): 45 (WebCore::FetchEvent::promiseIsSettled): 46 * workers/service/FetchEvent.h: 47 * workers/service/FetchEvent.idl: 48 49 Address FIXMEs and remove need for passing an ExecState to ExtendableEvent 50 and FetchEvent by using the new default conversion to DOMPromise. 51 1 52 2017-10-19 Sam Weinig <sam@webkit.org> 2 53 -
trunk/Source/WebCore/Modules/paymentrequest/PaymentRequestUpdateEvent.cpp
r220955 r223725 35 35 } 36 36 37 void PaymentRequestUpdateEvent::updateWith( JSC::JSPromise*)37 void PaymentRequestUpdateEvent::updateWith(Ref<DOMPromise>&&) 38 38 { 39 39 } -
trunk/Source/WebCore/Modules/paymentrequest/PaymentRequestUpdateEvent.h
r220955 r223725 30 30 #include "Event.h" 31 31 32 namespace JSC { 33 class JSPromise; 34 } 32 namespace WebCore { 35 33 36 namespace WebCore { 34 class DOMPromise; 37 35 38 36 class PaymentRequestUpdateEvent final : public Event { 39 37 public: 40 38 ~PaymentRequestUpdateEvent(); 41 void updateWith( JSC::JSPromise*);39 void updateWith(Ref<DOMPromise>&&); 42 40 }; 43 41 -
trunk/Source/WebCore/bindings/IDLTypes.h
r220620 r223725 221 221 }; 222 222 223 template<typename T> struct IDLPromise : IDL Type<DOMPromise> {223 template<typename T> struct IDLPromise : IDLWrapper<DOMPromise> { 224 224 using InnerType = T; 225 225 }; -
trunk/Source/WebCore/bindings/js/JSDOMConvertPromise.h
r220433 r223725 33 33 34 34 template<typename T> struct Converter<IDLPromise<T>> : DefaultConverter<IDLPromise<T>> { 35 using ReturnType = JSC::JSPromise*;35 using ReturnType = RefPtr<DOMPromise>; 36 36 37 37 // https://heycam.github.io/webidl/#es-promise … … 55 55 56 56 // 3. Return the IDL promise type value that is a reference to the same object as promise. 57 return promise;57 return DOMPromise::create(*globalObject, *promise); 58 58 } 59 59 }; … … 63 63 static constexpr bool needsGlobalObject = true; 64 64 65 static JSC::JSValue convert(JSC::ExecState&, JSDOMGlobalObject&, JSC::JSPromise& promise)65 static JSC::JSValue convert(JSC::ExecState&, JSDOMGlobalObject&, DOMPromise& promise) 66 66 { 67 return &promise;67 return promise.promise(); 68 68 } 69 69 -
trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp
r223562 r223725 50 50 } 51 51 52 Ref<DOMPromise> DOMPromise::create(JSC::ExecState& state, JSC::JSValue value)53 {54 auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject());55 56 auto promiseConstructor = globalObject.promiseConstructor();57 auto resolveFunction = promiseConstructor->get(&state, state.vm().propertyNames->builtinNames().resolvePrivateName());58 ASSERT(resolveFunction.isFunction());59 60 JSC::MarkedArgumentBuffer arguments;61 arguments.append(value);62 auto result = callFunction(state, resolveFunction, promiseConstructor, arguments);63 64 auto* promise = JSC::jsCast<JSC::JSPromise*>(result);65 ASSERT(promise);66 67 return create(globalObject, *promise);68 }69 70 52 void DOMPromise::whenSettled(std::function<void()>&& callback) 71 53 { -
trunk/Source/WebCore/bindings/js/JSDOMPromise.h
r223562 r223725 34 34 class DOMPromise : public DOMGuarded<JSC::JSPromise> { 35 35 public: 36 static Ref<DOMPromise> create(JSC::ExecState&, JSC::JSValue);37 36 static Ref<DOMPromise> create(JSDOMGlobalObject& globalObject, JSC::JSPromise& promise) 38 37 { -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r223476 r223725 1545 1545 } 1546 1546 1547 return "${name}.releaseNonNull()" if $codeGenerator->IsCallbackInterface($type) || $codeGenerator->IsCallbackFunction($type) ;1547 return "${name}.releaseNonNull()" if $codeGenerator->IsCallbackInterface($type) || $codeGenerator->IsCallbackFunction($type) || $codeGenerator->IsPromiseType($type); 1548 1548 return "*${name}" if $codeGenerator->IsWrapperType($type); 1549 1549 return "WTFMove(${name})"; -
trunk/Source/WebCore/dom/PromiseRejectionEvent.cpp
r223476 r223725 28 28 29 29 #include "DOMWrapperWorld.h" 30 #include "JSDOMPromise.h" 30 31 #include <heap/HeapInlines.h> 31 32 #include <heap/StrongInlines.h> 32 33 33 34 34 namespace WebCore { … … 37 37 PromiseRejectionEvent::PromiseRejectionEvent(ExecState& state, const AtomicString& type, const Init& initializer, IsTrusted isTrusted) 38 38 : Event(type, initializer, isTrusted) 39 , m_promise( state.vm(), initializer.promise)39 , m_promise(*(initializer.promise)) 40 40 , m_reason(state.vm(), initializer.reason) 41 41 { -
trunk/Source/WebCore/dom/PromiseRejectionEvent.h
r218593 r223725 28 28 #include "Event.h" 29 29 #include <heap/Strong.h> 30 #include <runtime/JSPromise.h>31 30 32 31 namespace WebCore { 32 33 class DOMPromise; 33 34 34 35 class PromiseRejectionEvent final : public Event { 35 36 public: 36 37 struct Init : EventInit { 37 JSC::JSPromise*promise;38 RefPtr<DOMPromise> promise; 38 39 JSC::JSValue reason; 39 40 }; … … 46 47 virtual ~PromiseRejectionEvent(); 47 48 48 JSC::JSPromise& promise() const { return *m_promise.get(); }49 DOMPromise& promise() const { return m_promise.get(); } 49 50 JSC::JSValue reason() const { return m_reason.get(); } 50 51 … … 54 55 PromiseRejectionEvent(JSC::ExecState&, const AtomicString&, const Init&, IsTrusted); 55 56 56 JSC::Strong<JSC::JSPromise> m_promise;57 Ref<DOMPromise> m_promise; 57 58 JSC::Strong<JSC::Unknown> m_reason; 58 59 }; -
trunk/Source/WebCore/dom/RejectedPromiseTracker.cpp
r223476 r223725 167 167 PromiseRejectionEvent::Init initializer; 168 168 initializer.cancelable = true; 169 initializer.promise = & promise;169 initializer.promise = &domPromise; 170 170 initializer.reason = promise.result(vm); 171 171 … … 196 196 197 197 PromiseRejectionEvent::Init initializer; 198 initializer.promise = &promise;198 initializer.promise = rejectedPromise.ptr(); 199 199 initializer.reason = promise.result(vm); 200 200 -
trunk/Source/WebCore/workers/service/ExtendableEvent.cpp
r223562 r223725 29 29 #if ENABLE(SERVICE_WORKER) 30 30 31 #include "JSDOMPromise.h" 32 31 33 namespace WebCore { 32 34 … … 36 38 } 37 39 38 ExceptionOr<void> ExtendableEvent::waitUntil( JSC::ExecState& state, JSC::JSValuepromise)40 ExceptionOr<void> ExtendableEvent::waitUntil(Ref<DOMPromise>&& promise) 39 41 { 40 42 if (!isTrusted()) … … 44 46 return Exception { InvalidStateError, ASCIILiteral("Event is being dispatched") }; 45 47 46 addPendingPromise(DOMPromise::create(state, promise)); 47 48 addPendingPromise(WTFMove(promise)); 48 49 return { }; 49 50 } -
trunk/Source/WebCore/workers/service/ExtendableEvent.h
r223562 r223725 30 30 #include "Event.h" 31 31 #include "ExtendableEventInit.h" 32 #include "JSDOMPromise.h"33 32 #include <wtf/WeakPtr.h> 34 33 35 34 namespace WebCore { 35 36 class DOMPromise; 36 37 37 38 class ExtendableEvent : public Event { … … 44 45 EventInterface eventInterface() const override { return ExtendableEventInterfaceType; } 45 46 46 ExceptionOr<void> waitUntil( JSC::ExecState&, JSC::JSValue);47 ExceptionOr<void> waitUntil(Ref<DOMPromise>&&); 47 48 48 49 WEBCORE_EXPORT void onFinishedWaitingForTesting(WTF::Function<void()>&&); -
trunk/Source/WebCore/workers/service/ExtendableEvent.idl
r223562 r223725 24 24 */ 25 25 26 // FIXME: Should be exposed on ServiceWorker only.26 // FIXME: Should be exposed on ServiceWorker only. 27 27 [ 28 28 Constructor(DOMString type, optional ExtendableEventInit eventInitDict), … … 32 32 ExportMacro=WEBCORE_EXPORT, 33 33 JSGenerateToNativeObject, 34 ] 35 interface ExtendableEvent : Event { 36 // FIXME: Binding generator should be able to wrap any non Promise value into a promise and pass it to waitUntil. 37 [CallWith=ScriptState, MayThrowException] void waitUntil(any f); 34 ] interface ExtendableEvent : Event { 35 [MayThrowException] void waitUntil(Promise<any> f); 38 36 }; -
trunk/Source/WebCore/workers/service/FetchEvent.cpp
r223577 r223725 27 27 #include "FetchEvent.h" 28 28 29 #include "JSDOMPromise.h" 29 30 #include "JSFetchResponse.h" 30 31 … … 42 43 } 43 44 44 ExceptionOr<void> FetchEvent::respondWith( JSC::ExecState& state, JSC::JSValuepromise)45 ExceptionOr<void> FetchEvent::respondWith(Ref<DOMPromise>&& promise) 45 46 { 46 47 if (isBeingDispatched()) … … 50 51 return Exception { InvalidStateError, ASCIILiteral("Event respondWith flag is set") }; 51 52 52 m_respondPromise = DOMPromise::create(state,promise);53 m_respondPromise = WTFMove(promise); 53 54 addPendingPromise(*m_respondPromise); 54 55 … … 134 135 135 136 auto body = m_response->consumeBody(); 136 WTF::switchOn(body, [] (Ref<FormData>&) { 137 // FIXME: Support FormData response bodies. 138 }, [this] (Ref<SharedBuffer>& buffer) { 139 m_responseBody = WTFMove(buffer); 140 }, [] (std::nullptr_t&) { 141 }); 137 WTF::switchOn(body, 138 [] (Ref<FormData>&) { 139 // FIXME: Support FormData response bodies. 140 }, 141 [this] (Ref<SharedBuffer>& buffer) { 142 m_responseBody = WTFMove(buffer); 143 }, 144 [] (std::nullptr_t&) { 145 } 146 ); 142 147 143 148 processResponse(); -
trunk/Source/WebCore/workers/service/FetchEvent.h
r223562 r223725 50 50 EventInterface eventInterface() const final { return FetchEventInterfaceType; } 51 51 52 ExceptionOr<void> respondWith( JSC::ExecState&, JSC::JSValue);52 ExceptionOr<void> respondWith(Ref<DOMPromise>&&); 53 53 54 54 WEBCORE_EXPORT void onResponse(WTF::Function<void()>&&); -
trunk/Source/WebCore/workers/service/FetchEvent.idl
r223562 r223725 24 24 */ 25 25 26 // FIXME: Should be exposed on ServiceWorker only.26 // FIXME: Should be exposed on ServiceWorker only. 27 27 [ 28 28 Constructor(DOMString type, FetchEventInit eventInitDict), … … 33 33 ExportToWrappedFunction, 34 34 JSGenerateToNativeObject 35 ] 36 interface FetchEvent : ExtendableEvent { 35 ] interface FetchEvent : ExtendableEvent { 37 36 [SameObject] readonly attribute FetchRequest request; 38 37 readonly attribute DOMString clientId; … … 40 39 readonly attribute DOMString targetClientId; 41 40 42 // FIXME: Binding generator should be able to wrap any non Promise value into a promise and pass it to respondWith. 43 [CallWith=ScriptState, MayThrowException] void respondWith(any r); 41 [MayThrowException] void respondWith(Promise<FetchResponse> r); 44 42 }; 45 43
Note: See TracChangeset
for help on using the changeset viewer.