Support arbitrary protos when wrapping DOM objects with constructors.

This commit is contained in:
Josh Matthews 2023-05-28 22:43:55 -04:00
parent d9600ff50f
commit dbff26bce0
197 changed files with 2028 additions and 586 deletions

View file

@ -8,7 +8,7 @@ use crate::dom::bindings::codegen::Bindings::XRInputSourceEventBinding::{
};
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::reflector::{reflect_dom_object2, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event;
@ -17,6 +17,7 @@ use crate::dom::window::Window;
use crate::dom::xrframe::XRFrame;
use crate::dom::xrinputsource::XRInputSource;
use dom_struct::dom_struct;
use js::rust::HandleObject;
use servo_atoms::Atom;
#[dom_struct]
@ -44,9 +45,22 @@ impl XRInputSourceEvent {
frame: &XRFrame,
source: &XRInputSource,
) -> DomRoot<XRInputSourceEvent> {
let trackevent = reflect_dom_object(
Self::new_with_proto(global, None, type_, bubbles, cancelable, frame, source)
}
fn new_with_proto(
global: &GlobalScope,
proto: Option<HandleObject>,
type_: Atom,
bubbles: bool,
cancelable: bool,
frame: &XRFrame,
source: &XRInputSource,
) -> DomRoot<XRInputSourceEvent> {
let trackevent = reflect_dom_object2(
Box::new(XRInputSourceEvent::new_inherited(frame, source)),
global,
proto,
);
{
let event = trackevent.upcast::<Event>();
@ -58,11 +72,13 @@ impl XRInputSourceEvent {
#[allow(non_snake_case)]
pub fn Constructor(
window: &Window,
proto: Option<HandleObject>,
type_: DOMString,
init: &XRInputSourceEventBinding::XRInputSourceEventInit,
) -> Fallible<DomRoot<XRInputSourceEvent>> {
Ok(XRInputSourceEvent::new(
Ok(XRInputSourceEvent::new_with_proto(
&window.global(),
proto,
Atom::from(type_),
init.parent.bubbles,
init.parent.cancelable,