Title: [206977] trunk/Source/WebCore
Revision
206977
Author
[email protected]
Date
2016-10-09 19:14:05 -0700 (Sun, 09 Oct 2016)

Log Message

Move ApplePaySession from legacy to new DOM exceptions
https://bugs.webkit.org/show_bug.cgi?id=163191

Reviewed by Sam Weinig.

* Modules/applepay/ApplePaySession.cpp:
(WebCore::ApplePaySession::create): Use ExceptionOr.
(WebCore::ApplePaySession::ApplePaySession): Moved initialization
of two of the data members to class definition.
(WebCore::ApplePaySession::supportsVersion): Use ExceptionOr.
(WebCore::ApplePaySession::canMakePayments): Ditto.
(WebCore::ApplePaySession::canMakePaymentsWithActiveCard): Ditto.
(WebCore::ApplePaySession::openPaymentSetup): Ditto.
(WebCore::ApplePaySession::begin): Ditto.
(WebCore::ApplePaySession::abort): Ditto.
(WebCore::ApplePaySession::completeMerchantValidation): Ditto.
(WebCore::ApplePaySession::completeShippingMethodSelection): Ditto.
(WebCore::ApplePaySession::completeShippingContactSelection): Ditto.
(WebCore::ApplePaySession::completePaymentMethodSelection): Ditto.
(WebCore::ApplePaySession::completePayment): Ditto.
(WebCore::ApplePaySession::validateMerchant): Use auto and get instead of
using a RefPtr type and * for event dispatching.
(WebCore::ApplePaySession::didAuthorizePayment): Ditto.
(WebCore::ApplePaySession::didSelectShippingMethod): Ditto.
(WebCore::ApplePaySession::didSelectShippingContact): Ditto.
(WebCore::ApplePaySession::didSelectPaymentMethod): Ditto.
(WebCore::ApplePaySession::didCancelPayment): Ditto.
(WebCore::ApplePaySession::paymentCoordinator): Moved dereferencing
inside the downcast.

* Modules/applepay/ApplePaySession.h: Updated for changes above.

* Modules/applepay/ApplePaySession.idl: Use MayThrowException.

* bindings/js/JSApplePaySessionCustom.cpp:
(WebCore::JSApplePaySession::completeShippingMethodSelection):
Use propagateException.
(WebCore::JSApplePaySession::completeShippingContactSelection): Ditto.
(WebCore::JSApplePaySession::completePaymentMethodSelection): Ditto.

* bindings/js/JSDOMBinding.h: Added implementation of toJSBoolean.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateConstructorDefinition): Generate the different arguments for
toJSNewlyCreated when ConstructorMayThrowException is specified that
activate the version of that function that handles exceptions.

* bindings/scripts/IDLAttributes.txt: Added ConstructorMayThrowException.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (206976 => 206977)


--- trunk/Source/WebCore/ChangeLog	2016-10-10 02:13:28 UTC (rev 206976)
+++ trunk/Source/WebCore/ChangeLog	2016-10-10 02:14:05 UTC (rev 206977)
@@ -1,5 +1,56 @@
 2016-10-09  Darin Adler  <[email protected]>
 
+        Move ApplePaySession from legacy to new DOM exceptions
+        https://bugs.webkit.org/show_bug.cgi?id=163191
+
+        Reviewed by Sam Weinig.
+
+        * Modules/applepay/ApplePaySession.cpp:
+        (WebCore::ApplePaySession::create): Use ExceptionOr.
+        (WebCore::ApplePaySession::ApplePaySession): Moved initialization
+        of two of the data members to class definition.
+        (WebCore::ApplePaySession::supportsVersion): Use ExceptionOr.
+        (WebCore::ApplePaySession::canMakePayments): Ditto.
+        (WebCore::ApplePaySession::canMakePaymentsWithActiveCard): Ditto.
+        (WebCore::ApplePaySession::openPaymentSetup): Ditto.
+        (WebCore::ApplePaySession::begin): Ditto.
+        (WebCore::ApplePaySession::abort): Ditto.
+        (WebCore::ApplePaySession::completeMerchantValidation): Ditto.
+        (WebCore::ApplePaySession::completeShippingMethodSelection): Ditto.
+        (WebCore::ApplePaySession::completeShippingContactSelection): Ditto.
+        (WebCore::ApplePaySession::completePaymentMethodSelection): Ditto.
+        (WebCore::ApplePaySession::completePayment): Ditto.
+        (WebCore::ApplePaySession::validateMerchant): Use auto and get instead of
+        using a RefPtr type and * for event dispatching.
+        (WebCore::ApplePaySession::didAuthorizePayment): Ditto.
+        (WebCore::ApplePaySession::didSelectShippingMethod): Ditto.
+        (WebCore::ApplePaySession::didSelectShippingContact): Ditto.
+        (WebCore::ApplePaySession::didSelectPaymentMethod): Ditto.
+        (WebCore::ApplePaySession::didCancelPayment): Ditto.
+        (WebCore::ApplePaySession::paymentCoordinator): Moved dereferencing
+        inside the downcast.
+
+        * Modules/applepay/ApplePaySession.h: Updated for changes above.
+
+        * Modules/applepay/ApplePaySession.idl: Use MayThrowException.
+
+        * bindings/js/JSApplePaySessionCustom.cpp:
+        (WebCore::JSApplePaySession::completeShippingMethodSelection):
+        Use propagateException.
+        (WebCore::JSApplePaySession::completeShippingContactSelection): Ditto.
+        (WebCore::JSApplePaySession::completePaymentMethodSelection): Ditto.
+
+        * bindings/js/JSDOMBinding.h: Added implementation of toJSBoolean.
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateConstructorDefinition): Generate the different arguments for
+        toJSNewlyCreated when ConstructorMayThrowException is specified that
+        activate the version of that function that handles exceptions.
+
+        * bindings/scripts/IDLAttributes.txt: Added ConstructorMayThrowException.
+
+2016-10-09  Darin Adler  <[email protected]>
+
         Replace all uses of ExceptionCodeWithMessage with WebCore::Exception
         https://bugs.webkit.org/show_bug.cgi?id=163178
 

