From ddfb8805dc1c2df97f0596cf063935b4f3c5b90b Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 27 Nov 2016 14:37:04 +0100 Subject: [PATCH] Make WebIDL static methods take a more specific global if possible --- components/script/dom/bindings/codegen/CodegenRust.py | 9 +++++---- components/script/dom/bluetoothuuid.rs | 10 +++++----- components/script/dom/css.rs | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 09681e579b90..28d0d9af459e 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -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::(global).unwrap();\n" % list(self.exposureSet)[0] + return CGList([CGGeneric(preamble), self.generate_code()]) def generate_code(self): raise NotImplementedError # Override me! diff --git a/components/script/dom/bluetoothuuid.rs b/components/script/dom/bluetoothuuid.rs index 11fb7af94cbf..fbf49142aa32 100644 --- a/components/script/dom/bluetoothuuid.rs +++ b/components/script/dom/bluetoothuuid.rs @@ -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 { + pub fn GetService(_: &Window, name: BluetoothServiceUUID) -> Fallible { Self::service(name) } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothuuid-getcharacteristic - pub fn GetCharacteristic(_: &GlobalScope, name: BluetoothCharacteristicUUID) -> Fallible { + pub fn GetCharacteristic(_: &Window, name: BluetoothCharacteristicUUID) -> Fallible { Self::characteristic(name) } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothuuid-getdescriptor - pub fn GetDescriptor(_: &GlobalScope, name: BluetoothDescriptorUUID) -> Fallible { + pub fn GetDescriptor(_: &Window, name: BluetoothDescriptorUUID) -> Fallible { Self::descriptor(name) } } diff --git a/components/script/dom/css.rs b/components/script/dom/css.rs index f2256007aeb2..2e04aed50bc3 100644 --- a/components/script/dom/css.rs +++ b/components/script/dom/css.rs @@ -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 { + pub fn Escape(_: &Window, ident: DOMString) -> Fallible { let mut escaped = String::new(); serialize_identifier(&ident, &mut escaped).unwrap(); Ok(DOMString::from(escaped))