mirror of
https://github.com/servo/servo.git
synced 2025-08-09 15:35:34 +01:00
Auto merge of #9255 - ckimes89:remove-globalfield, r=nox
Remove global fields from DOM objects Fixes #9227 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9255) <!-- Reviewable:end -->
This commit is contained in:
commit
53c4a782a0
19 changed files with 104 additions and 151 deletions
|
@ -44,17 +44,6 @@ pub enum GlobalRoot {
|
|||
Worker(Root<WorkerGlobalScope>),
|
||||
}
|
||||
|
||||
/// A traced reference to a global object, for use in fields of traced Rust
|
||||
/// structures.
|
||||
#[derive(JSTraceable, HeapSizeOf)]
|
||||
#[must_root]
|
||||
pub enum GlobalField {
|
||||
/// A field for a `Window` object.
|
||||
Window(JS<window::Window>),
|
||||
/// A field for a `WorkerGlobalScope` object.
|
||||
Worker(JS<WorkerGlobalScope>),
|
||||
}
|
||||
|
||||
impl<'a> GlobalRef<'a> {
|
||||
/// Get the `JSContext` for the `JSRuntime` associated with the thread
|
||||
/// this global object is on.
|
||||
|
@ -273,25 +262,6 @@ impl GlobalRoot {
|
|||
}
|
||||
}
|
||||
|
||||
impl GlobalField {
|
||||
/// Create a new `GlobalField` from a rooted reference.
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn from_rooted(global: &GlobalRef) -> GlobalField {
|
||||
match *global {
|
||||
GlobalRef::Window(window) => GlobalField::Window(JS::from_ref(window)),
|
||||
GlobalRef::Worker(worker) => GlobalField::Worker(JS::from_ref(worker)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a stack-bounded root for this reference.
|
||||
pub fn root(&self) -> GlobalRoot {
|
||||
match *self {
|
||||
GlobalField::Window(ref window) => GlobalRoot::Window(Root::from_ref(window)),
|
||||
GlobalField::Worker(ref worker) => GlobalRoot::Worker(Root::from_ref(worker)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the global object of the realm that the given DOM object's reflector was created in.
|
||||
pub fn global_root_from_reflector<T: Reflectable>(reflector: &T) -> GlobalRoot {
|
||||
global_root_from_object(*reflector.reflector().get_jsobject())
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
//! The `Reflector` struct.
|
||||
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::global::{GlobalRef, GlobalRoot, global_root_from_reflector};
|
||||
use dom::bindings::js::Root;
|
||||
use js::jsapi::{HandleObject, JSContext, JSObject};
|
||||
use std::cell::UnsafeCell;
|
||||
|
@ -75,4 +75,9 @@ pub trait Reflectable {
|
|||
fn reflector(&self) -> &Reflector;
|
||||
/// Initializes the Reflector
|
||||
fn init_reflector(&mut self, obj: *mut JSObject);
|
||||
|
||||
/// Returns the global object of the realm that the Reflectable was created in.
|
||||
fn global(&self) -> GlobalRoot where Self: Sized {
|
||||
global_root_from_reflector(self)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue