diff options
author | Rasmus Viitanen <rasviitanen@localhost.localdomain> | 2019-09-16 11:24:36 +0200 |
---|---|---|
committer | Rasmus Viitanen <rasviitanen@localhost.localdomain> | 2019-09-18 01:22:22 +0200 |
commit | 7e4e48c351a93361e06ce29f2f76c41e79373349 (patch) | |
tree | 107c25ca6ec02bfb9d5a7e14598fba919403e4b8 | |
parent | ec1da1d01c0f48544084d9cba4398b592c58e1fe (diff) | |
download | servo-7e4e48c351a93361e06ce29f2f76c41e79373349.tar.gz servo-7e4e48c351a93361e06ce29f2f76c41e79373349.zip |
add webidl bindings for DOMStringList
12 files changed, 84 insertions, 216 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) + } +} diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 02be0f69c83..34777a20fe0 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -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; diff --git a/components/script/dom/webidls/DOMStringList.webidl b/components/script/dom/webidls/DOMStringList.webidl new file mode 100644 index 00000000000..c2d1f235b63 --- /dev/null +++ b/components/script/dom/webidls/DOMStringList.webidl @@ -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); +}; diff --git a/tests/wpt/metadata/html/dom/idlharness.https.html.ini b/tests/wpt/metadata/html/dom/idlharness.https.html.ini index 9b0587ec407..379afb9cad1 100644 --- a/tests/wpt/metadata/html/dom/idlharness.https.html.ini +++ b/tests/wpt/metadata/html/dom/idlharness.https.html.ini @@ -167,9 +167,6 @@ [MessagePort interface object length] expected: FAIL - [DOMStringList interface object length] - expected: FAIL - [Navigator interface: window.navigator must inherit property "onLine" with the proper type] expected: FAIL @@ -179,9 +176,6 @@ [ApplicationCache interface: existence and properties of interface prototype object's "constructor" property] expected: FAIL - [DOMStringList interface: operation item(unsigned long)] - expected: FAIL - [Navigator interface: attribute hardwareConcurrency] expected: FAIL @@ -446,9 +440,6 @@ [OffscreenCanvas interface: existence and properties of interface prototype object] expected: FAIL - [DOMStringList interface: existence and properties of interface prototype object's "constructor" property] - expected: FAIL - [DataTransferItemList interface object length] expected: FAIL @@ -764,9 +755,6 @@ [CanvasRenderingContext2D interface: calling drawFocusIfNeeded(Path2D, Element) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError] expected: FAIL - [DOMStringList interface: existence and properties of interface object] - expected: FAIL - [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "scrollPathIntoView(Path2D)" with the proper type] expected: FAIL @@ -986,9 +974,6 @@ [ElementInternals interface: existence and properties of interface prototype object's @@unscopables property] expected: FAIL - [DOMStringList interface: existence and properties of interface prototype object's @@unscopables property] - expected: FAIL - [ElementInternals interface: existence and properties of interface prototype object's "constructor" property] expected: FAIL @@ -1181,9 +1166,6 @@ [OffscreenCanvasRenderingContext2D interface: operation getImageData(long, long, long, long)] expected: FAIL - [DOMStringList interface: existence and properties of interface prototype object] - expected: FAIL - [SVGSVGElement interface: attribute onpopstate] expected: FAIL @@ -1202,9 +1184,6 @@ [BroadcastChannel interface: operation close()] expected: FAIL - [DOMStringList interface: attribute length] - expected: FAIL - [SVGElement interface: attribute onresize] expected: FAIL @@ -1232,9 +1211,6 @@ [TextMetrics interface: attribute fontBoundingBoxDescent] expected: FAIL - [DOMStringList interface object name] - expected: FAIL - [ApplicationCache must be primary interface of window.applicationCache] expected: FAIL @@ -1520,9 +1496,6 @@ [TextMetrics interface object name] expected: FAIL - [DOMStringList interface: operation contains(DOMString)] - expected: FAIL - [External interface: existence and properties of interface prototype object's @@unscopables property] expected: FAIL diff --git a/tests/wpt/metadata/html/dom/idlharness.worker.js.ini b/tests/wpt/metadata/html/dom/idlharness.worker.js.ini index d65f2f13fc0..0cd3199c808 100644 --- a/tests/wpt/metadata/html/dom/idlharness.worker.js.ini +++ b/tests/wpt/metadata/html/dom/idlharness.worker.js.ini @@ -74,12 +74,6 @@ [MessagePort interface object length] expected: FAIL - [DOMStringList interface object length] - expected: FAIL - - [DOMStringList interface: operation item(unsigned long)] - expected: FAIL - [OffscreenCanvasRenderingContext2D interface: operation strokeText(DOMString, unrestricted double, unrestricted double, unrestricted double)] expected: FAIL @@ -194,9 +188,6 @@ [OffscreenCanvasRenderingContext2D interface: operation stroke(Path2D)] expected: FAIL - [DOMStringList interface: existence and properties of interface prototype object's "constructor" property] - expected: FAIL - [ImageBitmap interface: existence and properties of interface prototype object's @@unscopables property] expected: FAIL @@ -350,9 +341,6 @@ [OffscreenCanvasRenderingContext2D interface: operation setTransform(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double)] expected: FAIL - [DOMStringList interface: existence and properties of interface object] - expected: FAIL - [OffscreenCanvasRenderingContext2D interface object name] expected: FAIL @@ -440,15 +428,9 @@ [OffscreenCanvasRenderingContext2D interface: operation putImageData(ImageData, long, long, long, long, long, long)] expected: FAIL - [DOMStringList interface: existence and properties of interface prototype object's @@unscopables property] - expected: FAIL - [WorkerNavigator interface: member taintEnabled] expected: FAIL - [DOMStringList interface: operation contains(DOMString)] - expected: FAIL - [DedicatedWorkerGlobalScope interface: calling cancelAnimationFrame(unsigned long) on self with too few arguments must throw TypeError] expected: FAIL @@ -524,9 +506,6 @@ [BroadcastChannel interface: attribute onmessage] expected: FAIL - [DOMStringList interface: existence and properties of interface prototype object] - expected: FAIL - [Path2D interface: existence and properties of interface prototype object's "constructor" property] expected: FAIL @@ -542,9 +521,6 @@ [WorkerGlobalScope interface: self must inherit property "onunhandledrejection" with the proper type] expected: FAIL - [DOMStringList interface: attribute length] - expected: FAIL - [Path2D interface: operation ellipse(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, boolean)] expected: FAIL @@ -557,9 +533,6 @@ [WorkerGlobalScope interface: attribute ononline] expected: FAIL - [DOMStringList interface object name] - expected: FAIL - [OffscreenCanvasRenderingContext2D interface: attribute textBaseline] expected: FAIL diff --git a/tests/wpt/metadata/html/dom/interfaces.https.html.ini b/tests/wpt/metadata/html/dom/interfaces.https.html.ini index becd9b9ee8a..1bef10af1be 100644 --- a/tests/wpt/metadata/html/dom/interfaces.https.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.https.html.ini @@ -299,33 +299,6 @@ [HTMLAllCollection interface: calling item(DOMString) on document.all with too few arguments must throw TypeError] expected: FAIL - [DOMStringList interface: existence and properties of interface object] - expected: FAIL - - [DOMStringList interface object length] - expected: FAIL - - [DOMStringList interface object name] - expected: FAIL - - [DOMStringList interface: existence and properties of interface prototype object] - expected: FAIL - - [DOMStringList interface: existence and properties of interface prototype object's "constructor" property] - expected: FAIL - - [DOMStringList interface: existence and properties of interface prototype object's @@unscopables property] - expected: FAIL - - [DOMStringList interface: attribute length] - expected: FAIL - - [DOMStringList interface: operation item(unsigned long)] - expected: FAIL - - [DOMStringList interface: operation contains(DOMString)] - expected: FAIL - [HTMLElement interface: attribute translate] expected: FAIL @@ -9161,33 +9134,6 @@ [HTML IDL tests] expected: FAIL - [DOMStringList interface: existence and properties of interface object] - expected: FAIL - - [DOMStringList interface object length] - expected: FAIL - - [DOMStringList interface object name] - expected: FAIL - - [DOMStringList interface: existence and properties of interface prototype object] - expected: FAIL - - [DOMStringList interface: existence and properties of interface prototype object's "constructor" property] - expected: FAIL - - [DOMStringList interface: existence and properties of interface prototype object's @@unscopables property] - expected: FAIL - - [DOMStringList interface: attribute length] - expected: FAIL - - [DOMStringList interface: operation item(unsigned long)] - expected: FAIL - - [DOMStringList interface: operation contains(DOMString)] - expected: FAIL - [TextTrack interface: attribute inBandMetadataTrackDispatchType] expected: FAIL @@ -10709,24 +10655,5 @@ [SVGElement interface: attribute onformdata] expected: FAIL - [DOMStringList interface: calling item(unsigned long) on location.ancestorOrigins with too few arguments must throw TypeError] - expected: FAIL - - [DOMStringList interface: calling contains(DOMString) on location.ancestorOrigins with too few arguments must throw TypeError] - expected: FAIL - - [DOMStringList interface: location.ancestorOrigins must inherit property "contains(DOMString)" with the proper type] - expected: FAIL - [Stringification of location.ancestorOrigins] expected: FAIL - - [DOMStringList interface: location.ancestorOrigins must inherit property "item(unsigned long)" with the proper type] - expected: FAIL - - [DOMStringList must be primary interface of location.ancestorOrigins] - expected: FAIL - - [DOMStringList interface: location.ancestorOrigins must inherit property "length" with the proper type] - expected: FAIL - diff --git a/tests/wpt/metadata/html/dom/interfaces.worker.js.ini b/tests/wpt/metadata/html/dom/interfaces.worker.js.ini index 96a83788c9b..7babcdc0974 100644 --- a/tests/wpt/metadata/html/dom/interfaces.worker.js.ini +++ b/tests/wpt/metadata/html/dom/interfaces.worker.js.ini @@ -312,12 +312,6 @@ [MessagePort interface: attribute onmessageerror] expected: FAIL - [DOMStringList interface object length] - expected: FAIL - - [DOMStringList interface: operation item(unsigned long)] - expected: FAIL - [OffscreenCanvasRenderingContext2D interface: operation restore()] expected: FAIL @@ -381,9 +375,6 @@ [OffscreenCanvasRenderingContext2D interface: operation stroke(Path2D)] expected: FAIL - [DOMStringList interface: existence and properties of interface prototype object's "constructor" property] - expected: FAIL - [ImageBitmap interface: existence and properties of interface prototype object's @@unscopables property] expected: FAIL @@ -480,9 +471,6 @@ [OffscreenCanvasRenderingContext2D interface: operation setTransform(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double)] expected: FAIL - [DOMStringList interface: existence and properties of interface object] - expected: FAIL - [OffscreenCanvasRenderingContext2D interface object name] expected: FAIL @@ -537,15 +525,9 @@ [OffscreenCanvasRenderingContext2D interface: operation putImageData(ImageData, long, long, long, long, long, long)] expected: FAIL - [DOMStringList interface: existence and properties of interface prototype object's @@unscopables property] - expected: FAIL - [WorkerNavigator interface: member taintEnabled] expected: FAIL - [DOMStringList interface: operation contains(DOMString)] - expected: FAIL - [OffscreenCanvasRenderingContext2D interface: operation moveTo(unrestricted double, unrestricted double)] expected: FAIL @@ -579,9 +561,6 @@ [OffscreenCanvasRenderingContext2D interface: operation fill(Path2D, CanvasFillRule)] expected: FAIL - [DOMStringList interface: existence and properties of interface prototype object] - expected: FAIL - [OffscreenCanvasRenderingContext2D interface: operation createRadialGradient(double, double, double, double, double, double)] expected: FAIL @@ -591,18 +570,12 @@ [WorkerGlobalScope interface: self must inherit property "onunhandledrejection" with the proper type] expected: FAIL - [DOMStringList interface: attribute length] - expected: FAIL - [Path2D interface: operation ellipse(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, boolean)] expected: FAIL [MessageEvent interface: new MessageEvent("message", { data: 5 }) must inherit property "ports" with the proper type] expected: FAIL - [DOMStringList interface object name] - expected: FAIL - [OffscreenCanvasRenderingContext2D interface: operation isPointInStroke(Path2D, unrestricted double, unrestricted double)] expected: FAIL diff --git a/tests/wpt/metadata/html/infrastructure/common-dom-interfaces/collections/domstringlist-interface.html.ini b/tests/wpt/metadata/html/infrastructure/common-dom-interfaces/collections/domstringlist-interface.html.ini index e3241636027..d723cec933e 100644 --- a/tests/wpt/metadata/html/infrastructure/common-dom-interfaces/collections/domstringlist-interface.html.ini +++ b/tests/wpt/metadata/html/infrastructure/common-dom-interfaces/collections/domstringlist-interface.html.ini @@ -1,28 +1,5 @@ [domstringlist-interface.html] type: testharness - [DOMStringList interface: existence and properties of interface object] - expected: FAIL - - [DOMStringList interface object length] - expected: FAIL - - [DOMStringList interface object name] - expected: FAIL - - [DOMStringList interface: existence and properties of interface prototype object] - expected: FAIL - - [DOMStringList interface: existence and properties of interface prototype object's "constructor" property] - expected: FAIL - - [DOMStringList interface: attribute length] - expected: FAIL - - [DOMStringList interface: operation item(unsigned long)] - expected: FAIL - - [DOMStringList interface: operation contains(DOMString)] - expected: FAIL [DOMStringList must be primary interface of location.ancestorOrigins] expected: FAIL @@ -52,8 +29,4 @@ expected: FAIL [DOMStringList interface: location.ancestorOrigins must inherit property "contains(DOMString)" with the proper type] - expected: FAIL - - [DOMStringList interface: existence and properties of interface prototype object's @@unscopables property] - expected: FAIL - + expected: FAIL
\ No newline at end of file diff --git a/tests/wpt/metadata/html/infrastructure/common-dom-interfaces/collections/domstringlist-interface.worker.js.ini b/tests/wpt/metadata/html/infrastructure/common-dom-interfaces/collections/domstringlist-interface.worker.js.ini deleted file mode 100644 index 72ad8c9944b..00000000000 --- a/tests/wpt/metadata/html/infrastructure/common-dom-interfaces/collections/domstringlist-interface.worker.js.ini +++ /dev/null @@ -1,31 +0,0 @@ -[domstringlist-interface.worker.html] - type: testharness - [DOMStringList interface: existence and properties of interface object] - expected: FAIL - - [DOMStringList interface object length] - expected: FAIL - - [DOMStringList interface object name] - expected: FAIL - - [DOMStringList interface: existence and properties of interface prototype object] - expected: FAIL - - [DOMStringList interface: existence and properties of interface prototype object's "constructor" property] - expected: FAIL - - [DOMStringList interface: attribute length] - expected: FAIL - - [DOMStringList interface: operation item(unsigned long)] - expected: FAIL - - [DOMStringList interface: operation contains(DOMString)] - expected: FAIL - - [DOMStringList interface: existence and properties of interface prototype object's @@unscopables property] - expected: FAIL - - [Untitled] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index f1a55ead047..8748adcf4f7 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -18959,7 +18959,7 @@ "testharness" ], "mozilla/interfaces.html": [ - "f30dd3de4087a45476745c4a41dd6a5f7e9365e3", + "7aed97b42d8fe974ea489db66905d9fbc0edb84d", "testharness" ], "mozilla/interfaces.js": [ @@ -18967,7 +18967,7 @@ "support" ], "mozilla/interfaces.worker.js": [ - "d14b58eb87568f05c398ae6953d4a0c17943219b", + "802fe64ebfc86480f3c5adc80718f550d09d330b", "testharness" ], "mozilla/invalid-this.html": [ diff --git a/tests/wpt/mozilla/tests/mozilla/interfaces.html b/tests/wpt/mozilla/tests/mozilla/interfaces.html index f30dd3de408..7aed97b42d8 100644 --- a/tests/wpt/mozilla/tests/mozilla/interfaces.html +++ b/tests/wpt/mozilla/tests/mozilla/interfaces.html @@ -69,8 +69,9 @@ test_interfaces([ "DOMException", "DOMImplementation", "DOMParser", - "DOMTokenList", + "DOMStringList", "DOMStringMap", + "DOMTokenList", "Element", "ErrorEvent", "Event", diff --git a/tests/wpt/mozilla/tests/mozilla/interfaces.worker.js b/tests/wpt/mozilla/tests/mozilla/interfaces.worker.js index d14b58eb875..802fe64ebfc 100644 --- a/tests/wpt/mozilla/tests/mozilla/interfaces.worker.js +++ b/tests/wpt/mozilla/tests/mozilla/interfaces.worker.js @@ -18,6 +18,7 @@ test_interfaces([ "DOMQuad", "DOMRect", "DOMRectReadOnly", + "DOMStringList", "CustomEvent", "DedicatedWorkerGlobalScope", "DOMException", |