Modified: trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp (206976 => 206977)


--- trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp	2016-10-10 02:13:28 UTC (rev 206976)
+++ trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp	2016-10-10 02:14:05 UTC (rev 206977)
@@ -635,7 +635,7 @@
     return true;
 }
 
-RefPtr<ApplePaySession> ApplePaySession::create(Document& document, unsigned version, const Dictionary& dictionary, ExceptionCode& ec)
+ExceptionOr<Ref<ApplePaySession>> ApplePaySession::create(Document& document, unsigned version, const Dictionary& dictionary)
 {
     DOMWindow& window = *document.domWindow();
 
@@ -642,14 +642,12 @@
     String errorMessage;
     if (!canCallApplePaySessionAPIs(document, errorMessage)) {
         window.printErrorMessage(errorMessage);
-        ec = INVALID_ACCESS_ERR;
-        return nullptr;
+        return Exception { INVALID_ACCESS_ERR };
     }
 
     if (!ScriptController::processingUserGesture()) {
         window.printErrorMessage("Must create a new ApplePaySession from a user gesture handler.");
-        ec = INVALID_ACCESS_ERR;
-        return nullptr;
+        return Exception { INVALID_ACCESS_ERR };
     }
 
     auto& paymentCoordinator = document.frame()->mainFrame().paymentCoordinator();
@@ -656,28 +654,21 @@
 
     if (!version || !paymentCoordinator.supportsVersion(version)) {
         window.printErrorMessage(makeString("\"" + String::number(version), "\" is not a supported version."));
-        ec = INVALID_ACCESS_ERR;
-        return nullptr;
+        return Exception { INVALID_ACCESS_ERR };
     }
 
     auto paymentRequest = createPaymentRequest(version, window, dictionary);
-    if (!paymentRequest) {
-        ec = TYPE_MISMATCH_ERR;
-        return nullptr;
-    }
+    if (!paymentRequest)
+        return Exception { TYPE_MISMATCH_ERR };
 
-    if (!PaymentRequestValidator(window).validate(*paymentRequest)) {
-        ec = INVALID_ACCESS_ERR;
-        return nullptr;
-    }
+    if (!PaymentRequestValidator(window).validate(*paymentRequest))
+        return Exception { INVALID_ACCESS_ERR };
 
-    return adoptRef(new ApplePaySession(document, WTFMove(*paymentRequest)));
+    return adoptRef(*new ApplePaySession(document, WTFMove(*paymentRequest)));
 }
 
 ApplePaySession::ApplePaySession(Document& document, PaymentRequest&& paymentRequest)
     : ActiveDOMObject(&document)
-    , m_state(State::Idle)
-    , m_merchantValidationState(MerchantValidationState::Idle)
     , m_paymentRequest(WTFMove(paymentRequest))
 {
     suspendIfNeeded();
@@ -687,12 +678,10 @@
 {
 }
 
-bool ApplePaySession::supportsVersion(ScriptExecutionContext& scriptExecutionContext, unsigned version, ExceptionCode& ec)
+ExceptionOr<bool> ApplePaySession::supportsVersion(ScriptExecutionContext& scriptExecutionContext, unsigned version)
 {
-    if (!version) {
-        ec = INVALID_ACCESS_ERR;
-        return false;
-    }
+    if (!version)
+        return Exception { INVALID_ACCESS_ERR };
 
     auto& document = downcast<Document>(scriptExecutionContext);
     DOMWindow& window = *document.domWindow();
@@ -700,12 +689,10 @@
     String errorMessage;
     if (!canCallApplePaySessionAPIs(document, errorMessage)) {
         window.printErrorMessage(errorMessage);
-        ec = INVALID_ACCESS_ERR;
-        return false;
+        return Exception { INVALID_ACCESS_ERR };
     }
 
-    auto& paymentCoordinator = document.frame()->mainFrame().paymentCoordinator();
-    return paymentCoordinator.supportsVersion(version);
+    return document.frame()->mainFrame().paymentCoordinator().supportsVersion(version);
 }
 
 static bool shouldDiscloseApplePayCapability(Document& document)
@@ -717,7 +704,7 @@
     return document.frame()->settings().applePayCapabilityDisclosureAllowed();
 }
 
