aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/domstringlist.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-09-17 23:53:08 -0400
committerGitHub <noreply@github.com>2019-09-17 23:53:08 -0400
commit745857066c7484b654aa6c32edc0c589fe184e2a (patch)
treedba72d5b05d58e828ab084e8cb3c0977382882a6 /components/script/dom/domstringlist.rs
parent41d1a94f1abcd7d9d36245c8b059fd6a11e1cd97 (diff)
parent7e4e48c351a93361e06ce29f2f76c41e79373349 (diff)
downloadservo-745857066c7484b654aa6c32edc0c589fe184e2a.tar.gz
servo-745857066c7484b654aa6c32edc0c589fe184e2a.zip
Auto merge of #24220 - rasviitanen:domstringlist, r=jdm
add webidl bindings for DOMStringList <!-- Please describe your changes on the following line: --> To prepare for the implementation of `IndexedDB` a DOM interface for `DOMStringList` is added. This change: * Adds a new IDL file for `DOMStringList` * Lists `domstringlist.rs` in `mod.rs` * Defines a new DOMStruct `DOMStringList` * Changes some test expectations related to `DOMStringList` --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #24208 - [X] These changes do not require tests because: We are not yet able to fully test the functions of `DOMStringList` in the WPT, because it is not possible to create an object of the type `DOMStringList` until e.g. `indexeddb` or `location.ancestorOrigins` is implemented. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24220) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/domstringlist.rs')
-rw-r--r--components/script/dom/domstringlist.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/components/script/dom/domstringlist.rs b/components/script/dom/domstringlist.rs
new file mode 100644
index 00000000000..f9f55a69f03
--- /dev/null
+++ b/components/script/dom/domstringlist.rs
@@ -0,0 +1,59 @@
+/* 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 https://mozilla.org/MPL/2.0/. */
+
+use crate::dom::bindings::codegen::Bindings::DOMStringListBinding;
+use crate::dom::bindings::codegen::Bindings::DOMStringListBinding::DOMStringListMethods;
+use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
+use crate::dom::bindings::root::DomRoot;
+use crate::dom::bindings::str::DOMString;
+use crate::dom::window::Window;
+use dom_struct::dom_struct;
+
+#[dom_struct]
+pub struct DOMStringList {
+ reflector_: Reflector,
+ strings: Vec<DOMString>,
+}
+
+impl DOMStringList {
+ #[allow(unused)]
+ pub fn new_inherited(strings: Vec<DOMString>) -> DOMStringList {
+ DOMStringList {
+ reflector_: Reflector::new(),
+ strings,
+ }
+ }
+
+ #[allow(unused)]
+ pub fn new(window: &Window, strings: Vec<DOMString>) -> DomRoot<DOMStringList> {
+ reflect_dom_object(
+ Box::new(DOMStringList::new_inherited(strings)),
+ window,
+ DOMStringListBinding::Wrap,
+ )
+ }
+}
+
+// https://html.spec.whatwg.org/multipage/#domstringlist
+impl DOMStringListMethods for DOMStringList {
+ // https://html.spec.whatwg.org/multipage/#dom-domstringlist-length
+ fn Length(&self) -> u32 {
+ self.strings.len() as u32
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-domstringlist-item
+ fn Item(&self, index: u32) -> Option<DOMString> {
+ self.strings.get(index as usize).cloned()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-domstringlist-contains
+ fn Contains(&self, string: DOMString) -> bool {
+ self.strings.contains(&string)
+ }
+
+ // check-tidy: no specs after this line
+ fn IndexedGetter(&self, index: u32) -> Option<DOMString> {
+ self.Item(index)
+ }
+}