From 79a45c7da31d2d8ccd21b45dcf80c4ba21797786 Mon Sep 17 00:00:00 2001 From: Leo Ring <59373587+leo030303@users.noreply.github.com> Date: Mon, 4 Aug 2025 04:42:54 +0100 Subject: [PATCH] Implement HTMLDocument API (#38433) This updates the pull request from here https://github.com/servo/servo/pull/32553 that looks to be dormant. The main change is that I've switched out `reflector` with `document` based off this suggestion https://github.com/servo/servo/pull/32553#issuecomment-2179568743, and the `GetLocation` and `SupportedPropertyNames` methods pass through the values from `Document`. The implementation details are otherwise the same as the original PR Testing: I don't see any WPT tests for this feature, I could make a custom test if desired Fixes: https://github.com/servo/servo/issues/32536 --------- Signed-off-by: Leo Ring --- components/script/dom/htmldocument.rs | 36 +++++++++++++++++++ components/script/dom/mod.rs | 1 + .../webidls/HTMLDocument.webidl | 13 +++++++ .../meta/html/editing/dnd/historical.html.ini | 3 -- .../contextmenu-historical.html.ini | 3 -- ...rototype-constructor-set-receiver.html.ini | 3 -- .../invalid-this-value-cross-realm.html.ini | 3 -- tests/wpt/mozilla/meta/MANIFEST.json | 2 +- .../tests/mozilla/interfaces.https.html | 1 + 9 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 components/script/dom/htmldocument.rs create mode 100644 components/script_bindings/webidls/HTMLDocument.webidl delete mode 100644 tests/wpt/meta/html/editing/dnd/historical.html.ini delete mode 100644 tests/wpt/meta/html/semantics/interactive-elements/contextmenu-historical.html.ini delete mode 100644 tests/wpt/meta/webidl/ecmascript-binding/interface-prototype-constructor-set-receiver.html.ini delete mode 100644 tests/wpt/meta/webidl/ecmascript-binding/invalid-this-value-cross-realm.html.ini diff --git a/components/script/dom/htmldocument.rs b/components/script/dom/htmldocument.rs new file mode 100644 index 00000000000..91f112d19c3 --- /dev/null +++ b/components/script/dom/htmldocument.rs @@ -0,0 +1,36 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use dom_struct::dom_struct; +use script_bindings::codegen::GenericBindings::DocumentBinding::DocumentMethods; +use script_bindings::codegen::GenericBindings::HTMLDocumentBinding::HTMLDocumentMethods; +use script_bindings::root::DomRoot; +use script_bindings::script_runtime::CanGc; +use script_bindings::str::DOMString; + +use super::types::{Document, Location}; +use crate::dom::bindings::codegen::Bindings::DocumentBinding::NamedPropertyValue; + +/// +#[dom_struct] +pub(crate) struct HTMLDocument { + document: Document, +} + +impl HTMLDocumentMethods for HTMLDocument { + /// + fn GetLocation(&self) -> Option> { + self.document.GetLocation() + } + + /// + fn SupportedPropertyNames(&self) -> Vec { + self.document.SupportedPropertyNames() + } + + /// + fn NamedGetter(&self, name: DOMString) -> Option { + self.document.NamedGetter(name, CanGc::note()) + } +} diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index b98cb689b11..57e16ad4941 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -362,6 +362,7 @@ pub(crate) mod htmldialogelement; pub(crate) mod htmldirectoryelement; pub(crate) mod htmldivelement; pub(crate) mod htmldlistelement; +pub(crate) mod htmldocument; pub(crate) mod htmlelement; pub(crate) mod htmlembedelement; pub(crate) mod htmlfieldsetelement; diff --git a/components/script_bindings/webidls/HTMLDocument.webidl b/components/script_bindings/webidls/HTMLDocument.webidl new file mode 100644 index 00000000000..df9b699be39 --- /dev/null +++ b/components/script_bindings/webidls/HTMLDocument.webidl @@ -0,0 +1,13 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +// https://html.spec.whatwg.org/multipage/#htmldocument + +[LegacyOverrideBuiltIns, + Exposed=Window] +interface HTMLDocument : Document { + // DOM tree accessors + getter NamedPropertyValue (DOMString name); +}; diff --git a/tests/wpt/meta/html/editing/dnd/historical.html.ini b/tests/wpt/meta/html/editing/dnd/historical.html.ini deleted file mode 100644 index 79d9a3db08e..00000000000 --- a/tests/wpt/meta/html/editing/dnd/historical.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[historical.html] - [ondragexit must not be present on the GlobalEventHandlers locations] - expected: FAIL diff --git a/tests/wpt/meta/html/semantics/interactive-elements/contextmenu-historical.html.ini b/tests/wpt/meta/html/semantics/interactive-elements/contextmenu-historical.html.ini deleted file mode 100644 index f3254dc9984..00000000000 --- a/tests/wpt/meta/html/semantics/interactive-elements/contextmenu-historical.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[contextmenu-historical.html] - [onshow must not be present on the GlobalEventHandlers locations] - expected: FAIL diff --git a/tests/wpt/meta/webidl/ecmascript-binding/interface-prototype-constructor-set-receiver.html.ini b/tests/wpt/meta/webidl/ecmascript-binding/interface-prototype-constructor-set-receiver.html.ini deleted file mode 100644 index a8812c9bd59..00000000000 --- a/tests/wpt/meta/webidl/ecmascript-binding/interface-prototype-constructor-set-receiver.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[interface-prototype-constructor-set-receiver.html] - [Direct [[Set\]\] preserves [[Enumerable\]\]: false property attribute] - expected: FAIL diff --git a/tests/wpt/meta/webidl/ecmascript-binding/invalid-this-value-cross-realm.html.ini b/tests/wpt/meta/webidl/ecmascript-binding/invalid-this-value-cross-realm.html.ini deleted file mode 100644 index 534f7d25950..00000000000 --- a/tests/wpt/meta/webidl/ecmascript-binding/invalid-this-value-cross-realm.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[invalid-this-value-cross-realm.html] - [Cross-realm operation throws when called on incompatible object] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 014d6baa7d9..5fdfde6973e 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -13725,7 +13725,7 @@ ] ], "interfaces.https.html": [ - "efb780c382456b1fda514b33fe5b317c447fa09e", + "05ead2c3e2c362586506be77c8093c8bc4f0fb53", [ null, {} diff --git a/tests/wpt/mozilla/tests/mozilla/interfaces.https.html b/tests/wpt/mozilla/tests/mozilla/interfaces.https.html index efb780c3824..05ead2c3e2c 100644 --- a/tests/wpt/mozilla/tests/mozilla/interfaces.https.html +++ b/tests/wpt/mozilla/tests/mozilla/interfaces.https.html @@ -164,6 +164,7 @@ test_interfaces([ "HTMLDirectoryElement", "HTMLDivElement", "HTMLDListElement", + "HTMLDocument", "HTMLElement", "HTMLEmbedElement", "HTMLFieldSetElement",