From 58081579e9a537ba6bd71bcdcb2b066e14e037b8 Mon Sep 17 00:00:00 2001 From: eri Date: Sun, 24 Mar 2024 19:04:04 +0100 Subject: [PATCH] WebIDL: Remove `JSObject` from `Document::NamedGetter` (#31841) * WebIDL: Remove `JSObject` from `Document::NamedGetter` * fix: update rustdoc comment --- components/script/dom/document.rs | 28 +++++-------------- components/script/dom/webidls/Document.webidl | 5 +++- components/script/dom/xmldocument.rs | 12 ++++---- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index e6b7d07941e..c3f3b0f57ba 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -9,7 +9,6 @@ use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::{HashMap, HashSet, VecDeque}; use std::default::Default; use std::mem; -use std::ptr::NonNull; use std::rc::Rc; use std::slice::from_ref; use std::time::{Duration, Instant}; @@ -26,7 +25,6 @@ use euclid::default::{Point2D, Rect, Size2D}; use html5ever::{local_name, namespace_url, ns, LocalName, Namespace, QualName}; use hyper_serde::Serde; use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::JSObject; use js::rust::HandleObject; use keyboard_types::{Code, Key, KeyState}; use lazy_static::lazy_static; @@ -80,7 +78,7 @@ use crate::dom::bindings::callback::ExceptionHandling; use crate::dom::bindings::cell::{ref_filter_map, DomRefCell, Ref, RefMut}; use crate::dom::bindings::codegen::Bindings::BeforeUnloadEventBinding::BeforeUnloadEvent_Binding::BeforeUnloadEventMethods; use crate::dom::bindings::codegen::Bindings::DocumentBinding::{ - DocumentMethods, DocumentReadyState, + DocumentMethods, DocumentReadyState, NamedPropertyValue, }; use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods; use crate::dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElement_Binding::HTMLIFrameElementMethods; @@ -176,7 +174,7 @@ use crate::dom::window::{ReflowReason, Window}; use crate::dom::windowproxy::WindowProxy; use crate::fetch::FetchCanceller; use crate::realms::{AlreadyInRealm, InRealm}; -use crate::script_runtime::{CommonScriptMsg, JSContext, ScriptThreadEventCategory}; +use crate::script_runtime::{CommonScriptMsg, ScriptThreadEventCategory}; use crate::script_thread::{MainThreadScriptMsg, ScriptThread}; use crate::stylesheet_set::StylesheetSetRef; use crate::task::TaskBox; @@ -4860,8 +4858,8 @@ impl DocumentMethods for Document { } #[allow(unsafe_code)] - // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter - fn NamedGetter(&self, _cx: JSContext, name: DOMString) -> Option> { + /// + fn NamedGetter(&self, name: DOMString) -> Option { if name.is_empty() { return None; } @@ -4886,19 +4884,11 @@ impl DocumentMethods for Document { .downcast::() .and_then(|iframe| iframe.GetContentWindow()) { - unsafe { - return Some(NonNull::new_unchecked( - nested_window_proxy.reflector().get_jsobject().get(), - )); - } + return Some(NamedPropertyValue::WindowProxy(nested_window_proxy)); } // Step 3. - unsafe { - return Some(NonNull::new_unchecked( - first.reflector().get_jsobject().get(), - )); - } + return Some(NamedPropertyValue::Element(DomRoot::from_ref(first))); } // Step 4. @@ -4933,11 +4923,7 @@ impl DocumentMethods for Document { self.upcast(), Box::new(DocumentNamedGetter { name }), ); - unsafe { - Some(NonNull::new_unchecked( - collection.reflector().get_jsobject().get(), - )) - } + Some(NamedPropertyValue::HTMLCollection(collection)) } // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names diff --git a/components/script/dom/webidls/Document.webidl b/components/script/dom/webidls/Document.webidl index e33600dd17b..00cc5d81506 100644 --- a/components/script/dom/webidls/Document.webidl +++ b/components/script/dom/webidls/Document.webidl @@ -97,7 +97,7 @@ partial /*sealed*/ interface Document { readonly attribute DocumentReadyState readyState; // DOM tree accessors - getter object (DOMString name); + getter NamedPropertyValue (DOMString name); [CEReactions] attribute DOMString title; // [CEReactions] @@ -212,3 +212,6 @@ partial interface Document { [Throws] ShadowRoot servoGetMediaControls(DOMString id); }; + +// https://html.spec.whatwg.org/multipage/#dom-document-nameditem-filter +typedef (WindowProxy or Element or HTMLCollection) NamedPropertyValue; diff --git a/components/script/dom/xmldocument.rs b/components/script/dom/xmldocument.rs index 389a1aa9cd4..e376c6309ab 100644 --- a/components/script/dom/xmldocument.rs +++ b/components/script/dom/xmldocument.rs @@ -2,16 +2,15 @@ * 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 std::ptr::NonNull; - use dom_struct::dom_struct; -use js::jsapi::JSObject; use mime::Mime; use script_traits::DocumentActivity; use servo_url::{MutableOrigin, ServoUrl}; use crate::document_loader::DocumentLoader; -use crate::dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; +use crate::dom::bindings::codegen::Bindings::DocumentBinding::{ + DocumentMethods, NamedPropertyValue, +}; use crate::dom::bindings::codegen::Bindings::XMLDocumentBinding::XMLDocumentMethods; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::reflect_dom_object; @@ -21,7 +20,6 @@ use crate::dom::document::{Document, DocumentSource, HasBrowsingContext, IsHTMLD use crate::dom::location::Location; use crate::dom::node::Node; use crate::dom::window::Window; -use crate::script_runtime::JSContext; // https://dom.spec.whatwg.org/#xmldocument #[dom_struct] @@ -108,7 +106,7 @@ impl XMLDocumentMethods for XMLDocument { } // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter - fn NamedGetter(&self, _cx: JSContext, name: DOMString) -> Option> { - self.upcast::().NamedGetter(_cx, name) + fn NamedGetter(&self, name: DOMString) -> Option { + self.upcast::().NamedGetter(name) } }