Rename JS<T> to Dom<T>

This commit is contained in:
Anthony Ramine 2017-09-25 23:56:32 +02:00
parent 0e3c54c191
commit 7be32fb237
96 changed files with 494 additions and 494 deletions

View file

@ -6,7 +6,7 @@
use dom::bindings::error::{Error, Fallible, report_pending_exception};
use dom::bindings::reflector::DomObject;
use dom::bindings::root::{JS, Root};
use dom::bindings::root::{Dom, Root};
use dom::bindings::settings_stack::{AutoEntryScript, AutoIncumbentScript};
use dom::bindings::utils::AsCCharPtrPtr;
use dom::globalscope::GlobalScope;
@ -53,7 +53,7 @@ pub struct CallbackObject {
///
/// ["callback context"]: https://heycam.github.io/webidl/#dfn-callback-context
/// [sometimes]: https://github.com/whatwg/html/issues/2248
incumbent: Option<JS<GlobalScope>>
incumbent: Option<Dom<GlobalScope>>
}
impl Default for CallbackObject {
@ -69,7 +69,7 @@ impl CallbackObject {
CallbackObject {
callback: Heap::default(),
permanent_js_root: Heap::default(),
incumbent: GlobalScope::incumbent().map(|i| JS::from_ref(&*i)),
incumbent: GlobalScope::incumbent().map(|i| Dom::from_ref(&*i)),
}
}
@ -120,7 +120,7 @@ pub trait CallbackContainer {
///
/// ["callback context"]: https://heycam.github.io/webidl/#dfn-callback-context
fn incumbent(&self) -> Option<&GlobalScope> {
self.callback_holder().incumbent.as_ref().map(JS::deref)
self.callback_holder().incumbent.as_ref().map(Dom::deref)
}
}

View file

@ -1272,7 +1272,7 @@ class CGArgumentConverter(CGThing):
arg = "arg%d" % index
if argument.type.isGeckoInterface():
init = "rooted_vec!(let mut %s)" % arg
innerConverter.append(CGGeneric("%s.push(JS::from_ref(&*slot));" % arg))
innerConverter.append(CGGeneric("%s.push(Dom::from_ref(&*slot));" % arg))
else:
init = "let mut %s = vec![]" % arg
innerConverter.append(CGGeneric("%s.push(slot);" % arg))
@ -5712,7 +5712,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'dom::bindings::namespace::create_namespace_object',
'dom::bindings::reflector::MutDomObject',
'dom::bindings::reflector::DomObject',
'dom::bindings::root::JS',
'dom::bindings::root::Dom',
'dom::bindings::root::OptionalHeapSetter',
'dom::bindings::root::Root',
'dom::bindings::root::RootedReference',
@ -6961,7 +6961,7 @@ class CallbackGetter(CallbackMember):
needThisHandling=False)
def getRvalDecl(self):
return "JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());\n"
return "Dom::Rooted<Dom::Value> rval(cx, JS::UndefinedValue());\n"
def getCall(self):
replacements = {
@ -7195,7 +7195,7 @@ class GlobalGenRoots():
imports = [CGGeneric("use dom::types::*;\n"),
CGGeneric("use dom::bindings::conversions::{DerivedFrom, get_dom_class};\n"),
CGGeneric("use dom::bindings::inheritance::Castable;\n"),
CGGeneric("use dom::bindings::root::{JS, LayoutJS, Root};\n"),
CGGeneric("use dom::bindings::root::{Dom, LayoutJS, Root};\n"),
CGGeneric("use dom::bindings::trace::JSTraceable;\n"),
CGGeneric("use dom::bindings::reflector::DomObject;\n"),
CGGeneric("use js::jsapi::JSTracer;\n\n"),

View file

@ -11,7 +11,7 @@ use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyAndVal
use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyOrValueResult;
use dom::bindings::error::Fallible;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::root::{JS, Root};
use dom::bindings::root::{Dom, Root};
use dom::bindings::trace::JSTraceable;
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
@ -51,7 +51,7 @@ pub trait Iterable {
#[dom_struct]
pub struct IterableIterator<T: DomObject + JSTraceable + Iterable> {
reflector: Reflector,
iterable: JS<T>,
iterable: Dom<T>,
type_: IteratorType,
index: Cell<u32>,
}
@ -65,7 +65,7 @@ impl<T: DomObject + JSTraceable + Iterable> IterableIterator<T> {
let iterator = box IterableIterator {
reflector: Reflector::new(),
type_: type_,
iterable: JS::from_ref(iterable),
iterable: Dom::from_ref(iterable),
index: Cell::new(0),
};
reflect_dom_object(iterator, &*iterable.global(), wrap)

View file

@ -12,10 +12,10 @@
//! Here is a brief overview of the important types:
//!
//! - `Root<T>`: a stack-based reference to a rooted DOM object.
//! - `JS<T>`: a reference to a DOM object that can automatically be traced by
//! - `Dom<T>`: a reference to a DOM object that can automatically be traced by
//! the GC when encountered as a field of a Rust structure.
//!
//! `JS<T>` does not allow access to their inner value without explicitly
//! `Dom<T>` does not allow access to their inner value without explicitly
//! creating a stack-based root via the `root` method. This returns a `Root<T>`,
//! which causes the JS-owned value to be uncollectable for the duration of the
//! `Root` object's lifetime. A reference to the object can then be obtained
@ -50,24 +50,24 @@ use style::thread_state;
/// A traced reference to a DOM object
///
/// This type is critical to making garbage collection work with the DOM,
/// but it is very dangerous; if garbage collection happens with a `JS<T>`
/// on the stack, the `JS<T>` can point to freed memory.
/// but it is very dangerous; if garbage collection happens with a `Dom<T>`
/// on the stack, the `Dom<T>` can point to freed memory.
///
/// This should only be used as a field in other DOM objects.
#[must_root]
pub struct JS<T> {
pub struct Dom<T> {
ptr: NonZero<*const T>,
}
// JS<T> is similar to Rc<T>, in that it's not always clear how to avoid double-counting.
// Dom<T> is similar to Rc<T>, in that it's not always clear how to avoid double-counting.
// For now, we choose not to follow any such pointers.
impl<T> HeapSizeOf for JS<T> {
impl<T> HeapSizeOf for Dom<T> {
fn heap_size_of_children(&self) -> usize {
0
}
}
impl<T> JS<T> {
impl<T> Dom<T> {
/// Returns `LayoutJS<T>` containing the same pointer.
pub unsafe fn to_layout(&self) -> LayoutJS<T> {
debug_assert!(thread_state::get().is_layout());
@ -77,36 +77,36 @@ impl<T> JS<T> {
}
}
impl<T: DomObject> JS<T> {
/// Create a JS<T> from a &T
impl<T: DomObject> Dom<T> {
/// Create a Dom<T> from a &T
#[allow(unrooted_must_root)]
pub fn from_ref(obj: &T) -> JS<T> {
pub fn from_ref(obj: &T) -> Dom<T> {
debug_assert!(thread_state::get().is_script());
JS {
Dom {
ptr: unsafe { NonZero::new_unchecked(&*obj) },
}
}
}
impl<'root, T: DomObject + 'root> RootedReference<'root> for JS<T> {
impl<'root, T: DomObject + 'root> RootedReference<'root> for Dom<T> {
type Ref = &'root T;
fn r(&'root self) -> &'root T {
&self
}
}
impl<T: DomObject> Deref for JS<T> {
impl<T: DomObject> Deref for Dom<T> {
type Target = T;
fn deref(&self) -> &T {
debug_assert!(thread_state::get().is_script());
// We can only have &JS<T> from a rooted thing, so it's safe to deref
// We can only have &Dom<T> from a rooted thing, so it's safe to deref
// it to &T.
unsafe { &*self.ptr.get() }
}
}
unsafe impl<T: DomObject> JSTraceable for JS<T> {
unsafe impl<T: DomObject> JSTraceable for Dom<T> {
unsafe fn trace(&self, trc: *mut JSTracer) {
#[cfg(debug_assertions)]
let trace_str = format!("for {} on heap", type_name::<T>());
@ -169,13 +169,13 @@ impl<T: DomObject> LayoutJS<T> {
impl<T> Copy for LayoutJS<T> {}
impl<T> PartialEq for JS<T> {
fn eq(&self, other: &JS<T>) -> bool {
impl<T> PartialEq for Dom<T> {
fn eq(&self, other: &Dom<T>) -> bool {
self.ptr == other.ptr
}
}
impl<T> Eq for JS<T> {}
impl<T> Eq for Dom<T> {}
impl<T> PartialEq for LayoutJS<T> {
fn eq(&self, other: &LayoutJS<T>) -> bool {
@ -185,7 +185,7 @@ impl<T> PartialEq for LayoutJS<T> {
impl<T> Eq for LayoutJS<T> {}
impl<T> Hash for JS<T> {
impl<T> Hash for Dom<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.ptr.hash(state)
}
@ -197,12 +197,12 @@ impl<T> Hash for LayoutJS<T> {
}
}
impl <T> Clone for JS<T> {
impl <T> Clone for Dom<T> {
#[inline]
#[allow(unrooted_must_root)]
fn clone(&self) -> JS<T> {
fn clone(&self) -> Dom<T> {
debug_assert!(thread_state::get().is_script());
JS {
Dom {
ptr: self.ptr.clone(),
}
}
@ -231,14 +231,14 @@ impl LayoutJS<Node> {
}
/// A holder that provides interior mutability for GC-managed values such as
/// `JS<T>`. Essentially a `Cell<JS<T>>`, but safer.
/// `Dom<T>`. Essentially a `Cell<Dom<T>>`, but safer.
///
/// This should only be used as a field in other DOM objects; see warning
/// on `JS<T>`.
/// on `Dom<T>`.
#[must_root]
#[derive(JSTraceable)]
pub struct MutJS<T: DomObject> {
val: UnsafeCell<JS<T>>,
val: UnsafeCell<Dom<T>>,
}
impl<T: DomObject> MutJS<T> {
@ -246,7 +246,7 @@ impl<T: DomObject> MutJS<T> {
pub fn new(initial: &T) -> MutJS<T> {
debug_assert!(thread_state::get().is_script());
MutJS {
val: UnsafeCell::new(JS::from_ref(initial)),
val: UnsafeCell::new(Dom::from_ref(initial)),
}
}
@ -254,7 +254,7 @@ impl<T: DomObject> MutJS<T> {
pub fn set(&self, val: &T) {
debug_assert!(thread_state::get().is_script());
unsafe {
*self.val.get() = JS::from_ref(val);
*self.val.get() = Dom::from_ref(val);
}
}
@ -269,7 +269,7 @@ impl<T: DomObject> MutJS<T> {
impl<T: DomObject> HeapSizeOf for MutJS<T> {
fn heap_size_of_children(&self) -> usize {
// See comment on HeapSizeOf for JS<T>.
// See comment on HeapSizeOf for Dom<T>.
0
}
}
@ -291,15 +291,15 @@ impl<T: DomObject + PartialEq> PartialEq<T> for MutJS<T> {
}
/// A holder that provides interior mutability for GC-managed values such as
/// `JS<T>`, with nullability represented by an enclosing Option wrapper.
/// Essentially a `Cell<Option<JS<T>>>`, but safer.
/// `Dom<T>`, with nullability represented by an enclosing Option wrapper.
/// Essentially a `Cell<Option<Dom<T>>>`, but safer.
///
/// This should only be used as a field in other DOM objects; see warning
/// on `JS<T>`.
/// on `Dom<T>`.
#[must_root]
#[derive(JSTraceable)]
pub struct MutNullableJS<T: DomObject> {
ptr: UnsafeCell<Option<JS<T>>>,
ptr: UnsafeCell<Option<Dom<T>>>,
}
impl<T: DomObject> MutNullableJS<T> {
@ -307,7 +307,7 @@ impl<T: DomObject> MutNullableJS<T> {
pub fn new(initial: Option<&T>) -> MutNullableJS<T> {
debug_assert!(thread_state::get().is_script());
MutNullableJS {
ptr: UnsafeCell::new(initial.map(JS::from_ref)),
ptr: UnsafeCell::new(initial.map(Dom::from_ref)),
}
}
@ -327,7 +327,7 @@ impl<T: DomObject> MutNullableJS<T> {
}
}
/// Retrieve a copy of the inner optional `JS<T>` as `LayoutJS<T>`.
/// Retrieve a copy of the inner optional `Dom<T>` as `LayoutJS<T>`.
/// For use by layout, which can't use safe types like Temporary.
#[allow(unrooted_must_root)]
pub unsafe fn get_inner_as_layout(&self) -> Option<LayoutJS<T>> {
@ -348,7 +348,7 @@ impl<T: DomObject> MutNullableJS<T> {
pub fn set(&self, val: Option<&T>) {
debug_assert!(thread_state::get().is_script());
unsafe {
*self.ptr.get() = val.map(|p| JS::from_ref(p));
*self.ptr.get() = val.map(|p| Dom::from_ref(p));
}
}
@ -371,7 +371,7 @@ impl<T: DomObject> PartialEq for MutNullableJS<T> {
impl<'a, T: DomObject> PartialEq<Option<&'a T>> for MutNullableJS<T> {
fn eq(&self, other: &Option<&T>) -> bool {
unsafe {
*self.ptr.get() == other.map(JS::from_ref)
*self.ptr.get() == other.map(Dom::from_ref)
}
}
}
@ -388,20 +388,20 @@ impl<T: DomObject> Default for MutNullableJS<T> {
impl<T: DomObject> HeapSizeOf for MutNullableJS<T> {
fn heap_size_of_children(&self) -> usize {
// See comment on HeapSizeOf for JS<T>.
// See comment on HeapSizeOf for Dom<T>.
0
}
}
/// A holder that allows to lazily initialize the value only once
/// `JS<T>`, using OnceCell
/// Essentially a `OnceCell<JS<T>>`.
/// `Dom<T>`, using OnceCell
/// Essentially a `OnceCell<Dom<T>>`.
///
/// This should only be used as a field in other DOM objects; see warning
/// on `JS<T>`.
/// on `Dom<T>`.
#[must_root]
pub struct OnceCellJS<T: DomObject> {
ptr: OnceCell<JS<T>>,
ptr: OnceCell<Dom<T>>,
}
impl<T: DomObject> OnceCellJS<T> {
@ -412,7 +412,7 @@ impl<T: DomObject> OnceCellJS<T> {
where F: FnOnce() -> Root<T>
{
debug_assert!(thread_state::get().is_script());
&self.ptr.init_once(|| JS::from_ref(&cb()))
&self.ptr.init_once(|| Dom::from_ref(&cb()))
}
}
@ -428,7 +428,7 @@ impl<T: DomObject> Default for OnceCellJS<T> {
impl<T: DomObject> HeapSizeOf for OnceCellJS<T> {
fn heap_size_of_children(&self) -> usize {
// See comment on HeapSizeOf for JS<T>.
// See comment on HeapSizeOf for Dom<T>.
0
}
}
@ -468,7 +468,7 @@ pub trait RootedReference<'root> {
fn r(&'root self) -> Self::Ref;
}
impl<'root, T: JSTraceable + DomObject + 'root> RootedReference<'root> for [JS<T>] {
impl<'root, T: JSTraceable + DomObject + 'root> RootedReference<'root> for [Dom<T>] {
type Ref = &'root [&'root T];
fn r(&'root self) -> &'root [&'root T] {
unsafe { mem::transmute(self) }

View file

@ -2,7 +2,7 @@
* 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::root::{JS, Root};
use dom::bindings::root::{Dom, Root};
use dom::bindings::trace::JSTraceable;
use dom::globalscope::GlobalScope;
use js::jsapi::GetScriptedCallerGlobal;
@ -24,7 +24,7 @@ enum StackEntryKind {
#[allow(unrooted_must_root)]
#[derive(JSTraceable)]
struct StackEntry {
global: JS<GlobalScope>,
global: Dom<GlobalScope>,
kind: StackEntryKind,
}
@ -47,7 +47,7 @@ impl AutoEntryScript {
trace!("Prepare to run script with {:p}", global);
let mut stack = stack.borrow_mut();
stack.push(StackEntry {
global: JS::from_ref(global),
global: Dom::from_ref(global),
kind: StackEntryKind::Entry,
});
AutoEntryScript {
@ -109,7 +109,7 @@ impl AutoIncumbentScript {
// Step 1.
let mut stack = stack.borrow_mut();
stack.push(StackEntry {
global: JS::from_ref(global),
global: Dom::from_ref(global),
kind: StackEntryKind::Incumbent,
});
AutoIncumbentScript {

View file

@ -18,9 +18,9 @@
//! achieved via `unsafe_no_jsmanaged_fields!` or similar.
//! 3. For all fields, `Foo::trace()`
//! calls `trace()` on the field.
//! For example, for fields of type `JS<T>`, `JS<T>::trace()` calls
//! For example, for fields of type `Dom<T>`, `Dom<T>::trace()` calls
//! `trace_reflector()`.
//! 4. `trace_reflector()` calls `JS::TraceEdge()` with a
//! 4. `trace_reflector()` calls `Dom::TraceEdge()` with a
//! pointer to the `JSObject` for the reflector. This notifies the GC, which
//! will add the object to the graph, and will trace that object as well.
//! 5. When the GC finishes tracing, it [`finalizes`](../index.html#destruction)
@ -42,7 +42,7 @@ use dom::bindings::cell::DOMRefCell;
use dom::bindings::error::Error;
use dom::bindings::refcounted::{Trusted, TrustedPromise};
use dom::bindings::reflector::{DomObject, Reflector};
use dom::bindings::root::{JS, Root};
use dom::bindings::root::{Dom, Root};
use dom::bindings::str::{DOMString, USVString};
use dom::bindings::utils::WindowProxyHandler;
use dom::document::PendingRestyle;
@ -840,16 +840,16 @@ impl<'a, T: 'static + JSTraceable> RootedVec<'a, T> {
}
}
impl<'a, T: 'static + JSTraceable + DomObject> RootedVec<'a, JS<T>> {
/// Create a vector of items of type JS<T> that is rooted for
impl<'a, T: 'static + JSTraceable + DomObject> RootedVec<'a, Dom<T>> {
/// Create a vector of items of type Dom<T> that is rooted for
/// the lifetime of this struct
pub fn from_iter<I>(root: &'a mut RootableVec<JS<T>>, iter: I) -> Self
pub fn from_iter<I>(root: &'a mut RootableVec<Dom<T>>, iter: I) -> Self
where I: Iterator<Item = Root<T>>
{
unsafe {
RootedTraceableSet::add(root);
}
root.v.extend(iter.map(|item| JS::from_ref(&*item)));
root.v.extend(iter.map(|item| Dom::from_ref(&*item)));
RootedVec {
root: root,
}