-bool ApplePaySession::canMakePayments(ScriptExecutionContext& scriptExecutionContext, ExceptionCode& ec)
+ExceptionOr<bool> ApplePaySession::canMakePayments(ScriptExecutionContext& scriptExecutionContext)
 {
     auto& document = downcast<Document>(scriptExecutionContext);
     DOMWindow& window = *document.domWindow();
@@ -725,15 +712,13 @@
     String errorMessage;
     if (!canCallApplePaySessionAPIs(document, errorMessage)) {
         window.printErrorMessage(errorMessage);
-        ec = INVALID_ACCESS_ERR;
-        return false;
+        return Exception { INVALID_ACCESS_ERR };
     }
 
-    auto& paymentCoordinator = document.frame()->mainFrame().paymentCoordinator();
-    return paymentCoordinator.canMakePayments();
+    return document.frame()->mainFrame().paymentCoordinator().canMakePayments();
 }
 
-void ApplePaySession::canMakePaymentsWithActiveCard(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredPromise>&& passedPromise, ExceptionCode& ec)
+ExceptionOr<void> ApplePaySession::canMakePaymentsWithActiveCard(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredPromise>&& passedPromise)
 {
     auto& document = downcast<Document>(scriptExecutionContext);
     DOMWindow& window = *document.domWindow();
@@ -741,8 +726,7 @@
     String errorMessage;
     if (!canCallApplePaySessionAPIs(document, errorMessage)) {
         window.printErrorMessage(errorMessage);
-        ec = INVALID_ACCESS_ERR;
-        return;
+        return Exception { INVALID_ACCESS_ERR };
     }
 
     RefPtr<DeferredPromise> promise(WTFMove(passedPromise));
@@ -753,7 +737,7 @@
         RunLoop::main().dispatch([promise, canMakePayments]() mutable {
             promise->resolve(canMakePayments);
         });
-        return;
+        return { };
     }
 
     auto& paymentCoordinator = document.frame()->mainFrame().paymentCoordinator();
@@ -761,9 +745,10 @@
     paymentCoordinator.canMakePaymentsWithActiveCard(merchantIdentifier, document.domain(), [promise](bool canMakePayments) mutable {
         promise->resolve(canMakePayments);
     });
+    return { };
 }
 
-void ApplePaySession::openPaymentSetup(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredPromise>&& passedPromise, ExceptionCode& ec)
+ExceptionOr<void> ApplePaySession::openPaymentSetup(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredPromise>&& passedPromise)
 {
     auto& document = downcast<Document>(scriptExecutionContext);
     DOMWindow& window = *document.domWindow();
@@ -771,14 +756,12 @@
     String errorMessage;
     if (!canCallApplePaySessionAPIs(document, errorMessage)) {
         window.printErrorMessage(errorMessage);
-        ec = INVALID_ACCESS_ERR;
-        return;
+        return Exception { INVALID_ACCESS_ERR };
     }
 
     if (!ScriptController::processingUserGesture()) {
         window.printErrorMessage("Must call ApplePaySession.openPaymentSetup from a user gesture handler.");
-        ec = INVALID_ACCESS_ERR;
-        return;
+        return Exception { INVALID_ACCESS_ERR };
     }
 
     RefPtr<DeferredPromise> promise(WTFMove(passedPromise));
@@ -787,9 +770,11 @@
     paymentCoordinator.openPaymentSetup(merchantIdentifier, document.domain(), [promise](bool result) mutable {
         promise->resolve(result);
     });
+
+    return { };
 }
 
-void ApplePaySession::begin(ExceptionCode& ec)
+ExceptionOr<void> ApplePaySession::begin()
 {
     auto& document = *downcast<Document>(scriptExecutionContext());
     auto& window = *document.domWindow();
@@ -796,15 +781,12 @@
 
     if (!canBegin()) {
         window.printErrorMessage("Payment session is already active.");
-        ec = INVALID_ACCESS_ERR;
-        return;
+        return Exception { INVALID_ACCESS_ERR };
     }
 
     if (paymentCoordinator().hasActiveSession()) {
         window.printErrorMessage("Page already has an active payment session.");
-
-        ec = INVALID_ACCESS_ERR;
-        return;
+        return Exception { INVALID_ACCESS_ERR };
     }
 
     Vector<URL> linkIconURLs;
@@ -813,40 +795,36 @@
 
     if (!paymentCoordinator().beginPaymentSession(*this, document.url(), linkIconURLs, m_paymentRequest)) {
         window.printErrorMessage("There is already has an active payment session.");
-
-        ec = INVALID_ACCESS_ERR;
-        return;
+        return Exception { INVALID_ACCESS_ERR };
     }
 
     m_state = State::Active;
 
     setPendingActivity(this);
+
+    return { };
 }
 
