Repository: servo/servo
File: components/script/dom/macros.rs (Rust)

Code before:
        window_owned_event_handler!(pageshow, GetOnpageshow, SetOnpageshow);
        window_owned_event_handler!(pageswap, GetOnpageswap, SetOnpageswap);
        window_owned_event_handler!(popstate, GetOnpopstate, SetOnpopstate);
        window_owned_event_handler!(rejectionhandled, GetOnrejectionhandled,
                                    SetOnrejectionhandled);
        window_owned_event_handler!(storage, GetOnstorage, SetOnstorage);
        window_owned_event_handler!(unhandledrejection, GetOnunhandledrejection,
                                    SetOnunhandledrejection);
        window_owned_event_handler!(unload, GetOnunload, SetOnunload);
        window_owned_event_handler!(gamepadconnected, GetOngamepadconnected, SetOngamepadconnected);
        window_owned_event_handler!(gamepaddisconnected, GetOngamepaddisconnected, SetOngamepaddisconnected);
    );
);

// Event handlers that must be supported by WorkerGlobalScope.
macro_rules! worker_event_handlers (
    () => (
        error_event_handler!(error, GetOnerror, SetOnerror);
        event_handler!(languagechange, GetOnlanguagechange, SetOnlanguagechange);
        event_handler!(offline, GetOnoffline, SetOnoffline);
        event_handler!(online, GetOnonline, SetOnonline);
        event_handler!(rejectionhandled, GetOnrejectionhandled, SetOnrejectionhandled);
        event_handler!(unhandledrejection, GetOnunhandledrejection, SetOnunhandledrejection);
    )
);

/// DOM struct implementation for simple interfaces inheriting from PerformanceEntry.
macro_rules! impl_performance_entry_struct(
    ($binding:ident, $struct:ident, $type:expr) => (
        use base::cross_process_instant::CrossProcessInstant;
        use time::Duration;

        use crate::dom::bindings::reflector::reflect_dom_object;
        use crate::dom::bindings::root::DomRoot;
        use crate::dom::bindings::str::DOMString;
        use crate::dom::globalscope::GlobalScope;
        use crate::dom::performanceentry::PerformanceEntry;
        use crate::script_runtime::CanGc;
        use dom_struct::dom_struct;

        #[dom_struct]
        pub(crate) struct $struct {
            entry: PerformanceEntry,
        }

        impl $struct {
            fn new_inherited(name: DOMString, start_time: CrossProcessInstant, duration: Duration)
                -> $struct {
                $struct {
                    entry: PerformanceEntry::new_inherited(name,
                                                           DOMString::from($type),

Review comment (refactor):
Please remove this macro and just adding these event handlers to `workerglobalscope.rs`.


Code after:
        window_owned_event_handler!(pageshow, GetOnpageshow, SetOnpageshow);
        window_owned_event_handler!(pageswap, GetOnpageswap, SetOnpageswap);
        window_owned_event_handler!(popstate, GetOnpopstate, SetOnpopstate);
        window_owned_event_handler!(rejectionhandled, GetOnrejectionhandled,
                                    SetOnrejectionhandled);
        window_owned_event_handler!(storage, GetOnstorage, SetOnstorage);
        window_owned_event_handler!(unhandledrejection, GetOnunhandledrejection,
                                    SetOnunhandledrejection);
        window_owned_event_handler!(unload, GetOnunload, SetOnunload);
        window_owned_event_handler!(gamepadconnected, GetOngamepadconnected, SetOngamepadconnected);
        window_owned_event_handler!(gamepaddisconnected, GetOngamepaddisconnected, SetOngamepaddisconnected);
    );
);

/// DOM struct implementation for simple interfaces inheriting from PerformanceEntry.
macro_rules! impl_performance_entry_struct(
    ($binding:ident, $struct:ident, $type:expr) => (
        use base::cross_process_instant::CrossProcessInstant;
        use time::Duration;

        use crate::dom::bindings::reflector::reflect_dom_object;
        use crate::dom::bindings::root::DomRoot;
        use crate::dom::bindings::str::DOMString;
        use crate::dom::globalscope::GlobalScope;
        use crate::dom::performanceentry::PerformanceEntry;
        use crate::script_runtime::CanGc;
        use dom_struct::dom_struct;

        #[dom_struct]
        pub(crate) struct $struct {
            entry: PerformanceEntry,
        }

        impl $struct {
            fn new_inherited(name: DOMString, start_time: CrossProcessInstant, duration: Duration)
                -> $struct {
                $struct {
                    entry: PerformanceEntry::new_inherited(name,
                                                           DOMString::from($type),
                                                           Some(start_time),
                                                           duration)
                }
            }

            #[cfg_attr(crown, allow(crown::unrooted_must_root))]
            pub(crate) fn new(global: &GlobalScope,
                       name: DOMString,
                       start_time: CrossProcessInstant,
                       duration: Duration) -> DomRoot<$struct> {
                let entry = $struct::new_inherited(name, start_time, duration);
                reflect_dom_object(Box::new(entry), global, CanGc::note())