diff --git a/components/script/dom/beforeunloadevent.rs b/components/script/dom/beforeunloadevent.rs index d9162002016..3787bb5b62d 100644 --- a/components/script/dom/beforeunloadevent.rs +++ b/components/script/dom/beforeunloadevent.rs @@ -13,7 +13,7 @@ use dom::bindings::js::Root; use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::DOMString; use dom::event::{Event, EventBubbles, EventCancelable}; -use dom::globalscope::GlobalScope; +use dom::window::Window; use servo_atoms::Atom; // https://html.spec.whatwg.org/multipage/#beforeunloadevent @@ -31,17 +31,17 @@ impl BeforeUnloadEvent { } } - pub fn new_uninitialized(global: &GlobalScope) -> Root { + pub fn new_uninitialized(window: &Window) -> Root { reflect_dom_object(box BeforeUnloadEvent::new_inherited(), - global, + window, BeforeUnloadEventBinding::Wrap) } - pub fn new(global: &GlobalScope, + pub fn new(window: &Window, type_: Atom, bubbles: EventBubbles, cancelable: EventCancelable) -> Root { - let ev = BeforeUnloadEvent::new_uninitialized(global); + let ev = BeforeUnloadEvent::new_uninitialized(window); { let event = ev.upcast::(); event.init_event(type_, bool::from(bubbles), diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 8702120c92e..dd78af6ecd6 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -7,6 +7,7 @@ use devtools_traits::ScriptToDevtoolsControlMsg; use document_loader::{DocumentLoader, LoadType}; use dom::activation::{ActivationSource, synthetic_click_activation}; use dom::attr::Attr; +use dom::beforeunloadevent::BeforeUnloadEvent; use dom::bindings::callback::ExceptionHandling; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods; @@ -2603,6 +2604,8 @@ impl DocumentMethods for Document { fn CreateEvent(&self, mut interface: DOMString) -> Fallible> { interface.make_ascii_lowercase(); match &*interface { + "beforeunloadevent" => + Ok(Root::upcast(BeforeUnloadEvent::new_uninitialized(&self.window))), "closeevent" => Ok(Root::upcast(CloseEvent::new_uninitialized(self.window.upcast()))), "customevent" => @@ -2612,9 +2615,9 @@ impl DocumentMethods for Document { "events" | "event" | "htmlevents" | "svgevents" => Ok(Event::new_uninitialized(&self.window.upcast())), "focusevent" => - Ok(Root::upcast(FocusEvent::new_uninitialized(self.window.upcast()))), + Ok(Root::upcast(FocusEvent::new_uninitialized(&self.window))), "hashchangeevent" => - Ok(Root::upcast(HashChangeEvent::new_uninitialized(&self.window.upcast()))), + Ok(Root::upcast(HashChangeEvent::new_uninitialized(&self.window))), "keyboardevent" => Ok(Root::upcast(KeyboardEvent::new_uninitialized(&self.window))), "messageevent" => @@ -2622,9 +2625,9 @@ impl DocumentMethods for Document { "mouseevent" | "mouseevents" => Ok(Root::upcast(MouseEvent::new_uninitialized(&self.window))), "pagetransitionevent" => - Ok(Root::upcast(PageTransitionEvent::new_uninitialized(self.window.upcast()))), + Ok(Root::upcast(PageTransitionEvent::new_uninitialized(&self.window))), "popstateevent" => - Ok(Root::upcast(PopStateEvent::new_uninitialized(self.window.upcast()))), + Ok(Root::upcast(PopStateEvent::new_uninitialized(&self.window))), "progressevent" => Ok(Root::upcast(ProgressEvent::new_uninitialized(self.window.upcast()))), "storageevent" => { diff --git a/components/script/dom/focusevent.rs b/components/script/dom/focusevent.rs index c7e48531479..6ffed30e857 100644 --- a/components/script/dom/focusevent.rs +++ b/components/script/dom/focusevent.rs @@ -12,7 +12,6 @@ use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::DOMString; use dom::event::{EventBubbles, EventCancelable}; use dom::eventtarget::EventTarget; -use dom::globalscope::GlobalScope; use dom::uievent::UIEvent; use dom::window::Window; use std::default::Default; @@ -31,9 +30,9 @@ impl FocusEvent { } } - pub fn new_uninitialized(global: &GlobalScope) -> Root { + pub fn new_uninitialized(window: &Window) -> Root { reflect_dom_object(box FocusEvent::new_inherited(), - global, + window, FocusEventBinding::Wrap) } @@ -44,7 +43,7 @@ impl FocusEvent { view: Option<&Window>, detail: i32, related_target: Option<&EventTarget>) -> Root { - let ev = FocusEvent::new_uninitialized(window.upcast()); + let ev = FocusEvent::new_uninitialized(window); ev.upcast::().InitUIEvent(type_, bool::from(can_bubble), bool::from(cancelable), diff --git a/components/script/dom/hashchangeevent.rs b/components/script/dom/hashchangeevent.rs index b93b7a93631..cd4b2b0a71f 100644 --- a/components/script/dom/hashchangeevent.rs +++ b/components/script/dom/hashchangeevent.rs @@ -11,7 +11,7 @@ use dom::bindings::js::Root; use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::{DOMString, USVString}; use dom::event::Event; -use dom::globalscope::GlobalScope; +use dom::window::Window; use servo_atoms::Atom; // https://html.spec.whatwg.org/multipage/#hashchangeevent @@ -31,13 +31,13 @@ impl HashChangeEvent { } } - pub fn new_uninitialized(global: &GlobalScope) -> Root { + pub fn new_uninitialized(window: &Window) -> Root { reflect_dom_object(box HashChangeEvent::new_inherited(String::new(), String::new()), - global, + window, HashChangeEventBinding::Wrap) } - pub fn new(global: &GlobalScope, + pub fn new(window: &Window, type_: Atom, bubbles: bool, cancelable: bool, @@ -45,7 +45,7 @@ impl HashChangeEvent { new_url: String) -> Root { let ev = reflect_dom_object(box HashChangeEvent::new_inherited(old_url, new_url), - global, + window, HashChangeEventBinding::Wrap); { let event = ev.upcast::(); @@ -54,11 +54,11 @@ impl HashChangeEvent { ev } - pub fn Constructor(global: &GlobalScope, + pub fn Constructor(window: &Window, type_: DOMString, init: &HashChangeEventBinding::HashChangeEventInit) -> Fallible> { - Ok(HashChangeEvent::new(global, + Ok(HashChangeEvent::new(window, Atom::from(type_), init.parent.bubbles, init.parent.cancelable, diff --git a/components/script/dom/pagetransitionevent.rs b/components/script/dom/pagetransitionevent.rs index b40f6c1ab39..e76a6444d4c 100644 --- a/components/script/dom/pagetransitionevent.rs +++ b/components/script/dom/pagetransitionevent.rs @@ -11,7 +11,7 @@ use dom::bindings::js::Root; use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::DOMString; use dom::event::Event; -use dom::globalscope::GlobalScope; +use dom::window::Window; use servo_atoms::Atom; use std::cell::Cell; @@ -30,19 +30,19 @@ impl PageTransitionEvent { } } - pub fn new_uninitialized(global: &GlobalScope) -> Root { + pub fn new_uninitialized(window: &Window) -> Root { reflect_dom_object(box PageTransitionEvent::new_inherited(), - global, + window, PageTransitionEventBinding::Wrap) } - pub fn new(global: &GlobalScope, + pub fn new(window: &Window, type_: Atom, bubbles: bool, cancelable: bool, persisted: bool) -> Root { - let ev = PageTransitionEvent::new_uninitialized(global); + let ev = PageTransitionEvent::new_uninitialized(window); ev.persisted.set(persisted); { let event = ev.upcast::(); @@ -51,11 +51,11 @@ impl PageTransitionEvent { ev } - pub fn Constructor(global: &GlobalScope, + pub fn Constructor(window: &Window, type_: DOMString, init: &PageTransitionEventBinding::PageTransitionEventInit) -> Fallible> { - Ok(PageTransitionEvent::new(global, + Ok(PageTransitionEvent::new(window, Atom::from(type_), init.parent.bubbles, init.parent.cancelable, diff --git a/components/script/dom/popstateevent.rs b/components/script/dom/popstateevent.rs index 44183f7483f..fde05e30394 100644 --- a/components/script/dom/popstateevent.rs +++ b/components/script/dom/popstateevent.rs @@ -11,7 +11,7 @@ use dom::bindings::js::{MutHeapJSVal, Root}; use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::DOMString; use dom::event::Event; -use dom::globalscope::GlobalScope; +use dom::window::Window; use js::jsapi::{HandleValue, JSContext}; use js::jsval::JSVal; use servo_atoms::Atom; @@ -32,19 +32,19 @@ impl PopStateEvent { } } - pub fn new_uninitialized(global: &GlobalScope) -> Root { + pub fn new_uninitialized(window: &Window) -> Root { reflect_dom_object(box PopStateEvent::new_inherited(), - global, + window, PopStateEventBinding::Wrap) } - pub fn new(global: &GlobalScope, + pub fn new(window: &Window, type_: Atom, bubbles: bool, cancelable: bool, state: HandleValue) -> Root { - let ev = PopStateEvent::new_uninitialized(global); + let ev = PopStateEvent::new_uninitialized(window); ev.state.set(state.get()); { let event = ev.upcast::(); @@ -54,11 +54,11 @@ impl PopStateEvent { } #[allow(unsafe_code)] - pub fn Constructor(global: &GlobalScope, + pub fn Constructor(window: &Window, type_: DOMString, init: &PopStateEventBinding::PopStateEventInit) -> Fallible> { - Ok(PopStateEvent::new(global, + Ok(PopStateEvent::new(window, Atom::from(type_), init.parent.bubbles, init.parent.cancelable, diff --git a/components/script/dom/transitionevent.rs b/components/script/dom/transitionevent.rs index cc17e77eae1..4630ec70bc0 100644 --- a/components/script/dom/transitionevent.rs +++ b/components/script/dom/transitionevent.rs @@ -12,7 +12,6 @@ use dom::bindings::num::Finite; use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::DOMString; use dom::event::Event; -use dom::globalscope::GlobalScope; use dom::window::Window; use servo_atoms::Atom; @@ -25,7 +24,7 @@ pub struct TransitionEvent { } impl TransitionEvent { - pub fn new_inherited(init: &TransitionEventInit) -> TransitionEvent { + fn new_inherited(init: &TransitionEventInit) -> TransitionEvent { TransitionEvent { event: Event::new_inherited(), property_name: Atom::from(init.propertyName.clone()), @@ -34,11 +33,11 @@ impl TransitionEvent { } } - pub fn new(global: &GlobalScope, + pub fn new(window: &Window, type_: Atom, init: &TransitionEventInit) -> Root { let ev = reflect_dom_object(box TransitionEvent::new_inherited(init), - global, + window, TransitionEventBinding::Wrap); { let event = ev.upcast::(); @@ -50,8 +49,7 @@ impl TransitionEvent { pub fn Constructor(window: &Window, type_: DOMString, init: &TransitionEventInit) -> Fallible> { - let global = window.upcast::(); - Ok(TransitionEvent::new(global, Atom::from(type_), init)) + Ok(TransitionEvent::new(window, Atom::from(type_), init)) } } diff --git a/components/script/dom/webidls/BeforeUnloadEvent.webidl b/components/script/dom/webidls/BeforeUnloadEvent.webidl index 74b0cd8e62c..71fe9396d48 100644 --- a/components/script/dom/webidls/BeforeUnloadEvent.webidl +++ b/components/script/dom/webidls/BeforeUnloadEvent.webidl @@ -6,7 +6,7 @@ * https://html.spec.whatwg.org/multipage/#beforeunloadevent */ -[Exposed=(Window,Worker)] +[Exposed=Window] interface BeforeUnloadEvent : Event { attribute DOMString returnValue; }; diff --git a/components/script/dom/webidls/FocusEvent.webidl b/components/script/dom/webidls/FocusEvent.webidl index 42e560b72b4..14ec3ae67e9 100644 --- a/components/script/dom/webidls/FocusEvent.webidl +++ b/components/script/dom/webidls/FocusEvent.webidl @@ -3,7 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // https://w3c.github.io/uievents/#interface-FocusEvent -[Constructor(DOMString typeArg, optional FocusEventInit focusEventInitDict)] +[Constructor(DOMString typeArg, optional FocusEventInit focusEventInitDict), + Exposed=Window] interface FocusEvent : UIEvent { readonly attribute EventTarget? relatedTarget; }; diff --git a/components/script/dom/webidls/HashChangeEvent.webidl b/components/script/dom/webidls/HashChangeEvent.webidl index d34400c7ccc..3d81e8ad383 100644 --- a/components/script/dom/webidls/HashChangeEvent.webidl +++ b/components/script/dom/webidls/HashChangeEvent.webidl @@ -3,7 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // https://html.spec.whatwg.org/multipage/#hashchangeevent -[Constructor(DOMString type, optional HashChangeEventInit eventInitDict), Exposed=(Window,Worker)] +[Constructor(DOMString type, optional HashChangeEventInit eventInitDict), + Exposed=Window] interface HashChangeEvent : Event { readonly attribute USVString oldURL; readonly attribute USVString newURL; diff --git a/components/script/dom/webidls/Location.webidl b/components/script/dom/webidls/Location.webidl index 431ab87d5e5..d611a20b883 100644 --- a/components/script/dom/webidls/Location.webidl +++ b/components/script/dom/webidls/Location.webidl @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // https://html.spec.whatwg.org/multipage/#location -[Exposed=(Window,Worker), Unforgeable] interface Location { +[Exposed=Window, Unforgeable] interface Location { /*stringifier*/ attribute USVString href; readonly attribute USVString origin; attribute USVString protocol; diff --git a/components/script/dom/webidls/MouseEvent.webidl b/components/script/dom/webidls/MouseEvent.webidl index c95739429a8..e9f7a31db48 100644 --- a/components/script/dom/webidls/MouseEvent.webidl +++ b/components/script/dom/webidls/MouseEvent.webidl @@ -3,7 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // https://w3c.github.io/uievents/#interface-mouseevent -[Constructor(DOMString typeArg, optional MouseEventInit mouseEventInitDict)] +[Constructor(DOMString typeArg, optional MouseEventInit mouseEventInitDict), + Exposed=Window] interface MouseEvent : UIEvent { readonly attribute long screenX; readonly attribute long screenY; diff --git a/components/script/dom/webidls/PageTransitionEvent.webidl b/components/script/dom/webidls/PageTransitionEvent.webidl index 3f3ed0b797a..a23f3099bad 100644 --- a/components/script/dom/webidls/PageTransitionEvent.webidl +++ b/components/script/dom/webidls/PageTransitionEvent.webidl @@ -3,7 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // https://html.spec.whatwg.org/multipage/#the-pagetransitionevent-interface -[Constructor(DOMString type, optional PageTransitionEventInit eventInitDict), Exposed=(Window,Worker)] +[Constructor(DOMString type, optional PageTransitionEventInit eventInitDict), + Exposed=Window] interface PageTransitionEvent : Event { readonly attribute boolean persisted; }; diff --git a/components/script/dom/webidls/PopStateEvent.webidl b/components/script/dom/webidls/PopStateEvent.webidl index f5052df597f..4508cac6288 100644 --- a/components/script/dom/webidls/PopStateEvent.webidl +++ b/components/script/dom/webidls/PopStateEvent.webidl @@ -3,7 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // https://html.spec.whatwg.org/multipage/#the-popstateevent-interface -[Constructor(DOMString type, optional PopStateEventInit eventInitDict), Exposed=(Window,Worker)] +[Constructor(DOMString type, optional PopStateEventInit eventInitDict), + Exposed=Window] interface PopStateEvent : Event { readonly attribute any state; }; diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index ce02d763699..57cdd7044c4 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1624,7 +1624,7 @@ impl ScriptThread { // FIXME: Handle pseudo-elements properly pseudoElement: DOMString::new() }; - let transition_event = TransitionEvent::new(window.upcast(), + let transition_event = TransitionEvent::new(&window, atom!("transitionend"), &init); transition_event.upcast::().fire(node.upcast()); diff --git a/tests/wpt/metadata/dom/events/EventTarget-dispatchEvent.html.ini b/tests/wpt/metadata/dom/events/EventTarget-dispatchEvent.html.ini index 201224d1802..cdf64e987c2 100644 --- a/tests/wpt/metadata/dom/events/EventTarget-dispatchEvent.html.ini +++ b/tests/wpt/metadata/dom/events/EventTarget-dispatchEvent.html.ini @@ -3,9 +3,6 @@ [If the event's initialized flag is not set, an InvalidStateError must be thrown (AnimationEvent).] expected: FAIL - [If the event's initialized flag is not set, an InvalidStateError must be thrown (BeforeUnloadEvent).] - expected: FAIL - [If the event's initialized flag is not set, an InvalidStateError must be thrown (CompositionEvent).] expected: FAIL diff --git a/tests/wpt/metadata/dom/nodes/Document-createEvent.html.ini b/tests/wpt/metadata/dom/nodes/Document-createEvent.html.ini index c8062768eb4..783ad1e01c5 100644 --- a/tests/wpt/metadata/dom/nodes/Document-createEvent.html.ini +++ b/tests/wpt/metadata/dom/nodes/Document-createEvent.html.ini @@ -19,24 +19,6 @@ [createEvent('ANIMATIONEVENT') should be initialized correctly.] expected: FAIL - [BeforeUnloadEvent should be an alias for BeforeUnloadEvent.] - expected: FAIL - - [createEvent('BeforeUnloadEvent') should be initialized correctly.] - expected: FAIL - - [beforeunloadevent should be an alias for BeforeUnloadEvent.] - expected: FAIL - - [createEvent('beforeunloadevent') should be initialized correctly.] - expected: FAIL - - [BEFOREUNLOADEVENT should be an alias for BeforeUnloadEvent.] - expected: FAIL - - [createEvent('BEFOREUNLOADEVENT') should be initialized correctly.] - expected: FAIL - [CompositionEvent should be an alias for CompositionEvent.] expected: FAIL diff --git a/tests/wpt/metadata/workers/semantics/interface-objects/002.worker.js.ini b/tests/wpt/metadata/workers/semantics/interface-objects/002.worker.js.ini deleted file mode 100644 index d05ef098814..00000000000 --- a/tests/wpt/metadata/workers/semantics/interface-objects/002.worker.js.ini +++ /dev/null @@ -1,14 +0,0 @@ -[002.worker.html] - type: testharness - [The Location interface object should not be exposed.] - expected: FAIL - - [The PopStateEvent interface object should not be exposed.] - expected: FAIL - - [The HashChangeEvent interface object should not be exposed.] - expected: FAIL - - [The PageTransitionEvent interface object should not be exposed.] - expected: FAIL - diff --git a/tests/wpt/mozilla/tests/mozilla/interfaces.worker.js b/tests/wpt/mozilla/tests/mozilla/interfaces.worker.js index eca4a7562b6..f91ed7c8bc5 100644 --- a/tests/wpt/mozilla/tests/mozilla/interfaces.worker.js +++ b/tests/wpt/mozilla/tests/mozilla/interfaces.worker.js @@ -7,7 +7,6 @@ importScripts("interfaces.js"); // IMPORTANT: Do not change the list below without review from a DOM peer! test_interfaces([ - "BeforeUnloadEvent", "Blob", "CloseEvent", "CSSStyleDeclaration", @@ -30,21 +29,17 @@ test_interfaces([ "FileReader", "FileReaderSync", "FormData", - "HashChangeEvent", "Headers", "History", "ImageData", - "Location", "MediaError", "MessageEvent", "MimeType", "MimeTypeArray", - "PageTransitionEvent", "Performance", "PerformanceTiming", "Plugin", "PluginArray", - "PopStateEvent", "ProgressEvent", "Request", "Response", diff --git a/tests/wpt/web-platform-tests/workers/semantics/interface-objects/002.worker.js b/tests/wpt/web-platform-tests/workers/semantics/interface-objects/002.worker.js index 0f514988bd2..8fc0b6a46f9 100644 --- a/tests/wpt/web-platform-tests/workers/semantics/interface-objects/002.worker.js +++ b/tests/wpt/web-platform-tests/workers/semantics/interface-objects/002.worker.js @@ -16,6 +16,7 @@ var unexpected = [ "DrawingStyle", "CanvasGradient", "CanvasPattern", + "BeforeUnloadEvent", "PopStateEvent", "HashChangeEvent", "PageTransitionEvent",