Use Window in new methods instead of GlobalScope for interfaces with … (#36133)

…Window-only constructors

<!-- Please describe your changes on the following line: -->


---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by
`[X]` when the step is complete, and replace `___` with appropriate
data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #36118 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox
is checked, so that we can help you if you get stuck somewhere along the
way.-->

<!-- Pull requests that do not address these steps are welcome, but they
will require additional verification as part of the review process. -->

---------

Signed-off-by: richarddushime <mudaherarich@gmail.com>
Signed-off-by: Richard Dushime <45734838+richarddushime@users.noreply.github.com>
This commit is contained in:
Richard Dushime 2025-04-02 16:50:56 +02:00 committed by GitHub
parent 2ce306f450
commit 60baa8ce11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 226 additions and 240 deletions

View file

@ -5,7 +5,7 @@ use dom_struct::dom_struct;
use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::DOMRectListBinding::DOMRectListMethods; use crate::dom::bindings::codegen::Bindings::DOMRectListBinding::DOMRectListMethods;
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::{Reflector, reflect_dom_object_with_proto};
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::domrect::DOMRect; use crate::dom::domrect::DOMRect;
use crate::dom::window::Window; use crate::dom::window::Window;
@ -37,7 +37,7 @@ impl DOMRectList {
) -> DomRoot<DOMRectList> { ) -> DomRoot<DOMRectList> {
reflect_dom_object_with_proto( reflect_dom_object_with_proto(
Box::new(DOMRectList::new_inherited(rects)), Box::new(DOMRectList::new_inherited(rects)),
&*window.global(), window,
None, None,
can_gc, can_gc,
) )

View file

@ -11,12 +11,11 @@ use crate::dom::bindings::codegen::Bindings::FormDataEventBinding;
use crate::dom::bindings::codegen::Bindings::FormDataEventBinding::FormDataEventMethods; use crate::dom::bindings::codegen::Bindings::FormDataEventBinding::FormDataEventMethods;
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::event::{Event, EventBubbles, EventCancelable}; use crate::dom::event::{Event, EventBubbles, EventCancelable};
use crate::dom::formdata::FormData; use crate::dom::formdata::FormData;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -28,7 +27,7 @@ pub(crate) struct FormDataEvent {
impl FormDataEvent { impl FormDataEvent {
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
type_: Atom, type_: Atom,
can_bubble: EventBubbles, can_bubble: EventBubbles,
cancelable: EventCancelable, cancelable: EventCancelable,
@ -36,12 +35,12 @@ impl FormDataEvent {
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<FormDataEvent> { ) -> DomRoot<FormDataEvent> {
Self::new_with_proto( Self::new_with_proto(
global, None, type_, can_bubble, cancelable, form_data, can_gc, window, None, type_, can_bubble, cancelable, form_data, can_gc,
) )
} }
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
type_: Atom, type_: Atom,
can_bubble: EventBubbles, can_bubble: EventBubbles,
@ -54,7 +53,7 @@ impl FormDataEvent {
event: Event::new_inherited(), event: Event::new_inherited(),
form_data: Dom::from_ref(form_data), form_data: Dom::from_ref(form_data),
}), }),
global, window,
proto, proto,
can_gc, can_gc,
); );
@ -80,7 +79,7 @@ impl FormDataEventMethods<crate::DomTypeHolder> for FormDataEvent {
let cancelable = EventCancelable::from(init.parent.cancelable); let cancelable = EventCancelable::from(init.parent.cancelable);
let event = FormDataEvent::new_with_proto( let event = FormDataEvent::new_with_proto(
&window.global(), window,
proto, proto,
Atom::from(type_), Atom::from(type_),
bubbles, bubbles,

View file

@ -248,7 +248,8 @@ impl Gamepad {
} }
pub(crate) fn notify_event(&self, event_type: GamepadEventType, can_gc: CanGc) { pub(crate) fn notify_event(&self, event_type: GamepadEventType, can_gc: CanGc) {
let event = GamepadEvent::new_with_type(&self.global(), event_type, self, can_gc); let event =
GamepadEvent::new_with_type(self.global().as_window(), event_type, self, can_gc);
event event
.upcast::<Event>() .upcast::<Event>()
.fire(self.global().as_window().upcast::<EventTarget>(), can_gc); .fire(self.global().as_window().upcast::<EventTarget>(), can_gc);

View file

@ -11,12 +11,11 @@ use crate::dom::bindings::codegen::Bindings::GamepadEventBinding;
use crate::dom::bindings::codegen::Bindings::GamepadEventBinding::GamepadEventMethods; use crate::dom::bindings::codegen::Bindings::GamepadEventBinding::GamepadEventMethods;
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event; use crate::dom::event::Event;
use crate::dom::gamepad::Gamepad; use crate::dom::gamepad::Gamepad;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -40,18 +39,18 @@ impl GamepadEvent {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
cancelable: bool, cancelable: bool,
gamepad: &Gamepad, gamepad: &Gamepad,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<GamepadEvent> { ) -> DomRoot<GamepadEvent> {
Self::new_with_proto(global, None, type_, bubbles, cancelable, gamepad, can_gc) Self::new_with_proto(window, None, type_, bubbles, cancelable, gamepad, can_gc)
} }
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
@ -61,7 +60,7 @@ impl GamepadEvent {
) -> DomRoot<GamepadEvent> { ) -> DomRoot<GamepadEvent> {
let ev = reflect_dom_object_with_proto( let ev = reflect_dom_object_with_proto(
Box::new(GamepadEvent::new_inherited(gamepad)), Box::new(GamepadEvent::new_inherited(gamepad)),
global, window,
proto, proto,
can_gc, can_gc,
); );
@ -73,7 +72,7 @@ impl GamepadEvent {
} }
pub(crate) fn new_with_type( pub(crate) fn new_with_type(
global: &GlobalScope, window: &Window,
event_type: GamepadEventType, event_type: GamepadEventType,
gamepad: &Gamepad, gamepad: &Gamepad,
can_gc: CanGc, can_gc: CanGc,
@ -83,7 +82,7 @@ impl GamepadEvent {
GamepadEventType::Disconnected => "gamepaddisconnected", GamepadEventType::Disconnected => "gamepaddisconnected",
}; };
GamepadEvent::new(global, name.into(), false, false, gamepad, can_gc) GamepadEvent::new(window, name.into(), false, false, gamepad, can_gc)
} }
} }
@ -97,7 +96,7 @@ impl GamepadEventMethods<crate::DomTypeHolder> for GamepadEvent {
init: &GamepadEventBinding::GamepadEventInit, init: &GamepadEventBinding::GamepadEventInit,
) -> Fallible<DomRoot<GamepadEvent>> { ) -> Fallible<DomRoot<GamepadEvent>> {
Ok(GamepadEvent::new_with_proto( Ok(GamepadEvent::new_with_proto(
&window.global(), window,
proto, proto,
Atom::from(type_), Atom::from(type_),
init.parent.bubbles, init.parent.bubbles,

View file

@ -774,7 +774,7 @@ impl HTMLFormElement {
// Step 6.5 // Step 6.5
let event = SubmitEvent::new( let event = SubmitEvent::new(
&self.global(), self.global().as_window(),
atom!("submit"), atom!("submit"),
true, true,
true, true,
@ -1233,7 +1233,7 @@ impl HTMLFormElement {
// Step 7 // Step 7
let event = FormDataEvent::new( let event = FormDataEvent::new(
&window.global(), &window,
atom!("formdata"), atom!("formdata"),
EventBubbles::Bubbles, EventBubbles::Bubbles,
EventCancelable::NotCancelable, EventCancelable::NotCancelable,

View file

@ -1631,7 +1631,7 @@ impl HTMLMediaElement {
// Steps 7. // Steps 7.
let event = TrackEvent::new( let event = TrackEvent::new(
&self.global(), self.global().as_window(),
atom!("addtrack"), atom!("addtrack"),
false, false,
false, false,
@ -1689,7 +1689,7 @@ impl HTMLMediaElement {
// Steps 7. // Steps 7.
let event = TrackEvent::new( let event = TrackEvent::new(
&self.global(), self.global().as_window(),
atom!("addtrack"), atom!("addtrack"),
false, false,
false, false,

View file

@ -141,6 +141,7 @@ impl RTCDataChannel {
pub(crate) fn on_error(&self, error: WebRtcError, can_gc: CanGc) { pub(crate) fn on_error(&self, error: WebRtcError, can_gc: CanGc) {
let global = self.global(); let global = self.global();
let window = global.as_window();
let cx = GlobalScope::get_cx(); let cx = GlobalScope::get_cx();
let _ac = JSAutoRealm::new(*cx, self.reflector().get_jsobject().get()); let _ac = JSAutoRealm::new(*cx, self.reflector().get_jsobject().get());
let init = RTCErrorInit { let init = RTCErrorInit {
@ -154,8 +155,8 @@ impl RTCDataChannel {
let message = match error { let message = match error {
WebRtcError::Backend(message) => DOMString::from(message), WebRtcError::Backend(message) => DOMString::from(message),
}; };
let error = RTCError::new(&global, &init, message, can_gc); let error = RTCError::new(window, &init, message, can_gc);
let event = RTCErrorEvent::new(&global, atom!("error"), false, false, &error, can_gc); let event = RTCErrorEvent::new(window, atom!("error"), false, false, &error, can_gc);
event.upcast::<Event>().fire(self.upcast(), can_gc); event.upcast::<Event>().fire(self.upcast(), can_gc);
} }

View file

@ -11,11 +11,10 @@ use crate::dom::bindings::codegen::Bindings::RTCDataChannelEventBinding::{
RTCDataChannelEventInit, RTCDataChannelEventMethods, RTCDataChannelEventInit, RTCDataChannelEventMethods,
}; };
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event; use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::rtcdatachannel::RTCDataChannel; use crate::dom::rtcdatachannel::RTCDataChannel;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -35,18 +34,18 @@ impl RTCDataChannelEvent {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
cancelable: bool, cancelable: bool,
channel: &RTCDataChannel, channel: &RTCDataChannel,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<RTCDataChannelEvent> { ) -> DomRoot<RTCDataChannelEvent> {
Self::new_with_proto(global, None, type_, bubbles, cancelable, channel, can_gc) Self::new_with_proto(window, None, type_, bubbles, cancelable, channel, can_gc)
} }
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
@ -56,7 +55,7 @@ impl RTCDataChannelEvent {
) -> DomRoot<RTCDataChannelEvent> { ) -> DomRoot<RTCDataChannelEvent> {
let event = reflect_dom_object_with_proto( let event = reflect_dom_object_with_proto(
Box::new(RTCDataChannelEvent::new_inherited(channel)), Box::new(RTCDataChannelEvent::new_inherited(channel)),
global, window,
proto, proto,
can_gc, can_gc,
); );
@ -78,7 +77,7 @@ impl RTCDataChannelEventMethods<crate::DomTypeHolder> for RTCDataChannelEvent {
init: &RTCDataChannelEventInit, init: &RTCDataChannelEventInit,
) -> DomRoot<RTCDataChannelEvent> { ) -> DomRoot<RTCDataChannelEvent> {
RTCDataChannelEvent::new_with_proto( RTCDataChannelEvent::new_with_proto(
&window.global(), window,
proto, proto,
Atom::from(type_), Atom::from(type_),
init.parent.bubbles, init.parent.bubbles,

View file

@ -8,11 +8,10 @@ use js::rust::HandleObject;
use crate::dom::bindings::codegen::Bindings::RTCErrorBinding::{ use crate::dom::bindings::codegen::Bindings::RTCErrorBinding::{
RTCErrorDetailType, RTCErrorInit, RTCErrorMethods, RTCErrorDetailType, RTCErrorInit, RTCErrorMethods,
}; };
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::domexception::DOMException; use crate::dom::domexception::DOMException;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -41,16 +40,16 @@ impl RTCError {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
init: &RTCErrorInit, init: &RTCErrorInit,
message: DOMString, message: DOMString,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<RTCError> { ) -> DomRoot<RTCError> {
Self::new_with_proto(global, None, init, message, can_gc) Self::new_with_proto(window, None, init, message, can_gc)
} }
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
init: &RTCErrorInit, init: &RTCErrorInit,
message: DOMString, message: DOMString,
@ -58,7 +57,7 @@ impl RTCError {
) -> DomRoot<RTCError> { ) -> DomRoot<RTCError> {
reflect_dom_object_with_proto( reflect_dom_object_with_proto(
Box::new(RTCError::new_inherited(init, message)), Box::new(RTCError::new_inherited(init, message)),
global, window,
proto, proto,
can_gc, can_gc,
) )
@ -74,7 +73,7 @@ impl RTCErrorMethods<crate::DomTypeHolder> for RTCError {
init: &RTCErrorInit, init: &RTCErrorInit,
message: DOMString, message: DOMString,
) -> DomRoot<RTCError> { ) -> DomRoot<RTCError> {
RTCError::new_with_proto(&window.global(), proto, init, message, can_gc) RTCError::new_with_proto(window, proto, init, message, can_gc)
} }
// https://www.w3.org/TR/webrtc/#dom-rtcerror-errordetail // https://www.w3.org/TR/webrtc/#dom-rtcerror-errordetail

View file

@ -11,11 +11,10 @@ use crate::dom::bindings::codegen::Bindings::RTCErrorEventBinding::{
RTCErrorEventInit, RTCErrorEventMethods, RTCErrorEventInit, RTCErrorEventMethods,
}; };
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event; use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::rtcerror::RTCError; use crate::dom::rtcerror::RTCError;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -35,18 +34,18 @@ impl RTCErrorEvent {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
cancelable: bool, cancelable: bool,
error: &RTCError, error: &RTCError,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<RTCErrorEvent> { ) -> DomRoot<RTCErrorEvent> {
Self::new_with_proto(global, None, type_, bubbles, cancelable, error, can_gc) Self::new_with_proto(window, None, type_, bubbles, cancelable, error, can_gc)
} }
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
@ -56,7 +55,7 @@ impl RTCErrorEvent {
) -> DomRoot<RTCErrorEvent> { ) -> DomRoot<RTCErrorEvent> {
let event = reflect_dom_object_with_proto( let event = reflect_dom_object_with_proto(
Box::new(RTCErrorEvent::new_inherited(error)), Box::new(RTCErrorEvent::new_inherited(error)),
global, window,
proto, proto,
can_gc, can_gc,
); );
@ -78,7 +77,7 @@ impl RTCErrorEventMethods<crate::DomTypeHolder> for RTCErrorEvent {
init: &RTCErrorEventInit, init: &RTCErrorEventInit,
) -> DomRoot<RTCErrorEvent> { ) -> DomRoot<RTCErrorEvent> {
RTCErrorEvent::new_with_proto( RTCErrorEvent::new_with_proto(
&window.global(), window,
proto, proto,
Atom::from(type_), Atom::from(type_),
init.parent.bubbles, init.parent.bubbles,

View file

@ -9,10 +9,9 @@ use crate::dom::bindings::codegen::Bindings::RTCIceCandidateBinding::{
RTCIceCandidateInit, RTCIceCandidateMethods, RTCIceCandidateInit, RTCIceCandidateMethods,
}; };
use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::{Reflector, reflect_dom_object_with_proto};
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -42,7 +41,7 @@ impl RTCIceCandidate {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
candidate: DOMString, candidate: DOMString,
sdp_m_id: Option<DOMString>, sdp_m_id: Option<DOMString>,
sdp_m_line_index: Option<u16>, sdp_m_line_index: Option<u16>,
@ -50,7 +49,7 @@ impl RTCIceCandidate {
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<RTCIceCandidate> { ) -> DomRoot<RTCIceCandidate> {
Self::new_with_proto( Self::new_with_proto(
global, window,
None, None,
candidate, candidate,
sdp_m_id, sdp_m_id,
@ -61,7 +60,7 @@ impl RTCIceCandidate {
} }
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
candidate: DOMString, candidate: DOMString,
sdp_m_id: Option<DOMString>, sdp_m_id: Option<DOMString>,
@ -76,7 +75,7 @@ impl RTCIceCandidate {
sdp_m_line_index, sdp_m_line_index,
username_fragment, username_fragment,
)), )),
global, window,
proto, proto,
can_gc, can_gc,
) )
@ -97,7 +96,7 @@ impl RTCIceCandidateMethods<crate::DomTypeHolder> for RTCIceCandidate {
)); ));
} }
Ok(RTCIceCandidate::new_with_proto( Ok(RTCIceCandidate::new_with_proto(
&window.global(), window,
proto, proto,
config.candidate.clone(), config.candidate.clone(),
config.sdpMid.clone(), config.sdpMid.clone(),

View file

@ -38,7 +38,6 @@ use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
use crate::dom::bindings::str::USVString; use crate::dom::bindings::str::USVString;
use crate::dom::event::{Event, EventBubbles, EventCancelable}; use crate::dom::event::{Event, EventBubbles, EventCancelable};
use crate::dom::eventtarget::EventTarget; use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::mediastream::MediaStream; use crate::dom::mediastream::MediaStream;
use crate::dom::mediastreamtrack::MediaStreamTrack; use crate::dom::mediastreamtrack::MediaStreamTrack;
use crate::dom::promise::Promise; use crate::dom::promise::Promise;
@ -177,14 +176,14 @@ impl RTCPeerConnection {
} }
fn new( fn new(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
config: &RTCConfiguration, config: &RTCConfiguration,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<RTCPeerConnection> { ) -> DomRoot<RTCPeerConnection> {
let this = reflect_dom_object_with_proto( let this = reflect_dom_object_with_proto(
Box::new(RTCPeerConnection::new_inherited()), Box::new(RTCPeerConnection::new_inherited()),
global, window,
proto, proto,
can_gc, can_gc,
); );
@ -230,7 +229,7 @@ impl RTCPeerConnection {
return; return;
} }
let candidate = RTCIceCandidate::new( let candidate = RTCIceCandidate::new(
&self.global(), self.global().as_window(),
candidate.candidate.into(), candidate.candidate.into(),
None, None,
Some(candidate.sdp_mline_index as u16), Some(candidate.sdp_mline_index as u16),
@ -238,7 +237,7 @@ impl RTCPeerConnection {
can_gc, can_gc,
); );
let event = RTCPeerConnectionIceEvent::new( let event = RTCPeerConnectionIceEvent::new(
&self.global(), self.global().as_window(),
atom!("icecandidate"), atom!("icecandidate"),
Some(&candidate), Some(&candidate),
None, None,
@ -267,8 +266,14 @@ impl RTCPeerConnection {
return; return;
} }
let track = MediaStreamTrack::new(&self.global(), id, ty, can_gc); let track = MediaStreamTrack::new(&self.global(), id, ty, can_gc);
let event = let event = RTCTrackEvent::new(
RTCTrackEvent::new(&self.global(), atom!("track"), false, false, &track, can_gc); self.global().as_window(),
atom!("track"),
false,
false,
&track,
can_gc,
);
event.upcast::<Event>().fire(self.upcast(), can_gc); event.upcast::<Event>().fire(self.upcast(), can_gc);
} }
@ -294,7 +299,7 @@ impl RTCPeerConnection {
); );
let event = RTCDataChannelEvent::new( let event = RTCDataChannelEvent::new(
&self.global(), self.global().as_window(),
atom!("datachannel"), atom!("datachannel"),
false, false,
false, false,
@ -372,7 +377,7 @@ impl RTCPeerConnection {
// step 6 // step 6
if state == RTCIceGatheringState::Complete { if state == RTCIceGatheringState::Complete {
let event = RTCPeerConnectionIceEvent::new( let event = RTCPeerConnectionIceEvent::new(
&self.global(), self.global().as_window(),
atom!("icecandidate"), atom!("icecandidate"),
None, None,
None, None,
@ -502,12 +507,7 @@ impl RTCPeerConnectionMethods<crate::DomTypeHolder> for RTCPeerConnection {
can_gc: CanGc, can_gc: CanGc,
config: &RTCConfiguration, config: &RTCConfiguration,
) -> Fallible<DomRoot<RTCPeerConnection>> { ) -> Fallible<DomRoot<RTCPeerConnection>> {
Ok(RTCPeerConnection::new( Ok(RTCPeerConnection::new(window, proto, config, can_gc))
&window.global(),
proto,
config,
can_gc,
))
} }
// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-icecandidate // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-icecandidate

View file

@ -12,11 +12,10 @@ use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionIceEventBinding::{
}; };
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event; use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::rtcicecandidate::RTCIceCandidate; use crate::dom::rtcicecandidate::RTCIceCandidate;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -41,18 +40,18 @@ impl RTCPeerConnectionIceEvent {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
ty: Atom, ty: Atom,
candidate: Option<&RTCIceCandidate>, candidate: Option<&RTCIceCandidate>,
url: Option<DOMString>, url: Option<DOMString>,
trusted: bool, trusted: bool,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<RTCPeerConnectionIceEvent> { ) -> DomRoot<RTCPeerConnectionIceEvent> {
Self::new_with_proto(global, None, ty, candidate, url, trusted, can_gc) Self::new_with_proto(window, None, ty, candidate, url, trusted, can_gc)
} }
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
ty: Atom, ty: Atom,
candidate: Option<&RTCIceCandidate>, candidate: Option<&RTCIceCandidate>,
@ -62,7 +61,7 @@ impl RTCPeerConnectionIceEvent {
) -> DomRoot<RTCPeerConnectionIceEvent> { ) -> DomRoot<RTCPeerConnectionIceEvent> {
let e = reflect_dom_object_with_proto( let e = reflect_dom_object_with_proto(
Box::new(RTCPeerConnectionIceEvent::new_inherited(candidate, url)), Box::new(RTCPeerConnectionIceEvent::new_inherited(candidate, url)),
global, window,
proto, proto,
can_gc, can_gc,
); );
@ -83,7 +82,7 @@ impl RTCPeerConnectionIceEventMethods<crate::DomTypeHolder> for RTCPeerConnectio
init: &RTCPeerConnectionIceEventInit, init: &RTCPeerConnectionIceEventInit,
) -> Fallible<DomRoot<RTCPeerConnectionIceEvent>> { ) -> Fallible<DomRoot<RTCPeerConnectionIceEvent>> {
Ok(RTCPeerConnectionIceEvent::new_with_proto( Ok(RTCPeerConnectionIceEvent::new_with_proto(
&window.global(), window,
proto, proto,
ty.into(), ty.into(),
init.candidate init.candidate

View file

@ -9,10 +9,9 @@ use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{
RTCSdpType, RTCSessionDescriptionInit, RTCSessionDescriptionMethods, RTCSdpType, RTCSessionDescriptionInit, RTCSessionDescriptionMethods,
}; };
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::{Reflector, reflect_dom_object_with_proto};
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -33,7 +32,7 @@ impl RTCSessionDescription {
} }
fn new( fn new(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
ty: RTCSdpType, ty: RTCSdpType,
sdp: DOMString, sdp: DOMString,
@ -41,7 +40,7 @@ impl RTCSessionDescription {
) -> DomRoot<RTCSessionDescription> { ) -> DomRoot<RTCSessionDescription> {
reflect_dom_object_with_proto( reflect_dom_object_with_proto(
Box::new(RTCSessionDescription::new_inherited(ty, sdp)), Box::new(RTCSessionDescription::new_inherited(ty, sdp)),
global, window,
proto, proto,
can_gc, can_gc,
) )
@ -57,7 +56,7 @@ impl RTCSessionDescriptionMethods<crate::DomTypeHolder> for RTCSessionDescriptio
config: &RTCSessionDescriptionInit, config: &RTCSessionDescriptionInit,
) -> Fallible<DomRoot<RTCSessionDescription>> { ) -> Fallible<DomRoot<RTCSessionDescription>> {
Ok(RTCSessionDescription::new( Ok(RTCSessionDescription::new(
&window.global(), window,
proto, proto,
config.type_, config.type_,
config.sdp.clone(), config.sdp.clone(),

View file

@ -10,11 +10,10 @@ use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventM
use crate::dom::bindings::codegen::Bindings::RTCTrackEventBinding::{self, RTCTrackEventMethods}; use crate::dom::bindings::codegen::Bindings::RTCTrackEventBinding::{self, RTCTrackEventMethods};
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event; use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::mediastreamtrack::MediaStreamTrack; use crate::dom::mediastreamtrack::MediaStreamTrack;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -35,18 +34,18 @@ impl RTCTrackEvent {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
cancelable: bool, cancelable: bool,
track: &MediaStreamTrack, track: &MediaStreamTrack,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<RTCTrackEvent> { ) -> DomRoot<RTCTrackEvent> {
Self::new_with_proto(global, None, type_, bubbles, cancelable, track, can_gc) Self::new_with_proto(window, None, type_, bubbles, cancelable, track, can_gc)
} }
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
@ -56,7 +55,7 @@ impl RTCTrackEvent {
) -> DomRoot<RTCTrackEvent> { ) -> DomRoot<RTCTrackEvent> {
let trackevent = reflect_dom_object_with_proto( let trackevent = reflect_dom_object_with_proto(
Box::new(RTCTrackEvent::new_inherited(track)), Box::new(RTCTrackEvent::new_inherited(track)),
global, window,
proto, proto,
can_gc, can_gc,
); );
@ -78,7 +77,7 @@ impl RTCTrackEventMethods<crate::DomTypeHolder> for RTCTrackEvent {
init: &RTCTrackEventBinding::RTCTrackEventInit, init: &RTCTrackEventBinding::RTCTrackEventInit,
) -> Fallible<DomRoot<RTCTrackEvent>> { ) -> Fallible<DomRoot<RTCTrackEvent>> {
Ok(RTCTrackEvent::new_with_proto( Ok(RTCTrackEvent::new_with_proto(
&window.global(), window,
proto, proto,
Atom::from(type_), Atom::from(type_),
init.parent.bubbles, init.parent.bubbles,

View file

@ -10,11 +10,10 @@ use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods;
use crate::dom::bindings::codegen::Bindings::SubmitEventBinding; use crate::dom::bindings::codegen::Bindings::SubmitEventBinding;
use crate::dom::bindings::codegen::Bindings::SubmitEventBinding::SubmitEventMethods; use crate::dom::bindings::codegen::Bindings::SubmitEventBinding::SubmitEventMethods;
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event; use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlelement::HTMLElement; use crate::dom::htmlelement::HTMLElement;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -35,18 +34,18 @@ impl SubmitEvent {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
cancelable: bool, cancelable: bool,
submitter: Option<DomRoot<HTMLElement>>, submitter: Option<DomRoot<HTMLElement>>,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<SubmitEvent> { ) -> DomRoot<SubmitEvent> {
Self::new_with_proto(global, None, type_, bubbles, cancelable, submitter, can_gc) Self::new_with_proto(window, None, type_, bubbles, cancelable, submitter, can_gc)
} }
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
@ -56,7 +55,7 @@ impl SubmitEvent {
) -> DomRoot<SubmitEvent> { ) -> DomRoot<SubmitEvent> {
let ev = reflect_dom_object_with_proto( let ev = reflect_dom_object_with_proto(
Box::new(SubmitEvent::new_inherited(submitter)), Box::new(SubmitEvent::new_inherited(submitter)),
global, window,
proto, proto,
can_gc, can_gc,
); );
@ -78,7 +77,7 @@ impl SubmitEventMethods<crate::DomTypeHolder> for SubmitEvent {
init: &SubmitEventBinding::SubmitEventInit, init: &SubmitEventBinding::SubmitEventInit,
) -> DomRoot<SubmitEvent> { ) -> DomRoot<SubmitEvent> {
SubmitEvent::new_with_proto( SubmitEvent::new_with_proto(
&window.global(), window,
proto, proto,
Atom::from(type_), Atom::from(type_),
init.parent.bubbles, init.parent.bubbles,

View file

@ -79,7 +79,7 @@ impl TextTrackList {
if let Some(track) = this.item(idx) { if let Some(track) = this.item(idx) {
let event = TrackEvent::new( let event = TrackEvent::new(
&this.global(), this.global().as_window(),
atom!("addtrack"), atom!("addtrack"),
false, false,
false, false,

View file

@ -13,11 +13,10 @@ use crate::dom::bindings::codegen::Bindings::TrackEventBinding::TrackEventMethod
use crate::dom::bindings::codegen::UnionTypes::VideoTrackOrAudioTrackOrTextTrack; use crate::dom::bindings::codegen::UnionTypes::VideoTrackOrAudioTrackOrTextTrack;
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event; use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::texttrack::TextTrack; use crate::dom::texttrack::TextTrack;
use crate::dom::videotrack::VideoTrack; use crate::dom::videotrack::VideoTrack;
use crate::dom::window::Window; use crate::dom::window::Window;
@ -61,18 +60,18 @@ impl TrackEvent {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
cancelable: bool, cancelable: bool,
track: &Option<VideoTrackOrAudioTrackOrTextTrack>, track: &Option<VideoTrackOrAudioTrackOrTextTrack>,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<TrackEvent> { ) -> DomRoot<TrackEvent> {
Self::new_with_proto(global, None, type_, bubbles, cancelable, track, can_gc) Self::new_with_proto(window, None, type_, bubbles, cancelable, track, can_gc)
} }
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
@ -82,7 +81,7 @@ impl TrackEvent {
) -> DomRoot<TrackEvent> { ) -> DomRoot<TrackEvent> {
let te = reflect_dom_object_with_proto( let te = reflect_dom_object_with_proto(
Box::new(TrackEvent::new_inherited(track)), Box::new(TrackEvent::new_inherited(track)),
global, window,
proto, proto,
can_gc, can_gc,
); );
@ -104,7 +103,7 @@ impl TrackEventMethods<crate::DomTypeHolder> for TrackEvent {
init: &TrackEventBinding::TrackEventInit, init: &TrackEventBinding::TrackEventInit,
) -> Fallible<DomRoot<TrackEvent>> { ) -> Fallible<DomRoot<TrackEvent>> {
Ok(TrackEvent::new_with_proto( Ok(TrackEvent::new_with_proto(
&window.global(), window,
proto, proto,
Atom::from(type_), Atom::from(type_),
init.parent.bubbles, init.parent.bubbles,

View file

@ -14,11 +14,10 @@ use crate::dom::bindings::codegen::Bindings::VTTCueBinding::{
}; };
use crate::dom::bindings::error::{Error, ErrorResult}; use crate::dom::bindings::error::{Error, ErrorResult};
use crate::dom::bindings::num::Finite; use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::documentfragment::DocumentFragment; use crate::dom::documentfragment::DocumentFragment;
use crate::dom::globalscope::GlobalScope;
use crate::dom::texttrackcue::TextTrackCue; use crate::dom::texttrackcue::TextTrackCue;
use crate::dom::vttregion::VTTRegion; use crate::dom::vttregion::VTTRegion;
use crate::dom::window::Window; use crate::dom::window::Window;
@ -62,7 +61,7 @@ impl VTTCue {
} }
fn new( fn new(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
start_time: f64, start_time: f64,
end_time: f64, end_time: f64,
@ -71,7 +70,7 @@ impl VTTCue {
) -> DomRoot<Self> { ) -> DomRoot<Self> {
reflect_dom_object_with_proto( reflect_dom_object_with_proto(
Box::new(Self::new_inherited(start_time, end_time, text)), Box::new(Self::new_inherited(start_time, end_time, text)),
global, window,
proto, proto,
can_gc, can_gc,
) )
@ -88,14 +87,7 @@ impl VTTCueMethods<crate::DomTypeHolder> for VTTCue {
end_time: Finite<f64>, end_time: Finite<f64>,
text: DOMString, text: DOMString,
) -> DomRoot<Self> { ) -> DomRoot<Self> {
VTTCue::new( VTTCue::new(window, proto, *start_time, *end_time, text, can_gc)
&window.global(),
proto,
*start_time,
*end_time,
text,
can_gc,
)
} }
// https://w3c.github.io/webvtt/#dom-vttcue-region // https://w3c.github.io/webvtt/#dom-vttcue-region

View file

@ -11,10 +11,9 @@ use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::VTTRegionBinding::{ScrollSetting, VTTRegionMethods}; use crate::dom::bindings::codegen::Bindings::VTTRegionBinding::{ScrollSetting, VTTRegionMethods};
use crate::dom::bindings::error::{Error, ErrorResult, Fallible}; use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::num::Finite; use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::{Reflector, reflect_dom_object_with_proto};
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -46,8 +45,8 @@ impl VTTRegion {
} }
} }
fn new(global: &GlobalScope, proto: Option<HandleObject>, can_gc: CanGc) -> DomRoot<Self> { fn new(window: &Window, proto: Option<HandleObject>, can_gc: CanGc) -> DomRoot<Self> {
reflect_dom_object_with_proto(Box::new(Self::new_inherited()), global, proto, can_gc) reflect_dom_object_with_proto(Box::new(Self::new_inherited()), window, proto, can_gc)
} }
} }
@ -58,7 +57,7 @@ impl VTTRegionMethods<crate::DomTypeHolder> for VTTRegion {
proto: Option<HandleObject>, proto: Option<HandleObject>,
can_gc: CanGc, can_gc: CanGc,
) -> Fallible<DomRoot<Self>> { ) -> Fallible<DomRoot<Self>> {
Ok(VTTRegion::new(&window.global(), proto, can_gc)) Ok(VTTRegion::new(window, proto, can_gc))
} }
// https://w3c.github.io/webvtt/#dom-vttregion-id // https://w3c.github.io/webvtt/#dom-vttregion-id

View file

@ -12,6 +12,7 @@ use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::utils::to_frozen_array; use crate::dom::bindings::utils::to_frozen_array;
use crate::dom::dompointreadonly::DOMPointReadOnly; use crate::dom::dompointreadonly::DOMPointReadOnly;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrreferencespace::XRReferenceSpace; use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrrigidtransform::XRRigidTransform; use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::XRSession; use crate::dom::xrsession::XRSession;
@ -40,12 +41,13 @@ impl XRBoundedReferenceSpace {
#[allow(unused)] #[allow(unused)]
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
session: &XRSession, session: &XRSession,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRBoundedReferenceSpace> { ) -> DomRoot<XRBoundedReferenceSpace> {
let offset = XRRigidTransform::identity(global, can_gc); let offset = XRRigidTransform::identity(window, can_gc);
Self::new_offset(global, session, &offset, can_gc) let global = window.global();
Self::new_offset(&global, session, &offset, can_gc)
} }
#[allow(unused)] #[allow(unused)]

View file

@ -15,7 +15,7 @@ use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite; use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object}; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope; use crate::dom::window::Window;
use crate::dom::xrhittestresult::XRHitTestResult; use crate::dom::xrhittestresult::XRHitTestResult;
use crate::dom::xrhittestsource::XRHitTestSource; use crate::dom::xrhittestsource::XRHitTestSource;
use crate::dom::xrjointpose::XRJointPose; use crate::dom::xrjointpose::XRJointPose;
@ -50,14 +50,14 @@ impl XRFrame {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
session: &XRSession, session: &XRSession,
data: Frame, data: Frame,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRFrame> { ) -> DomRoot<XRFrame> {
reflect_dom_object( reflect_dom_object(
Box::new(XRFrame::new_inherited(session, data)), Box::new(XRFrame::new_inherited(session, data)),
global, window,
can_gc, can_gc,
) )
} }
@ -123,7 +123,7 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
return Ok(None); return Ok(None);
}; };
Ok(Some(XRViewerPose::new( Ok(Some(XRViewerPose::new(
&self.global(), self.global().as_window(),
&self.session, &self.session,
to_base, to_base,
viewer_pose, viewer_pose,
@ -155,7 +155,7 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
return Ok(None); return Ok(None);
}; };
let pose = space.then(&base_space.inverse()); let pose = space.then(&base_space.inverse());
Ok(Some(XRPose::new(&self.global(), pose, can_gc))) Ok(Some(XRPose::new(self.global().as_window(), pose, can_gc)))
} }
/// <https://immersive-web.github.io/webxr/#dom-xrframe-getpose> /// <https://immersive-web.github.io/webxr/#dom-xrframe-getpose>
@ -185,7 +185,7 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
}; };
let pose = joint_frame.pose.then(&base_space.inverse()); let pose = joint_frame.pose.then(&base_space.inverse());
Ok(Some(XRJointPose::new( Ok(Some(XRJointPose::new(
&self.global(), self.global().as_window(),
pose.cast_unit(), pose.cast_unit(),
Some(joint_frame.radius), Some(joint_frame.radius),
can_gc, can_gc,
@ -198,7 +198,7 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
.hit_test_results .hit_test_results
.iter() .iter()
.filter(|r| r.id == source.id()) .filter(|r| r.id == source.id())
.map(|r| XRHitTestResult::new(&self.global(), *r, self, CanGc::note())) .map(|r| XRHitTestResult::new(self.global().as_window(), *r, self, CanGc::note()))
.collect() .collect()
} }

View file

@ -8,7 +8,7 @@ use webxr_api::HitTestResult;
use crate::dom::bindings::codegen::Bindings::XRHitTestResultBinding::XRHitTestResultMethods; use crate::dom::bindings::codegen::Bindings::XRHitTestResultBinding::XRHitTestResultMethods;
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object}; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope; use crate::dom::window::Window;
use crate::dom::xrframe::XRFrame; use crate::dom::xrframe::XRFrame;
use crate::dom::xrpose::XRPose; use crate::dom::xrpose::XRPose;
use crate::dom::xrspace::XRSpace; use crate::dom::xrspace::XRSpace;
@ -33,14 +33,14 @@ impl XRHitTestResult {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
result: HitTestResult, result: HitTestResult,
frame: &XRFrame, frame: &XRFrame,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRHitTestResult> { ) -> DomRoot<XRHitTestResult> {
reflect_dom_object( reflect_dom_object(
Box::new(XRHitTestResult::new_inherited(result, frame)), Box::new(XRHitTestResult::new_inherited(result, frame)),
global, window,
can_gc, can_gc,
) )
} }
@ -51,6 +51,10 @@ impl XRHitTestResultMethods<crate::DomTypeHolder> for XRHitTestResult {
fn GetPose(&self, base: &XRSpace, can_gc: CanGc) -> Option<DomRoot<XRPose>> { fn GetPose(&self, base: &XRSpace, can_gc: CanGc) -> Option<DomRoot<XRPose>> {
let base = self.frame.get_pose(base)?; let base = self.frame.get_pose(base)?;
let pose = self.result.space.then(&base.inverse()); let pose = self.result.space.then(&base.inverse());
Some(XRPose::new(&self.global(), pose.cast_unit(), can_gc)) Some(XRPose::new(
self.global().as_window(),
pose.cast_unit(),
can_gc,
))
} }
} }

View file

@ -46,6 +46,7 @@ impl XRInputSourceArray {
can_gc: CanGc, can_gc: CanGc,
) { ) {
let global = self.global(); let global = self.global();
let window = global.as_window();
let mut added = vec![]; let mut added = vec![];
for info in inputs { for info in inputs {
@ -65,7 +66,7 @@ impl XRInputSourceArray {
} }
let event = XRInputSourcesChangeEvent::new( let event = XRInputSourcesChangeEvent::new(
&global, window,
atom!("inputsourceschange"), atom!("inputsourceschange"),
false, false,
true, true,
@ -79,6 +80,7 @@ impl XRInputSourceArray {
pub(crate) fn remove_input_source(&self, session: &XRSession, id: InputId, can_gc: CanGc) { pub(crate) fn remove_input_source(&self, session: &XRSession, id: InputId, can_gc: CanGc) {
let global = self.global(); let global = self.global();
let window = global.as_window();
let removed = if let Some(i) = self.input_sources.borrow().iter().find(|i| i.id() == id) { let removed = if let Some(i) = self.input_sources.borrow().iter().find(|i| i.id() == id) {
i.gamepad().update_connected(false, false, can_gc); i.gamepad().update_connected(false, false, can_gc);
[DomRoot::from_ref(&**i)] [DomRoot::from_ref(&**i)]
@ -87,7 +89,7 @@ impl XRInputSourceArray {
}; };
let event = XRInputSourcesChangeEvent::new( let event = XRInputSourcesChangeEvent::new(
&global, window,
atom!("inputsourceschange"), atom!("inputsourceschange"),
false, false,
true, true,
@ -108,6 +110,7 @@ impl XRInputSourceArray {
can_gc: CanGc, can_gc: CanGc,
) { ) {
let global = self.global(); let global = self.global();
let window = global.as_window();
let root; let root;
let removed = if let Some(i) = self.input_sources.borrow().iter().find(|i| i.id() == id) { let removed = if let Some(i) = self.input_sources.borrow().iter().find(|i| i.id() == id) {
i.gamepad().update_connected(false, false, can_gc); i.gamepad().update_connected(false, false, can_gc);
@ -124,7 +127,7 @@ impl XRInputSourceArray {
let added = [input]; let added = [input];
let event = XRInputSourcesChangeEvent::new( let event = XRInputSourcesChangeEvent::new(
&global, window,
atom!("inputsourceschange"), atom!("inputsourceschange"),
false, false,
true, true,

View file

@ -12,11 +12,10 @@ use crate::dom::bindings::codegen::Bindings::XRInputSourceEventBinding::{
}; };
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event; use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::dom::xrframe::XRFrame; use crate::dom::xrframe::XRFrame;
use crate::dom::xrinputsource::XRInputSource; use crate::dom::xrinputsource::XRInputSource;
@ -40,7 +39,7 @@ impl XRInputSourceEvent {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
cancelable: bool, cancelable: bool,
@ -49,13 +48,13 @@ impl XRInputSourceEvent {
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRInputSourceEvent> { ) -> DomRoot<XRInputSourceEvent> {
Self::new_with_proto( Self::new_with_proto(
global, None, type_, bubbles, cancelable, frame, source, can_gc, window, None, type_, bubbles, cancelable, frame, source, can_gc,
) )
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
@ -66,7 +65,7 @@ impl XRInputSourceEvent {
) -> DomRoot<XRInputSourceEvent> { ) -> DomRoot<XRInputSourceEvent> {
let trackevent = reflect_dom_object_with_proto( let trackevent = reflect_dom_object_with_proto(
Box::new(XRInputSourceEvent::new_inherited(frame, source)), Box::new(XRInputSourceEvent::new_inherited(frame, source)),
global, window,
proto, proto,
can_gc, can_gc,
); );
@ -88,7 +87,7 @@ impl XRInputSourceEventMethods<crate::DomTypeHolder> for XRInputSourceEvent {
init: &XRInputSourceEventBinding::XRInputSourceEventInit, init: &XRInputSourceEventBinding::XRInputSourceEventInit,
) -> Fallible<DomRoot<XRInputSourceEvent>> { ) -> Fallible<DomRoot<XRInputSourceEvent>> {
Ok(XRInputSourceEvent::new_with_proto( Ok(XRInputSourceEvent::new_with_proto(
&window.global(), window,
proto, proto,
Atom::from(type_), Atom::from(type_),
init.parent.bubbles, init.parent.bubbles,

View file

@ -13,7 +13,7 @@ use crate::dom::bindings::codegen::Bindings::XRInputSourcesChangeEventBinding::{
self, XRInputSourcesChangeEventMethods, self, XRInputSourcesChangeEventMethods,
}; };
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::utils::to_frozen_array; use crate::dom::bindings::utils::to_frozen_array;
@ -48,7 +48,7 @@ impl XRInputSourcesChangeEvent {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
cancelable: bool, cancelable: bool,
@ -58,14 +58,14 @@ impl XRInputSourcesChangeEvent {
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRInputSourcesChangeEvent> { ) -> DomRoot<XRInputSourcesChangeEvent> {
Self::new_with_proto( Self::new_with_proto(
global, None, type_, bubbles, cancelable, session, added, removed, can_gc, window, None, type_, bubbles, cancelable, session, added, removed, can_gc,
) )
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
@ -77,7 +77,7 @@ impl XRInputSourcesChangeEvent {
) -> DomRoot<XRInputSourcesChangeEvent> { ) -> DomRoot<XRInputSourcesChangeEvent> {
let changeevent = reflect_dom_object_with_proto( let changeevent = reflect_dom_object_with_proto(
Box::new(XRInputSourcesChangeEvent::new_inherited(session)), Box::new(XRInputSourcesChangeEvent::new_inherited(session)),
global, window,
proto, proto,
can_gc, can_gc,
); );
@ -85,7 +85,7 @@ impl XRInputSourcesChangeEvent {
let event = changeevent.upcast::<Event>(); let event = changeevent.upcast::<Event>();
event.init_event(type_, bubbles, cancelable); event.init_event(type_, bubbles, cancelable);
} }
let _ac = enter_realm(global); let _ac = enter_realm(window);
let cx = GlobalScope::get_cx(); let cx = GlobalScope::get_cx();
rooted!(in(*cx) let mut frozen_val: JSVal); rooted!(in(*cx) let mut frozen_val: JSVal);
to_frozen_array(added, cx, frozen_val.handle_mut(), can_gc); to_frozen_array(added, cx, frozen_val.handle_mut(), can_gc);
@ -106,7 +106,7 @@ impl XRInputSourcesChangeEventMethods<crate::DomTypeHolder> for XRInputSourcesCh
init: &XRInputSourcesChangeEventBinding::XRInputSourcesChangeEventInit, init: &XRInputSourcesChangeEventBinding::XRInputSourcesChangeEventInit,
) -> DomRoot<XRInputSourcesChangeEvent> { ) -> DomRoot<XRInputSourcesChangeEvent> {
XRInputSourcesChangeEvent::new_with_proto( XRInputSourcesChangeEvent::new_with_proto(
&window.global(), window,
proto, proto,
Atom::from(type_), Atom::from(type_),
init.parent.bubbles, init.parent.bubbles,

View file

@ -8,7 +8,7 @@ use crate::dom::bindings::codegen::Bindings::XRJointPoseBinding::XRJointPoseMeth
use crate::dom::bindings::num::Finite; use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::reflect_dom_object; use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::globalscope::GlobalScope; use crate::dom::window::Window;
use crate::dom::xrpose::XRPose; use crate::dom::xrpose::XRPose;
use crate::dom::xrrigidtransform::XRRigidTransform; use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::ApiRigidTransform; use crate::dom::xrsession::ApiRigidTransform;
@ -30,15 +30,15 @@ impl XRJointPose {
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
pose: ApiRigidTransform, pose: ApiRigidTransform,
radius: Option<f32>, radius: Option<f32>,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRJointPose> { ) -> DomRoot<XRJointPose> {
let transform = XRRigidTransform::new(global, pose, can_gc); let transform = XRRigidTransform::new(window, pose, can_gc);
reflect_dom_object( reflect_dom_object(
Box::new(XRJointPose::new_inherited(&transform, radius)), Box::new(XRJointPose::new_inherited(&transform, radius)),
global, window,
can_gc, can_gc,
) )
} }

View file

@ -8,7 +8,7 @@ use crate::dom::bindings::codegen::Bindings::XRPoseBinding::XRPoseMethods;
use crate::dom::bindings::reflector::{Reflector, reflect_dom_object}; use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::dompointreadonly::DOMPointReadOnly; use crate::dom::dompointreadonly::DOMPointReadOnly;
use crate::dom::globalscope::GlobalScope; use crate::dom::window::Window;
use crate::dom::xrrigidtransform::XRRigidTransform; use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::ApiRigidTransform; use crate::dom::xrsession::ApiRigidTransform;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -29,12 +29,12 @@ impl XRPose {
#[allow(unused)] #[allow(unused)]
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
transform: ApiRigidTransform, transform: ApiRigidTransform,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRPose> { ) -> DomRoot<XRPose> {
let transform = XRRigidTransform::new(global, transform, can_gc); let transform = XRRigidTransform::new(window, transform, can_gc);
reflect_dom_object(Box::new(XRPose::new_inherited(&transform)), global, can_gc) reflect_dom_object(Box::new(XRPose::new_inherited(&transform)), window, can_gc)
} }
} }

View file

@ -15,7 +15,6 @@ use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto};
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::dompointreadonly::DOMPointReadOnly; use crate::dom::dompointreadonly::DOMPointReadOnly;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::dom::xrrigidtransform::XRRigidTransform; use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::script_runtime::{CanGc, JSContext}; use crate::script_runtime::{CanGc, JSContext};
@ -40,12 +39,12 @@ impl XRRay {
} }
fn new( fn new(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
ray: Ray<ApiSpace>, ray: Ray<ApiSpace>,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRRay> { ) -> DomRoot<XRRay> {
reflect_dom_object_with_proto(Box::new(XRRay::new_inherited(ray)), global, proto, can_gc) reflect_dom_object_with_proto(Box::new(XRRay::new_inherited(ray)), window, proto, can_gc)
} }
pub(crate) fn ray(&self) -> Ray<ApiSpace> { pub(crate) fn ray(&self) -> Ray<ApiSpace> {
@ -82,12 +81,7 @@ impl XRRayMethods<crate::DomTypeHolder> for XRRay {
) )
.normalize(); .normalize();
Ok(Self::new( Ok(Self::new(window, proto, Ray { origin, direction }, can_gc))
&window.global(),
proto,
Ray { origin, direction },
can_gc,
))
} }
/// <https://immersive-web.github.io/hit-test/#dom-xrray-xrray-transform> /// <https://immersive-web.github.io/hit-test/#dom-xrray-xrray-transform>
@ -103,12 +97,7 @@ impl XRRayMethods<crate::DomTypeHolder> for XRRay {
.rotation .rotation
.transform_vector3d(Vector3D::new(0., 0., -1.)); .transform_vector3d(Vector3D::new(0., 0., -1.));
Ok(Self::new( Ok(Self::new(window, proto, Ray { origin, direction }, can_gc))
&window.global(),
proto,
Ray { origin, direction },
can_gc,
))
} }
/// <https://immersive-web.github.io/hit-test/#dom-xrray-origin> /// <https://immersive-web.github.io/hit-test/#dom-xrray-origin>

View file

@ -13,6 +13,7 @@ use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object}; use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object};
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrrigidtransform::XRRigidTransform; use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::{ApiPose, BaseTransform, XRSession, cast_transform}; use crate::dom::xrsession::{ApiPose, BaseTransform, XRSession, cast_transform};
use crate::dom::xrspace::XRSpace; use crate::dom::xrspace::XRSpace;
@ -40,13 +41,13 @@ impl XRReferenceSpace {
#[allow(unused)] #[allow(unused)]
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
session: &XRSession, session: &XRSession,
ty: XRReferenceSpaceType, ty: XRReferenceSpaceType,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRReferenceSpace> { ) -> DomRoot<XRReferenceSpace> {
let offset = XRRigidTransform::identity(global, can_gc); let offset = XRRigidTransform::identity(window, can_gc);
Self::new_offset(global, session, ty, &offset, can_gc) Self::new_offset(&window.global(), session, ty, &offset, can_gc)
} }
#[allow(unused)] #[allow(unused)]
@ -85,7 +86,7 @@ impl XRReferenceSpaceMethods<crate::DomTypeHolder> for XRReferenceSpace {
/// <https://immersive-web.github.io/webxr/#dom-xrreferencespace-getoffsetreferencespace> /// <https://immersive-web.github.io/webxr/#dom-xrreferencespace-getoffsetreferencespace>
fn GetOffsetReferenceSpace(&self, new: &XRRigidTransform, can_gc: CanGc) -> DomRoot<Self> { fn GetOffsetReferenceSpace(&self, new: &XRRigidTransform, can_gc: CanGc) -> DomRoot<Self> {
let offset = new.transform().then(&self.offset.transform()); let offset = new.transform().then(&self.offset.transform());
let offset = XRRigidTransform::new(&self.global(), offset, can_gc); let offset = XRRigidTransform::new(self.global().as_window(), offset, can_gc);
Self::new_offset( Self::new_offset(
&self.global(), &self.global(),
self.upcast::<XRSpace>().session(), self.upcast::<XRSpace>().session(),

View file

@ -12,11 +12,10 @@ use crate::dom::bindings::codegen::Bindings::XRReferenceSpaceEventBinding::{
}; };
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event; use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::dom::xrreferencespace::XRReferenceSpace; use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrrigidtransform::XRRigidTransform; use crate::dom::xrrigidtransform::XRRigidTransform;
@ -43,7 +42,7 @@ impl XRReferenceSpaceEvent {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
cancelable: bool, cancelable: bool,
@ -52,13 +51,13 @@ impl XRReferenceSpaceEvent {
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRReferenceSpaceEvent> { ) -> DomRoot<XRReferenceSpaceEvent> {
Self::new_with_proto( Self::new_with_proto(
global, None, type_, bubbles, cancelable, space, transform, can_gc, window, None, type_, bubbles, cancelable, space, transform, can_gc,
) )
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
@ -69,7 +68,7 @@ impl XRReferenceSpaceEvent {
) -> DomRoot<XRReferenceSpaceEvent> { ) -> DomRoot<XRReferenceSpaceEvent> {
let trackevent = reflect_dom_object_with_proto( let trackevent = reflect_dom_object_with_proto(
Box::new(XRReferenceSpaceEvent::new_inherited(space, transform)), Box::new(XRReferenceSpaceEvent::new_inherited(space, transform)),
global, window,
proto, proto,
can_gc, can_gc,
); );
@ -91,7 +90,7 @@ impl XRReferenceSpaceEventMethods<crate::DomTypeHolder> for XRReferenceSpaceEven
init: &XRReferenceSpaceEventInit, init: &XRReferenceSpaceEventInit,
) -> Fallible<DomRoot<XRReferenceSpaceEvent>> { ) -> Fallible<DomRoot<XRReferenceSpaceEvent>> {
Ok(XRReferenceSpaceEvent::new_with_proto( Ok(XRReferenceSpaceEvent::new_with_proto(
&window.global(), window,
proto, proto,
Atom::from(type_), Atom::from(type_),
init.parent.bubbles, init.parent.bubbles,

View file

@ -14,7 +14,6 @@ use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto};
use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::dompointreadonly::DOMPointReadOnly; use crate::dom::dompointreadonly::DOMPointReadOnly;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::dom::xrsession::ApiRigidTransform; use crate::dom::xrsession::ApiRigidTransform;
use crate::script_runtime::{CanGc, JSContext}; use crate::script_runtime::{CanGc, JSContext};
@ -45,28 +44,28 @@ impl XRRigidTransform {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
transform: ApiRigidTransform, transform: ApiRigidTransform,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRRigidTransform> { ) -> DomRoot<XRRigidTransform> {
Self::new_with_proto(global, None, transform, can_gc) Self::new_with_proto(window, None, transform, can_gc)
} }
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
transform: ApiRigidTransform, transform: ApiRigidTransform,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRRigidTransform> { ) -> DomRoot<XRRigidTransform> {
reflect_dom_object_with_proto( reflect_dom_object_with_proto(
Box::new(XRRigidTransform::new_inherited(transform)), Box::new(XRRigidTransform::new_inherited(transform)),
global, window,
proto, proto,
can_gc, can_gc,
) )
} }
pub(crate) fn identity(window: &GlobalScope, can_gc: CanGc) -> DomRoot<XRRigidTransform> { pub(crate) fn identity(window: &Window, can_gc: CanGc) -> DomRoot<XRRigidTransform> {
let transform = RigidTransform3D::identity(); let transform = RigidTransform3D::identity();
XRRigidTransform::new(window, transform, can_gc) XRRigidTransform::new(window, transform, can_gc)
} }
@ -123,10 +122,7 @@ impl XRRigidTransformMethods<crate::DomTypeHolder> for XRRigidTransform {
} }
let transform = RigidTransform3D::new(rotate, translate); let transform = RigidTransform3D::new(rotate, translate);
Ok(XRRigidTransform::new_with_proto( Ok(XRRigidTransform::new_with_proto(
&window.global(), window, proto, transform, can_gc,
proto,
transform,
can_gc,
)) ))
} }
@ -161,7 +157,8 @@ impl XRRigidTransformMethods<crate::DomTypeHolder> for XRRigidTransform {
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-inverse // https://immersive-web.github.io/webxr/#dom-xrrigidtransform-inverse
fn Inverse(&self, can_gc: CanGc) -> DomRoot<XRRigidTransform> { fn Inverse(&self, can_gc: CanGc) -> DomRoot<XRRigidTransform> {
self.inverse.or_init(|| { self.inverse.or_init(|| {
let transform = XRRigidTransform::new(&self.global(), self.transform.inverse(), can_gc); let transform =
XRRigidTransform::new(self.global().as_window(), self.transform.inverse(), can_gc);
transform.inverse.set(Some(self)); transform.inverse.set(Some(self));
transform transform
}) })

View file

@ -289,8 +289,14 @@ impl XRSession {
promise.resolve_native(&(), can_gc); promise.resolve_native(&(), can_gc);
} }
// Step 7 // Step 7
let event = let event = XRSessionEvent::new(
XRSessionEvent::new(&self.global(), atom!("end"), false, false, self, can_gc); self.global().as_window(),
atom!("end"),
false,
false,
self,
can_gc,
);
event.upcast::<Event>().fire(self.upcast(), can_gc); event.upcast::<Event>().fire(self.upcast(), can_gc);
}, },
XREvent::Select(input, kind, ty, frame) => { XREvent::Select(input, kind, ty, frame) => {
@ -303,11 +309,11 @@ impl XRSession {
let source = self.input_sources.find(input); let source = self.input_sources.find(input);
let atom_index = if kind == SelectKind::Squeeze { 1 } else { 0 }; let atom_index = if kind == SelectKind::Squeeze { 1 } else { 0 };
if let Some(source) = source { if let Some(source) = source {
let frame = XRFrame::new(&self.global(), self, frame, can_gc); let frame = XRFrame::new(self.global().as_window(), self, frame, can_gc);
frame.set_active(true); frame.set_active(true);
if ty == SelectEvent::Start { if ty == SelectEvent::Start {
let event = XRInputSourceEvent::new( let event = XRInputSourceEvent::new(
&self.global(), self.global().as_window(),
START_ATOMS[atom_index].clone(), START_ATOMS[atom_index].clone(),
false, false,
false, false,
@ -319,7 +325,7 @@ impl XRSession {
} else { } else {
if ty == SelectEvent::Select { if ty == SelectEvent::Select {
let event = XRInputSourceEvent::new( let event = XRInputSourceEvent::new(
&self.global(), self.global().as_window(),
EVENT_ATOMS[atom_index].clone(), EVENT_ATOMS[atom_index].clone(),
false, false,
false, false,
@ -330,7 +336,7 @@ impl XRSession {
event.upcast::<Event>().fire(self.upcast(), can_gc); event.upcast::<Event>().fire(self.upcast(), can_gc);
} }
let event = XRInputSourceEvent::new( let event = XRInputSourceEvent::new(
&self.global(), self.global().as_window(),
END_ATOMS[atom_index].clone(), END_ATOMS[atom_index].clone(),
false, false,
false, false,
@ -351,7 +357,7 @@ impl XRSession {
}; };
self.visibility_state.set(v); self.visibility_state.set(v);
let event = XRSessionEvent::new( let event = XRSessionEvent::new(
&self.global(), self.global().as_window(),
atom!("visibilitychange"), atom!("visibilitychange"),
false, false,
false, false,
@ -393,9 +399,10 @@ impl XRSession {
base == base_space base == base_space
}) })
.for_each(|space| { .for_each(|space| {
let offset = XRRigidTransform::new(&self.global(), transform, can_gc); let offset =
XRRigidTransform::new(self.global().as_window(), transform, can_gc);
let event = XRReferenceSpaceEvent::new( let event = XRReferenceSpaceEvent::new(
&self.global(), self.global().as_window(),
atom!("reset"), atom!("reset"),
false, false,
false, false,
@ -462,7 +469,7 @@ impl XRSession {
} }
let time = self.global().performance().to_dom_high_res_time_stamp(time); let time = self.global().performance().to_dom_high_res_time_stamp(time);
let frame = XRFrame::new(&self.global(), self, frame, CanGc::note()); let frame = XRFrame::new(self.global().as_window(), self, frame, CanGc::note());
// Step 8-9 // Step 8-9
frame.set_active(true); frame.set_active(true);
@ -603,7 +610,7 @@ impl XRSession {
self.framerate.set(rate); self.framerate.set(rate);
let event = XRSessionEvent::new( let event = XRSessionEvent::new(
&self.global(), self.global().as_window(),
Atom::from("frameratechange"), Atom::from("frameratechange"),
false, false,
false, false,
@ -862,13 +869,14 @@ impl XRSessionMethods<crate::DomTypeHolder> for XRSession {
} }
} }
if ty == XRReferenceSpaceType::Bounded_floor { if ty == XRReferenceSpaceType::Bounded_floor {
let space = XRBoundedReferenceSpace::new(&self.global(), self, can_gc); let space =
XRBoundedReferenceSpace::new(self.global().as_window(), self, can_gc);
self.reference_spaces self.reference_spaces
.borrow_mut() .borrow_mut()
.push(Dom::from_ref(space.reference_space())); .push(Dom::from_ref(space.reference_space()));
p.resolve_native(&space, can_gc); p.resolve_native(&space, can_gc);
} else { } else {
let space = XRReferenceSpace::new(&self.global(), self, ty, can_gc); let space = XRReferenceSpace::new(self.global().as_window(), self, ty, can_gc);
self.reference_spaces self.reference_spaces
.borrow_mut() .borrow_mut()
.push(Dom::from_ref(&*space)); .push(Dom::from_ref(&*space));

View file

@ -10,11 +10,10 @@ use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventM
use crate::dom::bindings::codegen::Bindings::XRSessionEventBinding::{self, XRSessionEventMethods}; use crate::dom::bindings::codegen::Bindings::XRSessionEventBinding::{self, XRSessionEventMethods};
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event; use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::dom::xrsession::XRSession; use crate::dom::xrsession::XRSession;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -35,18 +34,18 @@ impl XRSessionEvent {
} }
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
cancelable: bool, cancelable: bool,
session: &XRSession, session: &XRSession,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRSessionEvent> { ) -> DomRoot<XRSessionEvent> {
Self::new_with_proto(global, None, type_, bubbles, cancelable, session, can_gc) Self::new_with_proto(window, None, type_, bubbles, cancelable, session, can_gc)
} }
fn new_with_proto( fn new_with_proto(
global: &GlobalScope, window: &Window,
proto: Option<HandleObject>, proto: Option<HandleObject>,
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
@ -56,7 +55,7 @@ impl XRSessionEvent {
) -> DomRoot<XRSessionEvent> { ) -> DomRoot<XRSessionEvent> {
let trackevent = reflect_dom_object_with_proto( let trackevent = reflect_dom_object_with_proto(
Box::new(XRSessionEvent::new_inherited(session)), Box::new(XRSessionEvent::new_inherited(session)),
global, window,
proto, proto,
can_gc, can_gc,
); );
@ -78,7 +77,7 @@ impl XRSessionEventMethods<crate::DomTypeHolder> for XRSessionEvent {
init: &XRSessionEventBinding::XRSessionEventInit, init: &XRSessionEventBinding::XRSessionEventInit,
) -> Fallible<DomRoot<XRSessionEvent>> { ) -> Fallible<DomRoot<XRSessionEvent>> {
Ok(XRSessionEvent::new_with_proto( Ok(XRSessionEvent::new_with_proto(
&window.global(), window,
proto, proto,
Atom::from(type_), Atom::from(type_),
init.parent.bubbles, init.parent.bubbles,

View file

@ -15,6 +15,7 @@ use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::{Reflector, reflect_dom_object}; use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrrigidtransform::XRRigidTransform; use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::{BaseSpace, BaseTransform, XRSession, cast_transform}; use crate::dom::xrsession::{BaseSpace, BaseTransform, XRSession, cast_transform};
use crate::script_runtime::{CanGc, JSContext}; use crate::script_runtime::{CanGc, JSContext};
@ -55,7 +56,7 @@ impl XRView {
} }
pub(crate) fn new<V: Copy>( pub(crate) fn new<V: Copy>(
global: &GlobalScope, window: &Window,
session: &XRSession, session: &XRSession,
view: &View<V>, view: &View<V>,
eye: XREye, eye: XREye,
@ -64,7 +65,7 @@ impl XRView {
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRView> { ) -> DomRoot<XRView> {
let transform: RigidTransform3D<f32, V, BaseSpace> = view.transform.then(to_base); let transform: RigidTransform3D<f32, V, BaseSpace> = view.transform.then(to_base);
let transform = XRRigidTransform::new(global, cast_transform(transform), can_gc); let transform = XRRigidTransform::new(window, cast_transform(transform), can_gc);
reflect_dom_object( reflect_dom_object(
Box::new(XRView::new_inherited( Box::new(XRView::new_inherited(
@ -74,7 +75,7 @@ impl XRView {
viewport_index, viewport_index,
view.cast_unit(), view.cast_unit(),
)), )),
global, window,
can_gc, can_gc,
) )
} }

View file

@ -15,6 +15,7 @@ use crate::dom::bindings::codegen::Bindings::XRViewerPoseBinding::XRViewerPoseMe
use crate::dom::bindings::reflector::reflect_dom_object; use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrpose::XRPose; use crate::dom::xrpose::XRPose;
use crate::dom::xrrigidtransform::XRRigidTransform; use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::{BaseSpace, BaseTransform, XRSession, cast_transform}; use crate::dom::xrsession::{BaseSpace, BaseTransform, XRSession, cast_transform};
@ -39,17 +40,17 @@ impl XRViewerPose {
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub(crate) fn new( pub(crate) fn new(
global: &GlobalScope, window: &Window,
session: &XRSession, session: &XRSession,
to_base: BaseTransform, to_base: BaseTransform,
viewer_pose: &ViewerPose, viewer_pose: &ViewerPose,
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<XRViewerPose> { ) -> DomRoot<XRViewerPose> {
let _ac = enter_realm(global); let _ac = enter_realm(window);
rooted_vec!(let mut views); rooted_vec!(let mut views);
match &viewer_pose.views { match &viewer_pose.views {
Views::Inline => views.push(XRView::new( Views::Inline => views.push(XRView::new(
global, window,
session, session,
&session.inline_view(), &session.inline_view(),
XREye::None, XREye::None,
@ -58,7 +59,7 @@ impl XRViewerPose {
can_gc, can_gc,
)), )),
Views::Mono(view) => views.push(XRView::new( Views::Mono(view) => views.push(XRView::new(
global, window,
session, session,
view, view,
XREye::None, XREye::None,
@ -68,7 +69,7 @@ impl XRViewerPose {
)), )),
Views::Stereo(left, right) => { Views::Stereo(left, right) => {
views.push(XRView::new( views.push(XRView::new(
global, window,
session, session,
left, left,
XREye::Left, XREye::Left,
@ -77,7 +78,7 @@ impl XRViewerPose {
can_gc, can_gc,
)); ));
views.push(XRView::new( views.push(XRView::new(
global, window,
session, session,
right, right,
XREye::Right, XREye::Right,
@ -88,7 +89,7 @@ impl XRViewerPose {
}, },
Views::StereoCapture(left, right, third_eye) => { Views::StereoCapture(left, right, third_eye) => {
views.push(XRView::new( views.push(XRView::new(
global, window,
session, session,
left, left,
XREye::Left, XREye::Left,
@ -97,7 +98,7 @@ impl XRViewerPose {
can_gc, can_gc,
)); ));
views.push(XRView::new( views.push(XRView::new(
global, window,
session, session,
right, right,
XREye::Right, XREye::Right,
@ -106,7 +107,7 @@ impl XRViewerPose {
can_gc, can_gc,
)); ));
views.push(XRView::new( views.push(XRView::new(
global, window,
session, session,
third_eye, third_eye,
XREye::None, XREye::None,
@ -117,7 +118,7 @@ impl XRViewerPose {
}, },
Views::Cubemap(front, left, right, top, bottom, back) => { Views::Cubemap(front, left, right, top, bottom, back) => {
views.push(XRView::new( views.push(XRView::new(
global, window,
session, session,
front, front,
XREye::None, XREye::None,
@ -126,7 +127,7 @@ impl XRViewerPose {
can_gc, can_gc,
)); ));
views.push(XRView::new( views.push(XRView::new(
global, window,
session, session,
left, left,
XREye::None, XREye::None,
@ -135,7 +136,7 @@ impl XRViewerPose {
can_gc, can_gc,
)); ));
views.push(XRView::new( views.push(XRView::new(
global, window,
session, session,
right, right,
XREye::None, XREye::None,
@ -144,7 +145,7 @@ impl XRViewerPose {
can_gc, can_gc,
)); ));
views.push(XRView::new( views.push(XRView::new(
global, window,
session, session,
top, top,
XREye::None, XREye::None,
@ -153,7 +154,7 @@ impl XRViewerPose {
can_gc, can_gc,
)); ));
views.push(XRView::new( views.push(XRView::new(
global, window,
session, session,
bottom, bottom,
XREye::None, XREye::None,
@ -162,7 +163,7 @@ impl XRViewerPose {
can_gc, can_gc,
)); ));
views.push(XRView::new( views.push(XRView::new(
global, window,
session, session,
back, back,
XREye::None, XREye::None,
@ -174,10 +175,10 @@ impl XRViewerPose {
}; };
let transform: RigidTransform3D<f32, Viewer, BaseSpace> = let transform: RigidTransform3D<f32, Viewer, BaseSpace> =
viewer_pose.transform.then(&to_base); viewer_pose.transform.then(&to_base);
let transform = XRRigidTransform::new(global, cast_transform(transform), can_gc); let transform = XRRigidTransform::new(window, cast_transform(transform), can_gc);
let pose = reflect_dom_object( let pose = reflect_dom_object(
Box::new(XRViewerPose::new_inherited(&transform)), Box::new(XRViewerPose::new_inherited(&transform)),
global, window,
can_gc, can_gc,
); );

View file

@ -184,6 +184,7 @@ impl WindowProxy {
assert!(!js_proxy.is_null()); assert!(!js_proxy.is_null());
// Create a new browsing context. // Create a new browsing context.
let current = Some(window.upcast::<GlobalScope>().pipeline_id()); let current = Some(window.upcast::<GlobalScope>().pipeline_id());
let window_proxy = Box::new(WindowProxy::new_inherited( let window_proxy = Box::new(WindowProxy::new_inherited(
browsing_context_id, browsing_context_id,

View file

@ -65,7 +65,7 @@ impl GraphicsProviderMethods<D3D11> for GraphicsProvider {
// already created is appropriate. OpenXR returns a validation error // already created is appropriate. OpenXR returns a validation error
// unless we call this method, so we call it and ignore the results // unless we call this method, so we call it and ignore the results
// in the short term. // in the short term.
let _requirements = D3D11::requirements(&instance, system) let _requirements = D3D11::requirements(instance, system)
.map_err(|e| Error::BackendSpecific(format!("D3D11::requirements {:?}", e)))?; .map_err(|e| Error::BackendSpecific(format!("D3D11::requirements {:?}", e)))?;
unsafe { unsafe {

View file

@ -311,7 +311,7 @@ impl OpenXRInput {
InputId(0), InputId(0),
Handedness::Right, Handedness::Right,
&action_set, &action_set,
&session, session,
needs_hands, needs_hands,
supported_interaction_profiles.clone(), supported_interaction_profiles.clone(),
); );
@ -319,7 +319,7 @@ impl OpenXRInput {
InputId(1), InputId(1),
Handedness::Left, Handedness::Left,
&action_set, &action_set,
&session, session,
needs_hands, needs_hands,
supported_interaction_profiles.clone(), supported_interaction_profiles.clone(),
); );

View file

@ -560,9 +560,9 @@ impl LayerManagerAPI<SurfmanGL> for OpenXrLayerManager {
for surface_texture in mem::replace(&mut layer.surface_textures, vec![]) { for surface_texture in mem::replace(&mut layer.surface_textures, vec![]) {
if let Some(surface_texture) = surface_texture { if let Some(surface_texture) = surface_texture {
let mut surface = device let mut surface = device
.destroy_surface_texture(&mut context, surface_texture) .destroy_surface_texture(context, surface_texture)
.unwrap(); .unwrap();
device.destroy_surface(&mut context, &mut surface).unwrap(); device.destroy_surface(context, &mut surface).unwrap();
} }
} }
} }