-void ApplePaySession::abort(ExceptionCode& ec)
+ExceptionOr<void> ApplePaySession::abort()
 {
-    if (!canAbort()) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!canAbort())
+        return Exception { INVALID_ACCESS_ERR };
 
     m_state = State::Aborted;
     paymentCoordinator().abortPaymentSession();
 
     didReachFinalState();
+
+    return { };
 }
 
-void ApplePaySession::completeMerchantValidation(const Dictionary& merchantSessionDictionary, ExceptionCode& ec)
+ExceptionOr<void> ApplePaySession::completeMerchantValidation(const Dictionary& merchantSessionDictionary)
 {
-    if (!canCompleteMerchantValidation()) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!canCompleteMerchantValidation())
+        return Exception { INVALID_ACCESS_ERR };
 
-    if (!merchantSessionDictionary.initializerObject()) {
-        ec = TypeError;
-        return;
-    }
+    if (!merchantSessionDictionary.initializerObject())
+        return Exception { TypeError };
 
     auto& document = *downcast<Document>(scriptExecutionContext());
     auto& window = *document.domWindow();
@@ -855,15 +833,15 @@
     auto merchantSession = PaymentMerchantSession::fromJS(*merchantSessionDictionary.execState(), merchantSessionDictionary.initializerObject(), errorMessage);
     if (!merchantSession) {
         window.printErrorMessage(errorMessage);
-        ec = INVALID_ACCESS_ERR;
-        return;
+        return Exception { INVALID_ACCESS_ERR };
     }
 
     m_merchantValidationState = MerchantValidationState::ValidationComplete;
     paymentCoordinator().completeMerchantValidation(*merchantSession);
+
+    return { };
 }
 
-
 static Optional<PaymentAuthorizationStatus> toPaymentAuthorizationStatus(unsigned short status)
 {
     switch (status) {
@@ -896,36 +874,26 @@
     }
 }
 
-void ApplePaySession::completeShippingMethodSelection(unsigned short status, const Dictionary& newTotalDictionary, const ArrayValue& newLineItemsArray, ExceptionCode& ec)
+ExceptionOr<void> ApplePaySession::completeShippingMethodSelection(unsigned short status, const Dictionary& newTotalDictionary, const ArrayValue& newLineItemsArray)
 {
-    if (!canCompleteShippingMethodSelection()) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!canCompleteShippingMethodSelection())
+        return Exception { INVALID_ACCESS_ERR };
 
     auto authorizationStatus = toPaymentAuthorizationStatus(status);
-    if (!authorizationStatus) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!authorizationStatus)
+        return Exception { INVALID_ACCESS_ERR };
 
     auto& window = *downcast<Document>(scriptExecutionContext())->domWindow();
     auto newTotal = createLineItem(window, newTotalDictionary);
-    if (!newTotal) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!newTotal)
+        return Exception { INVALID_ACCESS_ERR };
 
-    if (!PaymentRequestValidator(window).validateTotal(*newTotal)) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!PaymentRequestValidator(window).validateTotal(*newTotal))
+        return Exception { INVALID_ACCESS_ERR };
 
     auto newLineItems = createLineItems(window, newLineItemsArray);
-    if (!newLineItems) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!newLineItems)
+        return Exception { INVALID_ACCESS_ERR };
 
     m_state = State::Active;
     PaymentRequest::TotalAndLineItems totalAndLineItems;
@@ -932,45 +900,35 @@
     totalAndLineItems.total = *newTotal;
     totalAndLineItems.lineItems = *newLineItems;
     paymentCoordinator().completeShippingMethodSelection(*authorizationStatus, totalAndLineItems);
+
+    return { };
 }
 
-void ApplePaySession::completeShippingContactSelection(unsigned short status, const ArrayValue& newShippingMethodsArray, const Dictionary& newTotalDictionary, const ArrayValue& newLineItemsArray, ExceptionCode& ec)
+ExceptionOr<void> ApplePaySession::completeShippingContactSelection(unsigned short status, const ArrayValue& newShippingMethodsArray, const Dictionary& newTotalDictionary, const ArrayValue& newLineItemsArray)
 {
-    if (!canCompleteShippingContactSelection()) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!canCompleteShippingContactSelection())
+        return Exception { INVALID_ACCESS_ERR };
 
     auto authorizationStatus = toPaymentAuthorizationStatus(status);
-    if (!authorizationStatus) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!authorizationStatus)
+        return Exception { INVALID_ACCESS_ERR };
 
     auto& window = *downcast<Document>(scriptExecutionContext())->domWindow();
 
     auto newShippingMethods = createShippingMethods(window, newShippingMethodsArray);
-    if (!newShippingMethods) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!newShippingMethods)
+        return Exception { INVALID_ACCESS_ERR };
 
     auto newTotal = createLineItem(window, newTotalDictionary);
