Bug 189386 - [Apple Pay] Dispatch a paymentmethodchange event when the payment method changes
Summary: [Apple Pay] Dispatch a paymentmethodchange event when the payment method changes
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:
 
Reported: 2018-09-06 17:06 PDT by Andy Estes
Modified: 2018-09-08 19:04 PDT (History)
13 users (show)

See Also:


Attachments
Patch (19.83 KB, patch)
2018-09-06 17:13 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (40.94 KB, patch)
2018-09-08 13:41 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (43.26 KB, patch)
2018-09-08 14:12 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews100 for mac-sierra (2.29 MB, application/zip)
2018-09-08 15:20 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews202 for win-future (12.87 MB, application/zip)
2018-09-08 15:49 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews117 for mac-sierra (3.04 MB, application/zip)
2018-09-08 15:51 PDT, EWS Watchlist
no flags Details
Patch (46.78 KB, patch)
2018-09-08 16:59 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 2018-09-06 17:06:16 PDT
[Apple Pay] Dispatch a paymentmethodchange event when the payment method changes
Comment 1 Andy Estes 2018-09-06 17:13:07 PDT
Created attachment 349095 [details]
Patch
Comment 2 youenn fablet 2018-09-06 17:33:10 PDT
Comment on attachment 349095 [details]
Patch

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

> Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.h:60
>      JSC::Strong<JSC::JSObject> m_methodDetails;

Cannot it create some unbreakable reference cycles if methodDetails makes a reference to the PaymentMethodChangeEvent?
There is a potentially similar issue with IDB (bug 189201).
Ideally, we might want to keep a strong but clear it at creation of the JSPaymentMethodChangeEvent and do regular marking at that time.
Other approaches might be to use DOMGuarded to clear the strong at document destruction time but this may have observable differences.
Comment 3 Andy Estes 2018-09-07 09:59:24 PDT
(In reply to youenn fablet from comment #2)
> Comment on attachment 349095 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=349095&action=review
> 
> > Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.h:60
> >      JSC::Strong<JSC::JSObject> m_methodDetails;
> 
> Cannot it create some unbreakable reference cycles if methodDetails makes a
> reference to the PaymentMethodChangeEvent?
> There is a potentially similar issue with IDB (bug 189201).
> Ideally, we might want to keep a strong but clear it at creation of the
> JSPaymentMethodChangeEvent and do regular marking at that time.
> Other approaches might be to use DOMGuarded to clear the strong at document
> destruction time but this may have observable differences.

Yeah, I guess it could, but I don't think there's a reference cycle right now.

methodDetails is composed only of DOMStrings (see ApplePayPaymentMethod.idl). Is your concern that a script might add references to methodDetails after we fire the event?

What if we froze methodDetails to prevent scripts from modifying it?

I'll also check out your suggestions.
Comment 4 Andy Estes 2018-09-08 13:41:19 PDT Comment hidden (obsolete)
Comment 5 EWS Watchlist 2018-09-08 13:44:42 PDT Comment hidden (obsolete)
Comment 6 Darin Adler 2018-09-08 13:55:55 PDT
(In reply to Andy Estes from comment #3)
> Is your concern that a script might add
> references to methodDetails after we fire the event?

Yes. This kind of thing can happen any time we use Strong in DOM bindings. That’s what the test fast/dom/reference-cycle-leaks.html is about, and ideally you would add new cases to that test to demonstrate that leaks do not occur.

One pattern to avoid this is that instead of Strong, we use JSValueInWrappedObject. Examples of this include CustomEvent.

> What if we froze methodDetails to prevent scripts from modifying it?

I don’t know exactly what "freezing" a JavaScript object would mean, but if we can somehow forbid attaching custom property values, than that would eliminate the reference cycle issue. But is that really compatible with what other web browsers would do?
Comment 7 Andy Estes 2018-09-08 14:04:44 PDT
(In reply to Darin Adler from comment #6)
> (In reply to Andy Estes from comment #3)
> > Is your concern that a script might add
> > references to methodDetails after we fire the event?
> 
> Yes. This kind of thing can happen any time we use Strong in DOM bindings.
> That’s what the test fast/dom/reference-cycle-leaks.html is about, and
> ideally you would add new cases to that test to demonstrate that leaks do
> not occur.

Ok, good to know. I'll add a test to reference-cycle-leaks.html.

> One pattern to avoid this is that instead of Strong, we use
> JSValueInWrappedObject. Examples of this include CustomEvent.

I switched to using JSValueInWrappedObject in my latest patch.
Comment 8 Andy Estes 2018-09-08 14:12:06 PDT Comment hidden (obsolete)
Comment 9 EWS Watchlist 2018-09-08 14:15:08 PDT Comment hidden (obsolete)
Comment 10 EWS Watchlist 2018-09-08 15:20:49 PDT Comment hidden (obsolete)
Comment 11 EWS Watchlist 2018-09-08 15:20:51 PDT Comment hidden (obsolete)
Comment 12 Andy Estes 2018-09-08 15:42:47 PDT
Need to move the new reference-cycle-leaks result to platform/mac-wk2.
Comment 13 EWS Watchlist 2018-09-08 15:49:39 PDT Comment hidden (obsolete)
Comment 14 EWS Watchlist 2018-09-08 15:49:51 PDT Comment hidden (obsolete)
Comment 15 EWS Watchlist 2018-09-08 15:51:18 PDT Comment hidden (obsolete)
Comment 16 EWS Watchlist 2018-09-08 15:51:20 PDT Comment hidden (obsolete)
Comment 17 Andy Estes 2018-09-08 16:59:19 PDT
Created attachment 349265 [details]
Patch
Comment 18 Darin Adler 2018-09-08 17:00:07 PDT
Comment on attachment 349261 [details]
Patch

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

> LayoutTests/fast/dom/reference-cycle-leaks.html:89
> +    leakDetectionNode.event = new PaymentMethodChangeEvent("x", { methodDetails: leakDetectionNode });

How does this handle platforms where we don't have PaymentMethodChangeEvent?
Comment 19 EWS Watchlist 2018-09-08 17:01:19 PDT
Attachment 349265 [details] did not pass style-queue:


ERROR: Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.cpp:40:  Code inside a namespace should not be indented.  [whitespace/indent] [4]
Total errors found: 1 in 18 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 20 Andy Estes 2018-09-08 17:02:23 PDT
(In reply to Darin Adler from comment #18)
> Comment on attachment 349261 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=349261&action=review
> 
> > LayoutTests/fast/dom/reference-cycle-leaks.html:89
> > +    leakDetectionNode.event = new PaymentMethodChangeEvent("x", { methodDetails: leakDetectionNode });
> 
> How does this handle platforms where we don't have PaymentMethodChangeEvent?

In the new patch, the baseline expected result prints "---- Did not test PaymentMethodChangeEvent because it is not enabled." Then mac-wk2 and ios-wk2 have platform expected results with PASS messages.
Comment 21 WebKit Commit Bot 2018-09-08 19:04:00 PDT
Comment on attachment 349265 [details]
Patch

Clearing flags on attachment: 349265

Committed r235833: <https://trac.webkit.org/changeset/235833>
Comment 22 WebKit Commit Bot 2018-09-08 19:04:02 PDT
All reviewed patches have been landed.  Closing bug.
Comment 23 Radar WebKit Bug Importer 2018-09-08 19:04:25 PDT
<rdar://problem/44268288>