Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for customisation of the "get the parent" algorithm #1230

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

keithamus
Copy link

@keithamus keithamus commented Oct 10, 2023

This modifies the EventTarget IDL to allow assignment of a parent EventTarget to an EventTarget instance, while also modifying the "get the parent" algorithm to default to returning that instance.

It also modifies the Event Dispatch algorithm to ensure that custom parent chains cannot cause loops.

  • At least two implementers are interested (and none opposed):
  • Tests are written and can be reviewed and commented upon at:
  • Implementation bugs are filed:
    • Chromium: …
    • Gecko: …
    • WebKit: …
    • Deno (only for aborting and events): …
    • Node.js (only for aborting and events): …
  • MDN issue is filed: …
  • The top of this comment includes a clear commit message to use.

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

@keithamus keithamus force-pushed the allow-for-customisation-of-the-get-the-parent-algorithm branch from 8de9564 to 652ef26 Compare October 10, 2023 23:09
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial feedback. Mainly around how to organize this. Overall I think this works, but would love to hear from @rniwa and @smaug---- especially.

dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated
Comment on lines 993 to 988
<p>Each {{EventTarget}} object also has an associated <dfn export>get the parent</dfn> algorithm,
which takes an <a>event</a> <var>event</var>, and returns an {{EventTarget}} object. Unless
specified otherwise it returns null.
which takes an <a>event</a> <var>event</var>, and returns an {{EventTarget}}. Unless otherwise
specified otherwise it returns the associated <a for=EventTarget>attached internals</a><a
for=EventTargetInternals">parent</a> attribute.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead we should make the parent setter overwrite this algorithm with an algorithm that returns the given value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I've added some steps which I think resolve this but let me know, I'm sure it could use some refinement.

dom.bs Outdated Show resolved Hide resolved
@keithamus keithamus force-pushed the allow-for-customisation-of-the-get-the-parent-algorithm branch 4 times, most recently from 2870b4a to 5eef8a5 Compare October 11, 2023 09:23
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated
for=EventTargetInternals>eventTarget</a> then<a>throw</a> a "{{HierarchyRequestError!!exception}}"
{{DOMException}}.

<li>Set <var>internal</var>'s <a for=EventTargetInternals>eventTarget</a> <a>get the parent</a>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find precedent for setting an algorithm so this is just made up, hopefully it suffices?

@keithamus keithamus force-pushed the allow-for-customisation-of-the-get-the-parent-algorithm branch from 5eef8a5 to def63ff Compare October 11, 2023 09:27
dom.bs Outdated
@@ -1322,6 +1373,9 @@ property of the event being dispatched.
<p>While <var>parent</var> is non-null:</p>

<ol>
<li>If the <var>event</var>'s <a for=Event>path</a> <a for=set>contains</a> <var>parent</var>
then <a>throw</a> a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be slow. I don't think we can do this in normal case when dispatching events to dom tree. The relevant code in implementations is so hot that extra virtual c++ calls show up, as an example.
We need to ensure that there are now loops when setting up the parents. That is already done for DOM nodes anyhow - DOM tree doesn't contain loops.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you prefer us to check the chain during setting of the parent? Would that suffice?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would, yeah.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I think I've resolved this

interface EventTargetInternals {
attribute EventTarget parent;
};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit cumbersome API, one needs to pass a callback and then use its param to change a property value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you prefer an init dictionary? One downside to this, as explained in #583 (comment) is that an init dictionary cannot allow setting the parent post-construction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I suppose we could also do what new Promise() does, but it doesn't seem as extensible:

new EventTarget(setParent => {
  setParent(someParent);
}

I think as long as the capability is only granted to whoever constructed the EventTarget object I'm okay, so alternative proposals welcome.

@keithamus keithamus force-pushed the allow-for-customisation-of-the-get-the-parent-algorithm branch 2 times, most recently from 3a8cd2b to 601544f Compare October 11, 2023 10:32
This modifies the EventTarget IDL to allow assignment of a parent
EventTarget to an EventTarget instance, while also modifying the "get
the parent" algorithm to default to returning that instance.

It also modifies the Event Dispatch algorithm to ensure that custom
parent chains cannot cause loops.
@keithamus keithamus force-pushed the allow-for-customisation-of-the-get-the-parent-algorithm branch from 601544f to b5db7fa Compare October 11, 2023 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants