aboutsummaryrefslogtreecommitdiffstats
path: root/components/selectors
diff options
context:
space:
mode:
Diffstat (limited to 'components/selectors')
-rw-r--r--components/selectors/Cargo.toml6
-rw-r--r--components/selectors/gecko_like_types.rs29
-rw-r--r--components/selectors/lib.rs3
-rw-r--r--components/selectors/parser.rs2
-rw-r--r--components/selectors/size_of_tests.rs66
5 files changed, 105 insertions, 1 deletions
diff --git a/components/selectors/Cargo.toml b/components/selectors/Cargo.toml
index 20ddf3b8ad2..ceef176eae1 100644
--- a/components/selectors/Cargo.toml
+++ b/components/selectors/Cargo.toml
@@ -17,6 +17,9 @@ path = "lib.rs"
# https://github.com/servo/servo/issues/16710
doctest = false
+[features]
+gecko_like_types = []
+
[dependencies]
bitflags = "0.7"
matches = "0.1"
@@ -24,3 +27,6 @@ cssparser = "0.13.3"
fnv = "1.0"
precomputed-hash = "0.1"
smallvec = "0.3"
+
+[dev-dependencies]
+size_of_test = {path = "../size_of_test"}
diff --git a/components/selectors/gecko_like_types.rs b/components/selectors/gecko_like_types.rs
new file mode 100644
index 00000000000..b00d8d95667
--- /dev/null
+++ b/components/selectors/gecko_like_types.rs
@@ -0,0 +1,29 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/. */
+
+//! These types need to have the same size and alignment as the respectively corresponding
+//! types in components/style/gecko/selector_parser.rs
+
+#[derive(Eq, PartialEq, Clone, Debug, Hash)]
+#[allow(dead_code)]
+pub enum PseudoClass {
+ Bare,
+ String(Box<[u16]>),
+ MozAny(Box<[()]>),
+}
+
+#[derive(Eq, PartialEq, Clone, Debug, Hash)]
+pub enum PseudoElement {
+ A,
+ B,
+}
+
+#[derive(Eq, PartialEq, Clone, Debug)]
+pub struct PseudoElementSelector(PseudoElement, u64);
+
+#[derive(Eq, PartialEq, Clone, Debug, Hash, Default)]
+pub struct Atom(usize);
+
+#[derive(Eq, PartialEq, Clone, Hash)]
+pub struct Impl;
diff --git a/components/selectors/lib.rs b/components/selectors/lib.rs
index 452e47963c7..d352d2f1d3c 100644
--- a/components/selectors/lib.rs
+++ b/components/selectors/lib.rs
@@ -7,12 +7,15 @@
#[macro_use] extern crate matches;
extern crate fnv;
extern crate precomputed_hash;
+#[cfg(test)] #[macro_use] extern crate size_of_test;
extern crate smallvec;
pub mod arcslice;
pub mod bloom;
pub mod matching;
pub mod parser;
+#[cfg(test)] mod size_of_tests;
+#[cfg(any(test, feature = "gecko_like_types"))] pub mod gecko_like_types;
mod tree;
pub mod visitor;
diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs
index 7c0f53ab0a6..5dd7760adc2 100644
--- a/components/selectors/parser.rs
+++ b/components/selectors/parser.rs
@@ -1505,7 +1505,7 @@ pub mod tests {
}
}
- fn parse_pseudo_element(&self, name: Cow<str>, input: &mut CssParser)
+ fn parse_pseudo_element(&self, name: Cow<str>, _input: &mut CssParser)
-> Result<PseudoElement, ()> {
match_ignore_ascii_case! { &name,
"before" => Ok(PseudoElement::Before),
diff --git a/components/selectors/size_of_tests.rs b/components/selectors/size_of_tests.rs
new file mode 100644
index 00000000000..1d06278abd5
--- /dev/null
+++ b/components/selectors/size_of_tests.rs
@@ -0,0 +1,66 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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 cssparser::ToCss;
+use gecko_like_types::*;
+use parser::*;
+use precomputed_hash::PrecomputedHash;
+use std::fmt;
+use visitor::SelectorVisitor;
+
+size_of_test!(size_of_selector, Selector<Impl>, 72);
+size_of_test!(size_of_pseudo_element, PseudoElementSelector, 16);
+size_of_test!(size_of_selector_inner, SelectorInner<Impl>, 40);
+size_of_test!(size_of_complex_selector, ComplexSelector<Impl>, 24);
+
+size_of_test!(size_of_component, Component<Impl>, 64);
+size_of_test!(size_of_attr_selector, AttrSelector<Impl>, 48);
+size_of_test!(size_of_pseudo_class, PseudoClass, 24);
+
+
+// Boilerplate
+
+impl SelectorImpl for Impl {
+ type AttrValue = Atom;
+ type Identifier = Atom;
+ type ClassName = Atom;
+ type LocalName = Atom;
+ type NamespaceUrl = Atom;
+ type NamespacePrefix = Atom;
+ type BorrowedLocalName = Atom;
+ type BorrowedNamespaceUrl = Atom;
+ type NonTSPseudoClass = PseudoClass;
+ type PseudoElementSelector = PseudoElementSelector;
+}
+
+impl SelectorMethods for PseudoClass {
+ type Impl = Impl;
+
+ fn visit<V>(&self, _visitor: &mut V) -> bool
+ where V: SelectorVisitor<Impl = Self::Impl> { unimplemented!() }
+}
+
+impl ToCss for PseudoClass {
+ fn to_css<W>(&self, _: &mut W) -> fmt::Result where W: fmt::Write { unimplemented!() }
+}
+
+impl ToCss for PseudoElementSelector {
+ fn to_css<W>(&self, _: &mut W) -> fmt::Result where W: fmt::Write { unimplemented!() }
+}
+
+impl fmt::Display for Atom {
+ fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { unimplemented!() }
+}
+
+impl From<String> for Atom {
+ fn from(_: String) -> Self { unimplemented!() }
+}
+
+impl<'a> From<&'a str> for Atom {
+ fn from(_: &'a str) -> Self { unimplemented!() }
+}
+
+impl PrecomputedHash for Atom {
+ fn precomputed_hash(&self) -> u32 { unimplemented!() }
+}