diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index bf3c9704..79941579 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -2940,6 +2940,34 @@ extern "C" { #[wasm_bindgen(method, js_class = "String", js_name = endsWith)] pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool; + /// The static String.fromCharCode() method returns a string created from + /// the specified sequence of UTF-16 code units. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode + /// + /// # Notes + /// + /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc... + /// with different arities. + #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)] + pub fn from_char_code1(a: u32) -> JsString; + + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode + #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)] + pub fn from_char_code2(a: u32, b: u32) -> JsString; + + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode + #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)] + pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString; + + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode + #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)] + pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString; + + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode + #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)] + pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString; + /// The `includes()` method determines whether one string may be found /// within another string, returning true or false as appropriate. /// diff --git a/crates/js-sys/tests/wasm/JsString.rs b/crates/js-sys/tests/wasm/JsString.rs index 973f2cef..4b276ba3 100644 --- a/crates/js-sys/tests/wasm/JsString.rs +++ b/crates/js-sys/tests/wasm/JsString.rs @@ -58,6 +58,19 @@ fn ends_with() { assert_eq!(js.ends_with("to be", 19), true); } +#[wasm_bindgen_test] +fn from_char_code() { + let s = "½+¾="; + let codes : Vec = s.chars() + .map(|char| char as u32) + .collect(); + + assert_eq!(JsString::from_char_code1(codes[0]), "½"); + assert_eq!(JsString::from_char_code2(codes[0], codes[1]), "½+"); + assert_eq!(JsString::from_char_code3(codes[0], codes[1], codes[2]), "½+¾"); + assert_eq!(JsString::from_char_code4(codes[0], codes[1], codes[2], codes[3]), "½+¾="); +} + #[wasm_bindgen_test] fn includes() { let str = JsString::from("Blue Whale"); diff --git a/crates/macro-support/src/parser.rs b/crates/macro-support/src/parser.rs index ae7815d5..18b198a6 100644 --- a/crates/macro-support/src/parser.rs +++ b/crates/macro-support/src/parser.rs @@ -473,7 +473,10 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option)> for syn::ForeignItemFn kind, } } else if let Some(cls) = opts.static_method_of() { - let class = cls.to_string(); + let class = opts + .js_class() + .map(Into::into) + .unwrap_or_else(|| cls.to_string()); let ty = ident_ty(cls.clone()); let kind = ast::MethodKind::Operation(ast::Operation {