Bug 240212 - Introduction.md: Explain active DOM objects
Summary: Introduction.md: Explain active DOM objects
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-05-07 22:44 PDT by Ryosuke Niwa
Modified: 2022-05-09 22:09 PDT (History)
7 users (show)

See Also:


Attachments
Patch (7.37 KB, patch)
2022-05-07 22:48 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Patch (7.09 KB, patch)
2022-05-07 22:51 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Patch for landing (7.63 KB, patch)
2022-05-09 22:06 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2022-05-07 22:44:45 PDT
Explain what active DOM objects do.
Comment 1 Ryosuke Niwa 2022-05-07 22:48:00 PDT
Created attachment 459008 [details]
Patch
Comment 2 Ryosuke Niwa 2022-05-07 22:51:52 PDT
Created attachment 459009 [details]
Patch
Comment 3 Wenson Hsieh 2022-05-08 22:20:34 PDT
Comment on attachment 459009 [details]
Patch

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

> Introduction.md:1023
> +    request.addEventListener("load", () => callback);

Nit - this should either be
```
request.addEventListener("load", () => callback());
```
or
```
request.addEventListener("load", callback);
```

> Introduction.md:1029
> +In WebKit, we consider these objects has a *pending activity*.

"these objects has a" doesn't read quite so well.
Comment 4 Chris Dumez 2022-05-09 07:43:10 PDT
Comment on attachment 459009 [details]
Patch

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

This is good but I think we should mention that ActiveDOMObject::virtualHasPendingActivity() should return true (or we should be hold a PendingActivity) as long as we may fire events at the object. This is a big source of confusion for people who sometimes think they only need a pending activity when they're about to fire an event (e.g. queueing an event). Fact is if you don't hold a pending activity as soon as your object is created, then its JS wrapper may get garbage collected before we even get a chance to queue an event.

>> Introduction.md:1029
>> +In WebKit, we consider these objects has a *pending activity*.
> 
> "these objects has a" doesn't read quite so well.

*have
Comment 5 Ryosuke Niwa 2022-05-09 09:06:15 PDT
(In reply to Chris Dumez from comment #4)
> Comment on attachment 459009 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=459009&action=review
> 
> This is good but I think we should mention that
> ActiveDOMObject::virtualHasPendingActivity() should return true (or we
> should be hold a PendingActivity) as long as we may fire events at the
> object. This is a big source of confusion for people who sometimes think
> they only need a pending activity when they're about to fire an event (e.g.
> queueing an event). Fact is if you don't hold a pending activity as soon as
> your object is created, then its JS wrapper may get garbage collected before
> we even get a chance to queue an event.

Okay. How about something like this:

Note that virtualHasPendingActivity should return true so long as there is a possibility of dispatching an event or invoke JavaScript in any way in the future. In other words, a pending activity should exit while an object is doing some work in C++ well before any event dispatching is scheduled. Anytime there is no pending activity, JS wrappers of an object can get deleted by the garbage collector.
Comment 6 Chris Dumez 2022-05-09 18:50:03 PDT
> In other words, a pending activity should exit

You probably mean “exist” but otherwise yes, lgtm.
Comment 7 Ryosuke Niwa 2022-05-09 21:58:39 PDT
(In reply to Wenson Hsieh from comment #3)
> Comment on attachment 459009 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=459009&action=review
> 
> > Introduction.md:1023
> > +    request.addEventListener("load", () => callback);
> 
> Nit - this should either be
> ```
> request.addEventListener("load", () => callback());
> ```
> or
> ```
> request.addEventListener("load", callback);
> ```

Oops, will do the latter.

> > Introduction.md:1029
> > +In WebKit, we consider these objects has a *pending activity*.
> 
> "these objects has a" doesn't read quite so well.

Rephrased it to:

In WebKit, we consider such an object to have a *pending activity*.
Expressing the presence of such a pending activity is a primary use case of
[`ActiveDOMObject`](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/dom/ActiveDOMObject.h).
Comment 8 Ryosuke Niwa 2022-05-09 21:59:32 PDT
(In reply to Chris Dumez from comment #6)
> > In other words, a pending activity should exit
> 
> You probably mean “exist” but otherwise yes, lgtm.

Fixed.
Comment 9 Ryosuke Niwa 2022-05-09 22:06:07 PDT
Created attachment 459093 [details]
Patch for landing
Comment 10 Ryosuke Niwa 2022-05-09 22:08:31 PDT
Committed r293999 (250435@trunk): <https://commits.webkit.org/250435@trunk>
Comment 11 Radar WebKit Bug Importer 2022-05-09 22:09:13 PDT
<rdar://problem/93006333>