Bug 234113

Summary: Add test case for execCommand to verify inserting an ordered list and deletion
Product: WebKit Reporter: Brandon <brandonstewart>
Component: HTML EditingAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, cdumez, changseok, esprehn+autocc, ews-watchlist, gyuyoung.kim, rniwa, sabouhallawa, simon.fraser, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
patch
cdumez: review-, cdumez: commit-queue-
patch
ews-feeder: commit-queue-
patch
none
patch none

Description Brandon 2021-12-09 17:21:39 PST
Do not immediately execute an event if another event is ongoing
Comment 1 Brandon 2021-12-09 17:23:10 PST
<rdar://86153015>
Comment 2 Brandon 2021-12-09 17:37:01 PST
Created attachment 446644 [details]
patch
Comment 3 Chris Dumez 2021-12-09 17:42:41 PST
Comment on attachment 446644 [details]
patch

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

> LayoutTests/ChangeLog:3
> +        Do not immediately execute an event if another event is ongoing

The title doesn't match the patch.

Should be something like:
The load & error events of an <img> element should be dispatched asynchronously.
Comment 4 Chris Dumez 2021-12-09 17:45:18 PST
Comment on attachment 446644 [details]
patch

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

> LayoutTests/ChangeLog:4
> +        https://bugs.webkit.org/show_bug.cgi?id=234113

Please add the radar number on the next line:
<rdar://86153015>
Comment 5 Chris Dumez 2021-12-10 07:58:15 PST
Comment on attachment 446644 [details]
patch

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

> Source/WebCore/html/HTMLImageLoader.cpp:64
> +    element().document().queueTaskToDispatchEvent(TaskSource::DOMManipulation, WTFMove(event));

I was wrong, despite us setting the event target, Document::queueTaskToDispatchEvent() will dispatch the event at the Document (not the image element).
You'll likely need to do something like this instead:
```
element.document().eventLoop().queueTask(TaskSource::DOMManipulation, [element = Ref { element() }, errorOccurred] {
    element.dispatchEvent(Event::create(errorOccurred ? eventNames().errorEvent : eventNames().loadEvent, Event::CanBubble::No, Event::IsCancelable::No));
});
```
Comment 6 Brandon 2021-12-10 13:16:33 PST
<rdar://85926354>

Radar number should be this one instead.
Comment 7 Brandon 2021-12-10 13:19:09 PST
Created attachment 446794 [details]
patch
Comment 8 Chris Dumez 2021-12-10 16:09:48 PST
Comment on attachment 446794 [details]
patch

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

> Source/WebCore/html/HTMLImageLoader.cpp:65
> +    element().document().eventLoop().queueTask(TaskSource::DOMManipulation, [element = Ref { element() }, errorOccurred] {

Many tests are failing. I think the issue is that the page load event can now fire *before* an image's load/error event. We likely need to delay the firing of the page's load event somehow. Or maybe we need to make something asynchronous earlier in the call stack instead.
Do you have a stack trace of this event getting called synchronously in the context of your test? It would help determinate how to best fix this.
Comment 9 Chris Dumez 2021-12-10 16:15:28 PST
Comment on attachment 446794 [details]
patch

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

>> Source/WebCore/html/HTMLImageLoader.cpp:65
>> +    element().document().eventLoop().queueTask(TaskSource::DOMManipulation, [element = Ref { element() }, errorOccurred] {
> 
> Many tests are failing. I think the issue is that the page load event can now fire *before* an image's load/error event. We likely need to delay the firing of the page's load event somehow. Or maybe we need to make something asynchronous earlier in the call stack instead.
> Do you have a stack trace of this event getting called synchronously in the context of your test? It would help determinate how to best fix this.

Yes, I think it is likely one of the callers need to be fixed instead.

You can see that some callers already call this function asynchronously (e.g. via `loadEventSender().dispatchEventSoon(*this);`) so adding a queueTask() here delays it one run loop iteration further.
Comment 10 Brandon 2021-12-13 13:16:13 PST
Created attachment 447049 [details]
patch
Comment 11 Brandon 2021-12-13 13:32:34 PST
Created attachment 447051 [details]
patch
Comment 12 Chris Dumez 2021-12-13 13:34:32 PST
Comment on attachment 447051 [details]
patch

r=me assuming the bots are happy.
Comment 13 EWS 2021-12-14 10:04:21 PST
Committed r287029 (245232@main): <https://commits.webkit.org/245232@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 447051 [details].