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

@ -9,12 +9,13 @@ use crate::dom::bindings::codegen::Bindings::TransitionEventBinding::{
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::reflector::reflect_dom_object2;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use js::rust::HandleObject;
use servo_atoms::Atom;
#[dom_struct]
@ -40,7 +41,16 @@ impl TransitionEvent {
type_: Atom,
init: &TransitionEventInit,
) -> DomRoot<TransitionEvent> {
let ev = reflect_dom_object(Box::new(TransitionEvent::new_inherited(init)), window);
Self::new_with_proto(window, None, type_, init)
}
fn new_with_proto(
window: &Window,
proto: Option<HandleObject>,
type_: Atom,
init: &TransitionEventInit,
) -> DomRoot<TransitionEvent> {
let ev = reflect_dom_object2(Box::new(TransitionEvent::new_inherited(init)), window, proto);
{
let event = ev.upcast::<Event>();
event.init_event(type_, init.parent.bubbles, init.parent.cancelable);
@ -51,10 +61,11 @@ impl TransitionEvent {
#[allow(non_snake_case)]
pub fn Constructor(
window: &Window,
proto: Option<HandleObject>,
type_: DOMString,
init: &TransitionEventInit,
) -> Fallible<DomRoot<TransitionEvent>> {
Ok(TransitionEvent::new(window, Atom::from(type_), init))
Ok(TransitionEvent::new_with_proto(window, proto, Atom::from(type_), init))
}
}