servo: Merge #14376 - Make WebIDL static items take a more specific global if possible (from nox:specialized-constructors); r=KiChjang,nox
authorAnthony Ramine <n.oxyde@gmail.com>
Wed, 30 Nov 2016 15:43:48 -0800
changeset 340252 0ae4b2ee67725363cbb790f08ed36263e0f8edd0
parent 340251 7ec63d91ff9e4fa8d56b2eb03344fe7dd647d084
child 340253 ed2f49cd71538c8922d83008cfd17e9f3028688b
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersKiChjang, nox
servo: Merge #14376 - Make WebIDL static items take a more specific global if possible (from nox:specialized-constructors); r=KiChjang,nox Source-Repo: https://github.com/servo/servo Source-Revision: e315da07319c115bd85f7da1baa1cf0577a1980b
servo/components/script/dom/bindings/codegen/CodegenRust.py
servo/components/script/dom/bluetoothuuid.rs
servo/components/script/dom/comment.rs
servo/components/script/dom/css.rs
servo/components/script/dom/document.rs
servo/components/script/dom/documentfragment.rs
servo/components/script/dom/domparser.rs
servo/components/script/dom/extendableevent.rs
servo/components/script/dom/extendablemessageevent.rs
servo/components/script/dom/focusevent.rs
servo/components/script/dom/htmlcanvaselement.rs
servo/components/script/dom/htmlimageelement.rs
servo/components/script/dom/keyboardevent.rs
servo/components/script/dom/mouseevent.rs
servo/components/script/dom/range.rs
servo/components/script/dom/serviceworkerglobalscope.rs
servo/components/script/dom/text.rs
servo/components/script/dom/transitionevent.rs
servo/components/script/dom/uievent.rs
servo/components/script/dom/webglactiveinfo.rs
servo/components/script/dom/webglbuffer.rs
servo/components/script/dom/webglcontextevent.rs
servo/components/script/dom/webglframebuffer.rs
servo/components/script/dom/webglobject.rs
servo/components/script/dom/webglprogram.rs
servo/components/script/dom/webglrenderbuffer.rs
servo/components/script/dom/webglrenderingcontext.rs
servo/components/script/dom/webglshader.rs
servo/components/script/dom/webglshaderprecisionformat.rs
servo/components/script/dom/webgltexture.rs
servo/components/script/dom/webgluniformlocation.rs
servo/components/script/dom/webidls/DOMMatrix.webidl
servo/components/script/dom/webidls/DOMMatrixReadOnly.webidl
servo/components/script/dom/webidls/WebGLActiveInfo.webidl
servo/components/script/dom/webidls/WebGLBuffer.webidl
servo/components/script/dom/webidls/WebGLContextEvent.webidl
servo/components/script/dom/webidls/WebGLFramebuffer.webidl
servo/components/script/dom/webidls/WebGLObject.webidl
servo/components/script/dom/webidls/WebGLProgram.webidl
servo/components/script/dom/webidls/WebGLRenderbuffer.webidl
servo/components/script/dom/webidls/WebGLRenderingContext.webidl
servo/components/script/dom/webidls/WebGLShader.webidl
servo/components/script/dom/webidls/WebGLShaderPrecisionFormat.webidl
servo/components/script/dom/webidls/WebGLTexture.webidl
servo/components/script/dom/webidls/WebGLUniformLocation.webidl
--- a/servo/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/servo/components/script/dom/bindings/codegen/CodegenRust.py
@@ -3163,17 +3163,17 @@ class CGCallGenerator(CGThing):
             result,
             CGGeneric(" = "),
             call,
             CGGeneric(";"),
         ]))
 
         if isFallible:
             if static:
