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 constructing and subclassing EventTarget #467

Merged
merged 2 commits into from
Jul 7, 2017

Conversation

domenic
Copy link
Member

@domenic domenic commented Jun 21, 2017

Closes #441. See also https://www.w3.org/Bugs/Public/show_bug.cgi?id=16487.

Tests: web-platform-tests/wpt#6306

Chrome is interested in implementing this; anyone else? @cdumez @smaug---- @travisleithead


Preview | Diff

@domenic domenic added needs implementer interest Moving the issue forward requires implementers to express interest needs tests Moving the issue forward requires someone to write tests labels Jun 21, 2017
@smaug----
Copy link
Collaborator

smaug---- commented Jun 21, 2017

What is the current API proposal? No parent chain?
What are the use cases we try to solve?

In general I'm supportive, just need to think a bit the API so that it fulfills the most common use cases.

@domenic
Copy link
Member Author

domenic commented Jun 21, 2017

Yes; as noted in the pull request,

+<p class="note">In the future we could allow custom <a>get the parent</a> algorithms. Let us know
+if this would be useful for your programs. For now, all author-created {{EventTarget}}s do not
+participate in a tree structure.</p>

domenic added a commit to web-platform-tests/wpt that referenced this pull request Jun 21, 2017
@domenic domenic removed the needs tests Moving the issue forward requires someone to write tests label Jun 21, 2017
domenic added a commit to web-platform-tests/wpt that referenced this pull request Jun 22, 2017
dom.bs Outdated
@@ -944,6 +944,11 @@ and a <dfn export for=EventTarget>legacy-canceled-activation behavior</dfn> algo
are not to be used for anything else. [[!HTML]]

<dl class=domintro>
<dt><code><var>target</var> = new EventTarget();</code>
Copy link
Member

Choose a reason for hiding this comment

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

We should link EventTarget here.

dom.bs Outdated
must run these steps:

<ol>
<li>Return a new {{EventTarget}} object, using the default <a>get the parent</a> algorithm, and
Copy link
Member

Choose a reason for hiding this comment

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

<li><p> or maybe inline it in the previous step. It seems that you get a default get the parent and no behavior should maybe be a note as it's just a statement of fact.

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.

LGTM overall. I guess we still need some implementer support and tests?

@domenic
Copy link
Member Author

domenic commented Jun 28, 2017

Got tests, got 1 implementer support; waiting for a second.

@domenic
Copy link
Member Author

domenic commented Jul 6, 2017

@annevk given #441 (comment), do you think this is mergeable? (Also want to review/merge the tests.)

@annevk
Copy link
Member

annevk commented Jul 7, 2017

I confirmed on IRC that it's all good. I also reviewed the tests.

@domenic domenic merged commit c4c1c8b into master Jul 7, 2017
@domenic domenic deleted the constructible-eventtarget branch July 7, 2017 18:55
domenic added a commit to web-platform-tests/wpt that referenced this pull request Jul 7, 2017
@annevk
Copy link
Member

annevk commented Jul 8, 2017

For next time, it's worth noting the tests in the commit message I think.

Also, did any browser bugs get filed?

@domenic
Copy link
Member Author

domenic commented Jul 8, 2017

I was going to but then the build failed so I didn't have a spec to point them to. That should be fixed now so I can file Monday. Will update the thread then.

@domenic
Copy link
Member Author

domenic commented Jul 10, 2017

Re-built the spec and it's showing up now, yay. Bugs:

bertogg pushed a commit to Igalia/webkit that referenced this pull request Feb 17, 2020
https://bugs.webkit.org/show_bug.cgi?id=174313

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* web-platform-tests/WebIDL/ecmascript-binding/constructors-expected.txt:
* web-platform-tests/dom/events/Event-subclasses-constructors-expected.txt:
* web-platform-tests/dom/events/EventTarget-constructible.any-expected.txt:
* web-platform-tests/dom/events/EventTarget-constructible.any.worker-expected.txt:
* web-platform-tests/dom/events/event-global-extra.window-expected.txt:
* web-platform-tests/dom/idlharness.any.worker-expected.txt:
* web-platform-tests/dom/idlharness.window-expected.txt:

Source/WebCore:

Currently, EventTarget can't be directly constructed or be subclassed in JavaScript.
The spec for EventTarget was updated (whatwg/dom#467) to allow
constructing and subclassing EventTarget. This feature was shipped in Chrome 64 and Firefox 59.

This patch introduces EventTargetConcrete class, a user-constructable version of EventTarget,
exposed as "EventTarget" to JavaScript. We don't use EventTarget directly because it is an abstract
class and making it non-abstract is unfavorable due to size increase of EventTarget and all of its
subclasses with code that is mostly unnecessary for them, resulting in a performance decrease.

To prevent definition of specific to EventTargetConcrete `toJS` and `toJSNewlyCreated` functions,
we don't define EventTargetConcrete interface type, but rather tweak make_event_factory.pl to
default to base interface (like it does for Event).

To allow subclassing of all DOM constructors, non-custom ones replace structures of newly created
wrapper objects with ones returned by InternalFunction::createSubclassStructure. Per WebIDL spec [1],
`setSubclassStructureIfNeeded` helper uses realm of `newTarget` for default prototypes.

This approach was chosen because a) detecting [[Construct]] with callFrame->newTarget() is
unreliable outside constructor, and b) passing `newTarget` down to `createWrapper` via
`toJSNewlyCreated` is quite awkward and would result in massive code change.

[1] https://heycam.github.io/webidl/#internally-create-a-new-object-implementing-the-interface
(step 3.3.2)

Tests: fast/dom/dom-constructors.html
       imported/w3c/web-platform-tests/WebIDL/ecmascript-binding/constructors.html
       imported/w3c/web-platform-tests/dom/events/Event-subclasses-constructors.html
       imported/w3c/web-platform-tests/dom/events/EventTarget-constructible.any.html
       imported/w3c/web-platform-tests/dom/idlharness.window.html

* Headers.cmake:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSDOMWrapperCache.h:
(WebCore::setSubclassStructureIfNeeded):
* bindings/js/JSEventTargetCustom.cpp:
(WebCore::toJSNewlyCreated):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateConstructorDefinition):
* bindings/scripts/InFilesCompiler.pm:
(generateInterfacesHeader):
* bindings/scripts/test/JS/*: Adjust bindings expectations.
* dom/EventTarget.cpp:
(WebCore::EventTarget::create):
* dom/EventTarget.h:
* dom/EventTarget.idl:
* dom/EventTargetConcrete.cpp: Added.
* dom/EventTargetConcrete.h: Added.
* dom/make_event_factory.pl:
(generateImplementation):

LayoutTests:

* fast/dom/dom-constructors-expected.txt:
* fast/dom/dom-constructors.html:
* platform/ios/imported/w3c/web-platform-tests/dom/events/Event-subclasses-constructors-expected.txt: Removed.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@256716 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs implementer interest Moving the issue forward requires implementers to express interest
Development

Successfully merging this pull request may close these issues.

3 participants