-    if (!newTotal) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!newTotal)
+        return Exception { INVALID_ACCESS_ERR };
 
-    if (!PaymentRequestValidator(window).validateTotal(*newTotal)) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!PaymentRequestValidator(window).validateTotal(*newTotal))
+        return Exception { INVALID_ACCESS_ERR };
 
     auto newLineItems = createLineItems(window, newLineItemsArray);
-    if (!newLineItems) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!newLineItems)
+        return Exception { INVALID_ACCESS_ERR };
 
     m_state = State::Active;
     PaymentRequest::TotalAndLineItems totalAndLineItems;
@@ -977,32 +935,26 @@
     totalAndLineItems.total = *newTotal;
     totalAndLineItems.lineItems = *newLineItems;
     paymentCoordinator().completeShippingContactSelection(*authorizationStatus, *newShippingMethods, totalAndLineItems);
+
+    return { };
 }
 
-void ApplePaySession::completePaymentMethodSelection(const Dictionary& newTotalDictionary, const ArrayValue& newLineItemsArray, ExceptionCode& ec)
+ExceptionOr<void> ApplePaySession::completePaymentMethodSelection(const Dictionary& newTotalDictionary, const ArrayValue& newLineItemsArray)
 {
-    if (!canCompletePaymentMethodSelection()) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!canCompletePaymentMethodSelection())
+        return Exception { INVALID_ACCESS_ERR };
 
-    auto& window = *downcast<Document>(scriptExecutionContext())->domWindow();
+    auto& window = *downcast<Document>(*scriptExecutionContext()).domWindow();
     auto newTotal = createLineItem(window, newTotalDictionary);
-    if (!newTotal) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!newTotal)
+        return Exception { INVALID_ACCESS_ERR };
 
-    if (!PaymentRequestValidator(window).validateTotal(*newTotal)) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!PaymentRequestValidator(window).validateTotal(*newTotal))
+        return Exception { INVALID_ACCESS_ERR };
 
     auto newLineItems = createLineItems(window, newLineItemsArray);
-    if (!newLineItems) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!newLineItems)
+        return Exception { INVALID_ACCESS_ERR };
 
     m_state = State::Active;
     PaymentRequest::TotalAndLineItems totalAndLineItems;
@@ -1009,30 +961,29 @@
     totalAndLineItems.total = *newTotal;
     totalAndLineItems.lineItems = *newLineItems;
     paymentCoordinator().completePaymentMethodSelection(totalAndLineItems);
+
+    return { };
 }
 
-void ApplePaySession::completePayment(unsigned short status, ExceptionCode& ec)
+ExceptionOr<void> ApplePaySession::completePayment(unsigned short status)
 {
-    if (!canCompletePayment()) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!canCompletePayment())
+        return Exception { INVALID_ACCESS_ERR };
 
     auto authorizationStatus = toPaymentAuthorizationStatus(status);
-    if (!authorizationStatus) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!authorizationStatus)
+        return Exception { INVALID_ACCESS_ERR };
 
     paymentCoordinator().completePaymentSession(*authorizationStatus);
 
     if (!isFinalStateStatus(*authorizationStatus)) {
         m_state = State::Active;
-        return;
+        return { };
     }
 
     m_state = State::Completed;
     unsetPendingActivity(this);
+    return { };
 }
 
 void ApplePaySession::validateMerchant(const URL& validationURL)
@@ -1053,8 +1004,8 @@
 
     m_merchantValidationState = MerchantValidationState::ValidatingMerchant;
 
-    RefPtr<ApplePayValidateMerchantEvent> event = ApplePayValidateMerchantEvent::create(eventNames().validatemerchantEvent, validationURL);
-    dispatchEvent(*event);
+    auto event = ApplePayValidateMerchantEvent::create(eventNames().validatemerchantEvent, validationURL);
+    dispatchEvent(event.get());
 }
 
 void ApplePaySession::didAuthorizePayment(const Payment& payment)
@@ -1063,8 +1014,8 @@
 
     m_state = State::Authorized;
 
-    RefPtr<ApplePayPaymentAuthorizedEvent> event = ApplePayPaymentAuthorizedEvent::create(eventNames().paymentauthorizedEvent, payment);
-    dispatchEvent(*event);
+    auto event = ApplePayPaymentAuthorizedEvent::create(eventNames().paymentauthorizedEvent, payment);
+    dispatchEvent(event.get());
 }
 
 void ApplePaySession::didSelectShippingMethod(const PaymentRequest::ShippingMethod& shippingMethod)
@@ -1077,8 +1028,8 @@
     }
 
     m_state = State::ShippingMethodSelected;
-    RefPtr<ApplePayShippingMethodSelectedEvent> event = ApplePayShippingMethodSelectedEvent::create(eventNames().shippingmethodselectedEvent, shippingMethod);
-    dispatchEvent(*event);
+    auto event = ApplePayShippingMethodSelectedEvent::create(eventNames().shippingmethodselectedEvent, shippingMethod);
+    dispatchEvent(event.get());
 }
 
 void ApplePaySession::didSelectShippingContact(const PaymentContact& shippingContact)
@@ -1091,8 +1042,8 @@
     }
 
     m_state = State::ShippingContactSelected;
-    RefPtr<ApplePayShippingContactSelectedEvent> event = ApplePayShippingContactSelectedEvent::create(eventNames().shippingcontactselectedEvent, shippingContact);
-    dispatchEvent(*event);
+    auto event = ApplePayShippingContactSelectedEvent::create(eventNames().shippingcontactselectedEvent, shippingContact);
+    dispatchEvent(event.get());
 }
 
 void ApplePaySession::didSelectPaymentMethod(const PaymentMethod& paymentMethod)
@@ -1105,8 +1056,8 @@
     }
 
     m_state = State::PaymentMethodSelected;
-    RefPtr<ApplePayPaymentMethodSelectedEvent> event = ApplePayPaymentMethodSelectedEvent::create(eventNames().paymentmethodselectedEvent, paymentMethod);
-    dispatchEvent(*event);
+    auto event = ApplePayPaymentMethodSelectedEvent::create(eventNames().paymentmethodselectedEvent, paymentMethod);
+    dispatchEvent(event.get());
 }
 
 void ApplePaySession::didCancelPayment()
@@ -1115,8 +1066,8 @@
 
     m_state = State::Canceled;
 
-    RefPtr<Event> event = Event::create(eventNames().cancelEvent, false, false);
-    dispatchEvent(*event);
+    auto event = Event::create(eventNames().cancelEvent, false, false);
+    dispatchEvent(event.get());
 
     didReachFinalState();
 }
@@ -1157,7 +1108,7 @@
 
 PaymentCoordinator& ApplePaySession::paymentCoordinator() const
 {
-    return downcast<Document>(scriptExecutionContext())->frame()->mainFrame().paymentCoordinator();
+    return downcast<Document>(*scriptExecutionContext()).frame()->mainFrame().paymentCoordinator();
 }
 
 bool ApplePaySession::canBegin() const

Modified: trunk/Source/WebCore/Modules/applepay/ApplePaySession.h (206976 => 206977)


--- trunk/Source/WebCore/Modules/applepay/ApplePaySession.h	2016-10-10 02:13:28 UTC (rev 206976)
+++ trunk/Source/WebCore/Modules/applepay/ApplePaySession.h	2016-10-10 02:14:05 UTC (rev 206977)
@@ -29,7 +29,7 @@
 
 #include "ActiveDOMObject.h"
 #include "EventTarget.h"
-#include "ExceptionCode.h"
+#include "ExceptionOr.h"
 #include "PaymentRequest.h"
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
@@ -48,7 +48,7 @@
 
 class ApplePaySession final : public RefCounted<ApplePaySession>, public ActiveDOMObject, public EventTargetWithInlineData {
 public:
-    static RefPtr<ApplePaySession> create(Document&, unsigned version, const Dictionary&, ExceptionCode&);
+    static ExceptionOr<Ref<ApplePaySession>> create(Document&, unsigned version, const Dictionary&);
     virtual ~ApplePaySession();
 
     // DOM API.
@@ -61,18 +61,18 @@
     static const unsigned short STATUS_PIN_INCORRECT = 6;
     static const unsigned short STATUS_PIN_LOCKOUT = 7;
 
-    static bool supportsVersion(ScriptExecutionContext&, unsigned version, ExceptionCode&);
-    static bool canMakePayments(ScriptExecutionContext&, ExceptionCode&);
-    static void canMakePaymentsWithActiveCard(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&, ExceptionCode&);
-    static void openPaymentSetup(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&, ExceptionCode&);
+    static ExceptionOr<bool> supportsVersion(ScriptExecutionContext&, unsigned version);
+    static ExceptionOr<bool> canMakePayments(ScriptExecutionContext&);
+    static ExceptionOr<void> canMakePaymentsWithActiveCard(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&);
+    static ExceptionOr<void> openPaymentSetup(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&);
 
-    void begin(ExceptionCode&);
-    void abort(ExceptionCode&);
-    void completeMerchantValidation(const Dictionary& merchantSessionDictionary, ExceptionCode&);
-    void completeShippingMethodSelection(unsigned short status, const Dictionary& newTotal, const ArrayValue& newLineItems, ExceptionCode&);
-    void completeShippingContactSelection(unsigned short status, const ArrayValue& newShippingMethods, const Dictionary& newTotal, const ArrayValue& newLineItems, ExceptionCode&);
-    void completePaymentMethodSelection(const Dictionary& newTotal, const ArrayValue& newLineItems, ExceptionCode&);
-    void completePayment(unsigned short status, ExceptionCode&);
+    ExceptionOr<void> begin();
+    ExceptionOr<void> abort();
+    ExceptionOr<void> completeMerchantValidation(const Dictionary& merchantSessionDictionary);
+    ExceptionOr<void> completeShippingMethodSelection(unsigned short status, const Dictionary& newTotal, const ArrayValue& newLineItems);
+    ExceptionOr<void> completeShippingContactSelection(unsigned short status, const ArrayValue& newShippingMethods, const Dictionary& newTotal, const ArrayValue& newLineItems);
+    ExceptionOr<void> completePaymentMethodSelection(const Dictionary& newTotal, const ArrayValue& newLineItems);
+    ExceptionOr<void> completePayment(unsigned short status);
 
     const PaymentRequest& paymentRequest() const { return m_paymentRequest; }
 
@@ -126,13 +126,13 @@
 
         Aborted,
         Canceled,
-    } m_state;
+    } m_state { State::Idle };
 
     enum class MerchantValidationState {
         Idle,
         ValidatingMerchant,
         ValidationComplete,
-    } m_merchantValidationState;
+    } m_merchantValidationState { MerchantValidationState::Idle };
 
     const PaymentRequest m_paymentRequest;
 };