-                glob = "&global"
+                glob = "global.upcast::<GlobalScope>()"
             else:
                 glob = "&this.global()"
 
             self.cgRoot.append(CGGeneric(
                 "let result = match result {\n"
                 "    Ok(result) => result,\n"
                 "    Err(e) => {\n"
                 "        throw_dom_exception(cx, %s, e);\n"
@@ -3373,22 +3373,23 @@ class CGAbstractStaticBindingMethod(CGAb
     """
     def __init__(self, descriptor, name):
         args = [
             Argument('*mut JSContext', 'cx'),
             Argument('libc::c_uint', 'argc'),
             Argument('*mut JSVal', 'vp'),
         ]
         CGAbstractMethod.__init__(self, descriptor, name, "bool", args, extern=True)
+        self.exposureSet = descriptor.interface.exposureSet
 
     def definition_body(self):
-        preamble = CGGeneric("""\
-let global = GlobalScope::from_object(JS_CALLEE(cx, vp).to_object());
-""")
-        return CGList([preamble, self.generate_code()])
+        preamble = "let global = GlobalScope::from_object(JS_CALLEE(cx, vp).to_object());\n"
+        if len(self.exposureSet) == 1:
+            preamble += "let global = Root::downcast::<dom::types::%s>(global).unwrap();\n" % list(self.exposureSet)[0]
+        return CGList([CGGeneric(preamble), self.generate_code()])
 
     def generate_code(self):
         raise NotImplementedError  # Override me!
 
 
 class CGSpecializedMethod(CGAbstractExternMethod):
     """
     A class for generating the C++ code for a specialized method that the JIT
@@ -5240,22 +5241,24 @@ class CGClassConstructHook(CGAbstractExt
         name = CONSTRUCT_HOOK_NAME
         if constructor:
             name += "_" + constructor.identifier.name
         else:
             constructor = descriptor.interface.ctor()
             assert constructor
         CGAbstractExternMethod.__init__(self, descriptor, name, 'bool', args)
         self.constructor = constructor
+        self.exposureSet = descriptor.interface.exposureSet
 
     def definition_body(self):
-        preamble = CGGeneric("""\
-let global = GlobalScope::from_object(JS_CALLEE(cx, vp).to_object());
-let args = CallArgs::from_vp(vp, argc);
-""")
+        preamble = """let global = GlobalScope::from_object(JS_CALLEE(cx, vp).to_object());\n"""
+        if len(self.exposureSet) == 1:
+            preamble += "let global = Root::downcast::<dom::types::%s>(global).unwrap();\n" % list(self.exposureSet)[0]
+        preamble += """let args = CallArgs::from_vp(vp, argc);\n"""
+        preamble = CGGeneric(preamble)
         name = self.constructor.identifier.name
         nativeName = MakeNativeName(self.descriptor.binaryNameFor(name))
         callGenerator = CGMethodCall(["&global"], nativeName, True,
                                      self.descriptor, self.constructor)
         return CGList([preamble, callGenerator])
 
 
 class CGClassFinalizeHook(CGAbstractClassHook):
@@ -5577,16 +5580,17 @@ def generate_imports(config, cgthings, d
         'dom::bindings::codegen::UnionTypes',
         'dom::bindings::error::Error',
         'dom::bindings::error::ErrorResult',
         'dom::bindings::error::Fallible',
         'dom::bindings::error::Error::JSFailed',
         'dom::bindings::error::throw_dom_exception',
         'dom::bindings::guard::Condition',
         'dom::bindings::guard::Guard',
+        'dom::bindings::inheritance::Castable',
         'dom::bindings::proxyhandler',
         'dom::bindings::proxyhandler::ensure_expando_object',
         'dom::bindings::proxyhandler::fill_property_descriptor',
         'dom::bindings::proxyhandler::get_expando_object',
         'dom::bindings::proxyhandler::get_property_descriptor',
         'dom::bindings::mozmap::MozMap',
         'dom::bindings::num::Finite',
         'dom::bindings::str::ByteString',
--- a/servo/components/script/dom/bluetoothuuid.rs
+++ b/servo/components/script/dom/bluetoothuuid.rs
@@ -2,17 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong;
 use dom::bindings::error::Error::Syntax;
 use dom::bindings::error::Fallible;
 use dom::bindings::reflector::Reflector;
 use dom::bindings::str::DOMString;
-use dom::globalscope::GlobalScope;
+use dom::window::Window;
 use regex::Regex;
 
 pub type UUID = DOMString;
 pub type BluetoothServiceUUID = StringOrUnsignedLong;
 pub type BluetoothCharacteristicUUID = StringOrUnsignedLong;
 pub type BluetoothDescriptorUUID = StringOrUnsignedLong;
 
 // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothuuid
@@ -266,32 +266,32 @@ const BLUETOOTH_ASSIGNED_DESCRIPTORS: &'
 const BASE_UUID: &'static str = "-0000-1000-8000-00805f9b34fb";
 const SERVICE_PREFIX: &'static str = "org.bluetooth.service";
 const CHARACTERISTIC_PREFIX: &'static str = "org.bluetooth.characteristic";
 const DESCRIPTOR_PREFIX: &'static str = "org.bluetooth.descriptor";
 const VALID_UUID_REGEX: &'static str = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
 
 impl BluetoothUUID {
     // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothuuid-canonicaluuid
-    pub fn CanonicalUUID(_: &GlobalScope, alias: u32) -> UUID {
+    pub fn CanonicalUUID(_: &Window, alias: u32) -> UUID {
         canonical_uuid(alias)
     }
 
     // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothuuid-getservice
-    pub fn GetService(_: &GlobalScope, name: BluetoothServiceUUID) -> Fallible<UUID> {
+    pub fn GetService(_: &Window, name: BluetoothServiceUUID) -> Fallible<UUID> {
         Self::service(name)
     }
 
     // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothuuid-getcharacteristic
-    pub fn GetCharacteristic(_: &GlobalScope, name: BluetoothCharacteristicUUID) -> Fallible<UUID> {
+    pub fn GetCharacteristic(_: &Window, name: BluetoothCharacteristicUUID) -> Fallible<UUID> {
         Self::characteristic(name)
     }
 
     // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothuuid-getdescriptor
-    pub fn GetDescriptor(_: &GlobalScope, name: BluetoothDescriptorUUID) -> Fallible<UUID> {
+    pub fn GetDescriptor(_: &Window, name: BluetoothDescriptorUUID) -> Fallible<UUID> {
         Self::descriptor(name)
     }
 }
 
 impl BluetoothUUID {
     pub fn service(name: BluetoothServiceUUID) -> Fallible<UUID> {
         resolve_uuid_name(name, BLUETOOTH_ASSIGNED_SERVICES, SERVICE_PREFIX)
     }
--- a/servo/components/script/dom/comment.rs
+++ b/servo/components/script/dom/comment.rs
@@ -4,18 +4,18 @@
 
 use dom::bindings::codegen::Bindings::CommentBinding;
 use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
 use dom::bindings::error::Fallible;
 use dom::bindings::js::Root;
 use dom::bindings::str::DOMString;
 use dom::characterdata::CharacterData;
 use dom::document::Document;
-use dom::globalscope::GlobalScope;
 use dom::node::Node;
+use dom::window::Window;
 
 /// An HTML comment.
 #[dom_struct]
 pub struct Comment {
     characterdata: CharacterData,
 }
 
 impl Comment {
@@ -26,13 +26,13 @@ impl Comment {
     }
 
     pub fn new(text: DOMString, document: &Document) -> Root<Comment> {
         Node::reflect_node(box Comment::new_inherited(text, document),
                            document,
                            CommentBinding::Wrap)
     }
 
-    pub fn Constructor(global: &GlobalScope, data: DOMString) -> Fallible<Root<Comment>> {
-        let document = global.as_window().Document();
+    pub fn Constructor(window: &Window, data: DOMString) -> Fallible<Root<Comment>> {
+        let document = window.Document();
         Ok(Comment::new(data, &document))
     }
 }
--- a/servo/components/script/dom/css.rs
+++ b/servo/components/script/dom/css.rs
@@ -1,23 +1,23 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use cssparser::serialize_identifier;
 use dom::bindings::error::Fallible;
 use dom::bindings::reflector::Reflector;
 use dom::bindings::str::DOMString;
-use dom::globalscope::GlobalScope;
+use dom::window::Window;
 
 #[dom_struct]
 pub struct CSS {
     reflector_: Reflector,
 }
 
 impl CSS {
     // http://dev.w3.org/csswg/cssom/#serialize-an-identifier
-    pub fn Escape(_: &GlobalScope, ident: DOMString) -> Fallible<DOMString> {
+    pub fn Escape(_: &Window, ident: DOMString) -> Fallible<DOMString> {
         let mut escaped = String::new();
         serialize_identifier(&ident, &mut escaped).unwrap();
         Ok(DOMString::from(escaped))
     }
 }
--- a/servo/components/script/dom/document.rs
+++ b/servo/components/script/dom/document.rs
@@ -1879,21 +1879,20 @@ impl Document {
             referrer_policy: Cell::new(referrer_policy),
             target_element: MutNullableHeap::new(None),
             last_click_info: DOMRefCell::new(None),
             ignore_destructive_writes_counter: Default::default(),
         }
     }
 
     // https://dom.spec.whatwg.org/#dom-document
-    pub fn Constructor(global: &GlobalScope) -> Fallible<Root<Document>> {
-        let win = global.as_window();
-        let doc = win.Document();
+    pub fn Constructor(window: &Window) -> Fallible<Root<Document>> {
+        let doc = window.Document();
         let docloader = DocumentLoader::new(&*doc.loader());
-        Ok(Document::new(win,
+        Ok(Document::new(window,
                          None,
                          None,
                          IsHTMLDocument::NonHTMLDocument,
                          None,
                          None,
                          DocumentSource::NotFromParser,
                          docloader,
                          None,
@@ -2421,17 +2420,17 @@ impl DocumentMethods for Document {
                 Ok(Root::upcast(
                     TouchEvent::new_uninitialized(&self.window,
                         &TouchList::new(&self.window, &[]),
                         &TouchList::new(&self.window, &[]),
                         &TouchList::new(&self.window, &[]),
                     )
                 )),
             "webglcontextevent" =>
-                Ok(Root::upcast(WebGLContextEvent::new_uninitialized(self.window.upcast()))),
+                Ok(Root::upcast(WebGLContextEvent::new_uninitialized(&self.window))),
             "storageevent" => {
                 let USVString(url) = self.URL();
                 Ok(Root::upcast(StorageEvent::new_uninitialized(&self.window, DOMString::from(url))))
             },
             "progressevent" =>
                 Ok(Root::upcast(ProgressEvent::new_uninitialized(self.window.upcast()))),
             "focusevent" =>
                 Ok(Root::upcast(FocusEvent::new_uninitialized(self.window.upcast()))),
--- a/servo/components/script/dom/documentfragment.rs
+++ b/servo/components/script/dom/documentfragment.rs
@@ -7,20 +7,20 @@ use dom::bindings::codegen::Bindings::Do
 use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
 use dom::bindings::codegen::UnionTypes::NodeOrString;
 use dom::bindings::error::{ErrorResult, Fallible};
 use dom::bindings::inheritance::Castable;
 use dom::bindings::js::Root;
 use dom::bindings::str::DOMString;
 use dom::document::Document;
 use dom::element::Element;
-use dom::globalscope::GlobalScope;
 use dom::htmlcollection::HTMLCollection;
 use dom::node::{Node, window_from_node};
 use dom::nodelist::NodeList;
+use dom::window::Window;
 use servo_atoms::Atom;
 
 // https://dom.spec.whatwg.org/#documentfragment
 #[dom_struct]
 pub struct DocumentFragment {
     node: Node,
 }
 
@@ -33,18 +33,18 @@ impl DocumentFragment {
     }
 
     pub fn new(document: &Document) -> Root<DocumentFragment> {
         Node::reflect_node(box DocumentFragment::new_inherited(document),
                            document,
                            DocumentFragmentBinding::Wrap)
     }
 
-    pub fn Constructor(global: &GlobalScope) -> Fallible<Root<DocumentFragment>> {
-        let document = global.as_window().Document();
+    pub fn Constructor(window: &Window) -> Fallible<Root<DocumentFragment>> {
+        let document = window.Document();
 
         Ok(DocumentFragment::new(&document))
     }
 }
 
 impl DocumentFragmentMethods for DocumentFragment {
     // https://dom.spec.whatwg.org/#dom-parentnode-children
     fn Children(&self) -> Root<HTMLCollection> {
--- a/servo/components/script/dom/domparser.rs
+++ b/servo/components/script/dom/domparser.rs
@@ -12,17 +12,16 @@ use dom::bindings::codegen::Bindings::DO
 use dom::bindings::codegen::Bindings::DocumentBinding::DocumentReadyState;
 use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
 use dom::bindings::error::Fallible;
 use dom::bindings::js::{JS, Root};
 use dom::bindings::reflector::{Reflector, reflect_dom_object};
 use dom::bindings::str::DOMString;
 use dom::document::{Document, IsHTMLDocument};
 use dom::document::DocumentSource;
-use dom::globalscope::GlobalScope;
 use dom::servoparser::ServoParser;
 use dom::window::Window;
 
 #[dom_struct]
 pub struct DOMParser {
     reflector_: Reflector,
     window: JS<Window>, // XXXjdm Document instead?
 }
@@ -36,18 +35,18 @@ impl DOMParser {
     }
 
     pub fn new(window: &Window) -> Root<DOMParser> {
         reflect_dom_object(box DOMParser::new_inherited(window),
                            window,
                            DOMParserBinding::Wrap)
     }
 
-    pub fn Constructor(global: &GlobalScope) -> Fallible<Root<DOMParser>> {
-        Ok(DOMParser::new(global.as_window()))
+    pub fn Constructor(window: &Window) -> Fallible<Root<DOMParser>> {
+        Ok(DOMParser::new(window))
     }
 }
 
 impl DOMParserMethods for DOMParser {
     // https://domparsing.spec.whatwg.org/#the-domparser-interface
     fn ParseFromString(&self,
                        s: DOMString,
                        ty: DOMParserBinding::SupportedType)
--- a/servo/components/script/dom/extendableevent.rs
+++ b/servo/components/script/dom/extendableevent.rs
@@ -5,17 +5,17 @@
 use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
 use dom::bindings::codegen::Bindings::ExtendableEventBinding;
 use dom::bindings::error::{Error, ErrorResult, Fallible};
 use dom::bindings::inheritance::Castable;
 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::serviceworkerglobalscope::ServiceWorkerGlobalScope;
 use js::jsapi::{HandleValue, JSContext};
 use servo_atoms::Atom;
 
 // https://w3c.github.io/ServiceWorker/#extendable-event
 #[dom_struct]
 pub struct ExtendableEvent {
     event: Event,
     extensions_allowed: bool
@@ -23,33 +23,33 @@ pub struct ExtendableEvent {
 
 impl ExtendableEvent {
     pub fn new_inherited() -> ExtendableEvent {
         ExtendableEvent {
             event: Event::new_inherited(),
             extensions_allowed: true
         }
     }
-    pub fn new(global: &GlobalScope,
+    pub fn new(worker: &ServiceWorkerGlobalScope,
                type_: Atom,
                bubbles: bool,
                cancelable: bool)
                -> Root<ExtendableEvent> {
-        let ev = reflect_dom_object(box ExtendableEvent::new_inherited(), global, ExtendableEventBinding::Wrap);
+        let ev = reflect_dom_object(box ExtendableEvent::new_inherited(), worker, ExtendableEventBinding::Wrap);
         {
             let event = ev.upcast::<Event>();
             event.init_event(type_, bubbles, cancelable);
         }
         ev
     }
 
-    pub fn Constructor(global: &GlobalScope,
+    pub fn Constructor(worker: &ServiceWorkerGlobalScope,
                        type_: DOMString,
                        init: &ExtendableEventBinding::ExtendableEventInit) -> Fallible<Root<ExtendableEvent>> {
-        Ok(ExtendableEvent::new(global,
+        Ok(ExtendableEvent::new(worker,
                                 Atom::from(type_),
                                 init.parent.bubbles,
                                 init.parent.cancelable))
     }
 
     // https://w3c.github.io/ServiceWorker/#wait-until-method
     pub fn WaitUntil(&self, _cx: *mut JSContext, _val: HandleValue) -> ErrorResult {
         // Step 1
--- a/servo/components/script/dom/extendablemessageevent.rs
+++ b/servo/components/script/dom/extendablemessageevent.rs
@@ -8,16 +8,17 @@ use dom::bindings::error::Fallible;
 use dom::bindings::inheritance::Castable;
 use dom::bindings::js::Root;
 use dom::bindings::reflector::reflect_dom_object;
 use dom::bindings::str::DOMString;
 use dom::event::Event;
 use dom::eventtarget::EventTarget;
 use dom::extendableevent::ExtendableEvent;
 use dom::globalscope::GlobalScope;
+use dom::serviceworkerglobalscope::ServiceWorkerGlobalScope;
 use js::jsapi::{HandleValue, Heap, JSContext};
 use js::jsval::JSVal;
 use servo_atoms::Atom;
 use std::default::Default;
 
 #[dom_struct]
 pub struct ExtendableMessageEvent {
     event: ExtendableEvent,
@@ -41,20 +42,21 @@ impl ExtendableMessageEvent {
         let ev = reflect_dom_object(ev, global, ExtendableMessageEventBinding::Wrap);
         {
             let event = ev.upcast::<Event>();
             event.init_event(type_, bubbles, cancelable);
         }
         ev
     }
 
-    pub fn Constructor(global: &GlobalScope,
+    pub fn Constructor(worker: &ServiceWorkerGlobalScope,
                        type_: DOMString,
                        init: &ExtendableMessageEventBinding::ExtendableMessageEventInit)
                        -> Fallible<Root<ExtendableMessageEvent>> {
+        let global = worker.upcast::<GlobalScope>();
         rooted!(in(global.get_cx()) let data = init.data);
         let ev = ExtendableMessageEvent::new(global,
                                              Atom::from(type_),
                                              init.parent.parent.bubbles,
                                              init.parent.parent.cancelable,
                                              data.handle(),
                                              init.origin.clone().unwrap(),
                                              init.lastEventId.clone().unwrap());
--- a/servo/components/script/dom/focusevent.rs
+++ b/servo/components/script/dom/focusevent.rs
@@ -48,22 +48,22 @@ impl FocusEvent {
         ev.upcast::<UIEvent>().InitUIEvent(type_,
                                            bool::from(can_bubble),
                                            bool::from(cancelable),
                                            view, detail);
         ev.related_target.set(related_target);
         ev
     }
 
-    pub fn Constructor(global: &GlobalScope,
+    pub fn Constructor(window: &Window,
                        type_: DOMString,
                        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(),
+        let event = FocusEvent::new(window,
                                     type_,
                                     bubbles,
                                     cancelable,
                                     init.parent.view.r(),
                                     init.parent.detail,
                                     init.relatedTarget.r());
         Ok(event)
     }
--- a/servo/components/script/dom/htmlcanvaselement.rs
+++ b/servo/components/script/dom/htmlcanvaselement.rs
@@ -172,17 +172,17 @@ impl HTMLCanvasElement {
                         debug!("Unexpected error on conversion of WebGLContextAttributes");
                         return None;
                     }
                 }
             } else {
                 GLContextAttributes::default()
             };
 
-            let maybe_ctx = WebGLRenderingContext::new(window.upcast(), self, size, attrs);
+            let maybe_ctx = WebGLRenderingContext::new(&window, self, size, attrs);
 
             *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_ref(&*ctx)));
         }
 
         if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() {
             Some(Root::from_ref(&*context))
         } else {
             None
--- a/servo/components/script/dom/htmlimageelement.rs
+++ b/servo/components/script/dom/htmlimageelement.rs
@@ -11,21 +11,21 @@ use dom::bindings::codegen::Bindings::Wi
 use dom::bindings::error::Fallible;
 use dom::bindings::inheritance::Castable;
 use dom::bindings::js::{LayoutJS, Root};
 use dom::bindings::refcounted::Trusted;
 use dom::bindings::str::DOMString;
 use dom::document::Document;
 use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
 use dom::eventtarget::EventTarget;
-use dom::globalscope::GlobalScope;
 use dom::htmlelement::HTMLElement;
 use dom::node::{Node, NodeDamage, document_from_node, window_from_node};
 use dom::values::UNSIGNED_LONG_MAX;
 use dom::virtualmethods::VirtualMethods;
+use dom::window::Window;
 use html5ever_atoms::LocalName;
 use ipc_channel::ipc;
 use ipc_channel::router::ROUTER;
 use net_traits::image::base::{Image, ImageMetadata};
 use net_traits::image_cache_thread::{ImageResponder, ImageResponse};
 use script_thread::Runnable;
 use servo_url::ServoUrl;
 use std::i32;
@@ -215,20 +215,20 @@ impl HTMLImageElement {
     pub fn new(local_name: LocalName,
                prefix: Option<DOMString>,
                document: &Document) -> Root<HTMLImageElement> {
         Node::reflect_node(box HTMLImageElement::new_inherited(local_name, prefix, document),
                            document,
                            HTMLImageElementBinding::Wrap)
     }
 
-    pub fn Image(global: &GlobalScope,
+    pub fn Image(window: &Window,
                  width: Option<u32>,
                  height: Option<u32>) -> Fallible<Root<HTMLImageElement>> {
-        let document = global.as_window().Document();
+        let document = window.Document();
         let image = HTMLImageElement::new(local_name!("img"), None, &document);
         if let Some(w) = width {
             image.SetWidth(w);
         }
         if let Some(h) = height {
             image.SetHeight(h);
         }
 
--- a/servo/components/script/dom/keyboardevent.rs
+++ b/servo/components/script/dom/keyboardevent.rs
@@ -7,17 +7,16 @@ use dom::bindings::codegen::Bindings::Ke
 use dom::bindings::codegen::Bindings::KeyboardEventBinding::{KeyboardEventConstants, KeyboardEventMethods};
 use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods;
 use dom::bindings::error::Fallible;
 use dom::bindings::inheritance::Castable;
 use dom::bindings::js::{Root, RootedReference};
 use dom::bindings::reflector::reflect_dom_object;
 use dom::bindings::str::DOMString;
 use dom::event::Event;
-use dom::globalscope::GlobalScope;
 use dom::uievent::UIEvent;
 use dom::window::Window;
 use msg::constellation_msg;
 use msg::constellation_msg::{Key, KeyModifiers};
 use std::borrow::Cow;
 use std::cell::Cell;
 
 no_jsmanaged_fields!(Key);
@@ -96,20 +95,20 @@ impl KeyboardEvent {
         ev.meta.set(meta_key);
         ev.char_code.set(char_code);
         ev.printable.set(ch);
         ev.key_code.set(key_code);
         ev.is_composing.set(is_composing);
         ev
     }
 
-    pub fn Constructor(global: &GlobalScope,
+    pub fn Constructor(window: &Window,
                        type_: DOMString,
                        init: &KeyboardEventBinding::KeyboardEventInit) -> Fallible<Root<KeyboardEvent>> {
-        let event = KeyboardEvent::new(global.as_window(),
+        let event = KeyboardEvent::new(window,
                                        type_,
                                        init.parent.parent.parent.bubbles,
                                        init.parent.parent.parent.cancelable,
                                        init.parent.parent.view.r(),
                                        init.parent.parent.detail,
                                        None,
                                        key_from_string(&init.key, init.location),
                                        init.key.clone(), init.code.clone(), init.location,
--- a/servo/components/script/dom/mouseevent.rs
+++ b/servo/components/script/dom/mouseevent.rs
@@ -7,17 +7,16 @@ use dom::bindings::codegen::Bindings::Mo
 use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods;
 use dom::bindings::error::Fallible;
 use dom::bindings::inheritance::Castable;
 use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference};
 use dom::bindings::reflector::reflect_dom_object;
 use dom::bindings::str::DOMString;
 use dom::event::{Event, EventBubbles, EventCancelable};
 use dom::eventtarget::EventTarget;
-use dom::globalscope::GlobalScope;
 use dom::uievent::UIEvent;
 use dom::window::Window;
 use std::cell::Cell;
 use std::default::Default;
 use util::prefs::PREFS;
 
 #[dom_struct]
 pub struct MouseEvent {
@@ -77,22 +76,22 @@ impl MouseEvent {
         ev.InitMouseEvent(type_, bool::from(can_bubble), bool::from(cancelable),
                           view, detail,
                           screen_x, screen_y, client_x, client_y,
                           ctrl_key, alt_key, shift_key, meta_key,
                           button, related_target);
         ev
     }
 
-    pub fn Constructor(global: &GlobalScope,
+    pub fn Constructor(window: &Window,
                        type_: DOMString,
                        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(),
+        let event = MouseEvent::new(window,
                                     type_,
                                     bubbles,
                                     cancelable,
                                     init.parent.parent.view.r(),
                                     init.parent.parent.detail,
                                     init.screenX, init.screenY,
                                     init.clientX, init.clientY, init.parent.ctrlKey,
                                     init.parent.altKey, init.parent.shiftKey, init.parent.metaKey,
--- a/servo/components/script/dom/range.rs
+++ b/servo/components/script/dom/range.rs
@@ -17,21 +17,21 @@ use dom::bindings::js::{JS, MutHeap, Roo
 use dom::bindings::reflector::{Reflector, reflect_dom_object};
 use dom::bindings::str::DOMString;
 use dom::bindings::trace::JSTraceable;
 use dom::bindings::weakref::{WeakRef, WeakRefVec};
 use dom::characterdata::CharacterData;
 use dom::document::Document;
 use dom::documentfragment::DocumentFragment;
 use dom::element::Element;
-use dom::globalscope::GlobalScope;
 use dom::htmlbodyelement::HTMLBodyElement;
 use dom::htmlscriptelement::HTMLScriptElement;
 use dom::node::{Node, UnbindContext};
 use dom::text::Text;
+use dom::window::Window;
 use heapsize::HeapSizeOf;
 use js::jsapi::JSTracer;
 use std::cell::{Cell, UnsafeCell};
 use std::cmp::{Ord, Ordering, PartialEq, PartialOrd};
 
 #[dom_struct]
 pub struct Range {
     reflector_: Reflector,
@@ -65,18 +65,18 @@ impl Range {
         start_container.ranges().push(WeakRef::new(&range));
         if start_container != end_container {
             end_container.ranges().push(WeakRef::new(&range));
         }
         range
     }
 
     // https://dom.spec.whatwg.org/#dom-range
-    pub fn Constructor(global: &GlobalScope) -> Fallible<Root<Range>> {
-        let document = global.as_window().Document();
+    pub fn Constructor(window: &Window) -> Fallible<Root<Range>> {
+        let document = window.Document();
         Ok(Range::new_with_doc(&document))
     }
 
     // https://dom.spec.whatwg.org/#contained
     fn contains(&self, node: &Node) -> bool {
         match (bp_position(node, 0, &self.StartContainer(), self.StartOffset()),
                bp_position(node, node.len(), &self.EndContainer(), self.EndOffset())) {
             (Some(Ordering::Greater), Some(Ordering::Less)) => true,
--- a/servo/components/script/dom/serviceworkerglobalscope.rs
+++ b/servo/components/script/dom/serviceworkerglobalscope.rs
@@ -314,17 +314,17 @@ impl ServiceWorkerGlobalScope {
 
     pub fn script_chan(&self) -> Box<ScriptChan + Send> {
         box ServiceWorkerChan {
             sender: self.own_sender.clone()
         }
     }
 
     fn dispatch_activate(&self) {
-        let event = ExtendableEvent::new(self.upcast(), atom!("activate"), false, false);
+        let event = ExtendableEvent::new(self, atom!("activate"), false, false);
         let event = (&*event).upcast::<Event>();
         self.upcast::<EventTarget>().dispatch_event(event);
     }
 }
 
 #[allow(unsafe_code)]
 unsafe extern "C" fn interrupt_callback(cx: *mut JSContext) -> bool {
     let worker =
--- a/servo/components/script/dom/text.rs
+++ b/servo/components/script/dom/text.rs
@@ -9,18 +9,18 @@ use dom::bindings::codegen::Bindings::Te
 use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
 use dom::bindings::error::{Error, Fallible};
 use dom::bindings::inheritance::Castable;
 use dom::bindings::js::Root;
 use dom::bindings::js::RootedReference;
 use dom::bindings::str::DOMString;
 use dom::characterdata::CharacterData;
 use dom::document::Document;
-use dom::globalscope::GlobalScope;
 use dom::node::Node;
+use dom::window::Window;
 
 /// An HTML text node.
 #[dom_struct]
 pub struct Text {
     characterdata: CharacterData,
 }
 
 impl Text {
@@ -30,18 +30,18 @@ impl Text {
         }
     }
 
     pub fn new(text: DOMString, document: &Document) -> Root<Text> {
         Node::reflect_node(box Text::new_inherited(text, document),
                            document, TextBinding::Wrap)
     }
 
-    pub fn Constructor(global: &GlobalScope, text: DOMString) -> Fallible<Root<Text>> {
-        let document = global.as_window().Document();
+    pub fn Constructor(window: &Window, text: DOMString) -> Fallible<Root<Text>> {
+        let document = window.Document();
         Ok(Text::new(text, &document))
     }
 }
 
 impl TextMethods for Text {
     // https://dom.spec.whatwg.org/#dom-text-splittextoffset
     fn SplitText(&self, offset: u32) -> Fallible<Root<Text>> {
         let cdata = self.upcast::<CharacterData>();
--- a/servo/components/script/dom/transitionevent.rs
+++ b/servo/components/script/dom/transitionevent.rs
@@ -8,16 +8,17 @@ use dom::bindings::codegen::Bindings::Tr
 use dom::bindings::error::Fallible;
 use dom::bindings::inheritance::Castable;
 use dom::bindings::js::Root;
 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;
 
 #[dom_struct]
 pub struct TransitionEvent {
     event: Event,
     property_name: Atom,
     elapsed_time: Finite<f32>,
     pseudo_element: DOMString,
@@ -41,19 +42,20 @@ impl TransitionEvent {
                                     TransitionEventBinding::Wrap);
         {
             let event = ev.upcast::<Event>();
             event.init_event(type_, init.parent.bubbles, init.parent.cancelable);
         }
         ev
     }
 
-    pub fn Constructor(global: &GlobalScope,
+    pub fn Constructor(window: &Window,
                        type_: DOMString,
                        init: &TransitionEventInit) -> Fallible<Root<TransitionEvent>> {
+        let global = window.upcast::<GlobalScope>();
         Ok(TransitionEvent::new(global, Atom::from(type_), init))
     }
 }
 
 impl TransitionEventMethods for TransitionEvent {
     // https://drafts.csswg.org/css-transitions/#Events-TransitionEvent-propertyName
     fn PropertyName(&self) -> DOMString {
         DOMString::from(&*self.property_name)
--- a/servo/components/script/dom/uievent.rs
+++ b/servo/components/script/dom/uievent.rs
@@ -7,17 +7,16 @@ use dom::bindings::codegen::Bindings::UI
 use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods;
 use dom::bindings::error::Fallible;
 use dom::bindings::inheritance::Castable;
 use dom::bindings::js::{JS, MutNullableHeap, RootedReference};
 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;
 use std::cell::Cell;
 use std::default::Default;
 
 // https://w3c.github.io/uievents/#interface-uievent
 #[dom_struct]
 pub struct UIEvent {
@@ -47,22 +46,22 @@ impl UIEvent {
                cancelable: EventCancelable,
                view: Option<&Window>,
                detail: i32) -> Root<UIEvent> {
         let ev = UIEvent::new_uninitialized(window);
         ev.InitUIEvent(type_, bool::from(can_bubble), bool::from(cancelable), view, detail);
         ev
     }
 
-    pub fn Constructor(global: &GlobalScope,
+    pub fn Constructor(window: &Window,
                        type_: DOMString,
                        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(),
+        let event = UIEvent::new(window,
                                  type_,
                                  bubbles, cancelable,
                                  init.view.r(), init.detail);
         Ok(event)
     }
 }
 
 impl UIEventMethods for UIEvent {
--- a/servo/components/script/dom/webglactiveinfo.rs
+++ b/servo/components/script/dom/webglactiveinfo.rs
@@ -3,17 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
 use dom::bindings::codegen::Bindings::WebGLActiveInfoBinding;
 use dom::bindings::codegen::Bindings::WebGLActiveInfoBinding::WebGLActiveInfoMethods;
 use dom::bindings::js::Root;
 use dom::bindings::reflector::{Reflector, reflect_dom_object};
 use dom::bindings::str::DOMString;
-use dom::globalscope::GlobalScope;
+use dom::window::Window;
 
 #[dom_struct]
 pub struct WebGLActiveInfo {
     reflector_: Reflector,
     size: i32,
     // NOTE: `ty` stands for `type`, which is a reserved keyword
     ty: u32,
     name: DOMString,
@@ -24,18 +24,18 @@ impl WebGLActiveInfo {
         WebGLActiveInfo {
             reflector_: Reflector::new(),
             size: size,
             ty: ty,
             name: name,
         }
     }
 
-    pub fn new(global: &GlobalScope, size: i32, ty: u32, name: DOMString) -> Root<WebGLActiveInfo> {
-        reflect_dom_object(box WebGLActiveInfo::new_inherited(size, ty, name), global, WebGLActiveInfoBinding::Wrap)
+    pub fn new(window: &Window, size: i32, ty: u32, name: DOMString) -> Root<WebGLActiveInfo> {
+        reflect_dom_object(box WebGLActiveInfo::new_inherited(size, ty, name), window, WebGLActiveInfoBinding::Wrap)
     }
 }
 
 impl WebGLActiveInfoMethods for WebGLActiveInfo {
     // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.11.1
     fn Size(&self) -> i32 {
         self.size
     }
--- a/servo/components/script/dom/webglbuffer.rs
+++ b/servo/components/script/dom/webglbuffer.rs
@@ -2,18 +2,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
 use canvas_traits::CanvasMsg;
 use dom::bindings::codegen::Bindings::WebGLBufferBinding;
 use dom::bindings::js::Root;
 use dom::bindings::reflector::reflect_dom_object;
-use dom::globalscope::GlobalScope;
 use dom::webglobject::WebGLObject;
+use dom::window::Window;
 use ipc_channel::ipc::IpcSender;
 use std::cell::Cell;
 use webrender_traits;
 use webrender_traits::{WebGLBufferId, WebGLCommand, WebGLError, WebGLResult};
 
 #[dom_struct]
 pub struct WebGLBuffer {
     webgl_object: WebGLObject,
@@ -35,31 +35,31 @@ impl WebGLBuffer {
             id: id,
             target: Cell::new(None),
             capacity: Cell::new(0),
             is_deleted: Cell::new(false),
             renderer: renderer,
         }
     }
 
-    pub fn maybe_new(global: &GlobalScope, renderer: IpcSender<CanvasMsg>)
+    pub fn maybe_new(window: &Window, renderer: IpcSender<CanvasMsg>)
                      -> Option<Root<WebGLBuffer>> {
         let (sender, receiver) = webrender_traits::channel::msg_channel().unwrap();
         renderer.send(CanvasMsg::WebGL(WebGLCommand::CreateBuffer(sender))).unwrap();
 
         let result = receiver.recv().unwrap();
-        result.map(|buffer_id| WebGLBuffer::new(global, renderer, buffer_id))
+        result.map(|buffer_id| WebGLBuffer::new(window, renderer, buffer_id))
     }
 
-    pub fn new(global: &GlobalScope,
+    pub fn new(window: &Window,
                renderer: IpcSender<CanvasMsg>,
                id: WebGLBufferId)
               -> Root<WebGLBuffer> {
         reflect_dom_object(box WebGLBuffer::new_inherited(renderer, id),
-                           global, WebGLBufferBinding::Wrap)
+                           window, WebGLBufferBinding::Wrap)
     }
 }
 
 
 impl WebGLBuffer {
     pub fn id(&self) -> WebGLBufferId {
         self.id
     }
--- a/servo/components/script/dom/webglcontextevent.rs
+++ b/servo/components/script/dom/webglcontextevent.rs
@@ -7,17 +7,17 @@ use dom::bindings::codegen::Bindings::We
 use dom::bindings::codegen::Bindings::WebGLContextEventBinding::WebGLContextEventInit;
 use dom::bindings::codegen::Bindings::WebGLContextEventBinding::WebGLContextEventMethods;
 use dom::bindings::error::Fallible;
 use dom::bindings::inheritance::Castable;
 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;
 
 #[dom_struct]
 pub struct WebGLContextEvent {
     event: Event,
     status_message: DOMString,
 }
 
@@ -36,56 +36,56 @@ impl WebGLContextEventMethods for WebGLC
 impl WebGLContextEvent {
     pub fn new_inherited(status_message: DOMString) -> WebGLContextEvent {
         WebGLContextEvent {
             event: Event::new_inherited(),
             status_message: status_message,
         }
     }
 
-    pub fn new_uninitialized(global_ref: &GlobalScope) -> Root<WebGLContextEvent> {
+    pub fn new_uninitialized(window: &Window) -> Root<WebGLContextEvent> {
         // according to https://www.khronos.org/registry/webgl/specs/1.0/#5.15 this is
         // additional information or the empty string if no additional information is
         // available.
         let status_message = DOMString::new();
         reflect_dom_object(
                         box WebGLContextEvent::new_inherited(status_message),
-                        global_ref,
+                        window,
                         WebGLContextEventBinding::Wrap)
     }
 
-    pub fn new(global: &GlobalScope,
+    pub fn new(window: &Window,
                type_: Atom,
                bubbles: EventBubbles,
                cancelable: EventCancelable,
                status_message: DOMString) -> Root<WebGLContextEvent> {
         let event = reflect_dom_object(
                         box WebGLContextEvent::new_inherited(status_message),
-                        global,
+                        window,
                         WebGLContextEventBinding::Wrap);
 
         {
             let parent = event.upcast::<Event>();
             parent.init_event(type_, bool::from(bubbles), bool::from(cancelable));
         }
 
         event
     }
 
-    pub fn Constructor(global: &GlobalScope,
+    pub fn Constructor(window: &Window,
                        type_: DOMString,
                        init: &WebGLContextEventInit) -> Fallible<Root<WebGLContextEvent>> {
         let status_message = match init.statusMessage.as_ref() {
             Some(message) => message.clone(),
             None => DOMString::new(),
         };
 
         let bubbles = EventBubbles::from(init.parent.bubbles);
 
         let cancelable = EventCancelable::from(init.parent.cancelable);
 
-        Ok(WebGLContextEvent::new(global,
+        Ok(WebGLContextEvent::new(window,
                                   Atom::from(type_),
                                   bubbles,
                                   cancelable,
                                   status_message))
     }
 }
--- a/servo/components/script/dom/webglframebuffer.rs
+++ b/servo/components/script/dom/webglframebuffer.rs
@@ -4,20 +4,20 @@
 
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
 use canvas_traits::CanvasMsg;
 use dom::bindings::cell::DOMRefCell;
 use dom::bindings::codegen::Bindings::WebGLFramebufferBinding;
 use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
 use dom::bindings::js::{HeapGCValue, JS, Root};
 use dom::bindings::reflector::reflect_dom_object;
-use dom::globalscope::GlobalScope;
 use dom::webglobject::WebGLObject;
 use dom::webglrenderbuffer::WebGLRenderbuffer;
 use dom::webgltexture::WebGLTexture;
+use dom::window::Window;
 use ipc_channel::ipc::IpcSender;
 use std::cell::Cell;
 use webrender_traits;
 use webrender_traits::{WebGLCommand, WebGLFramebufferBindingRequest, WebGLFramebufferId, WebGLResult, WebGLError};
 
 #[must_root]
 #[derive(JSTraceable, Clone, HeapSizeOf)]
 enum WebGLFramebufferAttachment {
@@ -61,31 +61,31 @@ impl WebGLFramebuffer {
             status: Cell::new(constants::FRAMEBUFFER_UNSUPPORTED),
             color: DOMRefCell::new(None),
             depth: DOMRefCell::new(None),
             stencil: DOMRefCell::new(None),
             depthstencil: DOMRefCell::new(None),
         }
     }
 
-    pub fn maybe_new(global: &GlobalScope, renderer: IpcSender<CanvasMsg>)
+    pub fn maybe_new(window: &Window, renderer: IpcSender<CanvasMsg>)
                      -> Option<Root<WebGLFramebuffer>> {
         let (sender, receiver) = webrender_traits::channel::msg_channel().unwrap();
         renderer.send(CanvasMsg::WebGL(WebGLCommand::CreateFramebuffer(sender))).unwrap();
 
         let result = receiver.recv().unwrap();
-        result.map(|fb_id| WebGLFramebuffer::new(global, renderer, fb_id))
+        result.map(|fb_id| WebGLFramebuffer::new(window, renderer, fb_id))
     }
 
-    pub fn new(global: &GlobalScope,
+    pub fn new(window: &Window,
                renderer: IpcSender<CanvasMsg>,
                id: WebGLFramebufferId)
                -> Root<WebGLFramebuffer> {
         reflect_dom_object(box WebGLFramebuffer::new_inherited(renderer, id),
-                           global,
+                           window,
                            WebGLFramebufferBinding::Wrap)
     }
 }
 
 
 impl WebGLFramebuffer {
     pub fn id(&self) -> WebGLFramebufferId {
         self.id
--- a/servo/components/script/dom/webglobject.rs
+++ b/servo/components/script/dom/webglobject.rs
@@ -1,26 +1,26 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
 use dom::bindings::codegen::Bindings::WebGLObjectBinding;
 use dom::bindings::js::Root;
 use dom::bindings::reflector::{Reflector, reflect_dom_object};
-use dom::globalscope::GlobalScope;
+use dom::window::Window;
 
 #[dom_struct]
 pub struct WebGLObject {
     reflector_: Reflector,
 }
 
 impl WebGLObject {
     pub fn new_inherited() -> WebGLObject {
         WebGLObject {
             reflector_: Reflector::new(),
         }
     }
 
-    pub fn new(global: &GlobalScope) -> Root<WebGLObject> {
-        reflect_dom_object(box WebGLObject::new_inherited(), global, WebGLObjectBinding::Wrap)
+    pub fn new(window: &Window) -> Root<WebGLObject> {
+        reflect_dom_object(box WebGLObject::new_inherited(), window, WebGLObjectBinding::Wrap)
     }
 }
--- a/servo/components/script/dom/webglprogram.rs
+++ b/servo/components/script/dom/webglprogram.rs
@@ -4,21 +4,21 @@
 
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
 use canvas_traits::CanvasMsg;
 use dom::bindings::codegen::Bindings::WebGLProgramBinding;
 use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
 use dom::bindings::js::{JS, MutNullableHeap, Root};
 use dom::bindings::reflector::{Reflectable, reflect_dom_object};
 use dom::bindings::str::DOMString;
-use dom::globalscope::GlobalScope;
 use dom::webglactiveinfo::WebGLActiveInfo;
 use dom::webglobject::WebGLObject;
 use dom::webglrenderingcontext::MAX_UNIFORM_AND_ATTRIBUTE_LEN;
 use dom::webglshader::WebGLShader;
+use dom::window::Window;
 use ipc_channel::ipc::IpcSender;
 use std::cell::Cell;
 use webrender_traits;
 use webrender_traits::{WebGLCommand, WebGLError, WebGLParameter};
 use webrender_traits::{WebGLProgramId, WebGLResult};
 
 #[dom_struct]
 pub struct WebGLProgram {
@@ -44,31 +44,31 @@ impl WebGLProgram {
             link_called: Cell::new(false),
             linked: Cell::new(false),
             fragment_shader: Default::default(),
             vertex_shader: Default::default(),
             renderer: renderer,
         }
     }
 
-    pub fn maybe_new(global: &GlobalScope, renderer: IpcSender<CanvasMsg>)
+    pub fn maybe_new(window: &Window, renderer: IpcSender<CanvasMsg>)
                      -> Option<Root<WebGLProgram>> {
         let (sender, receiver) = webrender_traits::channel::msg_channel().unwrap();
         renderer.send(CanvasMsg::WebGL(WebGLCommand::CreateProgram(sender))).unwrap();
 
         let result = receiver.recv().unwrap();
-        result.map(|program_id| WebGLProgram::new(global, renderer, program_id))
+        result.map(|program_id| WebGLProgram::new(window, renderer, program_id))
     }
 
-    pub fn new(global: &GlobalScope,
+    pub fn new(window: &Window,
                renderer: IpcSender<CanvasMsg>,
                id: WebGLProgramId)
                -> Root<WebGLProgram> {
         reflect_dom_object(box WebGLProgram::new_inherited(renderer, id),
-                           global,
+                           window,
                            WebGLProgramBinding::Wrap)
     }
 }
 
 
 impl WebGLProgram {
     pub fn id(&self) -> WebGLProgramId {
         self.id
@@ -226,31 +226,31 @@ impl WebGLProgram {
             return Err(WebGLError::InvalidValue);
         }
         let (sender, receiver) = webrender_traits::channel::msg_channel().unwrap();
         self.renderer
             .send(CanvasMsg::WebGL(WebGLCommand::GetActiveUniform(self.id, index, sender)))
             .unwrap();
 
         receiver.recv().unwrap().map(|(size, ty, name)|
-            WebGLActiveInfo::new(&self.global(), size, ty, DOMString::from(name)))
+            WebGLActiveInfo::new(self.global().as_window(), size, ty, DOMString::from(name)))
     }
 
     /// glGetActiveAttrib
     pub fn get_active_attrib(&self, index: u32) -> WebGLResult<Root<WebGLActiveInfo>> {
         if self.is_deleted() {
             return Err(WebGLError::InvalidValue);
         }
         let (sender, receiver) = webrender_traits::channel::msg_channel().unwrap();
         self.renderer
             .send(CanvasMsg::WebGL(WebGLCommand::GetActiveAttrib(self.id, index, sender)))
             .unwrap();
 
         receiver.recv().unwrap().map(|(size, ty, name)|
-            WebGLActiveInfo::new(&self.global(), size, ty, DOMString::from(name)))
+            WebGLActiveInfo::new(self.global().as_window(), size, ty, DOMString::from(name)))
     }
 
     /// glGetAttribLocation
     pub fn get_attrib_location(&self, name: DOMString) -> WebGLResult<Option<i32>> {
         if !self.is_linked() || self.is_deleted() {
             return Err(WebGLError::InvalidOperation);
         }
         if name.len() > MAX_UNIFORM_AND_ATTRIBUTE_LEN {
--- a/servo/components/script/dom/webglrenderbuffer.rs
+++ b/servo/components/script/dom/webglrenderbuffer.rs
@@ -3,18 +3,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
 use canvas_traits::CanvasMsg;
 use dom::bindings::codegen::Bindings::WebGLRenderbufferBinding;
 use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
 use dom::bindings::js::Root;
 use dom::bindings::reflector::reflect_dom_object;
-use dom::globalscope::GlobalScope;
 use dom::webglobject::WebGLObject;
+use dom::window::Window;
 use ipc_channel::ipc::IpcSender;
 use std::cell::Cell;
 use webrender_traits;
 use webrender_traits::{WebGLCommand, WebGLRenderbufferId, WebGLResult, WebGLError};
 
 #[dom_struct]
 pub struct WebGLRenderbuffer {
     webgl_object: WebGLObject,
@@ -37,31 +37,31 @@ impl WebGLRenderbuffer {
             ever_bound: Cell::new(false),
             is_deleted: Cell::new(false),
             renderer: renderer,
             internal_format: Cell::new(None),
             size: Cell::new(None),
         }
     }
 
-    pub fn maybe_new(global: &GlobalScope, renderer: IpcSender<CanvasMsg>)
+    pub fn maybe_new(window: &Window, renderer: IpcSender<CanvasMsg>)
                      -> Option<Root<WebGLRenderbuffer>> {
         let (sender, receiver) = webrender_traits::channel::msg_channel().unwrap();
         renderer.send(CanvasMsg::WebGL(WebGLCommand::CreateRenderbuffer(sender))).unwrap();
 
         let result = receiver.recv().unwrap();
-        result.map(|renderbuffer_id| WebGLRenderbuffer::new(global, renderer, renderbuffer_id))
+        result.map(|renderbuffer_id| WebGLRenderbuffer::new(window, renderer, renderbuffer_id))
     }
 
-    pub fn new(global: &GlobalScope,
+    pub fn new(window: &Window,
                renderer: IpcSender<CanvasMsg>,
                id: WebGLRenderbufferId)
                -> Root<WebGLRenderbuffer> {
         reflect_dom_object(box WebGLRenderbuffer::new_inherited(renderer, id),
-                           global,
+                           window,
                            WebGLRenderbufferBinding::Wrap)
     }
 }
 
 
 impl WebGLRenderbuffer {
     pub fn id(&self) -> WebGLRenderbufferId {
         self.id
--- a/servo/components/script/dom/webglrenderingcontext.rs
+++ b/servo/components/script/dom/webglrenderingcontext.rs
@@ -29,16 +29,17 @@ use dom::webglactiveinfo::WebGLActiveInf
 use dom::webglbuffer::WebGLBuffer;
 use dom::webglcontextevent::WebGLContextEvent;
 use dom::webglframebuffer::WebGLFramebuffer;
 use dom::webglprogram::WebGLProgram;
 use dom::webglrenderbuffer::WebGLRenderbuffer;
 use dom::webglshader::WebGLShader;
 use dom::webgltexture::{TexParameterValue, WebGLTexture};
 use dom::webgluniformlocation::WebGLUniformLocation;
+use dom::window::Window;
 use euclid::size::Size2D;
 use ipc_channel::ipc::{self, IpcSender};
 use js::conversions::ConversionBehavior;
 use js::jsapi::{JSContext, JSObject, JS_GetArrayBufferViewType, Type};
 use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue, UndefinedValue};
 use net_traits::image::base::PixelFormat;
 use net_traits::image_cache_thread::ImageResponse;
 use offscreen_gl_context::{GLContextAttributes, GLLimits};
@@ -130,23 +131,23 @@ pub struct WebGLRenderingContext {
     bound_buffer_array: MutNullableHeap<JS<WebGLBuffer>>,
     bound_buffer_element_array: MutNullableHeap<JS<WebGLBuffer>>,
     current_program: MutNullableHeap<JS<WebGLProgram>>,
     #[ignore_heap_size_of = "Because it's small"]
     current_vertex_attrib_0: Cell<(f32, f32, f32, f32)>,
 }
 
 impl WebGLRenderingContext {
-    fn new_inherited(global: &GlobalScope,
+    fn new_inherited(window: &Window,
                      canvas: &HTMLCanvasElement,
                      size: Size2D<i32>,
                      attrs: GLContextAttributes)
                      -> Result<WebGLRenderingContext, String> {
         let (sender, receiver) = ipc::channel().unwrap();
-        let constellation_chan = global.constellation_chan();
+        let constellation_chan = window.upcast::<GlobalScope>().constellation_chan();
         constellation_chan.send(ConstellationMsg::CreateWebGLPaintThread(size, attrs, sender))
                           .unwrap();
         let result = receiver.recv().unwrap();
 
         result.map(|(ipc_renderer, context_limits)| {
             WebGLRenderingContext {
                 reflector_: Reflector::new(),
                 ipc_renderer: ipc_renderer,
@@ -162,23 +163,23 @@ impl WebGLRenderingContext {
                 bound_renderbuffer: MutNullableHeap::new(None),
                 current_program: MutNullableHeap::new(None),
                 current_vertex_attrib_0: Cell::new((0f32, 0f32, 0f32, 1f32)),
             }
         })
     }
 
     #[allow(unrooted_must_root)]
-    pub fn new(global: &GlobalScope, canvas: &HTMLCanvasElement, size: Size2D<i32>, attrs: GLContextAttributes)
+    pub fn new(window: &Window, canvas: &HTMLCanvasElement, size: Size2D<i32>, attrs: GLContextAttributes)
                -> Option<Root<WebGLRenderingContext>> {
-        match WebGLRenderingContext::new_inherited(global, canvas, size, attrs) {
-            Ok(ctx) => Some(reflect_dom_object(box ctx, global, WebGLRenderingContextBinding::Wrap)),
+        match WebGLRenderingContext::new_inherited(window, canvas, size, attrs) {
+            Ok(ctx) => Some(reflect_dom_object(box ctx, window, WebGLRenderingContextBinding::Wrap)),
             Err(msg) => {
                 error!("Couldn't create WebGLRenderingContext: {}", msg);
-                let event = WebGLContextEvent::new(global,
+                let event = WebGLContextEvent::new(window,
                                                    atom!("webglcontextcreationerror"),
                                                    EventBubbles::DoesNotBubble,
                                                    EventCancelable::Cancelable,
                                                    DOMString::from(msg));
                 event.upcast::<Event>().fire(canvas.upcast());
                 None
             }
         }
@@ -1243,49 +1244,49 @@ impl WebGLRenderingContextMethods for We
             shader.compile()
         }
     }
 
     // TODO(emilio): Probably in the future we should keep track of the
     // generated objects, either here or in the webgl thread
     // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
     fn CreateBuffer(&self) -> Option<Root<WebGLBuffer>> {
-        WebGLBuffer::maybe_new(&self.global(), self.ipc_renderer.clone())
+        WebGLBuffer::maybe_new(self.global().as_window(), self.ipc_renderer.clone())
     }
 
     // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.6
     fn CreateFramebuffer(&self) -> Option<Root<WebGLFramebuffer>> {
-        WebGLFramebuffer::maybe_new(&self.global(), self.ipc_renderer.clone())
+        WebGLFramebuffer::maybe_new(self.global().as_window(), self.ipc_renderer.clone())
     }
 
     // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.7
     fn CreateRenderbuffer(&self) -> Option<Root<WebGLRenderbuffer>> {
-        WebGLRenderbuffer::maybe_new(&self.global(), self.ipc_renderer.clone())
+        WebGLRenderbuffer::maybe_new(self.global().as_window(), self.ipc_renderer.clone())
     }
 
     // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
     fn CreateTexture(&self) -> Option<Root<WebGLTexture>> {
-        WebGLTexture::maybe_new(&self.global(), self.ipc_renderer.clone())
+        WebGLTexture::maybe_new(self.global().as_window(), self.ipc_renderer.clone())
     }
 
     // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
     fn CreateProgram(&self) -> Option<Root<WebGLProgram>> {
-        WebGLProgram::maybe_new(&self.global(), self.ipc_renderer.clone())
+        WebGLProgram::maybe_new(self.global().as_window(), self.ipc_renderer.clone())
     }
 
     // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
     fn CreateShader(&self, shader_type: u32) -> Option<Root<WebGLShader>> {
         match shader_type {
             constants::VERTEX_SHADER | constants::FRAGMENT_SHADER => {},
             _ => {
                 self.webgl_error(InvalidEnum);
                 return None;
             }
         }
-        WebGLShader::maybe_new(&self.global(), self.ipc_renderer.clone(), shader_type)
+        WebGLShader::maybe_new(self.global().as_window(), self.ipc_renderer.clone(), shader_type)
     }
 
     // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
     fn DeleteBuffer(&self, buffer: Option<&WebGLBuffer>) {
         if let Some(buffer) = buffer {
             handle_object_deletion!(self, self.bound_buffer_array, buffer,
                                     Some(WebGLCommand::BindBuffer(constants::ARRAY_BUFFER, None)));
             handle_object_deletion!(self, self.bound_buffer_element_array, buffer,
@@ -1607,17 +1608,17 @@ impl WebGLRenderingContextMethods for We
     }
 
     // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
     fn GetUniformLocation(&self,
                           program: Option<&WebGLProgram>,
                           name: DOMString) -> Option<Root<WebGLUniformLocation>> {
         program.and_then(|p| {
             handle_potential_webgl_error!(self, p.get_uniform_location(name), None)
-                .map(|location| WebGLUniformLocation::new(&self.global(), location, p.id()))
+                .map(|location| WebGLUniformLocation::new(self.global().as_window(), location, p.id()))
         })
     }
 
     #[allow(unsafe_code)]
     // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
     unsafe fn GetVertexAttrib(&self, cx: *mut JSContext, index: u32, pname: u32) -> JSVal {
         if index == 0 && pname == constants::CURRENT_VERTEX_ATTRIB {
             rooted!(in(cx) let mut result = UndefinedValue());
--- a/servo/components/script/dom/webglshader.rs
+++ b/servo/components/script/dom/webglshader.rs
@@ -5,18 +5,18 @@
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
 use angle::hl::{BuiltInResources, Output, ShaderValidator};
 use canvas_traits::CanvasMsg;
 use dom::bindings::cell::DOMRefCell;
 use dom::bindings::codegen::Bindings::WebGLShaderBinding;
 use dom::bindings::js::Root;
 use dom::bindings::reflector::reflect_dom_object;
 use dom::bindings::str::DOMString;
-use dom::globalscope::GlobalScope;
 use dom::webglobject::WebGLObject;
+use dom::window::Window;
 use ipc_channel::ipc::IpcSender;
 use std::cell::Cell;
 use std::sync::{ONCE_INIT, Once};
 use webrender_traits;
 use webrender_traits::{WebGLCommand, WebGLParameter, WebGLResult, WebGLShaderId};
 
 #[derive(Clone, Copy, PartialEq, Debug, JSTraceable, HeapSizeOf)]
 pub enum ShaderCompilationStatus {
@@ -61,33 +61,34 @@ impl WebGLShader {
             info_log: DOMRefCell::new(None),
             is_deleted: Cell::new(false),
             attached_counter: Cell::new(0),
             compilation_status: Cell::new(ShaderCompilationStatus::NotCompiled),
             renderer: renderer,
         }
     }
 
-    pub fn maybe_new(global: &GlobalScope,
+    pub fn maybe_new(window: &Window,
                      renderer: IpcSender<CanvasMsg>,
-                     shader_type: u32) -> Option<Root<WebGLShader>> {
+                     shader_type: u32)
+                     -> Option<Root<WebGLShader>> {
         let (sender, receiver) = webrender_traits::channel::msg_channel().unwrap();
         renderer.send(CanvasMsg::WebGL(WebGLCommand::CreateShader(shader_type, sender))).unwrap();
 
         let result = receiver.recv().unwrap();
-        result.map(|shader_id| WebGLShader::new(global, renderer, shader_id, shader_type))
+        result.map(|shader_id| WebGLShader::new(window, renderer, shader_id, shader_type))
     }
 
-    pub fn new(global: &GlobalScope,
+    pub fn new(window: &Window,
                renderer: IpcSender<CanvasMsg>,
                id: WebGLShaderId,
                shader_type: u32)
                -> Root<WebGLShader> {
         reflect_dom_object(box WebGLShader::new_inherited(renderer, id, shader_type),
-                           global,
+                           window,
                            WebGLShaderBinding::Wrap)
     }
 }
 
 
 impl WebGLShader {
     pub fn id(&self) -> WebGLShaderId {
         self.id
--- a/servo/components/script/dom/webglshaderprecisionformat.rs
+++ b/servo/components/script/dom/webglshaderprecisionformat.rs
@@ -2,17 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
 use dom::bindings::codegen::Bindings::WebGLShaderPrecisionFormatBinding;
 use dom::bindings::codegen::Bindings::WebGLShaderPrecisionFormatBinding::WebGLShaderPrecisionFormatMethods;
 use dom::bindings::js::Root;
 use dom::bindings::reflector::{Reflector, reflect_dom_object};
-use dom::globalscope::GlobalScope;
+use dom::window::Window;
 
 #[dom_struct]
 pub struct WebGLShaderPrecisionFormat {
     reflector_: Reflector,
     range_min: i32,
     range_max: i32,
     precision: i32,
 }
@@ -22,23 +22,23 @@ impl WebGLShaderPrecisionFormat {
         WebGLShaderPrecisionFormat {
             reflector_: Reflector::new(),
             range_min: range_min,
             range_max: range_max,
             precision: precision,
         }
     }
 
-    pub fn new(global: &GlobalScope,
+    pub fn new(window: &Window,
                range_min: i32,
                range_max: i32,
                precision: i32) -> Root<WebGLShaderPrecisionFormat> {
         reflect_dom_object(
             box WebGLShaderPrecisionFormat::new_inherited(range_min, range_max, precision),
-            global,
+            window,
             WebGLShaderPrecisionFormatBinding::Wrap)
     }
 }
 
 impl WebGLShaderPrecisionFormatMethods for WebGLShaderPrecisionFormat {
     // https://www.khronos.org/registry/webgl/specs/1.0/#5.12.1
     fn RangeMin(&self) -> i32 {
         self.range_min
--- a/servo/components/script/dom/webgltexture.rs
+++ b/servo/components/script/dom/webgltexture.rs
@@ -4,19 +4,19 @@
 
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
 use canvas_traits::CanvasMsg;
 use dom::bindings::cell::DOMRefCell;
 use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
 use dom::bindings::codegen::Bindings::WebGLTextureBinding;
 use dom::bindings::js::Root;
 use dom::bindings::reflector::reflect_dom_object;
-use dom::globalscope::GlobalScope;
 use dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType};
 use dom::webglobject::WebGLObject;
+use dom::window::Window;
 use ipc_channel::ipc::IpcSender;
 use std::cell::Cell;
 use std::cmp;
 use webrender_traits;
 use webrender_traits::{WebGLCommand, WebGLError, WebGLResult, WebGLTextureId};
 
 pub enum TexParameterValue {
     Float(f32),
@@ -56,31 +56,31 @@ impl WebGLTexture {
             is_deleted: Cell::new(false),
             face_count: Cell::new(0),
             base_mipmap_level: 0,
             image_info_array: DOMRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]),
             renderer: renderer,
         }
     }
 
-    pub fn maybe_new(global: &GlobalScope, renderer: IpcSender<CanvasMsg>)
+    pub fn maybe_new(window: &Window, renderer: IpcSender<CanvasMsg>)
                      -> Option<Root<WebGLTexture>> {
         let (sender, receiver) = webrender_traits::channel::msg_channel().unwrap();
         renderer.send(CanvasMsg::WebGL(WebGLCommand::CreateTexture(sender))).unwrap();
 
         let result = receiver.recv().unwrap();
-        result.map(|texture_id| WebGLTexture::new(global, renderer, texture_id))
+        result.map(|texture_id| WebGLTexture::new(window, renderer, texture_id))
     }
 
-    pub fn new(global: &GlobalScope,
+    pub fn new(window: &Window,
                renderer: IpcSender<CanvasMsg>,
                id: WebGLTextureId)
                -> Root<WebGLTexture> {
         reflect_dom_object(box WebGLTexture::new_inherited(renderer, id),
-                           global,
+                           window,
                            WebGLTextureBinding::Wrap)
     }
 }
 
 
 impl WebGLTexture {
     pub fn id(&self) -> WebGLTextureId {
         self.id
--- a/servo/components/script/dom/webgluniformlocation.rs
+++ b/servo/components/script/dom/webgluniformlocation.rs
@@ -1,17 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
 use dom::bindings::codegen::Bindings::WebGLUniformLocationBinding;
 use dom::bindings::js::Root;
 use dom::bindings::reflector::{Reflector, reflect_dom_object};
-use dom::globalscope::GlobalScope;
+use dom::window::Window;
 use webrender_traits::WebGLProgramId;
 
 #[dom_struct]
 pub struct WebGLUniformLocation {
     reflector_: Reflector,
     id: i32,
     program_id: WebGLProgramId,
 }
@@ -22,22 +22,22 @@ impl WebGLUniformLocation {
                      -> WebGLUniformLocation {
         WebGLUniformLocation {
             reflector_: Reflector::new(),
             id: id,
             program_id: program_id,
         }
     }
 
-    pub fn new(global: &GlobalScope,
+    pub fn new(window: &Window,
                id: i32,
                program_id: WebGLProgramId)
                -> Root<WebGLUniformLocation> {
         reflect_dom_object(box WebGLUniformLocation::new_inherited(id, program_id),
-                           global,
+                           window,
                            WebGLUniformLocationBinding::Wrap)
     }
 
     pub fn id(&self) -> i32 {
         self.id
     }
 
     pub fn program_id(&self) -> WebGLProgramId {
--- a/servo/components/script/dom/webidls/DOMMatrix.webidl
+++ b/servo/components/script/dom/webidls/DOMMatrix.webidl
@@ -6,20 +6,19 @@
  * https://drafts.fxtf.org/geometry-1/#DOMMatrix
  *
  * Copyright:
  * To the extent possible under law, the editors have waived all copyright and
  * related or neighboring rights to this work.
  */
 
 [Constructor,
-// Constructor(DOMString transformList),
-Constructor(sequence<unrestricted double> numberSequence)
-// Exposed=(Window,Worker)
-]
+ // Constructor(DOMString transformList),
+ Constructor(sequence<unrestricted double> numberSequence),
+ Exposed=(Window,Worker)]
 interface DOMMatrix : DOMMatrixReadOnly {
 
     [NewObject, Throws] static DOMMatrix fromMatrix(optional DOMMatrixInit other);
 //  [NewObject] static DOMMatrix fromFloat32Array(Float32Array array32);
 //  [NewObject] static DOMMatrix fromFloat64Array(Float64Array array64);
 
     // These attributes are simple aliases for certain elements of the 4x4 matrix
     inherit attribute unrestricted double a;
--- a/servo/components/script/dom/webidls/DOMMatrixReadOnly.webidl
+++ b/servo/components/script/dom/webidls/DOMMatrixReadOnly.webidl
@@ -6,20 +6,19 @@
  * https://drafts.fxtf.org/geometry-1/#DOMMatrix
  *
  * Copyright:
  * To the extent possible under law, the editors have waived all copyright and
  * related or neighboring rights to this work.
  */
 
 [Constructor,
-// Constructor(DOMString transformList)
-Constructor(sequence<unrestricted double> numberSequence),
-// Exposed=(Window,Worker)
-]
+ // Constructor(DOMString transformList)
+ Constructor(sequence<unrestricted double> numberSequence),
+ Exposed=(Window,Worker)]
 interface DOMMatrixReadOnly {
 
     [NewObject, Throws] static DOMMatrixReadOnly fromMatrix(optional DOMMatrixInit other);
 //  [NewObject] static DOMMatrixReadOnly fromFloat32Array(Float32Array array32);
 //  [NewObject] static DOMMatrixReadOnly fromFloat64Array(Float64Array array64);
 
     // These attributes are simple aliases for certain elements of the 4x4 matrix
     readonly attribute unrestricted double a;
--- a/servo/components/script/dom/webidls/WebGLActiveInfo.webidl
+++ b/servo/components/script/dom/webidls/WebGLActiveInfo.webidl
@@ -1,13 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 //
 // WebGL IDL definitions scraped from the Khronos specification:
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.7
 //
 
+[Exposed=Window]
 interface WebGLActiveInfo {
     readonly attribute GLint size;
     readonly attribute GLenum type;
     readonly attribute DOMString name;
 };
--- a/servo/components/script/dom/webidls/WebGLBuffer.webidl
+++ b/servo/components/script/dom/webidls/WebGLBuffer.webidl
@@ -1,10 +1,11 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 //
 // WebGL IDL definitions scraped from the Khronos specification:
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.4
 //
 
+[Exposed=Window]
 interface WebGLBuffer : WebGLObject {
 };
--- a/servo/components/script/dom/webidls/WebGLContextEvent.webidl
+++ b/servo/components/script/dom/webidls/WebGLContextEvent.webidl
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15
-[Constructor(DOMString type, optional WebGLContextEventInit eventInit)]
+[Constructor(DOMString type, optional WebGLContextEventInit eventInit),
+ Exposed=Window]
 interface WebGLContextEvent : Event {
     readonly attribute DOMString statusMessage;
 };
 
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15
 dictionary WebGLContextEventInit : EventInit {
     DOMString statusMessage;
 };
--- a/servo/components/script/dom/webidls/WebGLFramebuffer.webidl
+++ b/servo/components/script/dom/webidls/WebGLFramebuffer.webidl
@@ -1,10 +1,11 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 //
 // WebGL IDL definitions scraped from the Khronos specification:
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.7
 //
 
+[Exposed=Window]
 interface WebGLFramebuffer : WebGLObject {
 };
--- a/servo/components/script/dom/webidls/WebGLObject.webidl
+++ b/servo/components/script/dom/webidls/WebGLObject.webidl
@@ -1,10 +1,11 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 //
 // WebGL IDL definitions scraped from the Khronos specification:
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.3
 //
 
+[Exposed=Window]
 interface WebGLObject {
 };
--- a/servo/components/script/dom/webidls/WebGLProgram.webidl
+++ b/servo/components/script/dom/webidls/WebGLProgram.webidl
@@ -1,10 +1,11 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 //
 // WebGL IDL definitions scraped from the Khronos specification:
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.6
 //
 
+[Exposed=Window]
 interface WebGLProgram : WebGLObject {
 };
--- a/servo/components/script/dom/webidls/WebGLRenderbuffer.webidl
+++ b/servo/components/script/dom/webidls/WebGLRenderbuffer.webidl
@@ -1,10 +1,11 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 //
 // WebGL IDL definitions scraped from the Khronos specification:
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.5
 //
 
+[Exposed=Window]
 interface WebGLRenderbuffer : WebGLObject {
 };
--- a/servo/components/script/dom/webidls/WebGLRenderingContext.webidl
+++ b/servo/components/script/dom/webidls/WebGLRenderingContext.webidl
@@ -36,17 +36,17 @@ dictionary WebGLContextAttributes {
     GLboolean stencil = false;
     GLboolean antialias = true;
     GLboolean premultipliedAlpha = true;
     GLboolean preserveDrawingBuffer = false;
     GLboolean preferLowPowerToHighPerformance = false;
     GLboolean failIfMajorPerformanceCaveat = false;
 };
 
-[NoInterfaceObject]
+[Exposed=Window, NoInterfaceObject]
 interface WebGLRenderingContextBase
 {
 
     /* ClearBufferMask */
     const GLenum DEPTH_BUFFER_BIT               = 0x00000100;
     const GLenum STENCIL_BUFFER_BIT             = 0x00000400;
     const GLenum COLOR_BUFFER_BIT               = 0x00004000;
 
@@ -757,12 +757,13 @@ interface WebGLRenderingContextBase
     void vertexAttrib4fv(GLuint indx, object values);
     //void vertexAttrib4fv(GLuint indx, sequence<GLfloat> values);
     void vertexAttribPointer(GLuint indx, GLint size, GLenum type,
                              GLboolean normalized, GLsizei stride, GLintptr offset);
 
     void viewport(GLint x, GLint y, GLsizei width, GLsizei height);
 };
 
+[Exposed=Window]
 interface WebGLRenderingContext
 {
 };
 WebGLRenderingContext implements WebGLRenderingContextBase;
--- a/servo/components/script/dom/webidls/WebGLShader.webidl
+++ b/servo/components/script/dom/webidls/WebGLShader.webidl
@@ -1,10 +1,11 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 //
 // WebGL IDL definitions scraped from the Khronos specification:
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.8
 //
 
+[Exposed=Window]
 interface WebGLShader : WebGLObject {
 };
--- a/servo/components/script/dom/webidls/WebGLShaderPrecisionFormat.webidl
+++ b/servo/components/script/dom/webidls/WebGLShaderPrecisionFormat.webidl
@@ -1,13 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 //
 // WebGL IDL definitions scraped from the Khronos specification:
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.7
 //
 
+[Exposed=Window]
 interface WebGLShaderPrecisionFormat {
     readonly attribute GLint rangeMin;
     readonly attribute GLint rangeMax;
     readonly attribute GLint precision;
 };
--- a/servo/components/script/dom/webidls/WebGLTexture.webidl
+++ b/servo/components/script/dom/webidls/WebGLTexture.webidl
@@ -1,10 +1,11 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 //
 // WebGL IDL definitions scraped from the Khronos specification:
 // https://www.khronos.org/registry/webgl/specs/latest/#5.9
 //
 
+[Exposed=Window]
 interface WebGLTexture : WebGLObject {
 };
--- a/servo/components/script/dom/webidls/WebGLUniformLocation.webidl
+++ b/servo/components/script/dom/webidls/WebGLUniformLocation.webidl
@@ -1,10 +1,11 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 //
 // WebGL IDL definitions scraped from the Khronos specification:
 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.10
 //
 
+[Exposed=Window]
 interface WebGLUniformLocation {
 };