WebIDL: Remove JSObject from Document::NamedGetter (#31841)

* WebIDL: Remove `JSObject` from `Document::NamedGetter`

* fix: update rustdoc comment
This commit is contained in:
eri 2024-03-24 19:04:04 +01:00 committed by GitHub
parent 1ab38fcd3f
commit 58081579e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 29 deletions

View file

@ -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<NonNull<JSObject>> {
/// <https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter>
fn NamedGetter(&self, name: DOMString) -> Option<NamedPropertyValue> {
if name.is_empty() {
return None;
}
@ -4886,19 +4884,11 @@ impl DocumentMethods for Document {
.downcast::<HTMLIFrameElement>()
.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

View file

@ -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;

View file

@ -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<NonNull<JSObject>> {
self.upcast::<Document>().NamedGetter(_cx, name)
fn NamedGetter(&self, name: DOMString) -> Option<NamedPropertyValue> {
self.upcast::<Document>().NamedGetter(name)
}
}