window: avoid NonNull<JSObject> in NamedGetter (#35508)

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
This commit is contained in:
Gae24 2025-02-17 13:48:21 +01:00 committed by GitHub
parent f5ed44c3aa
commit 56199fd153
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 22 deletions

View file

@ -9,7 +9,6 @@ use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::default::Default; use std::default::Default;
use std::io::{stderr, stdout, Write}; use std::io::{stderr, stdout, Write};
use std::ptr::NonNull;
use std::rc::Rc; use std::rc::Rc;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -88,7 +87,7 @@ use super::bindings::codegen::Bindings::MessagePortBinding::StructuredSerializeO
use super::bindings::trace::HashMapTracedValues; use super::bindings::trace::HashMapTracedValues;
use crate::dom::bindings::cell::{DomRefCell, Ref}; use crate::dom::bindings::cell::{DomRefCell, Ref};
use crate::dom::bindings::codegen::Bindings::DocumentBinding::{ use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
DocumentMethods, DocumentReadyState, DocumentMethods, DocumentReadyState, NamedPropertyValue,
}; };
use crate::dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods; use crate::dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
use crate::dom::bindings::codegen::Bindings::HistoryBinding::History_Binding::HistoryMethods; use crate::dom::bindings::codegen::Bindings::HistoryBinding::History_Binding::HistoryMethods;
@ -1475,9 +1474,8 @@ impl WindowMethods<crate::DomTypeHolder> for Window {
self.as_global_scope().is_secure_context() self.as_global_scope().is_secure_context()
} }
// https://html.spec.whatwg.org/multipage/#named-access-on-the-window-object /// <https://html.spec.whatwg.org/multipage/#dom-window-nameditem>
#[allow(unsafe_code)] fn NamedGetter(&self, name: DOMString) -> Option<NamedPropertyValue> {
fn NamedGetter(&self, _cx: JSContext, name: DOMString) -> Option<NonNull<JSObject>> {
if name.is_empty() { if name.is_empty() {
return None; return None;
} }
@ -1517,11 +1515,7 @@ impl WindowMethods<crate::DomTypeHolder> for Window {
.downcast::<HTMLIFrameElement>() .downcast::<HTMLIFrameElement>()
.and_then(|iframe| iframe.GetContentWindow()) .and_then(|iframe| iframe.GetContentWindow())
{ {
unsafe { return Some(NamedPropertyValue::WindowProxy(nested_window_proxy));
return Some(NonNull::new_unchecked(
nested_window_proxy.reflector().get_jsobject().get(),
));
}
} }
} }
@ -1531,11 +1525,7 @@ impl WindowMethods<crate::DomTypeHolder> for Window {
if elements.next().is_none() { if elements.next().is_none() {
// Step 3. // Step 3.
unsafe { return Some(NamedPropertyValue::Element(DomRoot::from_ref(first)));
return Some(NonNull::new_unchecked(
first.reflector().get_jsobject().get(),
));
}
} }
// Step 4. // Step 4.
@ -1569,11 +1559,7 @@ impl WindowMethods<crate::DomTypeHolder> for Window {
document.upcast(), document.upcast(),
Box::new(WindowNamedGetter { name }), Box::new(WindowNamedGetter { name }),
); );
unsafe { Some(NamedPropertyValue::HTMLCollection(collection))
Some(NonNull::new_unchecked(
collection.reflector().get_jsobject().get(),
))
}
} }
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names

View file

@ -132,7 +132,7 @@ unsafe extern "C" fn get_own_property_descriptor(
let window = Root::downcast::<Window>(GlobalScope::from_object(proxy.get())) let window = Root::downcast::<Window>(GlobalScope::from_object(proxy.get()))
.expect("global is not a window"); .expect("global is not a window");
if let Some(obj) = window.NamedGetter(cx, s.into()) { if let Some(obj) = window.NamedGetter(s.into()) {
rooted!(in(*cx) let mut rval = UndefinedValue()); rooted!(in(*cx) let mut rval = UndefinedValue());
obj.to_jsval(*cx, rval.handle_mut()); obj.to_jsval(*cx, rval.handle_mut());
set_property_descriptor( set_property_descriptor(

View file

@ -45,7 +45,7 @@
optional DOMString features = ""); optional DOMString features = "");
//getter WindowProxy (unsigned long index); //getter WindowProxy (unsigned long index);
getter object (DOMString name); getter NamedPropertyValue (DOMString name);
// the user agent // the user agent
readonly attribute Navigator navigator; readonly attribute Navigator navigator;