Changeset 206977 in webkit


Ignore:
Timestamp:
Oct 9, 2016 7:14:05 PM (8 years ago)
Author:
Darin Adler
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.
Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r206976 r206977  
     12016-10-09  Darin Adler  <darin@apple.com>
     2
     3        Move ApplePaySession from legacy to new DOM exceptions
     4        https://bugs.webkit.org/show_bug.cgi?id=163191
     5
     6        Reviewed by Sam Weinig.
     7
     8        * Modules/applepay/ApplePaySession.cpp:
     9        (WebCore::ApplePaySession::create): Use ExceptionOr.
     10        (WebCore::ApplePaySession::ApplePaySession): Moved initialization
     11        of two of the data members to class definition.
     12        (WebCore::ApplePaySession::supportsVersion): Use ExceptionOr.
     13        (WebCore::ApplePaySession::canMakePayments): Ditto.
     14        (WebCore::ApplePaySession::canMakePaymentsWithActiveCard): Ditto.
     15        (WebCore::ApplePaySession::openPaymentSetup): Ditto.
     16        (WebCore::ApplePaySession::begin): Ditto.
     17        (WebCore::ApplePaySession::abort): Ditto.
     18        (WebCore::ApplePaySession::completeMerchantValidation): Ditto.
     19        (WebCore::ApplePaySession::completeShippingMethodSelection): Ditto.
     20        (WebCore::ApplePaySession::completeShippingContactSelection): Ditto.
     21        (WebCore::ApplePaySession::completePaymentMethodSelection): Ditto.
     22        (WebCore::ApplePaySession::completePayment): Ditto.
     23        (WebCore::ApplePaySession::validateMerchant): Use auto and get instead of
     24        using a RefPtr type and * for event dispatching.
     25        (WebCore::ApplePaySession::didAuthorizePayment): Ditto.
     26        (WebCore::ApplePaySession::didSelectShippingMethod): Ditto.
     27        (WebCore::ApplePaySession::didSelectShippingContact): Ditto.
     28        (WebCore::ApplePaySession::didSelectPaymentMethod): Ditto.
     29        (WebCore::ApplePaySession::didCancelPayment): Ditto.
     30        (WebCore::ApplePaySession::paymentCoordinator): Moved dereferencing
     31        inside the downcast.
     32
     33        * Modules/applepay/ApplePaySession.h: Updated for changes above.
     34
     35        * Modules/applepay/ApplePaySession.idl: Use MayThrowException.
     36
     37        * bindings/js/JSApplePaySessionCustom.cpp:
     38        (WebCore::JSApplePaySession::completeShippingMethodSelection):
     39        Use propagateException.
     40        (WebCore::JSApplePaySession::completeShippingContactSelection): Ditto.
     41        (WebCore::JSApplePaySession::completePaymentMethodSelection): Ditto.
     42
     43        * bindings/js/JSDOMBinding.h: Added implementation of toJSBoolean.
     44
     45        * bindings/scripts/CodeGeneratorJS.pm:
     46        (GenerateConstructorDefinition): Generate the different arguments for
     47        toJSNewlyCreated when ConstructorMayThrowException is specified that
     48        activate the version of that function that handles exceptions.
     49
     50        * bindings/scripts/IDLAttributes.txt: Added ConstructorMayThrowException.
     51
    1522016-10-09  Darin Adler  <darin@apple.com>
    253
  • trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp

    r206881 r206977  
    636636}
    637637
    638 RefPtr<ApplePaySession> ApplePaySession::create(Document& document, unsigned version, const Dictionary& dictionary, ExceptionCode& ec)
     638ExceptionOr<Ref<ApplePaySession>> ApplePaySession::create(Document& document, unsigned version, const Dictionary& dictionary)
    639639{
    640640    DOMWindow& window = *document.domWindow();
     
    643643    if (!canCallApplePaySessionAPIs(document, errorMessage)) {
    644644        window.printErrorMessage(errorMessage);
    645         ec = INVALID_ACCESS_ERR;
    646         return nullptr;
     645        return Exception { INVALID_ACCESS_ERR };
    647646    }
    648647
    649648    if (!ScriptController::processingUserGesture()) {
    650649        window.printErrorMessage("Must create a new ApplePaySession from a user gesture handler.");
    651         ec = INVALID_ACCESS_ERR;
    652         return nullptr;
     650        return Exception { INVALID_ACCESS_ERR };
    653651    }
    654652
     
    657655    if (!version || !paymentCoordinator.supportsVersion(version)) {
    658656        window.printErrorMessage(makeString("\"" + String::number(version), "\" is not a supported version."));
    659         ec = INVALID_ACCESS_ERR;
    660         return nullptr;
     657        return Exception { INVALID_ACCESS_ERR };
    661658    }
    662659
    663660    auto paymentRequest = createPaymentRequest(version, window, dictionary);
    664     if (!paymentRequest) {
    665         ec = TYPE_MISMATCH_ERR;
    666         return nullptr;
    667     }
    668 
    669     if (!PaymentRequestValidator(window).validate(*paymentRequest)) {
    670         ec = INVALID_ACCESS_ERR;
    671         return nullptr;
    672     }
    673 
    674     return adoptRef(new ApplePaySession(document, WTFMove(*paymentRequest)));
     661    if (!paymentRequest)
     662        return Exception { TYPE_MISMATCH_ERR };
     663
     664    if (!PaymentRequestValidator(window).validate(*paymentRequest))
     665        return Exception { INVALID_ACCESS_ERR };
     666
     667    return adoptRef(*new ApplePaySession(document, WTFMove(*paymentRequest)));
    675668}
    676669
    677670ApplePaySession::ApplePaySession(Document& document, PaymentRequest&& paymentRequest)
    678671    : ActiveDOMObject(&document)
    679     , m_state(State::Idle)
    680     , m_merchantValidationState(MerchantValidationState::Idle)
    681672    , m_paymentRequest(WTFMove(paymentRequest))
    682673{
     
    688679}
    689680
    690 bool ApplePaySession::supportsVersion(ScriptExecutionContext& scriptExecutionContext, unsigned version, ExceptionCode& ec)
    691 {
    692     if (!version) {
    693         ec = INVALID_ACCESS_ERR;
    694         return false;
    695     }
     681ExceptionOr<bool> ApplePaySession::supportsVersion(ScriptExecutionContext& scriptExecutionContext, unsigned version)
     682{
     683    if (!version)
     684        return Exception { INVALID_ACCESS_ERR };
    696685
    697686    auto& document = downcast<Document>(scriptExecutionContext);
     
    701690    if (!canCallApplePaySessionAPIs(document, errorMessage)) {
    702691        window.printErrorMessage(errorMessage);
    703         ec = INVALID_ACCESS_ERR;
    704         return false;
    705     }
    706 
    707     auto& paymentCoordinator = document.frame()->mainFrame().paymentCoordinator();
    708     return paymentCoordinator.supportsVersion(version);
     692        return Exception { INVALID_ACCESS_ERR };
     693    }
     694
     695    return document.frame()->mainFrame().paymentCoordinator().supportsVersion(version);
    709696}
    710697
     
    718705}
    719706
    720 bool ApplePaySession::canMakePayments(ScriptExecutionContext& scriptExecutionContext, ExceptionCode& ec)
     707ExceptionOr<bool> ApplePaySession::canMakePayments(ScriptExecutionContext& scriptExecutionContext)
    721708{
    722709    auto& document = downcast<Document>(scriptExecutionContext);
     
    726713    if (!canCallApplePaySessionAPIs(document, errorMessage)) {
    727714        window.printErrorMessage(errorMessage);
    728         ec = INVALID_ACCESS_ERR;
    729         return false;
    730     }
    731 
    732     auto& paymentCoordinator = document.frame()->mainFrame().paymentCoordinator();
    733     return paymentCoordinator.canMakePayments();
    734 }
    735 
    736 void ApplePaySession::canMakePaymentsWithActiveCard(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredPromise>&& passedPromise, ExceptionCode& ec)
     715        return Exception { INVALID_ACCESS_ERR };
     716    }
     717
     718    return document.frame()->mainFrame().paymentCoordinator().canMakePayments();
     719}
     720
     721ExceptionOr<void> ApplePaySession::canMakePaymentsWithActiveCard(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredPromise>&& passedPromise)
    737722{
    738723    auto& document = downcast<Document>(scriptExecutionContext);
     
    742727    if (!canCallApplePaySessionAPIs(document, errorMessage)) {
    743728        window.printErrorMessage(errorMessage);
    744         ec = INVALID_ACCESS_ERR;
    745         return;
     729        return Exception { INVALID_ACCESS_ERR };
    746730    }
    747731
     
    754738            promise->resolve(canMakePayments);
    755739        });
    756         return;
     740        return { };
    757741    }
    758742
     
    762746        promise->resolve(canMakePayments);
    763747    });
    764 }
    765 
    766 void ApplePaySession::openPaymentSetup(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredPromise>&& passedPromise, ExceptionCode& ec)
     748    return { };
     749}
     750
     751ExceptionOr<void> ApplePaySession::openPaymentSetup(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredPromise>&& passedPromise)
    767752{
    768753    auto& document = downcast<Document>(scriptExecutionContext);
     
    772757    if (!canCallApplePaySessionAPIs(document, errorMessage)) {
    773758        window.printErrorMessage(errorMessage);
    774         ec = INVALID_ACCESS_ERR;
    775         return;
     759        return Exception { INVALID_ACCESS_ERR };
    776760    }
    777761
    778762    if (!ScriptController::processingUserGesture()) {
    779763        window.printErrorMessage("Must call ApplePaySession.openPaymentSetup from a user gesture handler.");
    780         ec = INVALID_ACCESS_ERR;
    781         return;
     764        return Exception { INVALID_ACCESS_ERR };
    782765    }
    783766
     
    788771        promise->resolve(result);
    789772    });
    790 }
    791 
    792 void ApplePaySession::begin(ExceptionCode& ec)
     773
     774    return { };
     775}
     776
     777ExceptionOr<void> ApplePaySession::begin()
    793778{
    794779    auto& document = *downcast<Document>(scriptExecutionContext());
     
    797782    if (!canBegin()) {
    798783        window.printErrorMessage("Payment session is already active.");
    799         ec = INVALID_ACCESS_ERR;
    800         return;
     784        return Exception { INVALID_ACCESS_ERR };
    801785    }
    802786
    803787    if (paymentCoordinator().hasActiveSession()) {
    804788        window.printErrorMessage("Page already has an active payment session.");
    805 
    806         ec = INVALID_ACCESS_ERR;
    807         return;
     789        return Exception { INVALID_ACCESS_ERR };
    808790    }
    809791
     
    814796    if (!paymentCoordinator().beginPaymentSession(*this, document.url(), linkIconURLs, m_paymentRequest)) {
    815797        window.printErrorMessage("There is already has an active payment session.");
    816 
    817         ec = INVALID_ACCESS_ERR;
    818         return;
     798        return Exception { INVALID_ACCESS_ERR };
    819799    }
    820800
     
    822802
    823803    setPendingActivity(this);
    824 }
    825 
    826 void ApplePaySession::abort(ExceptionCode& ec)
    827 {
    828     if (!canAbort()) {
    829         ec = INVALID_ACCESS_ERR;
    830         return;
    831     }
     804
     805    return { };
     806}
     807
     808ExceptionOr<void> ApplePaySession::abort()
     809{
     810    if (!canAbort())
     811        return Exception { INVALID_ACCESS_ERR };
    832812
    833813    m_state = State::Aborted;
     
    835815
    836816    didReachFinalState();
    837 }
    838 
    839 void ApplePaySession::completeMerchantValidation(const Dictionary& merchantSessionDictionary, ExceptionCode& ec)
    840 {
    841     if (!canCompleteMerchantValidation()) {
    842         ec = INVALID_ACCESS_ERR;
    843         return;
    844     }
    845 
    846     if (!merchantSessionDictionary.initializerObject()) {
    847         ec = TypeError;
    848         return;
    849     }
     817
     818    return { };
     819}
     820
     821ExceptionOr<void> ApplePaySession::completeMerchantValidation(const Dictionary& merchantSessionDictionary)
     822{
     823    if (!canCompleteMerchantValidation())
     824        return Exception { INVALID_ACCESS_ERR };
     825
     826    if (!merchantSessionDictionary.initializerObject())
     827        return Exception { TypeError };
    850828
    851829    auto& document = *downcast<Document>(scriptExecutionContext());
     
    856834    if (!merchantSession) {
    857835        window.printErrorMessage(errorMessage);
    858         ec = INVALID_ACCESS_ERR;
    859         return;
     836        return Exception { INVALID_ACCESS_ERR };
    860837    }
    861838
    862839    m_merchantValidationState = MerchantValidationState::ValidationComplete;
    863840    paymentCoordinator().completeMerchantValidation(*merchantSession);
    864 }
    865 
     841
     842    return { };
     843}
    866844
    867845static Optional<PaymentAuthorizationStatus> toPaymentAuthorizationStatus(unsigned short status)
     
    897875}
    898876
    899 void ApplePaySession::completeShippingMethodSelection(unsigned short status, const Dictionary& newTotalDictionary, const ArrayValue& newLineItemsArray, ExceptionCode& ec)
    900 {
    901     if (!canCompleteShippingMethodSelection()) {
    902         ec = INVALID_ACCESS_ERR;
    903         return;
    904     }
     877ExceptionOr<void> ApplePaySession::completeShippingMethodSelection(unsigned short status, const Dictionary& newTotalDictionary, const ArrayValue& newLineItemsArray)
     878{
     879    if (!canCompleteShippingMethodSelection())
     880        return Exception { INVALID_ACCESS_ERR };
    905881
    906882    auto authorizationStatus = toPaymentAuthorizationStatus(status);
    907     if (!authorizationStatus) {
    908         ec = INVALID_ACCESS_ERR;
    909         return;
    910     }
     883    if (!authorizationStatus)
     884        return Exception { INVALID_ACCESS_ERR };
    911885
    912886    auto& window = *downcast<Document>(scriptExecutionContext())->domWindow();
    913887    auto newTotal = createLineItem(window, newTotalDictionary);
    914     if (!newTotal) {
    915         ec = INVALID_ACCESS_ERR;
    916         return;
    917     }
    918 
    919     if (!PaymentRequestValidator(window).validateTotal(*newTotal)) {
    920         ec = INVALID_ACCESS_ERR;
    921         return;
    922     }
     888    if (!newTotal)
     889        return Exception { INVALID_ACCESS_ERR };
     890
     891    if (!PaymentRequestValidator(window).validateTotal(*newTotal))
     892        return Exception { INVALID_ACCESS_ERR };
    923893
    924894    auto newLineItems = createLineItems(window, newLineItemsArray);
    925     if (!newLineItems) {
    926         ec = INVALID_ACCESS_ERR;
    927         return;
    928     }
     895    if (!newLineItems)
     896        return Exception { INVALID_ACCESS_ERR };
    929897
    930898    m_state = State::Active;
     
    933901    totalAndLineItems.lineItems = *newLineItems;
    934902    paymentCoordinator().completeShippingMethodSelection(*authorizationStatus, totalAndLineItems);
    935 }
    936 
    937 void ApplePaySession::completeShippingContactSelection(unsigned short status, const ArrayValue& newShippingMethodsArray, const Dictionary& newTotalDictionary, const ArrayValue& newLineItemsArray, ExceptionCode& ec)
    938 {
    939     if (!canCompleteShippingContactSelection()) {
    940         ec = INVALID_ACCESS_ERR;
    941         return;
    942     }
     903
     904    return { };
     905}
     906
     907ExceptionOr<void> ApplePaySession::completeShippingContactSelection(unsigned short status, const ArrayValue& newShippingMethodsArray, const Dictionary& newTotalDictionary, const ArrayValue& newLineItemsArray)
     908{
     909    if (!canCompleteShippingContactSelection())
     910        return Exception { INVALID_ACCESS_ERR };
    943911
    944912    auto authorizationStatus = toPaymentAuthorizationStatus(status);
    945     if (!authorizationStatus) {
    946         ec = INVALID_ACCESS_ERR;
    947         return;
    948     }
     913    if (!authorizationStatus)
     914        return Exception { INVALID_ACCESS_ERR };
    949915
    950916    auto& window = *downcast<Document>(scriptExecutionContext())->domWindow();
    951917
    952918    auto newShippingMethods = createShippingMethods(window, newShippingMethodsArray);
    953     if (!newShippingMethods) {
    954         ec = INVALID_ACCESS_ERR;
    955         return;
    956     }
     919    if (!newShippingMethods)
     920        return Exception { INVALID_ACCESS_ERR };
    957921
    958922    auto newTotal = createLineItem(window, newTotalDictionary);
    959     if (!newTotal) {
    960         ec = INVALID_ACCESS_ERR;
    961         return;
    962     }
    963 
    964     if (!PaymentRequestValidator(window).validateTotal(*newTotal)) {
    965         ec = INVALID_ACCESS_ERR;
    966         return;
    967     }
     923    if (!newTotal)
     924        return Exception { INVALID_ACCESS_ERR };
     925
     926    if (!PaymentRequestValidator(window).validateTotal(*newTotal))
     927        return Exception { INVALID_ACCESS_ERR };
    968928
    969929    auto newLineItems = createLineItems(window, newLineItemsArray);
    970     if (!newLineItems) {
    971         ec = INVALID_ACCESS_ERR;
    972         return;
    973     }
     930    if (!newLineItems)
     931        return Exception { INVALID_ACCESS_ERR };
    974932
    975933    m_state = State::Active;
     
    978936    totalAndLineItems.lineItems = *newLineItems;
    979937    paymentCoordinator().completeShippingContactSelection(*authorizationStatus, *newShippingMethods, totalAndLineItems);
    980 }
    981 
    982 void ApplePaySession::completePaymentMethodSelection(const Dictionary& newTotalDictionary, const ArrayValue& newLineItemsArray, ExceptionCode& ec)
    983 {
    984     if (!canCompletePaymentMethodSelection()) {
    985         ec = INVALID_ACCESS_ERR;
    986         return;
    987     }
    988 
    989     auto& window = *downcast<Document>(scriptExecutionContext())->domWindow();
     938
     939    return { };
     940}
     941
     942ExceptionOr<void> ApplePaySession::completePaymentMethodSelection(const Dictionary& newTotalDictionary, const ArrayValue& newLineItemsArray)
     943{
     944    if (!canCompletePaymentMethodSelection())
     945        return Exception { INVALID_ACCESS_ERR };
     946
     947    auto& window = *downcast<Document>(*scriptExecutionContext()).domWindow();
    990948    auto newTotal = createLineItem(window, newTotalDictionary);
    991     if (!newTotal) {
    992         ec = INVALID_ACCESS_ERR;
    993         return;
    994     }
    995 
    996     if (!PaymentRequestValidator(window).validateTotal(*newTotal)) {
    997         ec = INVALID_ACCESS_ERR;
    998         return;
    999     }
     949    if (!newTotal)
     950        return Exception { INVALID_ACCESS_ERR };
     951
     952    if (!PaymentRequestValidator(window).validateTotal(*newTotal))
     953        return Exception { INVALID_ACCESS_ERR };
    1000954
    1001955    auto newLineItems = createLineItems(window, newLineItemsArray);
    1002     if (!newLineItems) {
    1003         ec = INVALID_ACCESS_ERR;
    1004         return;
    1005     }
     956    if (!newLineItems)
     957        return Exception { INVALID_ACCESS_ERR };
    1006958
    1007959    m_state = State::Active;
     
    1010962    totalAndLineItems.lineItems = *newLineItems;
    1011963    paymentCoordinator().completePaymentMethodSelection(totalAndLineItems);
    1012 }
    1013 
    1014 void ApplePaySession::completePayment(unsigned short status, ExceptionCode& ec)
    1015 {
    1016     if (!canCompletePayment()) {
    1017         ec = INVALID_ACCESS_ERR;
    1018         return;
    1019     }
     964
     965    return { };
     966}
     967
     968ExceptionOr<void> ApplePaySession::completePayment(unsigned short status)
     969{
     970    if (!canCompletePayment())
     971        return Exception { INVALID_ACCESS_ERR };
    1020972
    1021973    auto authorizationStatus = toPaymentAuthorizationStatus(status);
    1022     if (!authorizationStatus) {
    1023         ec = INVALID_ACCESS_ERR;
    1024         return;
    1025     }
     974    if (!authorizationStatus)
     975        return Exception { INVALID_ACCESS_ERR };
    1026976
    1027977    paymentCoordinator().completePaymentSession(*authorizationStatus);
     
    1029979    if (!isFinalStateStatus(*authorizationStatus)) {
    1030980        m_state = State::Active;
    1031         return;
     981        return { };
    1032982    }
    1033983
    1034984    m_state = State::Completed;
    1035985    unsetPendingActivity(this);
     986    return { };
    1036987}
    1037988
     
    10541005    m_merchantValidationState = MerchantValidationState::ValidatingMerchant;
    10551006
    1056     RefPtr<ApplePayValidateMerchantEvent> event = ApplePayValidateMerchantEvent::create(eventNames().validatemerchantEvent, validationURL);
    1057     dispatchEvent(*event);
     1007    auto event = ApplePayValidateMerchantEvent::create(eventNames().validatemerchantEvent, validationURL);
     1008    dispatchEvent(event.get());
    10581009}
    10591010
     
    10641015    m_state = State::Authorized;
    10651016
    1066     RefPtr<ApplePayPaymentAuthorizedEvent> event = ApplePayPaymentAuthorizedEvent::create(eventNames().paymentauthorizedEvent, payment);
    1067     dispatchEvent(*event);
     1017    auto event = ApplePayPaymentAuthorizedEvent::create(eventNames().paymentauthorizedEvent, payment);
     1018    dispatchEvent(event.get());
    10681019}
    10691020
     
    10781029
    10791030    m_state = State::ShippingMethodSelected;
    1080     RefPtr<ApplePayShippingMethodSelectedEvent> event = ApplePayShippingMethodSelectedEvent::create(eventNames().shippingmethodselectedEvent, shippingMethod);
    1081     dispatchEvent(*event);
     1031    auto event = ApplePayShippingMethodSelectedEvent::create(eventNames().shippingmethodselectedEvent, shippingMethod);
     1032    dispatchEvent(event.get());
    10821033}
    10831034
     
    10921043
    10931044    m_state = State::ShippingContactSelected;
    1094     RefPtr<ApplePayShippingContactSelectedEvent> event = ApplePayShippingContactSelectedEvent::create(eventNames().shippingcontactselectedEvent, shippingContact);
    1095     dispatchEvent(*event);
     1045    auto event = ApplePayShippingContactSelectedEvent::create(eventNames().shippingcontactselectedEvent, shippingContact);
     1046    dispatchEvent(event.get());
    10961047}
    10971048
     
    11061057
    11071058    m_state = State::PaymentMethodSelected;
    1108     RefPtr<ApplePayPaymentMethodSelectedEvent> event = ApplePayPaymentMethodSelectedEvent::create(eventNames().paymentmethodselectedEvent, paymentMethod);
    1109     dispatchEvent(*event);
     1059    auto event = ApplePayPaymentMethodSelectedEvent::create(eventNames().paymentmethodselectedEvent, paymentMethod);
     1060    dispatchEvent(event.get());
    11101061}
    11111062
     
    11161067    m_state = State::Canceled;
    11171068
    1118     RefPtr<Event> event = Event::create(eventNames().cancelEvent, false, false);
    1119     dispatchEvent(*event);
     1069    auto event = Event::create(eventNames().cancelEvent, false, false);
     1070    dispatchEvent(event.get());
    11201071
    11211072    didReachFinalState();
     
    11581109PaymentCoordinator& ApplePaySession::paymentCoordinator() const
    11591110{
    1160     return downcast<Document>(scriptExecutionContext())->frame()->mainFrame().paymentCoordinator();
     1111    return downcast<Document>(*scriptExecutionContext()).frame()->mainFrame().paymentCoordinator();
    11611112}
    11621113
  • trunk/Source/WebCore/Modules/applepay/ApplePaySession.h

    r206252 r206977  
    3030#include "ActiveDOMObject.h"
    3131#include "EventTarget.h"
    32 #include "ExceptionCode.h"
     32#include "ExceptionOr.h"
    3333#include "PaymentRequest.h"
    3434#include <wtf/Ref.h>
     
    4949class ApplePaySession final : public RefCounted<ApplePaySession>, public ActiveDOMObject, public EventTargetWithInlineData {
    5050public:
    51     static RefPtr<ApplePaySession> create(Document&, unsigned version, const Dictionary&, ExceptionCode&);
     51    static ExceptionOr<Ref<ApplePaySession>> create(Document&, unsigned version, const Dictionary&);
    5252    virtual ~ApplePaySession();
    5353
     
    6262    static const unsigned short STATUS_PIN_LOCKOUT = 7;
    6363
    64     static bool supportsVersion(ScriptExecutionContext&, unsigned version, ExceptionCode&);
    65     static bool canMakePayments(ScriptExecutionContext&, ExceptionCode&);
    66     static void canMakePaymentsWithActiveCard(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&, ExceptionCode&);
    67     static void openPaymentSetup(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&, ExceptionCode&);
     64    static ExceptionOr<bool> supportsVersion(ScriptExecutionContext&, unsigned version);
     65    static ExceptionOr<bool> canMakePayments(ScriptExecutionContext&);
     66    static ExceptionOr<void> canMakePaymentsWithActiveCard(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&);
     67    static ExceptionOr<void> openPaymentSetup(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&);
    6868
    69     void begin(ExceptionCode&);
    70     void abort(ExceptionCode&);
    71     void completeMerchantValidation(const Dictionary& merchantSessionDictionary, ExceptionCode&);
    72     void completeShippingMethodSelection(unsigned short status, const Dictionary& newTotal, const ArrayValue& newLineItems, ExceptionCode&);
    73     void completeShippingContactSelection(unsigned short status, const ArrayValue& newShippingMethods, const Dictionary& newTotal, const ArrayValue& newLineItems, ExceptionCode&);
    74     void completePaymentMethodSelection(const Dictionary& newTotal, const ArrayValue& newLineItems, ExceptionCode&);
    75     void completePayment(unsigned short status, ExceptionCode&);
     69    ExceptionOr<void> begin();
     70    ExceptionOr<void> abort();
     71    ExceptionOr<void> completeMerchantValidation(const Dictionary& merchantSessionDictionary);
     72    ExceptionOr<void> completeShippingMethodSelection(unsigned short status, const Dictionary& newTotal, const ArrayValue& newLineItems);
     73    ExceptionOr<void> completeShippingContactSelection(unsigned short status, const ArrayValue& newShippingMethods, const Dictionary& newTotal, const ArrayValue& newLineItems);
     74    ExceptionOr<void> completePaymentMethodSelection(const Dictionary& newTotal, const ArrayValue& newLineItems);
     75    ExceptionOr<void> completePayment(unsigned short status);
    7676
    7777    const PaymentRequest& paymentRequest() const { return m_paymentRequest; }
     
    127127        Aborted,
    128128        Canceled,
    129     } m_state;
     129    } m_state { State::Idle };
    130130
    131131    enum class MerchantValidationState {
     
    133133        ValidatingMerchant,
    134134        ValidationComplete,
    135     } m_merchantValidationState;
     135    } m_merchantValidationState { MerchantValidationState::Idle };
    136136
    137137    const PaymentRequest m_paymentRequest;
  • trunk/Source/WebCore/Modules/applepay/ApplePaySession.idl

    r206723 r206977  
    2929    Constructor(unsigned long version, Dictionary paymentRequest),
    3030    ConstructorCallWith=Document,
    31     ConstructorMayThrowLegacyException,
     31    ConstructorMayThrowException,
    3232    EnabledBySetting=ApplePay,
    3333] interface ApplePaySession : EventTarget {
     
    4141    const unsigned short STATUS_PIN_LOCKOUT = 7;
    4242
    43     [CallWith=ScriptExecutionContext, MayThrowLegacyException] static boolean supportsVersion(unsigned long version);
    44     [CallWith=ScriptExecutionContext, MayThrowLegacyException] static boolean canMakePayments();
    45     [CallWith=ScriptExecutionContext, MayThrowLegacyException] static Promise canMakePaymentsWithActiveCard(DOMString merchantIdentifier);
    46     [CallWith=ScriptExecutionContext, MayThrowLegacyException] static Promise openPaymentSetup(DOMString merchantIdentifier);
     43    [CallWith=ScriptExecutionContext, MayThrowException] static boolean supportsVersion(unsigned long version);
     44    [CallWith=ScriptExecutionContext, MayThrowException] static boolean canMakePayments();
     45    [CallWith=ScriptExecutionContext, MayThrowException] static Promise canMakePaymentsWithActiveCard(DOMString merchantIdentifier);
     46    [CallWith=ScriptExecutionContext, MayThrowException] static Promise openPaymentSetup(DOMString merchantIdentifier);
    4747
    48     [MayThrowLegacyException] void begin();
    49     [MayThrowLegacyException] void abort();
    50     [MayThrowLegacyException] void completeMerchantValidation(Dictionary merchantSession);
    51     [Custom, MayThrowLegacyException] void completeShippingMethodSelection(unsigned short status, Dictionary newTotal, sequence<Dictionary> newLineItems);
    52     [Custom, MayThrowLegacyException] void completeShippingContactSelection(unsigned short status, sequence<Dictionary> newShippingMethods, Dictionary newTotal, sequence<Dictionary> newLineItems);
    53     [Custom, MayThrowLegacyException] void completePaymentMethodSelection(Dictionary newTotal, sequence<Dictionary> newLineItems);
    54     [MayThrowLegacyException] void completePayment(unsigned short status);
     48    [MayThrowException] void begin();
     49    [MayThrowException] void abort();
     50    [MayThrowException] void completeMerchantValidation(Dictionary merchantSession);
     51    [Custom, MayThrowException] void completeShippingMethodSelection(unsigned short status, Dictionary newTotal, sequence<Dictionary> newLineItems);
     52    [Custom, MayThrowException] void completeShippingContactSelection(unsigned short status, sequence<Dictionary> newShippingMethods, Dictionary newTotal, sequence<Dictionary> newLineItems);
     53    [Custom, MayThrowException] void completePaymentMethodSelection(Dictionary newTotal, sequence<Dictionary> newLineItems);
     54    [MayThrowException] void completePayment(unsigned short status);
    5555
    5656    attribute EventHandler onvalidatemerchant;
  • trunk/Source/WebCore/bindings/js/JSApplePaySessionCustom.cpp

    r206386 r206977  
    5454        return JSValue::decode(throwVMError(&state, scope, createNotEnoughArgumentsError(&state)));
    5555
    56     ExceptionCode ec = 0;
    5756    uint16_t status = convert<uint16_t>(state, state.argument(0), NormalConversion);
    5857    RETURN_IF_EXCEPTION(scope, JSValue());
     
    6362    ArrayValue newLineItems { &state, state.argument(2) };
    6463    RETURN_IF_EXCEPTION(scope, JSValue());
    65     impl.completeShippingMethodSelection(status, newTotal, newLineItems, ec);
    66     setDOMException(&state, ec);
     64    propagateException(state, scope, impl.completeShippingMethodSelection(status, newTotal, newLineItems));
    6765
    6866    return jsUndefined();
     
    8482        return JSValue::decode(throwVMError(&state, scope, createNotEnoughArgumentsError(&state)));
    8583
    86     ExceptionCode ec = 0;
    8784    uint16_t status = convert<uint16_t>(state, state.argument(0), NormalConversion);
    8885    RETURN_IF_EXCEPTION(scope, JSValue());
     
    9693    ArrayValue newLineItems { &state, state.argument(3) };
    9794    RETURN_IF_EXCEPTION(scope, JSValue());
    98     impl.completeShippingContactSelection(status, newShippingMethods, newTotal, newLineItems, ec);
    99     setDOMException(&state, ec);
     95
     96    propagateException(state, scope, impl.completeShippingContactSelection(status, newShippingMethods, newTotal, newLineItems));
    10097
    10198    return jsUndefined();
     
    117114        return JSValue::decode(throwVMError(&state, scope, createNotEnoughArgumentsError(&state)));
    118115
    119     ExceptionCode ec = 0;
    120116    Dictionary newTotal = { &state, state.argument(0) };
    121117    RETURN_IF_EXCEPTION(scope, JSValue());
     
    123119    ArrayValue newLineItems { &state, state.argument(1) };
    124120    RETURN_IF_EXCEPTION(scope, JSValue());
    125     impl.completePaymentMethodSelection(newTotal, newLineItems, ec);
    126     setDOMException(&state, ec);
     121
     122    propagateException(state, scope, impl.completePaymentMethodSelection(newTotal, newLineItems));
    127123
    128124    return jsUndefined();
  • trunk/Source/WebCore/bindings/js/JSDOMBinding.h

    r206976 r206977  
    917917}
    918918
    919 template<typename T> inline JSC::JSValue toJSNewlyCreated(JSC::ExecState& state, JSDOMGlobalObject& globalObject, JSC::ThrowScope& throwScope, ExceptionOr<T>&& value)
     919inline JSC::JSValue toJSBoolean(JSC::ExecState& state, JSC::ThrowScope& throwScope, ExceptionOr<bool>&& value)
    920920{
    921921    if (UNLIKELY(value.hasException())) {
     
    923923        return { };
    924924    }
    925     return toJSNewlyCreated(&state, &globalObject, value.releaseReturnValue());
    926 }
    927 
    928 template<typename T> inline JSC::JSValue toJSNumber(JSC::ExecState& state, JSC::ThrowScope& throwScope, ExceptionOr<T>&& value)
     925    return JSC::jsBoolean(value.releaseReturnValue());
     926}
     927
     928template<typename T> inline JSC::JSValue toJSNewlyCreated(JSC::ExecState& state, JSDOMGlobalObject& globalObject, JSC::ThrowScope& throwScope, ExceptionOr<T>&& value)
    929929{
    930930    if (UNLIKELY(value.hasException())) {
     
    932932        return { };
    933933    }
     934    return toJSNewlyCreated(&state, &globalObject, value.releaseReturnValue());
     935}
     936
     937template<typename T> inline JSC::JSValue toJSNumber(JSC::ExecState& state, JSC::ThrowScope& throwScope, ExceptionOr<T>&& value)
     938{
     939    if (UNLIKELY(value.hasException())) {
     940        propagateException(state, throwScope, value.releaseException());
     941        return { };
     942    }
    934943    return JSC::jsNumber(value.releaseReturnValue());
    935944}
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r206976 r206977  
    55395539
    55405540            push(@$outputArray, "    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());\n") if $codeGenerator->ExtendedAttributeContains($interface->extendedAttributes->{ConstructorCallWith}, "ScriptState");
    5541             push(@$outputArray, "    return JSValue::encode(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object)));\n");
     5541            if ($interface->extendedAttributes->{ConstructorMayThrowException}) {
     5542                push(@$outputArray, "    return JSValue::encode(toJSNewlyCreated(*state, *castedThis->globalObject(), throwScope, WTFMove(object)));\n");
     5543            } else {
     5544                push(@$outputArray, "    return JSValue::encode(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object)));\n");
     5545            }
    55425546            push(@$outputArray, "}\n\n");
    55435547        }
  • trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt

    r206976 r206977  
    3434ConstructorCallWith=Document|ScriptExecutionContext|ScriptState
    3535ConstructorConditional=*
     36ConstructorMayThrowException
    3637ConstructorMayThrowLegacyException
    3738ConstructorTemplate=Event|TypedArray
Note: See TracChangeset for help on using the changeset viewer.