aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/event.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2023-05-28 22:43:55 -0400
committerJosh Matthews <josh@joshmatthews.net>2023-05-28 23:23:12 -0400
commitdbff26bce05d404027ef5bbfd85fb5995e4726bc (patch)
tree6ebb631eef396c2f387fe8269b0d59bde0dccae2 /components/script/dom/event.rs
parentd9600ff50f3c1bdd8c44e2dfc15a18416d80cb82 (diff)
downloadservo-dbff26bce05d404027ef5bbfd85fb5995e4726bc.tar.gz
servo-dbff26bce05d404027ef5bbfd85fb5995e4726bc.zip
Support arbitrary protos when wrapping DOM objects with constructors.
Diffstat (limited to 'components/script/dom/event.rs')
-rw-r--r--components/script/dom/event.rs24
1 files changed, 20 insertions, 4 deletions
diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs
index 8093bd852a9..205bf58e37e 100644
--- a/components/script/dom/event.rs
+++ b/components/script/dom/event.rs
@@ -12,7 +12,7 @@ use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::refcounted::Trusted;
-use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
+use crate::dom::bindings::reflector::{reflect_dom_object2, DomObject, Reflector};
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document;
@@ -28,6 +28,7 @@ use crate::dom::window::Window;
use crate::task::TaskOnce;
use devtools_traits::{TimelineMarker, TimelineMarkerType};
use dom_struct::dom_struct;
+use js::rust::HandleObject;
use metrics::ToMs;
use servo_atoms::Atom;
use std::cell::Cell;
@@ -72,7 +73,11 @@ impl Event {
}
pub fn new_uninitialized(global: &GlobalScope) -> DomRoot<Event> {
- reflect_dom_object(Box::new(Event::new_inherited()), global)
+ Self::new_uninitialized_with_proto(global, None)
+ }
+
+ pub fn new_uninitialized_with_proto(global: &GlobalScope, proto: Option<HandleObject>) -> DomRoot<Event> {
+ reflect_dom_object2(Box::new(Event::new_inherited()), global, proto)
}
pub fn new(
@@ -81,7 +86,17 @@ impl Event {
bubbles: EventBubbles,
cancelable: EventCancelable,
) -> DomRoot<Event> {
- let event = Event::new_uninitialized(global);
+ Self::new_with_proto(global, None, type_, bubbles, cancelable)
+ }
+
+ fn new_with_proto(
+ global: &GlobalScope,
+ proto: Option<HandleObject>,
+ type_: Atom,
+ bubbles: EventBubbles,
+ cancelable: EventCancelable,
+ ) -> DomRoot<Event> {
+ let event = Event::new_uninitialized_with_proto(global, proto);
event.init_event(type_, bool::from(bubbles), bool::from(cancelable));
event
}
@@ -89,12 +104,13 @@ impl Event {
#[allow(non_snake_case)]
pub fn Constructor(
global: &GlobalScope,
+ proto: Option<HandleObject>,
type_: DOMString,
init: &EventBinding::EventInit,
) -> Fallible<DomRoot<Event>> {
let bubbles = EventBubbles::from(init.bubbles);
let cancelable = EventCancelable::from(init.cancelable);
- Ok(Event::new(global, Atom::from(type_), bubbles, cancelable))
+ Ok(Event::new_with_proto(global, proto, Atom::from(type_), bubbles, cancelable))
}
pub fn init_event(&self, type_: Atom, bubbles: bool, cancelable: bool) {