Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for Document, EventTarget, NodeList and Iterator #541

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/backend/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ impl ToTokens for ast::ImportType {
fn none() -> Self::Abi { 0 }
}

impl<'a> ::wasm_bindgen::convert::OptionIntoWasmAbi for &'a #name {
fn none() -> Self::Abi { 0 }
}

impl ::wasm_bindgen::convert::FromWasmAbi for #name {
type Abi = <::wasm_bindgen::JsValue as
::wasm_bindgen::convert::FromWasmAbi>::Abi;
Expand Down
81 changes: 75 additions & 6 deletions crates/backend/src/defined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ pub enum ImportedTypeKind {
Reference,
}

impl<T> ImportedTypes for Option<T>
where
T: ImportedTypes,
{
fn imported_types<F>(&self, f: &mut F)
where
F: FnMut(&Ident, ImportedTypeKind),
{
if let Some(inner) = self {
inner.imported_types(f);
}
}
}

/// Iterate over definitions of and references to imported types in the AST.
pub trait ImportedTypes {
fn imported_types<F>(&self, f: &mut F)
Expand Down Expand Up @@ -147,19 +161,74 @@ impl ImportedTypes for syn::TypePath {
where
F: FnMut(&Ident, ImportedTypeKind),
{
if self.qself.is_some()
|| self.path.leading_colon.is_some()
|| self.path.segments.len() != 1
{
return;
self.qself.imported_types(f);
self.path.imported_types(f);
}
}

impl ImportedTypes for syn::QSelf {
fn imported_types<F>(&self, _: &mut F)
where
F: FnMut(&Ident, ImportedTypeKind),
{
// TODO
}
}

impl ImportedTypes for syn::Path {
fn imported_types<F>(&self, f: &mut F)
where
F: FnMut(&Ident, ImportedTypeKind),
{
for seg in self.segments.iter() {
seg.arguments.imported_types(f);
}
f(
&self.path.segments.last().unwrap().value().ident,
&self.segments.last().unwrap().value().ident,
ImportedTypeKind::Reference,
);
}
}

impl ImportedTypes for syn::PathArguments {
fn imported_types<F>(&self, f: &mut F)
where
F: FnMut(&Ident, ImportedTypeKind),
{
match self {
syn::PathArguments::AngleBracketed(data) => {
for arg in data.args.iter() {
arg.imported_types(f);
}
}
//TOCHECK
syn::PathArguments::Parenthesized(data) => {
for input in data.inputs.iter() {
input.imported_types(f);
}
// TODO do we need to handle output here?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so yeah if you get a chance, makes sense to go ahead and add it here!

// https://docs.rs/syn/0.14.0/syn/struct.ParenthesizedGenericArguments.html
}
syn::PathArguments::None => {}
}
}
}

impl ImportedTypes for syn::GenericArgument {
fn imported_types<F>(&self, f: &mut F)
where
F: FnMut(&Ident, ImportedTypeKind),
{
match self {
syn::GenericArgument::Lifetime(_) => {}
syn::GenericArgument::Type(ty) => ty.imported_types(f),
syn::GenericArgument::Binding(_) => {}, // TODO
syn::GenericArgument::Const(_) => {}, // TODO
}
}
}


impl ImportedTypes for ast::ImportFunction {
fn imported_types<F>(&self, f: &mut F)
where
Expand Down
58 changes: 56 additions & 2 deletions crates/web-sys/tests/all/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ fn element() {

#[wasm_bindgen]
pub fn test_element(element: &web_sys::Element) {
assert_eq!(element.local_name(), "div", "Shouldn't have a div local name");
/* Tests needed for:
namespace_uri
*/
assert_eq!(element.prefix(), None, "Shouldn't have a prefix");
assert_eq!(element.local_name(), "div", "Should have a div local name");
assert_eq!(element.tag_name(), "div", "Should be a div tag");
assert!(!element.has_attribute("id"), "Shouldn't have an id");
element.set_id("beep");
Expand All @@ -27,7 +31,11 @@ fn element() {
assert_eq!(element.class_name(), "", "Shouldn't have a class name");
element.set_class_name("test thing");
assert_eq!(element.class_name(), "test thing", "Should have a class name");
assert_eq!(element.get_attribute("class").unwrap(), "test thing", "Should have a class name");
assert_eq!(element.remove_attribute("class").unwrap(), (), "Should return nothing if removed");
/* Tests needed for:
get_attribute_ns
*/

/*TODO should we enable toggle_attribute tests? (Firefox Nightly + Chrome canary only)
// TODO toggle_attribute should permit a single argument when optional arguments are supported
Expand All @@ -44,11 +52,19 @@ fn element() {
// TODO check get_attribute here when supported
assert_eq!(element.remove_attribute("title").unwrap(), (), "Should return nothing if removed");
assert!(!element.has_attribute("title"), "Should not have a title");
/* Tests needed for:
set_attribute_ns
*/

assert!(!element.has_attributes(), "Should not have any attributes");
assert_eq!(element.set_attribute("title", "boop").unwrap(), (), "Should return nothing if set correctly");
assert!(element.has_attributes(), "Should have attributes");
assert_eq!(element.remove_attribute("title").unwrap(), (), "Should return nothing if removed");
/* Tests needed for:
remove_attribute_ns
has_attribure_ns
closest
*/

assert_eq!(element.matches(".this-is-a-thing").unwrap(), false, "Should not match selector");
assert_eq!(element.webkit_matches_selector(".this-is-a-thing").unwrap(), false, "Should not match selector");
Expand All @@ -57,15 +73,53 @@ fn element() {
assert_eq!(element.webkit_matches_selector(".this-is-a-thing").unwrap(), true, "Should match selector");
assert_eq!(element.remove_attribute("class").unwrap(), (), "Should return nothing if removed");


// TODO non standard moz_matches_selector should we even support?

/* Tests needed for:
insert_adjacent_element
insert_adjacent_text
set_pointer_capture
release_pointer_capture
has_pointer_capture
set_capture
release_capture
scroll_top
set_scroll_top
scroll_left
set_scroll_left
scroll_width
scroll_height
scroll,
scroll_to
scroll_by
client_top
client_left
client_width
client_height
scroll_top_max
scroll_left_max
*/
assert_eq!(element.inner_html(), "", "Should return no content");
element.set_inner_html("<strong>Hey!</strong><em>Web!</em>");
assert_eq!(element.inner_html(), "<strong>Hey!</strong><em>Web!</em>", "Should return HTML conent");
assert_eq!(element.query_selector_all("strong").unwrap().length(), 1, "Should return one element");
assert!(element.query_selector("strong").unwrap().is_some(), "Should return an element");
element.set_inner_html("");
assert_eq!(element.inner_html(), "", "Should return no content");

/* Tests needed for:
outer_html
set_outer_html
insert_adjacent_html
*/

assert!(element.query_selector(".none-existant").unwrap().is_none(), "Should return no results");
assert_eq!(element.query_selector_all(".none-existant").unwrap().length(), 0, "Should return no results");
/* Tests needed for:
slot
set_slot
request_fullscreen
request_pointer_lock
*/
}
"#,
Expand Down
Loading