aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-02-05 03:40:36 +0530
committerbors-servo <lbergstrom+bors@mozilla.com>2016-02-05 03:40:36 +0530
commit2a6707ce58df27d93e865bffb6b44d396b810c99 (patch)
tree849afb2986272f67b1abfc8720b8f530dc1c2227 /components/script/dom
parent9e68285d35a2e7b72c9edfd9e5e37399e724c4e6 (diff)
parentcb5cd8d881c39f549381e078b44f341dea733e68 (diff)
downloadservo-2a6707ce58df27d93e865bffb6b44d396b810c99.tar.gz
servo-2a6707ce58df27d93e865bffb6b44d396b810c99.zip
Auto merge of #9532 - nox:dedup-heapsize, r=Manishearth
Say farewell to in-tree HeapSizeOf <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9532) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/error.rs1
-rw-r--r--components/script/dom/bindings/js.rs2
-rw-r--r--components/script/dom/bindings/str.rs1
-rw-r--r--components/script/dom/bindings/utils.rs2
-rw-r--r--components/script/dom/bindings/weakref.rs2
-rw-r--r--components/script/dom/crypto.rs1
-rw-r--r--components/script/dom/element.rs1
-rw-r--r--components/script/dom/eventtarget.rs2
-rw-r--r--components/script/dom/node.rs51
-rw-r--r--components/script/dom/range.rs2
-rw-r--r--components/script/dom/xmlhttprequest.rs3
11 files changed, 50 insertions, 18 deletions
diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs
index 95f22e693e5..dafd14f58c9 100644
--- a/components/script/dom/bindings/error.rs
+++ b/components/script/dom/bindings/error.rs
@@ -14,7 +14,6 @@ use js::jsapi::{JSContext, JSObject, RootedValue};
use js::jsapi::{JS_IsExceptionPending, JS_ReportPendingException, JS_SetPendingException};
use js::jsapi::{JS_RestoreFrameChain, JS_SaveFrameChain};
use js::jsval::UndefinedValue;
-use util::mem::HeapSizeOf;
/// DOM exceptions that can be thrown by a native DOM method.
#[derive(Debug, Clone, HeapSizeOf)]
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs
index 6abf5f9b4e5..37d673f3c26 100644
--- a/components/script/dom/bindings/js.rs
+++ b/components/script/dom/bindings/js.rs
@@ -30,6 +30,7 @@ use dom::bindings::reflector::{Reflectable, Reflector};
use dom::bindings::trace::JSTraceable;
use dom::bindings::trace::trace_reflector;
use dom::node::Node;
+use heapsize::HeapSizeOf;
use js::jsapi::{Heap, JSObject, JSTracer};
use js::jsval::JSVal;
use layout_interface::TrustedNodeAddress;
@@ -40,7 +41,6 @@ use std::hash::{Hash, Hasher};
use std::mem;
use std::ops::Deref;
use std::ptr;
-use util::mem::HeapSizeOf;
use util::thread_state;
/// A traced reference to a DOM object
diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs
index df69bc77fd0..26c8568eadf 100644
--- a/components/script/dom/bindings/str.rs
+++ b/components/script/dom/bindings/str.rs
@@ -10,7 +10,6 @@ use std::hash::{Hash, Hasher};
use std::ops;
use std::str;
use std::str::FromStr;
-use util::mem::HeapSizeOf;
use util::str::is_token;
/// Encapsulates the IDL `ByteString` type.
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs
index d34d8f3f9f4..83e7a2e4cb2 100644
--- a/components/script/dom/bindings/utils.rs
+++ b/components/script/dom/bindings/utils.rs
@@ -13,6 +13,7 @@ use dom::bindings::inheritance::TopTypeId;
use dom::bindings::trace::trace_object;
use dom::browsingcontext;
use dom::window;
+use heapsize::HeapSizeOf;
use js;
use js::error::throw_type_error;
use js::glue::{CallJitGetterOp, CallJitMethodOp, CallJitSetterOp, IsWrapper};
@@ -36,7 +37,6 @@ use libc::{self, c_uint};
use std::default::Default;
use std::ffi::CString;
use std::ptr;
-use util::mem::HeapSizeOf;
use util::non_geckolib::jsstring_to_str;
/// Proxy handler for a WindowProxy.
diff --git a/components/script/dom/bindings/weakref.rs b/components/script/dom/bindings/weakref.rs
index e311d4a40bb..99adb8a0c02 100644
--- a/components/script/dom/bindings/weakref.rs
+++ b/components/script/dom/bindings/weakref.rs
@@ -15,6 +15,7 @@ use core::nonzero::NonZero;
use dom::bindings::js::Root;
use dom::bindings::reflector::Reflectable;
use dom::bindings::trace::JSTraceable;
+use heapsize::HeapSizeOf;
use js::jsapi::{JSTracer, JS_GetReservedSlot, JS_SetReservedSlot};
use js::jsval::PrivateValue;
use libc::c_void;
@@ -22,7 +23,6 @@ use std::cell::{Cell, UnsafeCell};
use std::iter::Iterator;
use std::mem;
use std::ops::{Deref, DerefMut, Drop};
-use util::mem::HeapSizeOf;
/// The index of the slot wherein a pointer to the weak holder cell is
/// stored for weak-referenceable bindings. We use slot 1 for holding it,
diff --git a/components/script/dom/crypto.rs b/components/script/dom/crypto.rs
index b8c595f3aa4..6e0351d37ee 100644
--- a/components/script/dom/crypto.rs
+++ b/components/script/dom/crypto.rs
@@ -20,6 +20,7 @@ no_jsmanaged_fields!(OsRng);
#[dom_struct]
pub struct Crypto {
reflector_: Reflector,
+ #[ignore_heap_size_of = "Defined in rand"]
rng: DOMRefCell<OsRng>,
}
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index d093380b008..3cdf3f6ba43 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -84,7 +84,6 @@ use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_sty
use style::selector_impl::{NonTSPseudoClass, ServoSelectorImpl};
use style::values::CSSFloat;
use style::values::specified::{self, CSSColor, CSSRGBA, LengthOrPercentage};
-use util::mem::HeapSizeOf;
use util::str::{DOMString, LengthOrPercentageOrAuto};
// TODO: Update focus state when the top-level browsing context gains or loses system focus,
diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs
index 48682ec2211..2cf9517d606 100644
--- a/components/script/dom/eventtarget.rs
+++ b/components/script/dom/eventtarget.rs
@@ -21,6 +21,7 @@ use dom::eventdispatcher::dispatch_event;
use dom::virtualmethods::VirtualMethods;
use dom::window::Window;
use fnv::FnvHasher;
+use heapsize::HeapSizeOf;
use js::jsapi::{CompileFunction, JS_GetFunctionObject, RootedValue};
use js::jsapi::{HandleObject, JSContext, RootedFunction};
use js::jsapi::{JSAutoCompartment, JSAutoRequest};
@@ -35,7 +36,6 @@ use std::rc::Rc;
use std::{intrinsics, ptr};
use string_cache::Atom;
use url::Url;
-use util::mem::HeapSizeOf;
use util::str::DOMString;
#[derive(PartialEq, Clone, JSTraceable)]
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 9c4e52b495d..a50aad1a78e 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -9,7 +9,6 @@ use core::nonzero::NonZero;
use devtools_traits::NodeInfo;
use document_loader::DocumentLoader;
use dom::attr::Attr;
-use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods;
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
@@ -47,6 +46,7 @@ use dom::text::Text;
use dom::virtualmethods::{VirtualMethods, vtable_for};
use dom::window::Window;
use euclid::rect::Rect;
+use heapsize::{HeapSizeOf, heap_size_of};
use js::jsapi::{JSContext, JSObject, JSRuntime};
use layout_interface::{LayoutChan, Msg};
use libc::{self, c_void, uintptr_t};
@@ -57,7 +57,7 @@ use selectors::matching::matches;
use selectors::parser::Selector;
use selectors::parser::parse_author_origin_selector_list_from_str;
use std::borrow::ToOwned;
-use std::cell::Cell;
+use std::cell::{Cell, UnsafeCell};
use std::cmp::max;
use std::default::Default;
use std::iter::{self, FilterMap, Peekable};
@@ -120,7 +120,7 @@ pub struct Node {
/// node is finalized.
style_and_layout_data: Cell<Option<OpaqueStyleAndLayoutData>>,
- unique_id: DOMRefCell<Option<Box<Uuid>>>,
+ unique_id: UniqueId,
}
bitflags! {
@@ -755,11 +755,7 @@ impl Node {
}
pub fn get_unique_id(&self) -> String {
- if self.unique_id.borrow().is_none() {
- let mut unique_id = self.unique_id.borrow_mut();
- *unique_id = Some(Box::new(Uuid::new_v4()));
- }
- self.unique_id.borrow().as_ref().unwrap().to_simple_string()
+ self.unique_id.borrow().to_simple_string()
}
pub fn summarize(&self) -> NodeInfo {
@@ -1266,7 +1262,7 @@ impl Node {
style_and_layout_data: Cell::new(None),
- unique_id: DOMRefCell::new(None),
+ unique_id: UniqueId::new(),
}
}
@@ -2438,3 +2434,40 @@ impl<'a> UnbindContext<'a> {
index
}
}
+
+/// A node's unique ID, for devtools.
+struct UniqueId {
+ cell: UnsafeCell<Option<Box<Uuid>>>,
+}
+
+no_jsmanaged_fields!(UniqueId);
+
+impl HeapSizeOf for UniqueId {
+ #[allow(unsafe_code)]
+ fn heap_size_of_children(&self) -> usize {
+ if let &Some(ref uuid) = unsafe { &*self.cell.get() } {
+ heap_size_of(&** uuid as *const Uuid as *const c_void)
+ } else {
+ 0
+ }
+ }
+}
+
+impl UniqueId {
+ /// Create a new `UniqueId` value. The underlying `Uuid` is lazily created.
+ fn new() -> UniqueId {
+ UniqueId { cell: UnsafeCell::new(None) }
+ }
+
+ /// The Uuid of that unique ID.
+ #[allow(unsafe_code)]
+ fn borrow(&self) -> &Uuid {
+ unsafe {
+ let ptr = self.cell.get();
+ if (*ptr).is_none() {
+ *ptr = Some(box Uuid::new_v4());
+ }
+ &(&*ptr).as_ref().unwrap()
+ }
+ }
+}
diff --git a/components/script/dom/range.rs b/components/script/dom/range.rs
index 03db51ba0d8..6807a7a2d3c 100644
--- a/components/script/dom/range.rs
+++ b/components/script/dom/range.rs
@@ -23,10 +23,10 @@ use dom::document::Document;
use dom::documentfragment::DocumentFragment;
use dom::node::{Node, UnbindContext};
use dom::text::Text;
+use heapsize::HeapSizeOf;
use js::jsapi::JSTracer;
use std::cell::{Cell, UnsafeCell};
use std::cmp::{Ord, Ordering, PartialEq, PartialOrd};
-use util::mem::HeapSizeOf;
use util::str::DOMString;
#[dom_struct]
diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs
index e6b7374ef39..59feddfcc22 100644
--- a/components/script/dom/xmlhttprequest.rs
+++ b/components/script/dom/xmlhttprequest.rs
@@ -62,7 +62,6 @@ use string_cache::Atom;
use time;
use timers::{ScheduledCallback, TimerHandle};
use url::Url;
-use util::mem::HeapSizeOf;
use util::str::DOMString;
pub type SendParam = BlobOrStringOrURLSearchParams;
@@ -127,11 +126,13 @@ pub struct XMLHttpRequest {
response_xml: MutNullableHeap<JS<Document>>,
#[ignore_heap_size_of = "Defined in hyper"]
response_headers: DOMRefCell<Headers>,
+ #[ignore_heap_size_of = "Defined in hyper"]
override_mime_type: DOMRefCell<Option<Mime>>,
#[ignore_heap_size_of = "Defined in rust-encoding"]
override_charset: DOMRefCell<Option<EncodingRef>>,
// Associated concepts
+ #[ignore_heap_size_of = "Defined in hyper"]
request_method: DOMRefCell<Method>,
request_url: DOMRefCell<Option<Url>>,
#[ignore_heap_size_of = "Defined in hyper"]