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 -->
This commit is contained in:
bors-servo 2019-09-17 23:53:08 -04:00 committed by GitHub
commit 745857066c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 84 additions and 216 deletions

View file

@ -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)
}
}

View file

@ -293,6 +293,7 @@ pub mod dompointreadonly;
pub mod domquad;
pub mod domrect;
pub mod domrectreadonly;
pub mod domstringlist;
pub mod domstringmap;
pub mod domtokenlist;
pub mod element;

View file

@ -0,0 +1,18 @@
/* 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/. */
/*
* The origin of this IDL file is
* https://html.spec.whatwg.org/multipage/#domstringlist
*
* Copyright:
* To the extent possible under law, the editors have waived all copyright and
* related or neighboring rights to this work.
*/
[Exposed=(Window,Worker)]
interface DOMStringList {
readonly attribute unsigned long length;
getter DOMString? item(unsigned long index);
boolean contains(DOMString string);
};