Skip to content

Commit ea0ca2a

Browse files
eeriipull[bot]
authored andcommitted
WebIDL: Remove JSObject from Document::NamedGetter (servo#31841)
* WebIDL: Remove `JSObject` from `Document::NamedGetter` * fix: update rustdoc comment
1 parent a3daa42 commit ea0ca2a

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed

components/script/dom/document.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
99
use std::collections::{HashMap, HashSet, VecDeque};
1010
use std::default::Default;
1111
use std::mem;
12-
use std::ptr::NonNull;
1312
use std::rc::Rc;
1413
use std::slice::from_ref;
1514
use std::time::{Duration, Instant};
@@ -26,7 +25,6 @@ use euclid::default::{Point2D, Rect, Size2D};
2625
use html5ever::{local_name, namespace_url, ns, LocalName, Namespace, QualName};
2726
use hyper_serde::Serde;
2827
use ipc_channel::ipc::{self, IpcSender};
29-
use js::jsapi::JSObject;
3028
use js::rust::HandleObject;
3129
use keyboard_types::{Code, Key, KeyState};
3230
use lazy_static::lazy_static;
@@ -80,7 +78,7 @@ use crate::dom::bindings::callback::ExceptionHandling;
8078
use crate::dom::bindings::cell::{ref_filter_map, DomRefCell, Ref, RefMut};
8179
use crate::dom::bindings::codegen::Bindings::BeforeUnloadEventBinding::BeforeUnloadEvent_Binding::BeforeUnloadEventMethods;
8280
use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
83-
DocumentMethods, DocumentReadyState,
81+
DocumentMethods, DocumentReadyState, NamedPropertyValue,
8482
};
8583
use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods;
8684
use crate::dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElement_Binding::HTMLIFrameElementMethods;
@@ -176,7 +174,7 @@ use crate::dom::window::{ReflowReason, Window};
176174
use crate::dom::windowproxy::WindowProxy;
177175
use crate::fetch::FetchCanceller;
178176
use crate::realms::{AlreadyInRealm, InRealm};
179-
use crate::script_runtime::{CommonScriptMsg, JSContext, ScriptThreadEventCategory};
177+
use crate::script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
180178
use crate::script_thread::{MainThreadScriptMsg, ScriptThread};
181179
use crate::stylesheet_set::StylesheetSetRef;
182180
use crate::task::TaskBox;
@@ -4860,8 +4858,8 @@ impl DocumentMethods for Document {
48604858
}
48614859

48624860
#[allow(unsafe_code)]
4863-
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
4864-
fn NamedGetter(&self, _cx: JSContext, name: DOMString) -> Option<NonNull<JSObject>> {
4861+
/// <https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter>
4862+
fn NamedGetter(&self, name: DOMString) -> Option<NamedPropertyValue> {
48654863
if name.is_empty() {
48664864
return None;
48674865
}
@@ -4886,19 +4884,11 @@ impl DocumentMethods for Document {
48864884
.downcast::<HTMLIFrameElement>()
48874885
.and_then(|iframe| iframe.GetContentWindow())
48884886
{
4889-
unsafe {
4890-
return Some(NonNull::new_unchecked(
4891-
nested_window_proxy.reflector().get_jsobject().get(),
4892-
));
4893-
}
4887+
return Some(NamedPropertyValue::WindowProxy(nested_window_proxy));
48944888
}
48954889

48964890
// Step 3.
4897-
unsafe {
4898-
return Some(NonNull::new_unchecked(
4899-
first.reflector().get_jsobject().get(),
4900-
));
4901-
}
4891+
return Some(NamedPropertyValue::Element(DomRoot::from_ref(first)));
49024892
}
49034893

49044894
// Step 4.
@@ -4933,11 +4923,7 @@ impl DocumentMethods for Document {
49334923
self.upcast(),
49344924
Box::new(DocumentNamedGetter { name }),
49354925
);
4936-
unsafe {
4937-
Some(NonNull::new_unchecked(
4938-
collection.reflector().get_jsobject().get(),
4939-
))
4940-
}
4926+
Some(NamedPropertyValue::HTMLCollection(collection))
49414927
}
49424928

49434929
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names

components/script/dom/webidls/Document.webidl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ partial /*sealed*/ interface Document {
9797
readonly attribute DocumentReadyState readyState;
9898

9999
// DOM tree accessors
100-
getter object (DOMString name);
100+
getter NamedPropertyValue (DOMString name);
101101
[CEReactions]
102102
attribute DOMString title;
103103
// [CEReactions]
@@ -212,3 +212,6 @@ partial interface Document {
212212
[Throws]
213213
ShadowRoot servoGetMediaControls(DOMString id);
214214
};
215+
216+
// https://html.spec.whatwg.org/multipage/#dom-document-nameditem-filter
217+
typedef (WindowProxy or Element or HTMLCollection) NamedPropertyValue;

components/script/dom/xmldocument.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
44

5-
use std::ptr::NonNull;
6-
75
use dom_struct::dom_struct;
8-
use js::jsapi::JSObject;
96
use mime::Mime;
107
use script_traits::DocumentActivity;
118
use servo_url::{MutableOrigin, ServoUrl};
129

1310
use crate::document_loader::DocumentLoader;
14-
use crate::dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
11+
use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
12+
DocumentMethods, NamedPropertyValue,
13+
};
1514
use crate::dom::bindings::codegen::Bindings::XMLDocumentBinding::XMLDocumentMethods;
1615
use crate::dom::bindings::inheritance::Castable;
1716
use crate::dom::bindings::reflector::reflect_dom_object;
@@ -21,7 +20,6 @@ use crate::dom::document::{Document, DocumentSource, HasBrowsingContext, IsHTMLD
2120
use crate::dom::location::Location;
2221
use crate::dom::node::Node;
2322
use crate::dom::window::Window;
24-
use crate::script_runtime::JSContext;
2523

2624
// https://dom.spec.whatwg.org/#xmldocument
2725
#[dom_struct]
@@ -108,7 +106,7 @@ impl XMLDocumentMethods for XMLDocument {
108106
}
109107

110108
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
111-
fn NamedGetter(&self, _cx: JSContext, name: DOMString) -> Option<NonNull<JSObject>> {
112-
self.upcast::<Document>().NamedGetter(_cx, name)
109+
fn NamedGetter(&self, name: DOMString) -> Option<NamedPropertyValue> {
110+
self.upcast::<Document>().NamedGetter(name)
113111
}
114112
}

0 commit comments

Comments
 (0)