Js sys use &str arguments (#555)

* js-sys: imports should take &str parameters instead of &JsString

* js-sys: Imports should take Option<&str> instead of Option<String>
This commit is contained in:
Nick Fitzgerald 2018-07-25 16:50:30 -07:00 committed by Alex Crichton
parent 19acb5bb72
commit 64591ef403
7 changed files with 83 additions and 83 deletions

View File

@ -583,7 +583,7 @@ extern "C" {
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
#[wasm_bindgen(constructor)] #[wasm_bindgen(constructor)]
pub fn new(message: &JsString) -> Error; pub fn new(message: &str) -> Error;
/// The message property is a human-readable description of the error. /// The message property is a human-readable description of the error.
/// ///
@ -591,7 +591,7 @@ extern "C" {
#[wasm_bindgen(method, getter, structural)] #[wasm_bindgen(method, getter, structural)]
pub fn message(this: &Error) -> JsString; pub fn message(this: &Error) -> JsString;
#[wasm_bindgen(method, setter, structural)] #[wasm_bindgen(method, setter, structural)]
pub fn set_message(this: &Error, message: &JsString); pub fn set_message(this: &Error, message: &str);
/// The name property represents a name for the type of error. The initial value is "Error". /// The name property represents a name for the type of error. The initial value is "Error".
/// ///
@ -599,7 +599,7 @@ extern "C" {
#[wasm_bindgen(method, getter, structural)] #[wasm_bindgen(method, getter, structural)]
pub fn name(this: &Error) -> JsString; pub fn name(this: &Error) -> JsString;
#[wasm_bindgen(method, setter, structural)] #[wasm_bindgen(method, setter, structural)]
pub fn set_name(this: &Error, name: &JsString); pub fn set_name(this: &Error, name: &str);
/// The toString() method returns a string representing the specified Error object /// The toString() method returns a string representing the specified Error object
/// ///
@ -1530,7 +1530,7 @@ extern "C" {
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
#[wasm_bindgen(static_method_of = Date)] #[wasm_bindgen(static_method_of = Date)]
pub fn parse(date: &JsString) -> f64; pub fn parse(date: &str) -> f64;
/// The setDate() method sets the day of the Date object relative to the beginning of the currently set month. /// The setDate() method sets the day of the Date object relative to the beginning of the currently set month.
/// ///
@ -1662,7 +1662,7 @@ extern "C" {
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
#[wasm_bindgen(method, js_name = toLocaleDateString)] #[wasm_bindgen(method, js_name = toLocaleDateString)]
pub fn to_locale_date_string(this: &Date, locale: &JsString, options: &JsValue) -> JsString; pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
/// The toLocaleString() method returns a string with a language sensitive /// The toLocaleString() method returns a string with a language sensitive
/// representation of this date. The new locales and options arguments /// representation of this date. The new locales and options arguments
@ -1674,7 +1674,7 @@ extern "C" {
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
#[wasm_bindgen(method, js_name = toLocaleString)] #[wasm_bindgen(method, js_name = toLocaleString)]
pub fn to_locale_string(this: &Date, locale: &JsString, options: &JsValue) -> JsString; pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
/// The toLocaleTimeString() method returns a string with a language sensitive /// The toLocaleTimeString() method returns a string with a language sensitive
/// representation of the time portion of this date. The new locales and options /// representation of the time portion of this date. The new locales and options
@ -1685,7 +1685,7 @@ extern "C" {
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString
#[wasm_bindgen(method, js_name = toLocaleTimeString)] #[wasm_bindgen(method, js_name = toLocaleTimeString)]
pub fn to_locale_time_string(this: &Date, locale: &JsString) -> JsString; pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
/// The toString() method returns a string representing /// The toString() method returns a string representing
/// the specified Date object. /// the specified Date object.
@ -2449,14 +2449,14 @@ extern "C" {
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
#[wasm_bindgen(method, js_class = "String", js_name = endsWith)] #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
pub fn ends_with(this: &JsString, search_string: &JsString, length: i32) -> bool; pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
/// The `includes()` method determines whether one string may be found /// The `includes()` method determines whether one string may be found
/// within another string, returning true or false as appropriate. /// within another string, returning true or false as appropriate.
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
#[wasm_bindgen(method, js_class = "String")] #[wasm_bindgen(method, js_class = "String")]
pub fn includes(this: &JsString, search_string: &JsString, position: i32) -> bool; pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
/// The `indexOf()` method returns the index within the calling String /// The `indexOf()` method returns the index within the calling String
/// object of the first occurrence of the specified value, starting the /// object of the first occurrence of the specified value, starting the
@ -2464,7 +2464,7 @@ extern "C" {
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
#[wasm_bindgen(method, js_class = "String", js_name = indexOf)] #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
pub fn index_of(this: &JsString, search_value: &JsString, from_index: i32) -> i32; pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
/// The `lastIndexOf()` method returns the index within the calling String /// The `lastIndexOf()` method returns the index within the calling String
/// object of the last occurrence of the specified value, searching /// object of the last occurrence of the specified value, searching
@ -2472,14 +2472,14 @@ extern "C" {
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf
#[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)] #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
pub fn last_index_of(this: &JsString, search_value: &JsString, from_index: i32) -> i32; pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
/// The normalize() method returns the Unicode Normalization Form /// The normalize() method returns the Unicode Normalization Form
/// of a given string (if the value isn't a string, it will be converted to one first). /// of a given string (if the value isn't a string, it will be converted to one first).
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
#[wasm_bindgen(method, js_class = "String")] #[wasm_bindgen(method, js_class = "String")]
pub fn normalize(this: &JsString, form: &JsString) -> JsString; pub fn normalize(this: &JsString, form: &str) -> JsString;
/// The `padEnd()` method pads the current string with a given string /// The `padEnd()` method pads the current string with a given string
/// (repeated, if needed) so that the resulting string reaches a given /// (repeated, if needed) so that the resulting string reaches a given
@ -2488,7 +2488,7 @@ extern "C" {
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd
#[wasm_bindgen(method, js_class = "String", js_name = padEnd)] #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
pub fn pad_end(this: &JsString, target_length: u32, pad_string: &JsString) -> JsString; pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
/// The `padStart()` method pads the current string with another string /// The `padStart()` method pads the current string with another string
/// (repeated, if needed) so that the resulting string reaches the given /// (repeated, if needed) so that the resulting string reaches the given
@ -2497,7 +2497,7 @@ extern "C" {
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
#[wasm_bindgen(method, js_class = "String", js_name = padStart)] #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
pub fn pad_start(this: &JsString, target_length: u32, pad_string: &JsString) -> JsString; pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
/// The repeat() method constructs and returns a new string which contains the specified /// The repeat() method constructs and returns a new string which contains the specified
/// number of copies of the string on which it was called, concatenated together. /// number of copies of the string on which it was called, concatenated together.
@ -2519,7 +2519,7 @@ extern "C" {
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
#[wasm_bindgen(method, js_class = "String", js_name = startsWith)] #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
pub fn starts_with(this: &JsString, search_string: &JsString, position: u32) -> bool; pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
/// The `substring()` method returns the part of the string between the /// The `substring()` method returns the part of the string between the
/// start and end indexes, or to the end of the string. /// start and end indexes, or to the end of the string.
@ -2540,14 +2540,14 @@ extern "C" {
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase
#[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)] #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
pub fn to_locale_lower_case(this: &JsString, local: Option<String>) -> JsString; pub fn to_locale_lower_case(this: &JsString, local: Option<&str>) -> JsString;
/// The toLocaleUpperCase() method returns the calling string value converted to upper case, /// The toLocaleUpperCase() method returns the calling string value converted to upper case,
/// according to any locale-specific case mappings. /// according to any locale-specific case mappings.
/// ///
/// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase /// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase
#[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)] #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
pub fn to_locale_upper_case(this: &JsString, local: Option<String>) -> JsString; pub fn to_locale_upper_case(this: &JsString, local: Option<&str>) -> JsString;
/// The `toLowerCase()` method returns the calling string value /// The `toLowerCase()` method returns the calling string value
/// converted to lower case. /// converted to lower case.
@ -2784,7 +2784,7 @@ extern "C" {
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for
#[wasm_bindgen(static_method_of = Symbol, js_name = for)] #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
pub fn for_(key: &JsString) -> Symbol; pub fn for_(key: &str) -> Symbol;
/// The Symbol.keyFor(sym) method retrieves a shared symbol key from the global symbol registry for the given symbol. /// The Symbol.keyFor(sym) method retrieves a shared symbol key from the global symbol registry for the given symbol.
/// ///

View File

@ -149,8 +149,8 @@ fn now() {
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn parse() { fn parse() {
let date = Date::parse(&"04 Dec 1995 00:12:00 GMT".into()); let date = Date::parse("04 Dec 1995 00:12:00 GMT");
let zero = Date::parse(&"01 Jan 1970 00:00:00 GMT".into()); let zero = Date::parse("01 Jan 1970 00:00:00 GMT");
assert_eq!(date, 818035920000.0); assert_eq!(date, 818035920000.0);
assert_eq!(zero, 0.0); assert_eq!(zero, 0.0);
@ -355,14 +355,14 @@ fn to_json() {
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn to_locale_date_string() { fn to_locale_date_string() {
let date = Date::new(&"August 19, 1975 23:15:30 UTC".into()); let date = Date::new(&"August 19, 1975 23:15:30 UTC".into());
let s = date.to_locale_date_string(&"de-DE".into(), &JsValue::undefined()); let s = date.to_locale_date_string("de-DE", &JsValue::undefined());
assert!(s.length() > 0); assert!(s.length() > 0);
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn to_locale_string() { fn to_locale_string() {
let date = Date::new(&"August 19, 1975 23:15:30 UTC".into()); let date = Date::new(&"August 19, 1975 23:15:30 UTC".into());
let s = date.to_locale_string(&"de-DE".into(), &JsValue::undefined()); let s = date.to_locale_string("de-DE", &JsValue::undefined());
assert!(s.length() > 0); assert!(s.length() > 0);
} }
@ -370,7 +370,7 @@ fn to_locale_string() {
fn to_locale_time_string() { fn to_locale_time_string() {
let date = Date::new(&"August 19, 1975 23:15:30".into()); let date = Date::new(&"August 19, 1975 23:15:30".into());
assert_eq!( assert_eq!(
JsValue::from(date.to_locale_time_string(&"en-US".into())), JsValue::from(date.to_locale_time_string("en-US")),
"11:15:30 PM", "11:15:30 PM",
); );
} }

View File

@ -4,34 +4,34 @@ use js_sys::*;
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn new() { fn new() {
let error = Error::new(&"some message".into()); let error = Error::new("some message");
assert_eq!(JsValue::from(error.message()), "some message"); assert_eq!(JsValue::from(error.message()), "some message");
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn set_message() { fn set_message() {
let error = Error::new(&"test".into()); let error = Error::new("test");
error.set_message(&"another".into()); error.set_message("another");
assert_eq!(JsValue::from(error.message()), "another"); assert_eq!(JsValue::from(error.message()), "another");
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn name() { fn name() {
let error = Error::new(&"test".into()); let error = Error::new("test");
assert_eq!(JsValue::from(error.name()), "Error"); assert_eq!(JsValue::from(error.name()), "Error");
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn set_name() { fn set_name() {
let error = Error::new(&"test".into()); let error = Error::new("test");
error.set_name(&"different".into()); error.set_name("different");
assert_eq!(JsValue::from(error.name()), "different"); assert_eq!(JsValue::from(error.name()), "different");
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn to_string() { fn to_string() {
let error = Error::new(&"error message 1".into()); let error = Error::new("error message 1");
assert_eq!(JsValue::from(error.to_string()), "Error: error message 1"); assert_eq!(JsValue::from(error.to_string()), "Error: error message 1");
error.set_name(&"error_name_1".into()); error.set_name("error_name_1");
assert_eq!(JsValue::from(error.to_string()), "error_name_1: error message 1"); assert_eq!(JsValue::from(error.to_string()), "error_name_1: error message 1");
} }

View File

@ -51,7 +51,7 @@ fn throw() {
let gen = one_two_generator(); let gen = one_two_generator();
gen.next(&JsValue::undefined()).unwrap(); gen.next(&JsValue::undefined()).unwrap();
assert!(gen.throw(&Error::new(&"something went wrong".into())).is_err()); assert!(gen.throw(&Error::new("something went wrong")).is_err());
let next = GeneratorResult::from(gen.next(&JsValue::undefined()).unwrap()); let next = GeneratorResult::from(gen.next(&JsValue::undefined()).unwrap());
assert!(next.value().is_undefined()); assert!(next.value().is_undefined());
assert!(next.done()); assert!(next.done());

View File

@ -53,9 +53,9 @@ fn ends_with() {
let js = JsString::from(s); let js = JsString::from(s);
// TODO: remove third parameter once we have optional parameters // TODO: remove third parameter once we have optional parameters
assert_eq!(js.ends_with(&"question.".into(), s.len() as i32), true); assert_eq!(js.ends_with("question.", s.len() as i32), true);
assert_eq!(js.ends_with(&"to be".into(), s.len() as i32), false); assert_eq!(js.ends_with("to be", s.len() as i32), false);
assert_eq!(js.ends_with(&"to be".into(), 19), true); assert_eq!(js.ends_with("to be", 19), true);
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
@ -63,13 +63,13 @@ fn includes() {
let str = JsString::from("Blue Whale"); let str = JsString::from("Blue Whale");
// TODO: remove second parameter once we have optional parameters // TODO: remove second parameter once we have optional parameters
assert_eq!(str.includes(&"Blue".into(), 0), true); assert_eq!(str.includes("Blue", 0), true);
assert_eq!(str.includes(&"Blute".into(), 0), false); assert_eq!(str.includes("Blute", 0), false);
assert_eq!(str.includes(&"Whale".into(), 0), true); assert_eq!(str.includes("Whale", 0), true);
assert_eq!(str.includes(&"Whale".into(), 5), true); assert_eq!(str.includes("Whale", 5), true);
assert_eq!(str.includes(&"Whale".into(), 7), false); assert_eq!(str.includes("Whale", 7), false);
assert_eq!(str.includes(&"".into(), 0), true); assert_eq!(str.includes("", 0), true);
assert_eq!(str.includes(&"".into(), 16), true); assert_eq!(str.includes("", 16), true);
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
@ -77,17 +77,17 @@ fn index_of() {
let str = JsString::from("Blue Whale"); let str = JsString::from("Blue Whale");
// TODO: remove second parameter once we have optional parameters // TODO: remove second parameter once we have optional parameters
assert_eq!(str.index_of(&"Blue".into(), 0), 0); assert_eq!(str.index_of("Blue", 0), 0);
// TODO: remove second parameter once we have optional parameters // TODO: remove second parameter once we have optional parameters
assert_eq!(str.index_of(&"Blute".into(), 0), -1); assert_eq!(str.index_of("Blute", 0), -1);
assert_eq!(str.index_of(&"Whale".into(), 0), 5); assert_eq!(str.index_of("Whale", 0), 5);
assert_eq!(str.index_of(&"Whale".into(), 5), 5); assert_eq!(str.index_of("Whale", 5), 5);
assert_eq!(str.index_of(&"Whale".into(), 7), -1); assert_eq!(str.index_of("Whale", 7), -1);
// TODO: remove second parameter once we have optional parameters // TODO: remove second parameter once we have optional parameters
assert_eq!(str.index_of(&"".into(), 0), 0); assert_eq!(str.index_of("", 0), 0);
assert_eq!(str.index_of(&"".into(), 9), 9); assert_eq!(str.index_of("", 9), 9);
assert_eq!(str.index_of(&"".into(), 10), 10); assert_eq!(str.index_of("", 10), 10);
assert_eq!(str.index_of(&"".into(), 11), 10); assert_eq!(str.index_of("", 11), 10);
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
@ -96,16 +96,16 @@ fn last_index_of() {
let len = js.length() as i32; let len = js.length() as i32;
// TODO: remove second parameter once we have optional parameters // TODO: remove second parameter once we have optional parameters
assert_eq!(js.last_index_of(&"a".into(), len), 3); assert_eq!(js.last_index_of("a", len), 3);
assert_eq!(js.last_index_of(&"a".into(), 2), 1); assert_eq!(js.last_index_of("a", 2), 1);
assert_eq!(js.last_index_of(&"a".into(), 0), -1); assert_eq!(js.last_index_of("a", 0), -1);
// TODO: remove second parameter once we have optional parameters // TODO: remove second parameter once we have optional parameters
assert_eq!(js.last_index_of(&"x".into(), len), -1); assert_eq!(js.last_index_of("x", len), -1);
assert_eq!(js.last_index_of(&"c".into(), -5), 0); assert_eq!(js.last_index_of("c", -5), 0);
assert_eq!(js.last_index_of(&"c".into(), 0), 0); assert_eq!(js.last_index_of("c", 0), 0);
// TODO: remove second parameter once we have optional parameters // TODO: remove second parameter once we have optional parameters
assert_eq!(js.last_index_of(&"".into(), len), 5); assert_eq!(js.last_index_of("", len), 5);
assert_eq!(js.last_index_of(&"".into(), 2), 2); assert_eq!(js.last_index_of("", 2), 2);
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
@ -113,10 +113,10 @@ fn normalize() {
let js = JsString::from("\u{1E9B}\u{0323}"); let js = JsString::from("\u{1E9B}\u{0323}");
// TODO: Handle undefined // TODO: Handle undefined
assert_eq!(JsValue::from(js.normalize(&"NFC".into())), "\u{1E9B}\u{0323}"); assert_eq!(JsValue::from(js.normalize("NFC")), "\u{1E9B}\u{0323}");
assert_eq!(JsValue::from(js.normalize(&"NFD".into())), "\u{017F}\u{0323}\u{0307}"); assert_eq!(JsValue::from(js.normalize("NFD")), "\u{017F}\u{0323}\u{0307}");
assert_eq!(JsValue::from(js.normalize(&"NFKC".into())), "\u{1E69}"); assert_eq!(JsValue::from(js.normalize("NFKC")), "\u{1E69}");
assert_eq!(JsValue::from(js.normalize(&"NFKD".into())), "\u{0073}\u{0323}\u{0307}"); assert_eq!(JsValue::from(js.normalize("NFKD")), "\u{0073}\u{0323}\u{0307}");
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
@ -124,13 +124,13 @@ fn pad_end() {
let js = JsString::from("abc"); let js = JsString::from("abc");
// TODO: remove second parameter once we have optional parameters // TODO: remove second parameter once we have optional parameters
assert_eq!(JsValue::from(js.pad_end(10, &" ".into())), "abc "); assert_eq!(JsValue::from(js.pad_end(10, " ")), "abc ");
// TODO: remove second parameter once we have optional parameters // TODO: remove second parameter once we have optional parameters
assert_eq!(JsValue::from(js.pad_end(10, &" ".into())), "abc "); assert_eq!(JsValue::from(js.pad_end(10, " ")), "abc ");
assert_eq!(JsValue::from(js.pad_end(10, &"foo".into())), "abcfoofoof"); assert_eq!(JsValue::from(js.pad_end(10, "foo")), "abcfoofoof");
assert_eq!(JsValue::from(js.pad_end(6, &"123456".into())), "abc123"); assert_eq!(JsValue::from(js.pad_end(6, "123456")), "abc123");
// TODO: remove second parameter once we have optional parameters // TODO: remove second parameter once we have optional parameters
assert_eq!(JsValue::from(js.pad_end(1, &" ".into())), "abc"); assert_eq!(JsValue::from(js.pad_end(1, " ")), "abc");
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
@ -138,12 +138,12 @@ fn pad_start() {
let js = JsString::from("abc"); let js = JsString::from("abc");
// TODO: remove second parameter once we have optional parameters // TODO: remove second parameter once we have optional parameters
assert_eq!(js.pad_start(10, &" ".into()), " abc"); assert_eq!(js.pad_start(10, " "), " abc");
assert_eq!(js.pad_start(10, &"foo".into()), "foofoofabc"); assert_eq!(js.pad_start(10, "foo"), "foofoofabc");
assert_eq!(js.pad_start(6, &"123465".into()), "123abc"); assert_eq!(js.pad_start(6, "123465"), "123abc");
assert_eq!(js.pad_start(8, &"0".into()), "00000abc"); assert_eq!(js.pad_start(8, "0"), "00000abc");
// TODO: remove second parameter once we have optional parameters // TODO: remove second parameter once we have optional parameters
assert_eq!(js.pad_start(1, &" ".into()), "abc"); assert_eq!(js.pad_start(1, " "), "abc");
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
@ -162,9 +162,9 @@ fn starts_with() {
let js = JsString::from("To be, or not to be, that is the question."); let js = JsString::from("To be, or not to be, that is the question.");
// TODO: remove second parameter for both assertions once we have optional parameters // TODO: remove second parameter for both assertions once we have optional parameters
assert!(js.starts_with(&"To be".into(), 0)); assert!(js.starts_with("To be", 0));
assert!(!js.starts_with(&"not to be".into(), 0)); assert!(!js.starts_with("not to be", 0));
assert!(js.starts_with(&"not to be".into(), 10)); assert!(js.starts_with("not to be", 10));
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]

View File

@ -74,19 +74,19 @@ fn to_string_tag() {
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn for_() { fn for_() {
let foo = JsValue::from(Symbol::for_(&"foo".into())); let foo = JsValue::from(Symbol::for_("foo"));
let bar = JsValue::from(Symbol::for_(&"bar".into())); let bar = JsValue::from(Symbol::for_("bar"));
assert_eq!(foo, foo); assert_eq!(foo, foo);
assert_eq!(bar, bar); assert_eq!(bar, bar);
assert_ne!(foo, bar); assert_ne!(foo, bar);
assert_ne!(bar, foo); assert_ne!(bar, foo);
assert_eq!(Symbol::for_(&"mario".into()).to_string(), "Symbol(mario)"); assert_eq!(Symbol::for_("mario").to_string(), "Symbol(mario)");
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn key_for() { fn key_for() {
let sym = Symbol::for_(&"foo".into()); let sym = Symbol::for_("foo");
assert_eq!(Symbol::key_for(&sym), "foo"); assert_eq!(Symbol::key_for(&sym), "foo");
assert!(Symbol::key_for(&Symbol::iterator()).is_undefined()); assert!(Symbol::key_for(&Symbol::iterator()).is_undefined());
assert!(Symbol::key_for(&gensym(JsValue::undefined())).is_undefined()); assert!(Symbol::key_for(&gensym(JsValue::undefined())).is_undefined());
@ -95,13 +95,13 @@ fn key_for() {
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn to_string() { fn to_string() {
assert_eq!(Symbol::iterator().to_string(), "Symbol(Symbol.iterator)"); assert_eq!(Symbol::iterator().to_string(), "Symbol(Symbol.iterator)");
assert_eq!(Symbol::for_(&"foo".into()).to_string(), "Symbol(foo)"); assert_eq!(Symbol::for_("foo").to_string(), "Symbol(foo)");
assert_eq!(gensym("desc".into()).to_string(), "Symbol(desc)"); assert_eq!(gensym("desc".into()).to_string(), "Symbol(desc)");
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn value_of() { fn value_of() {
let a = Symbol::for_(&"foo".into()); let a = Symbol::for_("foo");
assert_eq!(JsValue::from(a.value_of()), JsValue::from(a)); assert_eq!(JsValue::from(a.value_of()), JsValue::from(a));
let a = gensym(JsValue::undefined()); let a = gensym(JsValue::undefined());
assert_eq!(JsValue::from(a.value_of()), JsValue::from(a)); assert_eq!(JsValue::from(a.value_of()), JsValue::from(a));

View File

@ -55,7 +55,7 @@ pub fn run() {
.get_element_by_id("current-time") .get_element_by_id("current-time")
.set_inner_html(&String::from( .set_inner_html(&String::from(
Date::new(&JsValue::undefined()) Date::new(&JsValue::undefined())
.to_locale_string(&"en-GB".into(), &JsValue::undefined()), .to_locale_string("en-GB", &JsValue::undefined()),
)); ));
} }