Skip to content

Commit 84b5a31

Browse files
Initial support for Document, EventTarget, NodeList and Iterator
1 parent c786ec1 commit 84b5a31

File tree

6 files changed

+95
-10
lines changed

6 files changed

+95
-10
lines changed

crates/web-sys/tests/all/element.rs

+41-1
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,62 @@ fn element() {
5050
assert!(element.has_attributes(), "Should have attributes");
5151
assert_eq!(element.remove_attribute("title").unwrap(), (), "Should return nothing if removed");
5252
53+
// closest
54+
5355
assert_eq!(element.matches(".this-is-a-thing").unwrap(), false, "Should not match selector");
5456
assert_eq!(element.webkit_matches_selector(".this-is-a-thing").unwrap(), false, "Should not match selector");
5557
element.set_class_name("this-is-a-thing");
5658
assert_eq!(element.matches(".this-is-a-thing").unwrap(), true, "Should match selector");
5759
assert_eq!(element.webkit_matches_selector(".this-is-a-thing").unwrap(), true, "Should match selector");
5860
assert_eq!(element.remove_attribute("class").unwrap(), (), "Should return nothing if removed");
5961
60-
6162
// TODO non standard moz_matches_selector should we even support?
63+
6264
/* Tests needed for:
65+
insert_adjacent_element
6366
insert_adjacent_text
6467
set_pointer_capture
6568
release_pointer_capture
6669
has_pointer_capture
6770
set_capture
6871
release_capture
72+
scroll_top
73+
set_scroll_top
74+
scroll_left
75+
set_scroll_left
76+
scroll_width
77+
scroll_height
78+
scroll,
79+
scroll_to
80+
scroll_by
81+
client_top
82+
client_left
83+
client_width
84+
client_height
85+
scroll_top_max
86+
scroll_left_max
87+
*/
88+
assert_eq!(element.inner_html(), "", "Should return no content");
89+
element.set_inner_html("<strong>Hey!</strong><em>Web!</em>");
90+
assert_eq!(element.inner_html(), "<strong>Hey!</strong><em>Web!</em>", "Should return HTML conent");
91+
assert_eq!(element.query_selector_all("strong").unwrap().length(), 1, "Should return one element");
92+
assert!(element.query_selector("strong").unwrap().is_some(), "Should return an element");
93+
element.set_inner_html("");
94+
assert_eq!(element.inner_html(), "", "Should return no content");
95+
96+
/* Tests needed for:
97+
outer_html
98+
set_outer_html
99+
insert_adjacent_html
100+
*/
101+
102+
assert!(element.query_selector(".none-existant").unwrap().is_none(), "Should return no results");
103+
assert_eq!(element.query_selector_all(".none-existant").unwrap().length(), 0, "Should return no results");
104+
/* Tests needed for:
105+
slot
106+
set_slot
107+
request_fullscreen
108+
request_pointer_lock
69109
*/
70110
}
71111
"#,

crates/web-sys/webidls/enabled/Document.webidl

+5-4
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,9 @@ partial interface Document {
147147
[SameObject] readonly attribute HTMLCollection links;
148148
[SameObject] readonly attribute HTMLCollection forms;
149149
[SameObject] readonly attribute HTMLCollection scripts;
150-
/*TODO
151150
[Pure]
152151
NodeList getElementsByName(DOMString elementName);
153-
*/
152+
154153
//(Not implemented)readonly attribute DOMElementMap cssElementMap;
155154

156155
// dynamic markup insertion
@@ -341,10 +340,8 @@ partial interface Document {
341340
partial interface Document {
342341
[Throws, Pure]
343342
Element? querySelector(DOMString selectors);
344-
/*TODO
345343
[Throws, Pure]
346344
NodeList querySelectorAll(DOMString selectors);
347-
*/
348345

349346
//(Not implemented)Element? find(DOMString selectors, optional (Element or sequence<Node>)? refNodes);
350347
//(Not implemented)NodeList findAll(DOMString selectors, optional (Element or sequence<Node>)? refNodes);
@@ -406,10 +403,12 @@ partial interface Document {
406403
// XXXbz and another hack for the fact that we can't usefully have optional
407404
// distinguishing arguments but need a working zero-arg form of
408405
// createTouchList().
406+
/*TODO
409407
[NewObject, Func="nsGenericHTMLElement::TouchEventsEnabled"]
410408
TouchList createTouchList();
411409
[NewObject, Func="nsGenericHTMLElement::TouchEventsEnabled"]
412410
TouchList createTouchList(sequence<Touch> touches);
411+
*/
413412

414413
[ChromeOnly]
415414
attribute boolean styleSheetChangeEventsEnabled;
@@ -489,8 +488,10 @@ partial interface Document {
489488

490489
// http://w3c.github.io/selection-api/#extensions-to-document-interface
491490
partial interface Document {
491+
/*TODO
492492
[Throws]
493493
Selection? getSelection();
494+
*/
494495
};
495496

496497
// Extension to give chrome JS the ability to determine whether

crates/web-sys/webidls/enabled/Element.webidl

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ interface Element : Node {
2929
attribute DOMString id;
3030
[CEReactions, Pure]
3131
attribute DOMString className;
32+
/*TODO
3233
[Constant, PutForwards=value]
3334
readonly attribute DOMTokenList classList;
35+
*/
3436

3537
[SameObject]
3638
readonly attribute NamedNodeMap attributes;
@@ -248,10 +250,8 @@ partial interface Element {
248250
partial interface Element {
249251
[Throws, Pure]
250252
Element? querySelector(DOMString selectors);
251-
/*TODO
252253
[Throws, Pure]
253254
NodeList querySelectorAll(DOMString selectors);
254-
*/
255255
};
256256

257257
// https://dom.spec.whatwg.org/#dictdef-shadowrootinit

crates/webidl/src/lib.rs

+47-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ mod util;
2727
use std::collections::BTreeSet;
2828
use std::fs;
2929
use std::io::{self, Read};
30-
use std::iter::FromIterator;
30+
use std::iter::{self, FromIterator};
3131
use std::path::Path;
3232

3333
use backend::defined::{ImportedTypeDefinitions, RemoveUndefinedImports};
34-
use backend::util::{ident_ty, rust_ident, wrap_import_function};
34+
use backend::util::{ident_ty, raw_ident, rust_ident, wrap_import_function};
3535
use failure::ResultExt;
3636
use heck::{CamelCase, ShoutySnakeCase};
3737
use quote::ToTokens;
@@ -401,8 +401,10 @@ impl<'a> WebidlParse<&'a str> for webidl::ast::InterfaceMember {
401401
webidl::ast::InterfaceMember::Const(cnst) => {
402402
cnst.webidl_parse(program, first_pass, self_name)
403403
}
404+
webidl::ast::InterfaceMember::Iterable(iterable) => {
405+
iterable.webidl_parse(program, first_pass, self_name)
406+
}
404407
// TODO
405-
webidl::ast::InterfaceMember::Iterable(_)
406408
| webidl::ast::InterfaceMember::Maplike(_)
407409
| webidl::ast::InterfaceMember::Setlike(_) => {
408410
warn!("Unsupported WebIDL interface member: {:?}", self);
@@ -520,6 +522,48 @@ impl<'a> WebidlParse<&'a str> for webidl::ast::RegularAttribute {
520522
}
521523
}
522524

525+
impl<'a> WebidlParse<&'a str> for webidl::ast::Iterable {
526+
fn webidl_parse(
527+
&self,
528+
program: &mut backend::ast::Program,
529+
first_pass: &FirstPassRecord<'_>,
530+
self_name: &'a str,
531+
) -> Result<()> {
532+
if util::is_chrome_only(&self.extended_attributes) {
533+
return Ok(());
534+
}
535+
536+
let throws = util::throws(&self.extended_attributes);
537+
let return_value = webidl::ast::ReturnType::NonVoid(self.value_type.clone());
538+
let args = [];
539+
first_pass
540+
.create_basic_method(
541+
&args,
542+
Some(&"values".to_string()),
543+
&return_value,
544+
self_name,
545+
false,
546+
true, // Should be false
547+
)
548+
.map(wrap_import_function)
549+
.map(|import| program.imports.push(import));
550+
551+
first_pass
552+
.create_basic_method(
553+
&args,
554+
Some(&"item".to_string()),
555+
&return_value,
556+
self_name,
557+
false,
558+
true, // Should be false
559+
)
560+
.map(wrap_import_function)
561+
.map(|import| program.imports.push(import));
562+
563+
Ok(())
564+
}
565+
}
566+
523567
impl<'a> WebidlParse<&'a str> for webidl::ast::StaticAttribute {
524568
fn webidl_parse(
525569
&self,

0 commit comments

Comments
 (0)