Modified: trunk/Source/WebCore/Modules/applepay/ApplePaySession.idl (206976 => 206977)


--- trunk/Source/WebCore/Modules/applepay/ApplePaySession.idl	2016-10-10 02:13:28 UTC (rev 206976)
+++ trunk/Source/WebCore/Modules/applepay/ApplePaySession.idl	2016-10-10 02:14:05 UTC (rev 206977)
@@ -28,7 +28,7 @@
     Conditional=APPLE_PAY,
     Constructor(unsigned long version, Dictionary paymentRequest),
     ConstructorCallWith=Document,
-    ConstructorMayThrowLegacyException,
+    ConstructorMayThrowException,
     EnabledBySetting=ApplePay,
 ] interface ApplePaySession : EventTarget {
     const unsigned short STATUS_SUCCESS = 0;
@@ -40,18 +40,18 @@
     const unsigned short STATUS_PIN_INCORRECT = 6;
     const unsigned short STATUS_PIN_LOCKOUT = 7;
 
-    [CallWith=ScriptExecutionContext, MayThrowLegacyException] static boolean supportsVersion(unsigned long version);
-    [CallWith=ScriptExecutionContext, MayThrowLegacyException] static boolean canMakePayments();
-    [CallWith=ScriptExecutionContext, MayThrowLegacyException] static Promise canMakePaymentsWithActiveCard(DOMString merchantIdentifier);
-    [CallWith=ScriptExecutionContext, MayThrowLegacyException] static Promise openPaymentSetup(DOMString merchantIdentifier);
+    [CallWith=ScriptExecutionContext, MayThrowException] static boolean supportsVersion(unsigned long version);
+    [CallWith=ScriptExecutionContext, MayThrowException] static boolean canMakePayments();
+    [CallWith=ScriptExecutionContext, MayThrowException] static Promise canMakePaymentsWithActiveCard(DOMString merchantIdentifier);
+    [CallWith=ScriptExecutionContext, MayThrowException] static Promise openPaymentSetup(DOMString merchantIdentifier);
 
-    [MayThrowLegacyException] void begin();
-    [MayThrowLegacyException] void abort();
-    [MayThrowLegacyException] void completeMerchantValidation(Dictionary merchantSession);
-    [Custom, MayThrowLegacyException] void completeShippingMethodSelection(unsigned short status, Dictionary newTotal, sequence<Dictionary> newLineItems);
-    [Custom, MayThrowLegacyException] void completeShippingContactSelection(unsigned short status, sequence<Dictionary> newShippingMethods, Dictionary newTotal, sequence<Dictionary> newLineItems);
-    [Custom, MayThrowLegacyException] void completePaymentMethodSelection(Dictionary newTotal, sequence<Dictionary> newLineItems);
-    [MayThrowLegacyException] void completePayment(unsigned short status);
+    [MayThrowException] void begin();
+    [MayThrowException] void abort();
+    [MayThrowException] void completeMerchantValidation(Dictionary merchantSession);
+    [Custom, MayThrowException] void completeShippingMethodSelection(unsigned short status, Dictionary newTotal, sequence<Dictionary> newLineItems);
+    [Custom, MayThrowException] void completeShippingContactSelection(unsigned short status, sequence<Dictionary> newShippingMethods, Dictionary newTotal, sequence<Dictionary> newLineItems);
+    [Custom, MayThrowException] void completePaymentMethodSelection(Dictionary newTotal, sequence<Dictionary> newLineItems);
+    [MayThrowException] void completePayment(unsigned short status);
 
     attribute EventHandler onvalidatemerchant;
     attribute EventHandler onpaymentmethodselected;

Modified: trunk/Source/WebCore/bindings/js/JSApplePaySessionCustom.cpp (206976 => 206977)


--- trunk/Source/WebCore/bindings/js/JSApplePaySessionCustom.cpp	2016-10-10 02:13:28 UTC (rev 206976)
+++ trunk/Source/WebCore/bindings/js/JSApplePaySessionCustom.cpp	2016-10-10 02:14:05 UTC (rev 206977)
@@ -53,7 +53,6 @@
     if (UNLIKELY(state.argumentCount() < 3))
         return JSValue::decode(throwVMError(&state, scope, createNotEnoughArgumentsError(&state)));
 
-    ExceptionCode ec = 0;
     uint16_t status = convert<uint16_t>(state, state.argument(0), NormalConversion);
     RETURN_IF_EXCEPTION(scope, JSValue());
 
@@ -62,8 +61,7 @@
 
     ArrayValue newLineItems { &state, state.argument(2) };
     RETURN_IF_EXCEPTION(scope, JSValue());
-    impl.completeShippingMethodSelection(status, newTotal, newLineItems, ec);
-    setDOMException(&state, ec);
+    propagateException(state, scope, impl.completeShippingMethodSelection(status, newTotal, newLineItems));
 
     return jsUndefined();
 }
