Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make WebIDL static items take a more specific global if possible #14376

Merged
merged 4 commits into from Dec 1, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -3168,7 +3168,7 @@ def __init__(self, errorResult, arguments, argsPre, returnType,

if isFallible:
if static:
glob = "&global"
glob = "global.upcast::<GlobalScope>()"
else:
glob = "&this.global()"

@@ -3378,12 +3378,13 @@ def __init__(self, descriptor, name):
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!
@@ -5245,12 +5246,14 @@ def __init__(self, descriptor, constructor=None):
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,
@@ -5582,6 +5585,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'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',
@@ -7,7 +7,7 @@ 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;
@@ -271,22 +271,22 @@ const VALID_UUID_REGEX: &'static str = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-

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)
}
}
@@ -9,8 +9,8 @@ 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]
@@ -31,8 +31,8 @@ impl Comment {
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))
}
}
@@ -6,7 +6,7 @@ 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 {
@@ -15,7 +15,7 @@ pub struct CSS {

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))
@@ -1884,11 +1884,10 @@ impl Document {
}

// 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,
@@ -2426,7 +2425,7 @@ impl DocumentMethods for Document {
)
)),
"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))))
@@ -12,10 +12,10 @@ 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
@@ -38,8 +38,8 @@ impl DocumentFragment {
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))
}
@@ -17,7 +17,6 @@ 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;

@@ -41,8 +40,8 @@ impl DOMParser {
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))
}
}

@@ -10,7 +10,7 @@ use dom::bindings::js::Root;
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::event::Event;
use dom::globalscope::GlobalScope;
use dom::serviceworkerglobalscope::ServiceWorkerGlobalScope;
use js::jsapi::{HandleValue, JSContext};
use servo_atoms::Atom;

@@ -28,23 +28,23 @@ impl ExtendableEvent {
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))
@@ -13,6 +13,7 @@ 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;
@@ -46,10 +47,11 @@ impl ExtendableMessageEvent {
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_),
@@ -53,12 +53,12 @@ impl FocusEvent {
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,
@@ -177,7 +177,7 @@ impl HTMLCanvasElement {
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)));
}
@@ -16,11 +16,11 @@ 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;
@@ -220,10 +220,10 @@ impl HTMLImageElement {
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);
@@ -12,7 +12,6 @@ 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;
@@ -101,10 +100,10 @@ impl KeyboardEvent {
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,
@@ -12,7 +12,6 @@ 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;
@@ -82,12 +81,12 @@ impl MouseEvent {
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,
@@ -22,11 +22,11 @@ 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};
@@ -70,8 +70,8 @@ impl 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))
}

@@ -319,7 +319,7 @@ impl ServiceWorkerGlobalScope {
}

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);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.