Bug 175755 - [Payment Request] Implement the PaymentRequest constructor
Summary: [Payment Request] Implement the PaymentRequest constructor
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Andy Estes
URL:
Keywords: InRadar
Depends on:
Blocks: 174796
  Show dependency treegraph
 
Reported: 2017-08-20 01:49 PDT by Andy Estes
Modified: 2017-08-21 11:58 PDT (History)
11 users (show)

See Also:


Attachments
Patch (122.49 KB, patch)
2017-08-20 03:37 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (115.46 KB, patch)
2017-08-20 20:36 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (115.49 KB, patch)
2017-08-20 20:37 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (115.53 KB, patch)
2017-08-21 09:58 PDT, Andy Estes
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Estes 2017-08-20 01:49:52 PDT
[Payment Request] Implement the PaymentRequest constructor
Comment 1 Andy Estes 2017-08-20 03:37:04 PDT Comment hidden (obsolete)
Comment 2 Build Bot 2017-08-20 03:39:57 PDT Comment hidden (obsolete)
Comment 3 Sam Weinig 2017-08-20 12:20:16 PDT
Comment on attachment 318601 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=318601&action=review

> Source/WebCore/Modules/paymentrequest/PaymentCurrencyAmount.cpp:33
> +static bool isValidCurrency(const String& currency)

I think adding a comment indicating this is the IsWellFormedCurrencyCode operation (and a link) would be helpful).  Also, given that is an ECMA script concept, does an implementation of this concept exist in JSC already?

> Source/WebCore/Modules/paymentrequest/PaymentCurrencyAmount.cpp:47
> +static bool isValidDecimalMonetaryValue(const String& value)

Again, annotating what part of the spec this is implementing would be helpful. (Same for other functions below).

> Source/WebCore/Modules/paymentrequest/PaymentCurrencyAmount.h:40
> +    ExceptionOr<void> validate();

I've been trying to keep these structs that map to dictionaries as pure data types, but I am not sure I have great reason why.  In cases like this, I made the function global, and took the dictionary as a parameter.  If this is only used from PaymentRequest.cpp, I might even just make this a static in there.

> Source/WebCore/Modules/paymentrequest/PaymentDetailsModifier.idl:32
> +    JSON data;

I think it would be worth noting that the spec has the an object.  

I'm not sure if this change is exactly right, with respect to exceptions.  The JSON type will throw on dictionary conversion if the type cannot be converted or otherwise.  That is probably not the correct time to throw.

> Source/WebCore/Modules/paymentrequest/PaymentMethodData.idl:30
> -    object data;
> +    JSON data;

Same comment as in PaymentDetailsModifier.idl.

> Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:67
> +        // FIXME: Rethrow any exceptions that occurred while stringifying paymentMethod.data.

I am not sure you will have made it here if stringifying paymentMethod.data threw an exception.

> Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:99
> +    modifierData.reserveCapacity(paymentDetails.modifiers.size());

You can use reserveInitialCapacity here.

> Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:113
> +        // FIXME: Rethrow any exceptions that occurred while stringifying paymentMethod.data.

I am not sure you will have made it here if stringifying paymentMethod.data threw an exception.
Comment 4 Andy Estes 2017-08-20 15:54:53 PDT
(In reply to Sam Weinig from comment #3)
> Comment on attachment 318601 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=318601&action=review
> 
> > Source/WebCore/Modules/paymentrequest/PaymentDetailsModifier.idl:32
> > +    JSON data;
> 
> I'm not sure if this change is exactly right, with respect to exceptions. 
> The JSON type will throw on dictionary conversion if the type cannot be
> converted or otherwise.  That is probably not the correct time to throw.

I think you're right. I was under the impression that the bindings for JSON wouldn't throw on errors but would just give a null String instead. I'm probably wrong about that.

I'll take another pass and try to get the JSON stringification correct. I'll also address your other comments.

Thanks for taking a look!
Comment 5 Andy Estes 2017-08-20 19:44:13 PDT
(In reply to Sam Weinig from comment #3)
> Comment on attachment 318601 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=318601&action=review
> 
> > Source/WebCore/Modules/paymentrequest/PaymentCurrencyAmount.cpp:33
> > +static bool isValidCurrency(const String& currency)
> 
> Also, given that is an ECMA script concept, does an implementation of this concept exist in JSC already?

There is an implementation in IntlNumberFormat, but I couldn't see how to easily reuse it. It's a simple algorithm, so I didn't feel too bad about duplicating it.
Comment 6 Andy Estes 2017-08-20 20:36:59 PDT Comment hidden (obsolete)
Comment 7 Andy Estes 2017-08-20 20:37:56 PDT Comment hidden (obsolete)
Comment 8 Build Bot 2017-08-20 20:39:10 PDT Comment hidden (obsolete)
Comment 9 Darin Adler 2017-08-21 09:04:07 PDT
Comment on attachment 318612 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=318612&action=review

> Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:55
> +static bool isValidDecimalMonetaryValue(const String& value)

Should take a StringView.

> Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:66
> +    for (unsigned i = 0; i < value.length(); ++i) {

Should use a modern for loop since StringView offers that:

    for (auto character : value.codeUnits()) {
Comment 10 Andy Estes 2017-08-21 09:58:04 PDT Comment hidden (obsolete)
Comment 11 Build Bot 2017-08-21 10:00:19 PDT Comment hidden (obsolete)
Comment 12 WebKit Commit Bot 2017-08-21 10:41:08 PDT
Comment on attachment 318640 [details]
Patch

Clearing flags on attachment: 318640

Committed r220971: <http://trac.webkit.org/changeset/220971>
Comment 13 WebKit Commit Bot 2017-08-21 10:41:10 PDT
All reviewed patches have been landed.  Closing bug.
Comment 14 Radar WebKit Bug Importer 2017-08-21 10:42:00 PDT
<rdar://problem/33994157>