Remove global field from Storage

This commit is contained in:
Chad Kimes 2016-01-10 22:07:59 -05:00
parent 0d217b5f71
commit c62f1e15fb

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::Bindings::StorageBinding; use dom::bindings::codegen::Bindings::StorageBinding;
use dom::bindings::codegen::Bindings::StorageBinding::StorageMethods; use dom::bindings::codegen::Bindings::StorageBinding::StorageMethods;
use dom::bindings::error::{Error, ErrorResult}; use dom::bindings::error::{Error, ErrorResult};
use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::global::{GlobalRef, global_root_from_reflector};
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::js::{Root, RootedReference}; use dom::bindings::js::{Root, RootedReference};
use dom::bindings::refcounted::Trusted; use dom::bindings::refcounted::Trusted;
@ -24,31 +24,29 @@ use util::str::DOMString;
#[dom_struct] #[dom_struct]
pub struct Storage { pub struct Storage {
reflector_: Reflector, reflector_: Reflector,
global: GlobalField,
storage_type: StorageType storage_type: StorageType
} }
impl Storage { impl Storage {
fn new_inherited(global: &GlobalRef, storage_type: StorageType) -> Storage { fn new_inherited(storage_type: StorageType) -> Storage {
Storage { Storage {
reflector_: Reflector::new(), reflector_: Reflector::new(),
global: GlobalField::from_rooted(global),
storage_type: storage_type storage_type: storage_type
} }
} }
pub fn new(global: &GlobalRef, storage_type: StorageType) -> Root<Storage> { pub fn new(global: &GlobalRef, storage_type: StorageType) -> Root<Storage> {
reflect_dom_object(box Storage::new_inherited(global, storage_type), *global, StorageBinding::Wrap) reflect_dom_object(box Storage::new_inherited(storage_type), *global, StorageBinding::Wrap)
} }
fn get_url(&self) -> Url { fn get_url(&self) -> Url {
let global_root = self.global.root(); let global_root = global_root_from_reflector(self);
let global_ref = global_root.r(); let global_ref = global_root.r();
global_ref.get_url() global_ref.get_url()
} }
fn get_storage_thread(&self) -> StorageThread { fn get_storage_thread(&self) -> StorageThread {
let global_root = self.global.root(); let global_root = global_root_from_reflector(self);
let global_ref = global_root.r(); let global_ref = global_root.r();
global_ref.as_window().storage_thread() global_ref.as_window().storage_thread()
} }
@ -154,7 +152,7 @@ impl Storage {
/// https://html.spec.whatwg.org/multipage/#send-a-storage-notification /// https://html.spec.whatwg.org/multipage/#send-a-storage-notification
fn broadcast_change_notification(&self, key: Option<String>, old_value: Option<String>, fn broadcast_change_notification(&self, key: Option<String>, old_value: Option<String>,
new_value: Option<String>) { new_value: Option<String>) {
let global_root = self.global.root(); let global_root = global_root_from_reflector(self);
let global_ref = global_root.r(); let global_ref = global_root.r();
let main_script_chan = global_ref.as_window().main_thread_script_chan(); let main_script_chan = global_ref.as_window().main_thread_script_chan();
let script_chan = global_ref.dom_manipulation_thread_source(); let script_chan = global_ref.dom_manipulation_thread_source();
@ -183,7 +181,7 @@ impl MainThreadRunnable for StorageEventRunnable {
let this = *self; let this = *self;
let storage_root = this.element.root(); let storage_root = this.element.root();
let storage = storage_root.r(); let storage = storage_root.r();
let global_root = storage.global.root(); let global_root = global_root_from_reflector(storage);
let global_ref = global_root.r(); let global_ref = global_root.r();
let ev_window = global_ref.as_window(); let ev_window = global_ref.as_window();
let ev_url = storage.get_url(); let ev_url = storage.get_url();