Skip to content

Commit 4b4bed5

Browse files
jonathanKingstonalexcrichton
authored andcommitted
Initial support for Document, EventTarget, NodeList and Iterator (#541)
* Adding document and node support * Initial support for Document, EventTarget, NodeList and Iterator * Add in support for output option type
1 parent 15d0fcf commit 4b4bed5

File tree

9 files changed

+229
-14
lines changed

9 files changed

+229
-14
lines changed

crates/backend/src/codegen.rs

+4
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,10 @@ impl ToTokens for ast::ImportType {
517517
fn none() -> Self::Abi { 0 }
518518
}
519519

520+
impl<'a> ::wasm_bindgen::convert::OptionIntoWasmAbi for &'a #name {
521+
fn none() -> Self::Abi { 0 }
522+
}
523+
520524
impl ::wasm_bindgen::convert::FromWasmAbi for #name {
521525
type Abi = <::wasm_bindgen::JsValue as
522526
::wasm_bindgen::convert::FromWasmAbi>::Abi;

crates/backend/src/defined.rs

+75-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ pub enum ImportedTypeKind {
1010
Reference,
1111
}
1212

13+
impl<T> ImportedTypes for Option<T>
14+
where
15+
T: ImportedTypes,
16+
{
17+
fn imported_types<F>(&self, f: &mut F)
18+
where
19+
F: FnMut(&Ident, ImportedTypeKind),
20+
{
21+
if let Some(inner) = self {
22+
inner.imported_types(f);
23+
}
24+
}
25+
}
26+
1327
/// Iterate over definitions of and references to imported types in the AST.
1428
pub trait ImportedTypes {
1529
fn imported_types<F>(&self, f: &mut F)
@@ -147,19 +161,74 @@ impl ImportedTypes for syn::TypePath {
147161
where
148162
F: FnMut(&Ident, ImportedTypeKind),
149163
{
150-
if self.qself.is_some()
151-
|| self.path.leading_colon.is_some()
152-
|| self.path.segments.len() != 1
153-
{
154-
return;
164+
self.qself.imported_types(f);
165+
self.path.imported_types(f);
166+
}
167+
}
168+
169+
impl ImportedTypes for syn::QSelf {
170+
fn imported_types<F>(&self, _: &mut F)
171+
where
172+
F: FnMut(&Ident, ImportedTypeKind),
173+
{
174+
// TODO
175+
}
176+
}
177+
178+
impl ImportedTypes for syn::Path {
179+
fn imported_types<F>(&self, f: &mut F)
180+
where
181+
F: FnMut(&Ident, ImportedTypeKind),
182+
{
183+
for seg in self.segments.iter() {
184+
seg.arguments.imported_types(f);
155185
}
156186
f(
157-
&self.path.segments.last().unwrap().value().ident,
187+
&self.segments.last().unwrap().value().ident,
158188
ImportedTypeKind::Reference,
159189
);
160190
}
161191
}
162192

193+
impl ImportedTypes for syn::PathArguments {
194+
fn imported_types<F>(&self, f: &mut F)
195+
where
196+
F: FnMut(&Ident, ImportedTypeKind),
197+
{
198+
match self {
199+
syn::PathArguments::AngleBracketed(data) => {
200+
for arg in data.args.iter() {
201+
arg.imported_types(f);
202+
}
203+
}
204+
//TOCHECK
205+
syn::PathArguments::Parenthesized(data) => {
206+
for input in data.inputs.iter() {
207+
input.imported_types(f);
208+
}
209+
// TODO do we need to handle output here?
210+
// https://docs.rs/syn/0.14.0/syn/struct.ParenthesizedGenericArguments.html
211+
}
212+
syn::PathArguments::None => {}
213+
}
214+
}
215+
}
216+
217+
impl ImportedTypes for syn::GenericArgument {
218+
fn imported_types<F>(&self, f: &mut F)
219+
where
220+
F: FnMut(&Ident, ImportedTypeKind),
221+
{
222+
match self {
223+
syn::GenericArgument::Lifetime(_) => {}
224+
syn::GenericArgument::Type(ty) => ty.imported_types(f),
225+
syn::GenericArgument::Binding(_) => {}, // TODO
226+
syn::GenericArgument::Const(_) => {}, // TODO
227+
}
228+
}
229+
}
230+
231+
163232
impl ImportedTypes for ast::ImportFunction {
164233
fn imported_types<F>(&self, f: &mut F)
165234
where

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

+56-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ fn element() {
1313
1414
#[wasm_bindgen]
1515
pub fn test_element(element: &web_sys::Element) {
16-
assert_eq!(element.local_name(), "div", "Shouldn't have a div local name");
16+
/* Tests needed for:
17+
namespace_uri
18+
*/
19+
assert_eq!(element.prefix(), None, "Shouldn't have a prefix");
20+
assert_eq!(element.local_name(), "div", "Should have a div local name");
1721
assert_eq!(element.tag_name(), "div", "Should be a div tag");
1822
assert!(!element.has_attribute("id"), "Shouldn't have an id");
1923
element.set_id("beep");
@@ -27,7 +31,11 @@ fn element() {
2731
assert_eq!(element.class_name(), "", "Shouldn't have a class name");
2832
element.set_class_name("test thing");
2933
assert_eq!(element.class_name(), "test thing", "Should have a class name");
34+
assert_eq!(element.get_attribute("class").unwrap(), "test thing", "Should have a class name");
3035
assert_eq!(element.remove_attribute("class").unwrap(), (), "Should return nothing if removed");
36+
/* Tests needed for:
37+
get_attribute_ns
38+
*/
3139
3240
/*TODO should we enable toggle_attribute tests? (Firefox Nightly + Chrome canary only)
3341
// TODO toggle_attribute should permit a single argument when optional arguments are supported
@@ -44,11 +52,19 @@ fn element() {
4452
// TODO check get_attribute here when supported
4553
assert_eq!(element.remove_attribute("title").unwrap(), (), "Should return nothing if removed");
4654
assert!(!element.has_attribute("title"), "Should not have a title");
55+
/* Tests needed for:
56+
set_attribute_ns
57+
*/
4758
4859
assert!(!element.has_attributes(), "Should not have any attributes");
4960
assert_eq!(element.set_attribute("title", "boop").unwrap(), (), "Should return nothing if set correctly");
5061
assert!(element.has_attributes(), "Should have attributes");
5162
assert_eq!(element.remove_attribute("title").unwrap(), (), "Should return nothing if removed");
63+
/* Tests needed for:
64+
remove_attribute_ns
65+
has_attribure_ns
66+
closest
67+
*/
5268
5369
assert_eq!(element.matches(".this-is-a-thing").unwrap(), false, "Should not match selector");
5470
assert_eq!(element.webkit_matches_selector(".this-is-a-thing").unwrap(), false, "Should not match selector");
@@ -57,15 +73,53 @@ fn element() {
5773
assert_eq!(element.webkit_matches_selector(".this-is-a-thing").unwrap(), true, "Should match selector");
5874
assert_eq!(element.remove_attribute("class").unwrap(), (), "Should return nothing if removed");
5975
60-
6176
// TODO non standard moz_matches_selector should we even support?
77+
6278
/* Tests needed for:
79+
insert_adjacent_element
6380
insert_adjacent_text
6481
set_pointer_capture
6582
release_pointer_capture
6683
has_pointer_capture
6784
set_capture
6885
release_capture
86+
scroll_top
87+
set_scroll_top
88+
scroll_left
89+
set_scroll_left
90+
scroll_width
91+
scroll_height
92+
scroll,
93+
scroll_to
94+
scroll_by
95+
client_top
96+
client_left
97+
client_width
98+
client_height
99+
scroll_top_max
100+
scroll_left_max
101+
*/
102+
assert_eq!(element.inner_html(), "", "Should return no content");
103+
element.set_inner_html("<strong>Hey!</strong><em>Web!</em>");
104+
assert_eq!(element.inner_html(), "<strong>Hey!</strong><em>Web!</em>", "Should return HTML conent");
105+
assert_eq!(element.query_selector_all("strong").unwrap().length(), 1, "Should return one element");
106+
assert!(element.query_selector("strong").unwrap().is_some(), "Should return an element");
107+
element.set_inner_html("");
108+
assert_eq!(element.inner_html(), "", "Should return no content");
109+
110+
/* Tests needed for:
111+
outer_html
112+
set_outer_html
113+
insert_adjacent_html
114+
*/
115+
116+
assert!(element.query_selector(".none-existant").unwrap().is_none(), "Should return no results");
117+
assert_eq!(element.query_selector_all(".none-existant").unwrap().length(), 0, "Should return no results");
118+
/* Tests needed for:
119+
slot
120+
set_slot
121+
request_fullscreen
122+
request_pointer_lock
69123
*/
70124
}
71125
"#,

0 commit comments

Comments
 (0)