Auto merge of #29805 - jdm:dom-protos, r=mrobinson

Support extending DOM classes in JS

Adds support for determining the correct prototype as part of a `new` call for non-HTML constructors. Support for HTML constructors [was added](https://github.com/servo/servo/blob/master/components/script/dom/bindings/htmlconstructor.rs#L116) as part of the custom element work, but that wasn't enough for extending other DOM objects like `EventTarget`.

This work is based on Gecko's code in https://searchfox.org/mozilla-central/rev/2d678a843ceab81e43f7ffb83212197dc10e944a/dom/bindings/BindingUtils.cpp#3667, and is split into two parts:
1) the actualy new implementation (demonstrating that extending `EventTarget` works as expected)
2) plumbing the new prototype through all of the rest of the DOM object construction code.

This ends up being more complex than the way it's done in Gecko because they have lazy DOM reflectors, so their native DOM objects can be constructed without any knowledge of a JS prototype. Servo's reflectors are eager, however, so we need to propagate prototype information into individual constructors. As a result, this was a tedious set of changes to make.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #29770
- [x] There are tests for these changes
This commit is contained in:
bors-servo 2023-06-01 05:06:09 +02:00 committed by GitHub
commit fd7698c3ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
208 changed files with 2657 additions and 696 deletions

View file

@ -23,22 +23,3 @@
[CompositionEvent constructor (argument with non-default values)]
expected: FAIL
[SubclassedEvent constructor (no argument)]
expected: FAIL
[SubclassedEvent constructor (undefined argument)]
expected: FAIL
[SubclassedEvent constructor (null argument)]
expected: FAIL
[SubclassedEvent constructor (empty argument)]
expected: FAIL
[SubclassedEvent constructor (argument with default values)]
expected: FAIL
[SubclassedEvent constructor (argument with non-default values)]
expected: FAIL

View file

@ -1,11 +0,0 @@
[EventTarget-constructible.any.worker.html]
type: testharness
[EventTarget can be subclassed]
expected: FAIL
[EventTarget-constructible.any.html]
type: testharness
[EventTarget can be subclassed]
expected: FAIL

View file

@ -2781,9 +2781,6 @@
[HTMLTableColElement interface: document.createElement("col") must inherit property "vAlign" with the proper type]
expected: FAIL
[HTMLAudioElement interface: named constructor without 'new']
expected: FAIL
[HTMLEmbedElement interface: attribute name]
expected: FAIL
@ -3912,9 +3909,6 @@
[HTMLAllCollection interface: existence and properties of interface prototype object's @@unscopables property]
expected: FAIL
[HTMLImageElement interface: named constructor without 'new']
expected: FAIL
[HTMLModElement interface: document.createElement("del") must inherit property "cite" with the proper type]
expected: FAIL
@ -4131,9 +4125,6 @@
[SVGAElement includes HTMLHyperlinkElementUtils: member names are unique]
expected: FAIL
[HTMLOptionElement interface: named constructor without 'new']
expected: FAIL
[HTMLElement interface: attribute onwebkitanimationiteration]
expected: FAIL

View file

@ -1,4 +0,0 @@
[audio_constructor.html]
[Calling Audio should throw]
expected: FAIL

View file

@ -1,36 +0,0 @@
[constructors.html]
[Constructor in child window with normal NewTarget from parent window]
expected: FAIL
[Constructor in parent window with normal NewTarget from child window]
expected: FAIL
[Subclass constructor in parent window]
expected: FAIL
[Subclass constructor in child window]
expected: FAIL
[Subclass constructor in parent window with parent class in child window]
expected: FAIL
[Subclass constructor in child window with parent class in parent window]
expected: FAIL
[Constructor in child window with bad NewTarget from parent window]
expected: FAIL
[Constructor in parent window with bad NewTarget from child window]
expected: FAIL
[Constructor in parent window with bad NewTarget from parent window that's a bound child window function]
expected: FAIL
[Constructor in child window with bad NewTarget from child window that's a bound parent window function]
expected: FAIL
[Constructor in parent window with bad NewTarget from parent window that's a proxy for a child window function]
expected: FAIL
[Constructor in child window with bad NewTarget from child window that's a proxy for a parent window function]
expected: FAIL

View file

@ -1,4 +0,0 @@
[legacy-factor-function-subclass.window.html]
[[LegacyFactoryFunction\] can be subclassed and correctly handles NewTarget]
expected: FAIL