aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/bindings/global.rs9
-rw-r--r--components/script/dom/bluetooth.rs4
-rw-r--r--components/script/dom/bluetoothremotegattcharacteristic.rs4
-rw-r--r--components/script/dom/bluetoothremotegattdescriptor.rs4
-rw-r--r--components/script/dom/bluetoothremotegattserver.rs4
-rw-r--r--components/script/dom/bluetoothremotegattservice.rs4
-rw-r--r--components/script/dom/comment.rs2
-rw-r--r--components/script/dom/document.rs2
-rw-r--r--components/script/dom/documentfragment.rs2
-rw-r--r--components/script/dom/domparser.rs2
-rw-r--r--components/script/dom/focusevent.rs3
-rw-r--r--components/script/dom/globalscope.rs5
-rw-r--r--components/script/dom/htmlformcontrolscollection.rs3
-rw-r--r--components/script/dom/htmlimageelement.rs2
-rw-r--r--components/script/dom/keyboardevent.rs3
-rw-r--r--components/script/dom/mouseevent.rs3
-rw-r--r--components/script/dom/range.rs2
-rw-r--r--components/script/dom/storage.rs6
-rw-r--r--components/script/dom/testbinding.rs2
-rw-r--r--components/script/dom/text.rs2
-rw-r--r--components/script/dom/uievent.rs3
-rw-r--r--components/script/dom/xmlhttprequest.rs2
22 files changed, 30 insertions, 43 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs
index 84b75cc9443..7366d507649 100644
--- a/components/script/dom/bindings/global.rs
+++ b/components/script/dom/bindings/global.rs
@@ -68,15 +68,6 @@ impl<'a> GlobalRef<'a> {
}
}
- /// Extract a `Window`, causing thread failure if the global object is not
- /// a `Window`.
- pub fn as_window(&self) -> &window::Window {
- match *self {
- GlobalRef::Window(window) => window,
- GlobalRef::Worker(_) => panic!("expected a Window scope"),
- }
- }
-
/// Get the `ResourceThreads` for this global scope.
pub fn resource_threads(&self) -> ResourceThreads {
match *self {
diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs
index 02bccb80f91..143bc04855a 100644
--- a/components/script/dom/bluetooth.rs
+++ b/components/script/dom/bluetooth.rs
@@ -60,9 +60,7 @@ impl Bluetooth {
}
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
- let global_root = self.global();
- let global_ref = global_root.r();
- global_ref.as_window().bluetooth_thread()
+ self.global_scope().as_window().bluetooth_thread()
}
fn request_device(&self, option: &RequestDeviceOptions) -> Fallible<Root<BluetoothDevice>> {
diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs
index 0dbb7c4670e..faa6eba4bef 100644
--- a/components/script/dom/bluetoothremotegattcharacteristic.rs
+++ b/components/script/dom/bluetoothremotegattcharacteristic.rs
@@ -74,9 +74,7 @@ impl BluetoothRemoteGATTCharacteristic {
}
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
- let global_root = self.global();
- let global_ref = global_root.r();
- global_ref.as_window().bluetooth_thread()
+ self.global_scope().as_window().bluetooth_thread()
}
fn get_instance_id(&self) -> String {
diff --git a/components/script/dom/bluetoothremotegattdescriptor.rs b/components/script/dom/bluetoothremotegattdescriptor.rs
index ee4c6ce1af5..2bc2821f607 100644
--- a/components/script/dom/bluetoothremotegattdescriptor.rs
+++ b/components/script/dom/bluetoothremotegattdescriptor.rs
@@ -61,9 +61,7 @@ impl BluetoothRemoteGATTDescriptor {
}
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
- let global_root = self.global();
- let global_ref = global_root.r();
- global_ref.as_window().bluetooth_thread()
+ self.global_scope().as_window().bluetooth_thread()
}
fn get_instance_id(&self) -> String {
diff --git a/components/script/dom/bluetoothremotegattserver.rs b/components/script/dom/bluetoothremotegattserver.rs
index 7bb4d8fb05d..a9712216d61 100644
--- a/components/script/dom/bluetoothremotegattserver.rs
+++ b/components/script/dom/bluetoothremotegattserver.rs
@@ -46,9 +46,7 @@ impl BluetoothRemoteGATTServer {
}
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
- let global_root = self.global();
- let global_ref = global_root.r();
- global_ref.as_window().bluetooth_thread()
+ self.global_scope().as_window().bluetooth_thread()
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
diff --git a/components/script/dom/bluetoothremotegattservice.rs b/components/script/dom/bluetoothremotegattservice.rs
index df1718ef403..29e2625b818 100644
--- a/components/script/dom/bluetoothremotegattservice.rs
+++ b/components/script/dom/bluetoothremotegattservice.rs
@@ -61,9 +61,7 @@ impl BluetoothRemoteGATTService {
}
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
- let global_root = self.global();
- let global_ref = global_root.r();
- global_ref.as_window().bluetooth_thread()
+ self.global_scope().as_window().bluetooth_thread()
}
fn get_instance_id(&self) -> String {
diff --git a/components/script/dom/comment.rs b/components/script/dom/comment.rs
index 43115e1dd51..2eec7652e25 100644
--- a/components/script/dom/comment.rs
+++ b/components/script/dom/comment.rs
@@ -32,7 +32,7 @@ impl Comment {
}
pub fn Constructor(global: GlobalRef, data: DOMString) -> Fallible<Root<Comment>> {
- let document = global.as_window().Document();
+ let document = global.as_global_scope().as_window().Document();
Ok(Comment::new(data, document.r()))
}
}
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index da7b895a4f3..5a5507b0c20 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -1820,7 +1820,7 @@ impl Document {
// https://dom.spec.whatwg.org/#dom-document
pub fn Constructor(global: GlobalRef) -> Fallible<Root<Document>> {
- let win = global.as_window();
+ let win = global.as_global_scope().as_window();
let doc = win.Document();
let doc = doc.r();
let docloader = DocumentLoader::new(&*doc.loader());
diff --git a/components/script/dom/documentfragment.rs b/components/script/dom/documentfragment.rs
index 0fba19d5aff..bf05e36fce3 100644
--- a/components/script/dom/documentfragment.rs
+++ b/components/script/dom/documentfragment.rs
@@ -39,7 +39,7 @@ impl DocumentFragment {
}
pub fn Constructor(global: GlobalRef) -> Fallible<Root<DocumentFragment>> {
- let document = global.as_window().Document();
+ let document = global.as_global_scope().as_window().Document();
Ok(DocumentFragment::new(document.r()))
}
diff --git a/components/script/dom/domparser.rs b/components/script/dom/domparser.rs
index cf82cad01ca..6d830e40bfd 100644
--- a/components/script/dom/domparser.rs
+++ b/components/script/dom/domparser.rs
@@ -43,7 +43,7 @@ impl DOMParser {
}
pub fn Constructor(global: GlobalRef) -> Fallible<Root<DOMParser>> {
- Ok(DOMParser::new(global.as_window()))
+ Ok(DOMParser::new(global.as_global_scope().as_window()))
}
}
diff --git a/components/script/dom/focusevent.rs b/components/script/dom/focusevent.rs
index cb65d40088f..8d3f6b57256 100644
--- a/components/script/dom/focusevent.rs
+++ b/components/script/dom/focusevent.rs
@@ -59,7 +59,8 @@ impl FocusEvent {
init: &FocusEventBinding::FocusEventInit) -> Fallible<Root<FocusEvent>> {
let bubbles = EventBubbles::from(init.parent.parent.bubbles);
let cancelable = EventCancelable::from(init.parent.parent.cancelable);
- let event = FocusEvent::new(global.as_window(), type_,
+ let event = FocusEvent::new(global.as_global_scope().as_window(),
+ type_,
bubbles,
cancelable,
init.parent.view.r(),
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs
index 4828dfec696..33873f4668f 100644
--- a/components/script/dom/globalscope.rs
+++ b/components/script/dom/globalscope.rs
@@ -190,6 +190,11 @@ impl GlobalScope {
}
unreachable!();
}
+
+ /// Extract a `Window`, panic if the global object is not a `Window`.
+ pub fn as_window(&self) -> &Window {
+ self.downcast::<Window>().expect("expected a Window scope")
+ }
}
fn timestamp_in_ms(time: Timespec) -> u64 {
diff --git a/components/script/dom/htmlformcontrolscollection.rs b/components/script/dom/htmlformcontrolscollection.rs
index 2450b26c179..5edc19232d4 100644
--- a/components/script/dom/htmlformcontrolscollection.rs
+++ b/components/script/dom/htmlformcontrolscollection.rs
@@ -65,8 +65,7 @@ impl HTMLFormControlsCollectionMethods for HTMLFormControlsCollection {
// Step 4-5
let once = iter::once(Root::upcast::<Node>(elem));
let list = once.chain(peekable.map(Root::upcast));
- let global = self.global();
- let global = global.r();
+ let global = self.global_scope();
let window = global.as_window();
Some(RadioNodeListOrElement::RadioNodeList(RadioNodeList::new_simple_list(window, list)))
}
diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index c6652913c42..d96bb0cab3a 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -228,7 +228,7 @@ impl HTMLImageElement {
pub fn Image(global: GlobalRef,
width: Option<u32>,
height: Option<u32>) -> Fallible<Root<HTMLImageElement>> {
- let document = global.as_window().Document();
+ let document = global.as_global_scope().as_window().Document();
let image = HTMLImageElement::new(atom!("img"), None, document.r());
if let Some(w) = width {
image.SetWidth(w);
diff --git a/components/script/dom/keyboardevent.rs b/components/script/dom/keyboardevent.rs
index 06987f55b12..812b9f63051 100644
--- a/components/script/dom/keyboardevent.rs
+++ b/components/script/dom/keyboardevent.rs
@@ -104,7 +104,8 @@ impl KeyboardEvent {
pub fn Constructor(global: GlobalRef,
type_: DOMString,
init: &KeyboardEventBinding::KeyboardEventInit) -> Fallible<Root<KeyboardEvent>> {
- let event = KeyboardEvent::new(global.as_window(), type_,
+ let event = KeyboardEvent::new(global.as_global_scope().as_window(),
+ type_,
init.parent.parent.parent.bubbles,
init.parent.parent.parent.cancelable,
init.parent.parent.view.r(),
diff --git a/components/script/dom/mouseevent.rs b/components/script/dom/mouseevent.rs
index 096b119641f..41c7d88dc6d 100644
--- a/components/script/dom/mouseevent.rs
+++ b/components/script/dom/mouseevent.rs
@@ -87,7 +87,8 @@ impl MouseEvent {
init: &MouseEventBinding::MouseEventInit) -> Fallible<Root<MouseEvent>> {
let bubbles = EventBubbles::from(init.parent.parent.parent.bubbles);
let cancelable = EventCancelable::from(init.parent.parent.parent.cancelable);
- let event = MouseEvent::new(global.as_window(), type_,
+ let event = MouseEvent::new(global.as_global_scope().as_window(),
+ type_,
bubbles,
cancelable,
init.parent.parent.view.r(),
diff --git a/components/script/dom/range.rs b/components/script/dom/range.rs
index 80018b661f3..7e636164da5 100644
--- a/components/script/dom/range.rs
+++ b/components/script/dom/range.rs
@@ -71,7 +71,7 @@ impl Range {
// https://dom.spec.whatwg.org/#dom-range
pub fn Constructor(global: GlobalRef) -> Fallible<Root<Range>> {
- let document = global.as_window().Document();
+ let document = global.as_global_scope().as_window().Document();
Ok(Range::new_with_doc(document.r()))
}
diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs
index 2f0ff42125a..76b04f60d6f 100644
--- a/components/script/dom/storage.rs
+++ b/components/script/dom/storage.rs
@@ -44,9 +44,7 @@ impl Storage {
}
fn get_storage_thread(&self) -> IpcSender<StorageThreadMsg> {
- let global_root = self.global();
- let global_ref = global_root.r();
- global_ref.as_window().resource_threads().sender()
+ self.global_scope().as_window().resource_threads().sender()
}
}
@@ -154,7 +152,7 @@ impl Storage {
new_value: Option<String>) {
let global_root = self.global();
let global_ref = global_root.r();
- let window = global_ref.as_window();
+ let window = global_ref.as_global_scope().as_window();
let task_source = window.dom_manipulation_task_source();
let trusted_storage = Trusted::new(self);
task_source.queue(box StorageEventRunnable::new(trusted_storage, key, old_value, new_value),
diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs
index fdb20fc5114..eb3defbe6a5 100644
--- a/components/script/dom/testbinding.rs
+++ b/components/script/dom/testbinding.rs
@@ -750,7 +750,7 @@ impl TestBindingMethods for TestBinding {
}
fn AdvanceClock(&self, ms: i32, tick: bool) {
- self.global().r().as_window().advance_animation_clock(ms, tick);
+ self.global_scope().as_window().advance_animation_clock(ms, tick);
}
fn Panic(&self) { panic!("explicit panic from script") }
diff --git a/components/script/dom/text.rs b/components/script/dom/text.rs
index 5d377e1e05d..fec47d6fc84 100644
--- a/components/script/dom/text.rs
+++ b/components/script/dom/text.rs
@@ -36,7 +36,7 @@ impl Text {
}
pub fn Constructor(global: GlobalRef, text: DOMString) -> Fallible<Root<Text>> {
- let document = global.as_window().Document();
+ let document = global.as_global_scope().as_window().Document();
Ok(Text::new(text, document.r()))
}
}
diff --git a/components/script/dom/uievent.rs b/components/script/dom/uievent.rs
index 0b64e36c62f..698645f5a6c 100644
--- a/components/script/dom/uievent.rs
+++ b/components/script/dom/uievent.rs
@@ -57,7 +57,8 @@ impl UIEvent {
init: &UIEventBinding::UIEventInit) -> Fallible<Root<UIEvent>> {
let bubbles = EventBubbles::from(init.parent.bubbles);
let cancelable = EventCancelable::from(init.parent.cancelable);
- let event = UIEvent::new(global.as_window(), type_,
+ let event = UIEvent::new(global.as_global_scope().as_window(),
+ type_,
bubbles, cancelable,
init.view.r(), init.detail);
Ok(event)
diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs
index 84c7c903c7a..c08ea52dae8 100644
--- a/components/script/dom/xmlhttprequest.rs
+++ b/components/script/dom/xmlhttprequest.rs
@@ -1224,7 +1224,7 @@ impl XMLHttpRequest {
fn new_doc(&self, is_html_document: IsHTMLDocument) -> Root<Document> {
let wr = self.global();
let wr = wr.r();
- let win = wr.as_window();
+ let win = wr.as_global_scope().as_window();
let doc = win.Document();
let doc = doc.r();
let docloader = DocumentLoader::new(&*doc.loader());