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::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::domrect::DOMRect;
use crate::dom::window::Window;
@ -37,7 +37,7 @@ impl DOMRectList {
) -> DomRoot<DOMRectList> {
reflect_dom_object_with_proto(
Box::new(DOMRectList::new_inherited(rects)),
&*window.global(),
window,
None,
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::error::Fallible;
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::str::DOMString;
use crate::dom::event::{Event, EventBubbles, EventCancelable};
use crate::dom::formdata::FormData;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
@ -28,7 +27,7 @@ pub(crate) struct FormDataEvent {
impl FormDataEvent {
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
type_: Atom,
can_bubble: EventBubbles,
cancelable: EventCancelable,
@ -36,12 +35,12 @@ impl FormDataEvent {
can_gc: CanGc,
) -> DomRoot<FormDataEvent> {
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(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
type_: Atom,
can_bubble: EventBubbles,
@ -54,7 +53,7 @@ impl FormDataEvent {
event: Event::new_inherited(),
form_data: Dom::from_ref(form_data),
}),
global,
window,
proto,
can_gc,
);
@ -80,7 +79,7 @@ impl FormDataEventMethods<crate::DomTypeHolder> for FormDataEvent {
let cancelable = EventCancelable::from(init.parent.cancelable);
let event = FormDataEvent::new_with_proto(
&window.global(),
window,
proto,
Atom::from(type_),
bubbles,

View file

@ -248,7 +248,8 @@ impl Gamepad {
}
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
.upcast::<Event>()
.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::error::Fallible;
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::str::DOMString;
use crate::dom::event::Event;
use crate::dom::gamepad::Gamepad;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
@ -40,18 +39,18 @@ impl GamepadEvent {
}
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
type_: Atom,
bubbles: bool,
cancelable: bool,
gamepad: &Gamepad,
can_gc: CanGc,
) -> 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(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
type_: Atom,
bubbles: bool,
@ -61,7 +60,7 @@ impl GamepadEvent {
) -> DomRoot<GamepadEvent> {
let ev = reflect_dom_object_with_proto(
Box::new(GamepadEvent::new_inherited(gamepad)),
global,
window,
proto,
can_gc,
);
@ -73,7 +72,7 @@ impl GamepadEvent {
}
pub(crate) fn new_with_type(
global: &GlobalScope,
window: &Window,
event_type: GamepadEventType,
gamepad: &Gamepad,
can_gc: CanGc,
@ -83,7 +82,7 @@ impl GamepadEvent {
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,
) -> Fallible<DomRoot<GamepadEvent>> {
Ok(GamepadEvent::new_with_proto(
&window.global(),
window,
proto,
Atom::from(type_),
init.parent.bubbles,

View file

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

View file

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

View file

@ -141,6 +141,7 @@ impl RTCDataChannel {
pub(crate) fn on_error(&self, error: WebRtcError, can_gc: CanGc) {
let global = self.global();
let window = global.as_window();
let cx = GlobalScope::get_cx();
let _ac = JSAutoRealm::new(*cx, self.reflector().get_jsobject().get());
let init = RTCErrorInit {
@ -154,8 +155,8 @@ impl RTCDataChannel {
let message = match error {
WebRtcError::Backend(message) => DOMString::from(message),
};
let error = RTCError::new(&global, &init, message, can_gc);
let event = RTCErrorEvent::new(&global, atom!("error"), false, false, &error, can_gc);
let error = RTCError::new(window, &init, message, can_gc);
let event = RTCErrorEvent::new(window, atom!("error"), false, false, &error, 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,
};
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::str::DOMString;
use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::rtcdatachannel::RTCDataChannel;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
@ -35,18 +34,18 @@ impl RTCDataChannelEvent {
}
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
type_: Atom,
bubbles: bool,
cancelable: bool,
channel: &RTCDataChannel,
can_gc: CanGc,
) -> 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(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
type_: Atom,
bubbles: bool,
@ -56,7 +55,7 @@ impl RTCDataChannelEvent {
) -> DomRoot<RTCDataChannelEvent> {
let event = reflect_dom_object_with_proto(
Box::new(RTCDataChannelEvent::new_inherited(channel)),
global,
window,
proto,
can_gc,
);
@ -78,7 +77,7 @@ impl RTCDataChannelEventMethods<crate::DomTypeHolder> for RTCDataChannelEvent {
init: &RTCDataChannelEventInit,
) -> DomRoot<RTCDataChannelEvent> {
RTCDataChannelEvent::new_with_proto(
&window.global(),
window,
proto,
Atom::from(type_),
init.parent.bubbles,

View file

@ -8,11 +8,10 @@ use js::rust::HandleObject;
use crate::dom::bindings::codegen::Bindings::RTCErrorBinding::{
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::str::DOMString;
use crate::dom::domexception::DOMException;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
@ -41,16 +40,16 @@ impl RTCError {
}
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
init: &RTCErrorInit,
message: DOMString,
can_gc: CanGc,
) -> 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(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
init: &RTCErrorInit,
message: DOMString,
@ -58,7 +57,7 @@ impl RTCError {
) -> DomRoot<RTCError> {
reflect_dom_object_with_proto(
Box::new(RTCError::new_inherited(init, message)),
global,
window,
proto,
can_gc,
)
@ -74,7 +73,7 @@ impl RTCErrorMethods<crate::DomTypeHolder> for RTCError {
init: &RTCErrorInit,
message: DOMString,
) -> 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

View file

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

View file

@ -9,10 +9,9 @@ use crate::dom::bindings::codegen::Bindings::RTCIceCandidateBinding::{
RTCIceCandidateInit, RTCIceCandidateMethods,
};
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::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
@ -42,7 +41,7 @@ impl RTCIceCandidate {
}
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
candidate: DOMString,
sdp_m_id: Option<DOMString>,
sdp_m_line_index: Option<u16>,
@ -50,7 +49,7 @@ impl RTCIceCandidate {
can_gc: CanGc,
) -> DomRoot<RTCIceCandidate> {
Self::new_with_proto(
global,
window,
None,
candidate,
sdp_m_id,
@ -61,7 +60,7 @@ impl RTCIceCandidate {
}
fn new_with_proto(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
candidate: DOMString,
sdp_m_id: Option<DOMString>,
@ -76,7 +75,7 @@ impl RTCIceCandidate {
sdp_m_line_index,
username_fragment,
)),
global,
window,
proto,
can_gc,
)
@ -97,7 +96,7 @@ impl RTCIceCandidateMethods<crate::DomTypeHolder> for RTCIceCandidate {
));
}
Ok(RTCIceCandidate::new_with_proto(
&window.global(),
window,
proto,
config.candidate.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::event::{Event, EventBubbles, EventCancelable};
use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::mediastream::MediaStream;
use crate::dom::mediastreamtrack::MediaStreamTrack;
use crate::dom::promise::Promise;
@ -177,14 +176,14 @@ impl RTCPeerConnection {
}
fn new(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
config: &RTCConfiguration,
can_gc: CanGc,
) -> DomRoot<RTCPeerConnection> {
let this = reflect_dom_object_with_proto(
Box::new(RTCPeerConnection::new_inherited()),
global,
window,
proto,
can_gc,
);
@ -230,7 +229,7 @@ impl RTCPeerConnection {
return;
}
let candidate = RTCIceCandidate::new(
&self.global(),
self.global().as_window(),
candidate.candidate.into(),
None,
Some(candidate.sdp_mline_index as u16),
@ -238,7 +237,7 @@ impl RTCPeerConnection {
can_gc,
);
let event = RTCPeerConnectionIceEvent::new(
&self.global(),
self.global().as_window(),
atom!("icecandidate"),
Some(&candidate),
None,
@ -267,8 +266,14 @@ impl RTCPeerConnection {
return;
}
let track = MediaStreamTrack::new(&self.global(), id, ty, can_gc);
let event =
RTCTrackEvent::new(&self.global(), atom!("track"), false, false, &track, can_gc);
let event = RTCTrackEvent::new(
self.global().as_window(),
atom!("track"),
false,
false,
&track,
can_gc,
);
event.upcast::<Event>().fire(self.upcast(), can_gc);
}
@ -294,7 +299,7 @@ impl RTCPeerConnection {
);
let event = RTCDataChannelEvent::new(
&self.global(),
self.global().as_window(),
atom!("datachannel"),
false,
false,
@ -372,7 +377,7 @@ impl RTCPeerConnection {
// step 6
if state == RTCIceGatheringState::Complete {
let event = RTCPeerConnectionIceEvent::new(
&self.global(),
self.global().as_window(),
atom!("icecandidate"),
None,
None,
@ -502,12 +507,7 @@ impl RTCPeerConnectionMethods<crate::DomTypeHolder> for RTCPeerConnection {
can_gc: CanGc,
config: &RTCConfiguration,
) -> Fallible<DomRoot<RTCPeerConnection>> {
Ok(RTCPeerConnection::new(
&window.global(),
proto,
config,
can_gc,
))
Ok(RTCPeerConnection::new(window, proto, config, can_gc))
}
// 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::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::str::DOMString;
use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::rtcicecandidate::RTCIceCandidate;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
@ -41,18 +40,18 @@ impl RTCPeerConnectionIceEvent {
}
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
ty: Atom,
candidate: Option<&RTCIceCandidate>,
url: Option<DOMString>,
trusted: bool,
can_gc: CanGc,
) -> 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(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
ty: Atom,
candidate: Option<&RTCIceCandidate>,
@ -62,7 +61,7 @@ impl RTCPeerConnectionIceEvent {
) -> DomRoot<RTCPeerConnectionIceEvent> {
let e = reflect_dom_object_with_proto(
Box::new(RTCPeerConnectionIceEvent::new_inherited(candidate, url)),
global,
window,
proto,
can_gc,
);
@ -83,7 +82,7 @@ impl RTCPeerConnectionIceEventMethods<crate::DomTypeHolder> for RTCPeerConnectio
init: &RTCPeerConnectionIceEventInit,
) -> Fallible<DomRoot<RTCPeerConnectionIceEvent>> {
Ok(RTCPeerConnectionIceEvent::new_with_proto(
&window.global(),
window,
proto,
ty.into(),
init.candidate

View file

@ -9,10 +9,9 @@ use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{
RTCSdpType, RTCSessionDescriptionInit, RTCSessionDescriptionMethods,
};
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::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
@ -33,7 +32,7 @@ impl RTCSessionDescription {
}
fn new(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
ty: RTCSdpType,
sdp: DOMString,
@ -41,7 +40,7 @@ impl RTCSessionDescription {
) -> DomRoot<RTCSessionDescription> {
reflect_dom_object_with_proto(
Box::new(RTCSessionDescription::new_inherited(ty, sdp)),
global,
window,
proto,
can_gc,
)
@ -57,7 +56,7 @@ impl RTCSessionDescriptionMethods<crate::DomTypeHolder> for RTCSessionDescriptio
config: &RTCSessionDescriptionInit,
) -> Fallible<DomRoot<RTCSessionDescription>> {
Ok(RTCSessionDescription::new(
&window.global(),
window,
proto,
config.type_,
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::error::Fallible;
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::str::DOMString;
use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::mediastreamtrack::MediaStreamTrack;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
@ -35,18 +34,18 @@ impl RTCTrackEvent {
}
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
type_: Atom,
bubbles: bool,
cancelable: bool,
track: &MediaStreamTrack,
can_gc: CanGc,
) -> 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(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
type_: Atom,
bubbles: bool,
@ -56,7 +55,7 @@ impl RTCTrackEvent {
) -> DomRoot<RTCTrackEvent> {
let trackevent = reflect_dom_object_with_proto(
Box::new(RTCTrackEvent::new_inherited(track)),
global,
window,
proto,
can_gc,
);
@ -78,7 +77,7 @@ impl RTCTrackEventMethods<crate::DomTypeHolder> for RTCTrackEvent {
init: &RTCTrackEventBinding::RTCTrackEventInit,
) -> Fallible<DomRoot<RTCTrackEvent>> {
Ok(RTCTrackEvent::new_with_proto(
&window.global(),
window,
proto,
Atom::from(type_),
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::SubmitEventMethods;
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::str::DOMString;
use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlelement::HTMLElement;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
@ -35,18 +34,18 @@ impl SubmitEvent {
}
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
type_: Atom,
bubbles: bool,
cancelable: bool,
submitter: Option<DomRoot<HTMLElement>>,
can_gc: CanGc,
) -> 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(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
type_: Atom,
bubbles: bool,
@ -56,7 +55,7 @@ impl SubmitEvent {
) -> DomRoot<SubmitEvent> {
let ev = reflect_dom_object_with_proto(
Box::new(SubmitEvent::new_inherited(submitter)),
global,
window,
proto,
can_gc,
);
@ -78,7 +77,7 @@ impl SubmitEventMethods<crate::DomTypeHolder> for SubmitEvent {
init: &SubmitEventBinding::SubmitEventInit,
) -> DomRoot<SubmitEvent> {
SubmitEvent::new_with_proto(
&window.global(),
window,
proto,
Atom::from(type_),
init.parent.bubbles,

View file

@ -79,7 +79,7 @@ impl TextTrackList {
if let Some(track) = this.item(idx) {
let event = TrackEvent::new(
&this.global(),
this.global().as_window(),
atom!("addtrack"),
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::error::Fallible;
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::str::DOMString;
use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::texttrack::TextTrack;
use crate::dom::videotrack::VideoTrack;
use crate::dom::window::Window;
@ -61,18 +60,18 @@ impl TrackEvent {
}
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
type_: Atom,
bubbles: bool,
cancelable: bool,
track: &Option<VideoTrackOrAudioTrackOrTextTrack>,
can_gc: CanGc,
) -> 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(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
type_: Atom,
bubbles: bool,
@ -82,7 +81,7 @@ impl TrackEvent {
) -> DomRoot<TrackEvent> {
let te = reflect_dom_object_with_proto(
Box::new(TrackEvent::new_inherited(track)),
global,
window,
proto,
can_gc,
);
@ -104,7 +103,7 @@ impl TrackEventMethods<crate::DomTypeHolder> for TrackEvent {
init: &TrackEventBinding::TrackEventInit,
) -> Fallible<DomRoot<TrackEvent>> {
Ok(TrackEvent::new_with_proto(
&window.global(),
window,
proto,
Atom::from(type_),
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::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::str::DOMString;
use crate::dom::documentfragment::DocumentFragment;
use crate::dom::globalscope::GlobalScope;
use crate::dom::texttrackcue::TextTrackCue;
use crate::dom::vttregion::VTTRegion;
use crate::dom::window::Window;
@ -62,7 +61,7 @@ impl VTTCue {
}
fn new(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
start_time: f64,
end_time: f64,
@ -71,7 +70,7 @@ impl VTTCue {
) -> DomRoot<Self> {
reflect_dom_object_with_proto(
Box::new(Self::new_inherited(start_time, end_time, text)),
global,
window,
proto,
can_gc,
)
@ -88,14 +87,7 @@ impl VTTCueMethods<crate::DomTypeHolder> for VTTCue {
end_time: Finite<f64>,
text: DOMString,
) -> DomRoot<Self> {
VTTCue::new(
&window.global(),
proto,
*start_time,
*end_time,
text,
can_gc,
)
VTTCue::new(window, proto, *start_time, *end_time, text, can_gc)
}
// 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::error::{Error, ErrorResult, Fallible};
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::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
@ -46,8 +45,8 @@ impl VTTRegion {
}
}
fn new(global: &GlobalScope, proto: Option<HandleObject>, can_gc: CanGc) -> DomRoot<Self> {
reflect_dom_object_with_proto(Box::new(Self::new_inherited()), global, proto, can_gc)
fn new(window: &Window, proto: Option<HandleObject>, can_gc: CanGc) -> DomRoot<Self> {
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>,
can_gc: CanGc,
) -> 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

View file

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

View file

@ -15,7 +15,7 @@ use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
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::xrhittestsource::XRHitTestSource;
use crate::dom::xrjointpose::XRJointPose;
@ -50,14 +50,14 @@ impl XRFrame {
}
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
session: &XRSession,
data: Frame,
can_gc: CanGc,
) -> DomRoot<XRFrame> {
reflect_dom_object(
Box::new(XRFrame::new_inherited(session, data)),
global,
window,
can_gc,
)
}
@ -123,7 +123,7 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
return Ok(None);
};
Ok(Some(XRViewerPose::new(
&self.global(),
self.global().as_window(),
&self.session,
to_base,
viewer_pose,
@ -155,7 +155,7 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
return Ok(None);
};
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>
@ -185,7 +185,7 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
};
let pose = joint_frame.pose.then(&base_space.inverse());
Ok(Some(XRJointPose::new(
&self.global(),
self.global().as_window(),
pose.cast_unit(),
Some(joint_frame.radius),
can_gc,
@ -198,7 +198,7 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
.hit_test_results
.iter()
.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()
}

View file

@ -8,7 +8,7 @@ use webxr_api::HitTestResult;
use crate::dom::bindings::codegen::Bindings::XRHitTestResultBinding::XRHitTestResultMethods;
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
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::xrpose::XRPose;
use crate::dom::xrspace::XRSpace;
@ -33,14 +33,14 @@ impl XRHitTestResult {
}
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
result: HitTestResult,
frame: &XRFrame,
can_gc: CanGc,
) -> DomRoot<XRHitTestResult> {
reflect_dom_object(
Box::new(XRHitTestResult::new_inherited(result, frame)),
global,
window,
can_gc,
)
}
@ -51,6 +51,10 @@ impl XRHitTestResultMethods<crate::DomTypeHolder> for XRHitTestResult {
fn GetPose(&self, base: &XRSpace, can_gc: CanGc) -> Option<DomRoot<XRPose>> {
let base = self.frame.get_pose(base)?;
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,
) {
let global = self.global();
let window = global.as_window();
let mut added = vec![];
for info in inputs {
@ -65,7 +66,7 @@ impl XRInputSourceArray {
}
let event = XRInputSourcesChangeEvent::new(
&global,
window,
atom!("inputsourceschange"),
false,
true,
@ -79,6 +80,7 @@ impl XRInputSourceArray {
pub(crate) fn remove_input_source(&self, session: &XRSession, id: InputId, can_gc: CanGc) {
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) {
i.gamepad().update_connected(false, false, can_gc);
[DomRoot::from_ref(&**i)]
@ -87,7 +89,7 @@ impl XRInputSourceArray {
};
let event = XRInputSourcesChangeEvent::new(
&global,
window,
atom!("inputsourceschange"),
false,
true,
@ -108,6 +110,7 @@ impl XRInputSourceArray {
can_gc: CanGc,
) {
let global = self.global();
let window = global.as_window();
let root;
let removed = if let Some(i) = self.input_sources.borrow().iter().find(|i| i.id() == id) {
i.gamepad().update_connected(false, false, can_gc);
@ -124,7 +127,7 @@ impl XRInputSourceArray {
let added = [input];
let event = XRInputSourcesChangeEvent::new(
&global,
window,
atom!("inputsourceschange"),
false,
true,

View file

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

View file

@ -13,7 +13,7 @@ use crate::dom::bindings::codegen::Bindings::XRInputSourcesChangeEventBinding::{
self, XRInputSourcesChangeEventMethods,
};
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::str::DOMString;
use crate::dom::bindings::utils::to_frozen_array;
@ -48,7 +48,7 @@ impl XRInputSourcesChangeEvent {
#[allow(clippy::too_many_arguments)]
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
type_: Atom,
bubbles: bool,
cancelable: bool,
@ -58,14 +58,14 @@ impl XRInputSourcesChangeEvent {
can_gc: CanGc,
) -> DomRoot<XRInputSourcesChangeEvent> {
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(clippy::too_many_arguments)]
fn new_with_proto(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
type_: Atom,
bubbles: bool,
@ -77,7 +77,7 @@ impl XRInputSourcesChangeEvent {
) -> DomRoot<XRInputSourcesChangeEvent> {
let changeevent = reflect_dom_object_with_proto(
Box::new(XRInputSourcesChangeEvent::new_inherited(session)),
global,
window,
proto,
can_gc,
);
@ -85,7 +85,7 @@ impl XRInputSourcesChangeEvent {
let event = changeevent.upcast::<Event>();
event.init_event(type_, bubbles, cancelable);
}
let _ac = enter_realm(global);
let _ac = enter_realm(window);
let cx = GlobalScope::get_cx();
rooted!(in(*cx) let mut frozen_val: JSVal);
to_frozen_array(added, cx, frozen_val.handle_mut(), can_gc);
@ -106,7 +106,7 @@ impl XRInputSourcesChangeEventMethods<crate::DomTypeHolder> for XRInputSourcesCh
init: &XRInputSourcesChangeEventBinding::XRInputSourcesChangeEventInit,
) -> DomRoot<XRInputSourcesChangeEvent> {
XRInputSourcesChangeEvent::new_with_proto(
&window.global(),
window,
proto,
Atom::from(type_),
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::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrpose::XRPose;
use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::ApiRigidTransform;
@ -30,15 +30,15 @@ impl XRJointPose {
#[allow(unsafe_code)]
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
pose: ApiRigidTransform,
radius: Option<f32>,
can_gc: CanGc,
) -> DomRoot<XRJointPose> {
let transform = XRRigidTransform::new(global, pose, can_gc);
let transform = XRRigidTransform::new(window, pose, can_gc);
reflect_dom_object(
Box::new(XRJointPose::new_inherited(&transform, radius)),
global,
window,
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::root::{Dom, DomRoot};
use crate::dom::dompointreadonly::DOMPointReadOnly;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::ApiRigidTransform;
use crate::script_runtime::CanGc;
@ -29,12 +29,12 @@ impl XRPose {
#[allow(unused)]
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
transform: ApiRigidTransform,
can_gc: CanGc,
) -> DomRoot<XRPose> {
let transform = XRRigidTransform::new(global, transform, can_gc);
reflect_dom_object(Box::new(XRPose::new_inherited(&transform)), global, can_gc)
let transform = XRRigidTransform::new(window, transform, 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::root::DomRoot;
use crate::dom::dompointreadonly::DOMPointReadOnly;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::script_runtime::{CanGc, JSContext};
@ -40,12 +39,12 @@ impl XRRay {
}
fn new(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
ray: Ray<ApiSpace>,
can_gc: CanGc,
) -> 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> {
@ -82,12 +81,7 @@ impl XRRayMethods<crate::DomTypeHolder> for XRRay {
)
.normalize();
Ok(Self::new(
&window.global(),
proto,
Ray { origin, direction },
can_gc,
))
Ok(Self::new(window, proto, Ray { origin, direction }, can_gc))
}
/// <https://immersive-web.github.io/hit-test/#dom-xrray-xrray-transform>
@ -103,12 +97,7 @@ impl XRRayMethods<crate::DomTypeHolder> for XRRay {
.rotation
.transform_vector3d(Vector3D::new(0., 0., -1.));
Ok(Self::new(
&window.global(),
proto,
Ray { origin, direction },
can_gc,
))
Ok(Self::new(window, proto, Ray { origin, direction }, can_gc))
}
/// <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::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::{ApiPose, BaseTransform, XRSession, cast_transform};
use crate::dom::xrspace::XRSpace;
@ -40,13 +41,13 @@ impl XRReferenceSpace {
#[allow(unused)]
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
session: &XRSession,
ty: XRReferenceSpaceType,
can_gc: CanGc,
) -> DomRoot<XRReferenceSpace> {
let offset = XRRigidTransform::identity(global, can_gc);
Self::new_offset(global, session, ty, &offset, can_gc)
let offset = XRRigidTransform::identity(window, can_gc);
Self::new_offset(&window.global(), session, ty, &offset, can_gc)
}
#[allow(unused)]
@ -85,7 +86,7 @@ impl XRReferenceSpaceMethods<crate::DomTypeHolder> for XRReferenceSpace {
/// <https://immersive-web.github.io/webxr/#dom-xrreferencespace-getoffsetreferencespace>
fn GetOffsetReferenceSpace(&self, new: &XRRigidTransform, can_gc: CanGc) -> DomRoot<Self> {
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.global(),
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::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::str::DOMString;
use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrrigidtransform::XRRigidTransform;
@ -43,7 +42,7 @@ impl XRReferenceSpaceEvent {
}
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
type_: Atom,
bubbles: bool,
cancelable: bool,
@ -52,13 +51,13 @@ impl XRReferenceSpaceEvent {
can_gc: CanGc,
) -> DomRoot<XRReferenceSpaceEvent> {
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)]
fn new_with_proto(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
type_: Atom,
bubbles: bool,
@ -69,7 +68,7 @@ impl XRReferenceSpaceEvent {
) -> DomRoot<XRReferenceSpaceEvent> {
let trackevent = reflect_dom_object_with_proto(
Box::new(XRReferenceSpaceEvent::new_inherited(space, transform)),
global,
window,
proto,
can_gc,
);
@ -91,7 +90,7 @@ impl XRReferenceSpaceEventMethods<crate::DomTypeHolder> for XRReferenceSpaceEven
init: &XRReferenceSpaceEventInit,
) -> Fallible<DomRoot<XRReferenceSpaceEvent>> {
Ok(XRReferenceSpaceEvent::new_with_proto(
&window.global(),
window,
proto,
Atom::from(type_),
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::root::{DomRoot, MutNullableDom};
use crate::dom::dompointreadonly::DOMPointReadOnly;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrsession::ApiRigidTransform;
use crate::script_runtime::{CanGc, JSContext};
@ -45,28 +44,28 @@ impl XRRigidTransform {
}
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
transform: ApiRigidTransform,
can_gc: CanGc,
) -> DomRoot<XRRigidTransform> {
Self::new_with_proto(global, None, transform, can_gc)
Self::new_with_proto(window, None, transform, can_gc)
}
fn new_with_proto(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
transform: ApiRigidTransform,
can_gc: CanGc,
) -> DomRoot<XRRigidTransform> {
reflect_dom_object_with_proto(
Box::new(XRRigidTransform::new_inherited(transform)),
global,
window,
proto,
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();
XRRigidTransform::new(window, transform, can_gc)
}
@ -123,10 +122,7 @@ impl XRRigidTransformMethods<crate::DomTypeHolder> for XRRigidTransform {
}
let transform = RigidTransform3D::new(rotate, translate);
Ok(XRRigidTransform::new_with_proto(
&window.global(),
proto,
transform,
can_gc,
window, proto, transform, can_gc,
))
}
@ -161,7 +157,8 @@ impl XRRigidTransformMethods<crate::DomTypeHolder> for XRRigidTransform {
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-inverse
fn Inverse(&self, can_gc: CanGc) -> DomRoot<XRRigidTransform> {
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
})

View file

@ -289,8 +289,14 @@ impl XRSession {
promise.resolve_native(&(), can_gc);
}
// Step 7
let event =
XRSessionEvent::new(&self.global(), atom!("end"), false, false, self, can_gc);
let event = XRSessionEvent::new(
self.global().as_window(),
atom!("end"),
false,
false,
self,
can_gc,
);
event.upcast::<Event>().fire(self.upcast(), can_gc);
},
XREvent::Select(input, kind, ty, frame) => {
@ -303,11 +309,11 @@ impl XRSession {
let source = self.input_sources.find(input);
let atom_index = if kind == SelectKind::Squeeze { 1 } else { 0 };
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);
if ty == SelectEvent::Start {
let event = XRInputSourceEvent::new(
&self.global(),
self.global().as_window(),
START_ATOMS[atom_index].clone(),
false,
false,
@ -319,7 +325,7 @@ impl XRSession {
} else {
if ty == SelectEvent::Select {
let event = XRInputSourceEvent::new(
&self.global(),
self.global().as_window(),
EVENT_ATOMS[atom_index].clone(),
false,
false,
@ -330,7 +336,7 @@ impl XRSession {
event.upcast::<Event>().fire(self.upcast(), can_gc);
}
let event = XRInputSourceEvent::new(
&self.global(),
self.global().as_window(),
END_ATOMS[atom_index].clone(),
false,
false,
@ -351,7 +357,7 @@ impl XRSession {
};
self.visibility_state.set(v);
let event = XRSessionEvent::new(
&self.global(),
self.global().as_window(),
atom!("visibilitychange"),
false,
false,
@ -393,9 +399,10 @@ impl XRSession {
base == base_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(
&self.global(),
self.global().as_window(),
atom!("reset"),
false,
false,
@ -462,7 +469,7 @@ impl XRSession {
}
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
frame.set_active(true);
@ -603,7 +610,7 @@ impl XRSession {
self.framerate.set(rate);
let event = XRSessionEvent::new(
&self.global(),
self.global().as_window(),
Atom::from("frameratechange"),
false,
false,
@ -862,13 +869,14 @@ impl XRSessionMethods<crate::DomTypeHolder> for XRSession {
}
}
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
.borrow_mut()
.push(Dom::from_ref(space.reference_space()));
p.resolve_native(&space, can_gc);
} 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
.borrow_mut()
.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::error::Fallible;
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::str::DOMString;
use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrsession::XRSession;
use crate::script_runtime::CanGc;
@ -35,18 +34,18 @@ impl XRSessionEvent {
}
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
type_: Atom,
bubbles: bool,
cancelable: bool,
session: &XRSession,
can_gc: CanGc,
) -> 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(
global: &GlobalScope,
window: &Window,
proto: Option<HandleObject>,
type_: Atom,
bubbles: bool,
@ -56,7 +55,7 @@ impl XRSessionEvent {
) -> DomRoot<XRSessionEvent> {
let trackevent = reflect_dom_object_with_proto(
Box::new(XRSessionEvent::new_inherited(session)),
global,
window,
proto,
can_gc,
);
@ -78,7 +77,7 @@ impl XRSessionEventMethods<crate::DomTypeHolder> for XRSessionEvent {
init: &XRSessionEventBinding::XRSessionEventInit,
) -> Fallible<DomRoot<XRSessionEvent>> {
Ok(XRSessionEvent::new_with_proto(
&window.global(),
window,
proto,
Atom::from(type_),
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::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::{BaseSpace, BaseTransform, XRSession, cast_transform};
use crate::script_runtime::{CanGc, JSContext};
@ -55,7 +56,7 @@ impl XRView {
}
pub(crate) fn new<V: Copy>(
global: &GlobalScope,
window: &Window,
session: &XRSession,
view: &View<V>,
eye: XREye,
@ -64,7 +65,7 @@ impl XRView {
can_gc: CanGc,
) -> DomRoot<XRView> {
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(
Box::new(XRView::new_inherited(
@ -74,7 +75,7 @@ impl XRView {
viewport_index,
view.cast_unit(),
)),
global,
window,
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::root::DomRoot;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrpose::XRPose;
use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::{BaseSpace, BaseTransform, XRSession, cast_transform};
@ -39,17 +40,17 @@ impl XRViewerPose {
#[allow(unsafe_code)]
pub(crate) fn new(
global: &GlobalScope,
window: &Window,
session: &XRSession,
to_base: BaseTransform,
viewer_pose: &ViewerPose,
can_gc: CanGc,
) -> DomRoot<XRViewerPose> {
let _ac = enter_realm(global);
let _ac = enter_realm(window);
rooted_vec!(let mut views);
match &viewer_pose.views {
Views::Inline => views.push(XRView::new(
global,
window,
session,
&session.inline_view(),
XREye::None,
@ -58,7 +59,7 @@ impl XRViewerPose {
can_gc,
)),
Views::Mono(view) => views.push(XRView::new(
global,
window,
session,
view,
XREye::None,
@ -68,7 +69,7 @@ impl XRViewerPose {
)),
Views::Stereo(left, right) => {
views.push(XRView::new(
global,
window,
session,
left,
XREye::Left,
@ -77,7 +78,7 @@ impl XRViewerPose {
can_gc,
));
views.push(XRView::new(
global,
window,
session,
right,
XREye::Right,
@ -88,7 +89,7 @@ impl XRViewerPose {
},
Views::StereoCapture(left, right, third_eye) => {
views.push(XRView::new(
global,
window,
session,
left,
XREye::Left,
@ -97,7 +98,7 @@ impl XRViewerPose {
can_gc,
));
views.push(XRView::new(
global,
window,
session,
right,
XREye::Right,
@ -106,7 +107,7 @@ impl XRViewerPose {
can_gc,
));
views.push(XRView::new(
global,
window,
session,
third_eye,
XREye::None,
@ -117,7 +118,7 @@ impl XRViewerPose {
},
Views::Cubemap(front, left, right, top, bottom, back) => {
views.push(XRView::new(
global,
window,
session,
front,
XREye::None,
@ -126,7 +127,7 @@ impl XRViewerPose {
can_gc,
));
views.push(XRView::new(
global,
window,
session,
left,
XREye::None,
@ -135,7 +136,7 @@ impl XRViewerPose {
can_gc,
));
views.push(XRView::new(
global,
window,
session,
right,
XREye::None,
@ -144,7 +145,7 @@ impl XRViewerPose {
can_gc,
));
views.push(XRView::new(
global,
window,
session,
top,
XREye::None,
@ -153,7 +154,7 @@ impl XRViewerPose {
can_gc,
));
views.push(XRView::new(
global,
window,
session,
bottom,
XREye::None,
@ -162,7 +163,7 @@ impl XRViewerPose {
can_gc,
));
views.push(XRView::new(
global,
window,
session,
back,
XREye::None,
@ -174,10 +175,10 @@ impl XRViewerPose {
};
let transform: RigidTransform3D<f32, Viewer, BaseSpace> =
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(
Box::new(XRViewerPose::new_inherited(&transform)),
global,
window,
can_gc,
);

View file

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

View file

@ -65,7 +65,7 @@ impl GraphicsProviderMethods<D3D11> for GraphicsProvider {
// already created is appropriate. OpenXR returns a validation error
// unless we call this method, so we call it and ignore the results
// 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)))?;
unsafe {

View file

@ -311,7 +311,7 @@ impl OpenXRInput {
InputId(0),
Handedness::Right,
&action_set,
&session,
session,
needs_hands,
supported_interaction_profiles.clone(),
);
@ -319,7 +319,7 @@ impl OpenXRInput {
InputId(1),
Handedness::Left,
&action_set,
&session,
session,
needs_hands,
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![]) {
if let Some(surface_texture) = surface_texture {
let mut surface = device
.destroy_surface_texture(&mut context, surface_texture)
.destroy_surface_texture(context, surface_texture)
.unwrap();
device.destroy_surface(&mut context, &mut surface).unwrap();
device.destroy_surface(context, &mut surface).unwrap();
}
}
}