Run rustfmt

This commit is contained in:
Alex Crichton 2019-10-28 20:15:05 -07:00
parent a20dd26dde
commit 513285f73d
13 changed files with 100 additions and 69 deletions

View File

@ -456,10 +456,7 @@ impl TryToTokens for ast::Export {
},
)
} else {
(
quote! { #syn_ret },
quote! { #ret },
)
(quote! { #syn_ret }, quote! { #ret })
};
let projection = quote! { <#ret_ty as wasm_bindgen::convert::ReturnWasmAbi> };
let convert_ret = quote! { #projection::return_abi(#ret_expr) };

View File

@ -198,7 +198,7 @@ fn shared_function<'a>(func: &'a ast::Function, _intern: &'a Interner) -> Functi
.enumerate()
.map(|(idx, arg)| {
if let syn::Pat::Ident(x) = &*arg.pat {
return x.ident.to_string()
return x.ident.to_string();
}
format!("arg{}", idx)
})

View File

@ -520,9 +520,7 @@ fn check_standard_import(import: &AuxImport) -> Result<(), Error> {
| AuxImport::Value(AuxValue::ClassSetter(js, name)) => {
format!("field access of `{}` for {}", name, desc_js(js))
}
AuxImport::ValueWithThis(js, method) => {
format!("method `{}.{}`", desc_js(js), method)
}
AuxImport::ValueWithThis(js, method) => format!("method `{}.{}`", desc_js(js), method),
AuxImport::Instanceof(js) => format!("instance of check of {}", desc_js(js)),
AuxImport::Static(js) => format!("static js value {}", desc_js(js)),
AuxImport::StructuralMethod(name) => format!("structural method `{}`", name),

View File

@ -29,45 +29,37 @@ fn to_rust(arr: &Array) -> Vec<JsValue> {
#[wasm_bindgen_test]
fn from_iter() {
assert_eq!(
to_rust(&vec![
JsValue::from("a"),
JsValue::from("b"),
JsValue::from("c"),
].into_iter().collect()),
to_rust(
&vec![JsValue::from("a"), JsValue::from("b"), JsValue::from("c"),]
.into_iter()
.collect()
),
vec!["a", "b", "c"],
);
assert_eq!(
to_rust(&vec![
JsValue::from("a"),
JsValue::from("b"),
JsValue::from("c"),
].iter().collect()),
to_rust(
&vec![JsValue::from("a"), JsValue::from("b"), JsValue::from("c"),]
.iter()
.collect()
),
vec!["a", "b", "c"],
);
let array = js_array![1u32, 2u32, 3u32];
assert_eq!(
to_rust(&vec![
array.clone(),
].into_iter().collect()),
to_rust(&vec![array.clone(),].into_iter().collect()),
vec![JsValue::from(array.clone())],
);
assert_eq!(
to_rust(&vec![
array.clone(),
].iter().collect()),
to_rust(&vec![array.clone(),].iter().collect()),
vec![JsValue::from(array)],
);
assert_eq!(
to_rust(&vec![
5,
10,
20,
].into_iter().map(JsValue::from).collect()),
to_rust(&vec![5, 10, 20,].into_iter().map(JsValue::from).collect()),
vec![5, 10, 20],
);
@ -80,11 +72,7 @@ fn from_iter() {
vec!["a", "b", "c"],
);
let v = vec![
"a",
"b",
"c",
];
let v = vec!["a", "b", "c"];
assert_eq!(
to_rust(&Array::from_iter(v.into_iter().map(|s| JsValue::from(s)))),

View File

@ -1019,18 +1019,16 @@ impl MacroParse<()> for syn::ItemEnum {
attrs: _,
lit: syn::Lit::Int(int_lit),
}),
)) => {
match int_lit.base10_digits().parse::<u32>() {
Ok(v) => v,
Err(_) => {
bail_span!(
int_lit,
"enums with #[wasm_bindgen] can only support \
numbers that can be represented as u32"
);
}
)) => match int_lit.base10_digits().parse::<u32>() {
Ok(v) => v,
Err(_) => {
bail_span!(
int_lit,
"enums with #[wasm_bindgen] can only support \
numbers that can be represented as u32"
);
}
}
},
None => i as u32,
Some((_, expr)) => bail_span!(
expr,

View File

@ -1,9 +1,9 @@
use js_sys::Promise;
use std::task::{Poll, Context};
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::Duration;
use wasm_bindgen::prelude::*;
use std::future::Future;
use wasm_bindgen_futures::JsFuture;
pub struct Timeout {

View File

@ -1,5 +1,5 @@
use std::time::Duration;
use sample::Timeout;
use std::time::Duration;
use wasm_bindgen_test::*;
#[wasm_bindgen_test]

View File

@ -33,20 +33,58 @@ fn test_html_element() {
element.set_hidden(true);
assert!(element.hidden(), "Should be hidden");
assert_eq!(element.class_list().get(0), None, "Shouldn't have class at index 0");
assert_eq!(
element.class_list().get(0),
None,
"Shouldn't have class at index 0"
);
element.class_list().add_2("a", "b").unwrap();
assert_eq!(element.class_list().get(0).unwrap(), "a", "Should have class at index 0");
assert_eq!(element.class_list().get(1).unwrap(), "b", "Should have class at index 1");
assert_eq!(element.class_list().get(2), None, "Shouldn't have class at index 2");
assert_eq!(
element.class_list().get(0).unwrap(),
"a",
"Should have class at index 0"
);
assert_eq!(
element.class_list().get(1).unwrap(),
"b",
"Should have class at index 1"
);
assert_eq!(
element.class_list().get(2),
None,
"Shouldn't have class at index 2"
);
assert_eq!(element.dataset().get("id"), None, "Shouldn't have data-id");
element.dataset().set("id", "123").unwrap();
assert_eq!(element.dataset().get("id").unwrap(), "123", "Should have data-id");
assert_eq!(
element.dataset().get("id").unwrap(),
"123",
"Should have data-id"
);
assert_eq!(element.style().get(0), None, "Shouldn't have style property name at index 0");
element.style().set_property("background-color", "red").unwrap();
assert_eq!(element.style().get(0).unwrap(), "background-color", "Should have style property at index 0");
assert_eq!(element.style().get_property_value("background-color").unwrap(), "red", "Should have style property");
assert_eq!(
element.style().get(0),
None,
"Shouldn't have style property name at index 0"
);
element
.style()
.set_property("background-color", "red")
.unwrap();
assert_eq!(
element.style().get(0).unwrap(),
"background-color",
"Should have style property at index 0"
);
assert_eq!(
element
.style()
.get_property_value("background-color")
.unwrap(),
"red",
"Should have style property"
);
// TODO add a click handler here
element.click();

View File

@ -62,11 +62,19 @@ async fn exchange_sdps(
) -> (RtcPeerConnection, RtcPeerConnection) {
let offer = JsFuture::from(p1.create_offer()).await.unwrap();
let offer = offer.unchecked_into::<RtcSessionDescriptionInit>();
JsFuture::from(p1.set_local_description(&offer)).await.unwrap();
JsFuture::from(p2.set_remote_description(&offer)).await.unwrap();
JsFuture::from(p1.set_local_description(&offer))
.await
.unwrap();
JsFuture::from(p2.set_remote_description(&offer))
.await
.unwrap();
let answer = JsFuture::from(p2.create_answer()).await.unwrap();
let answer = answer.unchecked_into::<RtcSessionDescriptionInit>();
JsFuture::from(p2.set_local_description(&answer)).await.unwrap();
JsFuture::from(p1.set_remote_description(&answer)).await.unwrap();
JsFuture::from(p2.set_local_description(&answer))
.await
.unwrap();
JsFuture::from(p1.set_remote_description(&answer))
.await
.unwrap();
(p1, p2)
}

View File

@ -585,11 +585,13 @@ impl<'src> FirstPassRecord<'src> {
// otherwise be marked with catch).
match ret_ty {
IdlType::Nullable(_) => ret_ty,
ref ty @ _ => if catch {
ret_ty
} else {
IdlType::Nullable(Box::new(ty.clone()))
},
ref ty @ _ => {
if catch {
ret_ty
} else {
IdlType::Nullable(Box::new(ty.clone()))
}
}
}
} else {
ret_ty

View File

@ -820,9 +820,9 @@ pub fn function_table() -> JsValue {
#[doc(hidden)]
pub mod __rt {
use crate::JsValue;
use core::cell::{Cell, UnsafeCell};
use core::ops::{Deref, DerefMut};
use crate::JsValue;
pub extern crate core;
#[cfg(feature = "std")]

View File

@ -8,7 +8,9 @@ extern "C" {
#[wasm_bindgen_test]
async fn smoke() {
wasm_bindgen_futures::JsFuture::from(call_exports()).await.unwrap();
wasm_bindgen_futures::JsFuture::from(call_exports())
.await
.unwrap();
}
#[wasm_bindgen]

View File

@ -1,5 +1,5 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen::{JsCast, intern, unintern};
use wasm_bindgen::{intern, unintern, JsCast};
use wasm_bindgen_test::*;
#[wasm_bindgen(module = "tests/wasm/simple.js")]