diff options
Diffstat (limited to 'components/script/dom/event.rs')
-rw-r--r-- | components/script/dom/event.rs | 24 |
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) { |