@@ -83,7 +81,6 @@
     if (UNLIKELY(state.argumentCount() < 4))
         return JSValue::decode(throwVMError(&state, scope, createNotEnoughArgumentsError(&state)));
 
-    ExceptionCode ec = 0;
     uint16_t status = convert<uint16_t>(state, state.argument(0), NormalConversion);
     RETURN_IF_EXCEPTION(scope, JSValue());
 
@@ -95,9 +92,9 @@
 
     ArrayValue newLineItems { &state, state.argument(3) };
     RETURN_IF_EXCEPTION(scope, JSValue());
-    impl.completeShippingContactSelection(status, newShippingMethods, newTotal, newLineItems, ec);
-    setDOMException(&state, ec);
 
+    propagateException(state, scope, impl.completeShippingContactSelection(status, newShippingMethods, newTotal, newLineItems));
+
     return jsUndefined();
 }
 
@@ -116,15 +113,14 @@
     if (UNLIKELY(state.argumentCount() < 2))
         return JSValue::decode(throwVMError(&state, scope, createNotEnoughArgumentsError(&state)));
 
-    ExceptionCode ec = 0;
     Dictionary newTotal = { &state, state.argument(0) };
     RETURN_IF_EXCEPTION(scope, JSValue());
 
     ArrayValue newLineItems { &state, state.argument(1) };
     RETURN_IF_EXCEPTION(scope, JSValue());
-    impl.completePaymentMethodSelection(newTotal, newLineItems, ec);
-    setDOMException(&state, ec);
 
+    propagateException(state, scope, impl.completePaymentMethodSelection(newTotal, newLineItems));
+
     return jsUndefined();
 }
 

Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.h (206976 => 206977)


--- trunk/Source/WebCore/bindings/js/JSDOMBinding.h	2016-10-10 02:13:28 UTC (rev 206976)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.h	2016-10-10 02:14:05 UTC (rev 206977)
@@ -916,6 +916,15 @@
     return toJS(&state, &globalObject, value.releaseReturnValue());
 }
 
+inline JSC::JSValue toJSBoolean(JSC::ExecState& state, JSC::ThrowScope& throwScope, ExceptionOr<bool>&& value)
+{
+    if (UNLIKELY(value.hasException())) {
+        propagateException(state, throwScope, value.releaseException());
+        return { };
+    }
+    return JSC::jsBoolean(value.releaseReturnValue());
+}
+
 template<typename T> inline JSC::JSValue toJSNewlyCreated(JSC::ExecState& state, JSDOMGlobalObject& globalObject, JSC::ThrowScope& throwScope, ExceptionOr<T>&& value)
 {
     if (UNLIKELY(value.hasException())) {

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (206976 => 206977)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-10-10 02:13:28 UTC (rev 206976)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-10-10 02:14:05 UTC (rev 206977)
@@ -5538,7 +5538,11 @@
             }
 
             push(@$outputArray, "    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());\n") if $codeGenerator->ExtendedAttributeContains($interface->extendedAttributes->{ConstructorCallWith}, "ScriptState");
-            push(@$outputArray, "    return JSValue::encode(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object)));\n");
+            if ($interface->extendedAttributes->{ConstructorMayThrowException}) {
+                push(@$outputArray, "    return JSValue::encode(toJSNewlyCreated(*state, *castedThis->globalObject(), throwScope, WTFMove(object)));\n");
+            } else {
+                push(@$outputArray, "    return JSValue::encode(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object)));\n");
+            }
             push(@$outputArray, "}\n\n");
         }
     }

Modified: trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt (206976 => 206977)


--- trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt	2016-10-10 02:13:28 UTC (rev 206976)
+++ trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt	2016-10-10 02:14:05 UTC (rev 206977)
@@ -33,6 +33,7 @@
 Constructor
 ConstructorCallWith=Document|ScriptExecutionContext|ScriptState
 ConstructorConditional=*
+ConstructorMayThrowException
 ConstructorMayThrowLegacyException
 ConstructorTemplate=Event|TypedArray
 Custom
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to