mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 12:31:22 +00:00
Merge branch 'master' into add-wasm-bindgen-skip-attr
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "wasm-bindgen-anyref-xform"
|
||||
version = "0.2.40"
|
||||
version = "0.2.42"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/anyref-xform"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.40"
|
||||
version = "0.2.42"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/backend"
|
||||
@ -22,4 +22,4 @@ log = "0.4"
|
||||
proc-macro2 = "0.4.8"
|
||||
quote = '0.6'
|
||||
syn = { version = '0.15', features = ['full'] }
|
||||
wasm-bindgen-shared = { path = "../shared", version = "=0.2.40" }
|
||||
wasm-bindgen-shared = { path = "../shared", version = "=0.2.42" }
|
||||
|
@ -183,6 +183,7 @@ pub struct ImportType {
|
||||
pub attrs: Vec<syn::Attribute>,
|
||||
pub doc_comment: Option<String>,
|
||||
pub instanceof_shim: String,
|
||||
pub is_type_of: Option<syn::Expr>,
|
||||
pub extends: Vec<syn::Path>,
|
||||
pub vendor_prefixes: Vec<Ident>,
|
||||
}
|
||||
|
@ -291,11 +291,13 @@ impl ToTokens for ast::StructField {
|
||||
let ty = &self.ty;
|
||||
let getter = &self.getter;
|
||||
let setter = &self.setter;
|
||||
|
||||
let assert_copy = quote! { assert_copy::<#ty>() };
|
||||
let assert_copy = respan(assert_copy, ty);
|
||||
(quote! {
|
||||
#[no_mangle]
|
||||
#[doc(hidden)]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
|
||||
#[allow(clippy::all)]
|
||||
#[cfg_attr(all(target_arch = "wasm32", not(target_os = "emscripten")), no_mangle)]
|
||||
pub unsafe extern "C" fn #getter(js: u32)
|
||||
-> <#ty as wasm_bindgen::convert::IntoWasmAbi>::Abi
|
||||
{
|
||||
@ -303,7 +305,7 @@ impl ToTokens for ast::StructField {
|
||||
use wasm_bindgen::convert::{GlobalStack, IntoWasmAbi};
|
||||
|
||||
fn assert_copy<T: Copy>(){}
|
||||
assert_copy::<#ty>();
|
||||
#assert_copy;
|
||||
|
||||
let js = js as *mut WasmRefCell<#struct_name>;
|
||||
assert_not_null(js);
|
||||
@ -576,6 +578,24 @@ impl ToTokens for ast::ImportType {
|
||||
let const_name = format!("__wbg_generated_const_{}", rust_name);
|
||||
let const_name = Ident::new(&const_name, Span::call_site());
|
||||
let instanceof_shim = Ident::new(&self.instanceof_shim, Span::call_site());
|
||||
|
||||
let internal_obj = match self.extends.first() {
|
||||
Some(target) => {
|
||||
quote! { #target }
|
||||
}
|
||||
None => {
|
||||
quote! { wasm_bindgen::JsValue }
|
||||
}
|
||||
};
|
||||
|
||||
let is_type_of = self.is_type_of.as_ref().map(|is_type_of| quote! {
|
||||
#[inline]
|
||||
fn is_type_of(val: &JsValue) -> bool {
|
||||
let is_type_of: fn(&JsValue) -> bool = #is_type_of;
|
||||
is_type_of(val)
|
||||
}
|
||||
});
|
||||
|
||||
(quote! {
|
||||
#[allow(bad_style)]
|
||||
#(#attrs)*
|
||||
@ -583,7 +603,7 @@ impl ToTokens for ast::ImportType {
|
||||
#[repr(transparent)]
|
||||
#[allow(clippy::all)]
|
||||
#vis struct #rust_name {
|
||||
obj: wasm_bindgen::JsValue,
|
||||
obj: #internal_obj
|
||||
}
|
||||
|
||||
#[allow(bad_style)]
|
||||
@ -602,6 +622,15 @@ impl ToTokens for ast::ImportType {
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::Deref for #rust_name {
|
||||
type Target = #internal_obj;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &#internal_obj {
|
||||
&self.obj
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoWasmAbi for #rust_name {
|
||||
type Abi = <JsValue as IntoWasmAbi>::Abi;
|
||||
|
||||
@ -627,7 +656,7 @@ impl ToTokens for ast::ImportType {
|
||||
#[inline]
|
||||
unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self {
|
||||
#rust_name {
|
||||
obj: JsValue::from_abi(js, extra),
|
||||
obj: JsValue::from_abi(js, extra).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -654,7 +683,7 @@ impl ToTokens for ast::ImportType {
|
||||
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor {
|
||||
let tmp = <JsValue as RefFromWasmAbi>::ref_from_abi(js, extra);
|
||||
core::mem::ManuallyDrop::new(#rust_name {
|
||||
obj: core::mem::ManuallyDrop::into_inner(tmp),
|
||||
obj: core::mem::ManuallyDrop::into_inner(tmp).into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -663,20 +692,20 @@ impl ToTokens for ast::ImportType {
|
||||
impl From<JsValue> for #rust_name {
|
||||
#[inline]
|
||||
fn from(obj: JsValue) -> #rust_name {
|
||||
#rust_name { obj }
|
||||
#rust_name { obj: obj.into() }
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<JsValue> for #rust_name {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &JsValue { &self.obj }
|
||||
fn as_ref(&self) -> &JsValue { self.obj.as_ref() }
|
||||
}
|
||||
|
||||
|
||||
impl From<#rust_name> for JsValue {
|
||||
#[inline]
|
||||
fn from(obj: #rust_name) -> JsValue {
|
||||
obj.obj
|
||||
obj.obj.into()
|
||||
}
|
||||
}
|
||||
|
||||
@ -699,9 +728,11 @@ impl ToTokens for ast::ImportType {
|
||||
panic!("cannot check instanceof on non-wasm targets");
|
||||
}
|
||||
|
||||
#is_type_of
|
||||
|
||||
#[inline]
|
||||
fn unchecked_from_js(val: JsValue) -> Self {
|
||||
#rust_name { obj: val }
|
||||
#rust_name { obj: val.into() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -714,24 +745,9 @@ impl ToTokens for ast::ImportType {
|
||||
|
||||
()
|
||||
};
|
||||
}).to_tokens(tokens);
|
||||
|
||||
let deref_target = match self.extends.first() {
|
||||
Some(target) => quote! { #target },
|
||||
None => quote! { JsValue },
|
||||
};
|
||||
(quote! {
|
||||
#[allow(clippy::all)]
|
||||
impl core::ops::Deref for #rust_name {
|
||||
type Target = #deref_target;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &#deref_target {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
})
|
||||
.to_tokens(tokens);
|
||||
|
||||
for superclass in self.extends.iter() {
|
||||
(quote! {
|
||||
#[allow(clippy::all)]
|
||||
@ -1430,3 +1446,31 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
|
||||
.to_tokens(tokens);
|
||||
}
|
||||
}
|
||||
|
||||
fn respan(
|
||||
input: TokenStream,
|
||||
span: &dyn ToTokens,
|
||||
) -> TokenStream {
|
||||
let mut first_span = Span::call_site();
|
||||
let mut last_span = Span::call_site();
|
||||
let mut spans = TokenStream::new();
|
||||
span.to_tokens(&mut spans);
|
||||
|
||||
for (i, token) in spans.into_iter().enumerate() {
|
||||
if i == 0 {
|
||||
first_span = token.span();
|
||||
}
|
||||
last_span = token.span();
|
||||
}
|
||||
|
||||
let mut new_tokens = Vec::new();
|
||||
for (i, mut token) in input.into_iter().enumerate() {
|
||||
if i == 0 {
|
||||
token.set_span(first_span);
|
||||
} else {
|
||||
token.set_span(last_span);
|
||||
}
|
||||
new_tokens.push(token);
|
||||
}
|
||||
new_tokens.into_iter().collect()
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "wasm-bindgen-cli-support"
|
||||
version = "0.2.40"
|
||||
version = "0.2.42"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/cli-support"
|
||||
@ -19,7 +19,7 @@ rustc-demangle = "0.1.13"
|
||||
serde_json = "1.0"
|
||||
tempfile = "3.0"
|
||||
walrus = "0.5.0"
|
||||
wasm-bindgen-anyref-xform = { path = '../anyref-xform', version = '=0.2.40' }
|
||||
wasm-bindgen-shared = { path = "../shared", version = '=0.2.40' }
|
||||
wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.40' }
|
||||
wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.40' }
|
||||
wasm-bindgen-anyref-xform = { path = '../anyref-xform', version = '=0.2.42' }
|
||||
wasm-bindgen-shared = { path = "../shared", version = '=0.2.42' }
|
||||
wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.42' }
|
||||
wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.42' }
|
||||
|
@ -311,6 +311,7 @@ impl<'a> Context<'a> {
|
||||
/// `--target no-modules`, `--target web`, or for bundlers. This is the very
|
||||
/// last step performed in `finalize`.
|
||||
fn finalize_js(&mut self, module_name: &str, needs_manual_start: bool) -> (String, String) {
|
||||
let mut ts = self.typescript.clone();
|
||||
let mut js = String::new();
|
||||
if self.config.mode.no_modules() {
|
||||
js.push_str("(function() {\n");
|
||||
@ -318,7 +319,7 @@ impl<'a> Context<'a> {
|
||||
|
||||
// Depending on the output mode, generate necessary glue to actually
|
||||
// import the wasm file in one way or another.
|
||||
let mut init = String::new();
|
||||
let mut init = (String::new(), String::new());
|
||||
match &self.config.mode {
|
||||
// In `--target no-modules` mode we need to both expose a name on
|
||||
// the global object as well as generate our own custom start
|
||||
@ -353,7 +354,8 @@ impl<'a> Context<'a> {
|
||||
| OutputMode::Node {
|
||||
experimental_modules: true,
|
||||
} => {
|
||||
js.push_str(&format!("import * as wasm from './{}_bg';\n", module_name));
|
||||
self.imports
|
||||
.push_str(&format!("import * as wasm from './{}_bg';\n", module_name));
|
||||
if needs_manual_start {
|
||||
self.footer.push_str("wasm.__wbindgen_start();\n");
|
||||
}
|
||||
@ -364,14 +366,22 @@ impl<'a> Context<'a> {
|
||||
// expose the same initialization function as `--target no-modules`
|
||||
// as the default export of the module.
|
||||
OutputMode::Web => {
|
||||
js.push_str("const __exports = {};\n");
|
||||
self.imports_post.push_str("const __exports = {};\n");
|
||||
self.imports_post.push_str("let wasm;\n");
|
||||
init = self.gen_init(&module_name, needs_manual_start);
|
||||
self.footer.push_str("export default init;\n");
|
||||
}
|
||||
}
|
||||
|
||||
let (init_js, init_ts) = init;
|
||||
|
||||
ts.push_str(&init_ts);
|
||||
|
||||
// Emit all the JS for importing all our functionality
|
||||
assert!(
|
||||
!self.config.mode.uses_es_modules() || js.is_empty(),
|
||||
"ES modules require imports to be at the start of the file"
|
||||
);
|
||||
js.push_str(&self.imports);
|
||||
js.push_str("\n");
|
||||
js.push_str(&self.imports_post);
|
||||
@ -382,7 +392,7 @@ impl<'a> Context<'a> {
|
||||
js.push_str("\n");
|
||||
|
||||
// Generate the initialization glue, if there was any
|
||||
js.push_str(&init);
|
||||
js.push_str(&init_js);
|
||||
js.push_str("\n");
|
||||
js.push_str(&self.footer);
|
||||
js.push_str("\n");
|
||||
@ -394,7 +404,7 @@ impl<'a> Context<'a> {
|
||||
js = js.replace("\n\n\n", "\n\n");
|
||||
}
|
||||
|
||||
(js, self.typescript.clone())
|
||||
(js, ts)
|
||||
}
|
||||
|
||||
fn wire_up_initial_intrinsics(&mut self) -> Result<(), Error> {
|
||||
@ -773,6 +783,14 @@ impl<'a> Context<'a> {
|
||||
))
|
||||
})?;
|
||||
|
||||
self.bind("__wbindgen_function_table", &|me| {
|
||||
me.function_table_needed = true;
|
||||
Ok(format!(
|
||||
"function() {{ return {}; }}",
|
||||
me.add_heap_object("wasm.__wbg_function_table")
|
||||
))
|
||||
})?;
|
||||
|
||||
self.bind("__wbindgen_rethrow", &|me| {
|
||||
Ok(format!(
|
||||
"function(idx) {{ throw {}; }}",
|
||||
@ -842,7 +860,34 @@ impl<'a> Context<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn gen_init(&mut self, module_name: &str, needs_manual_start: bool) -> String {
|
||||
fn ts_for_init_fn(has_memory: bool) -> String {
|
||||
let (memory_doc, memory_param) = if has_memory {
|
||||
(
|
||||
"* @param {WebAssembly.Memory} maybe_memory\n",
|
||||
", maybe_memory: WebAssembly.Memory",
|
||||
)
|
||||
} else {
|
||||
("", "")
|
||||
};
|
||||
format!(
|
||||
"\n\
|
||||
/**\n\
|
||||
* If `module_or_path` is {{RequestInfo}}, makes a request and\n\
|
||||
* for everything else, calls `WebAssembly.instantiate` directly.\n\
|
||||
*\n\
|
||||
* @param {{RequestInfo | BufferSource | WebAssembly.Module}} module_or_path\n\
|
||||
{}\
|
||||
*\n\
|
||||
* @returns {{Promise<any>}}\n\
|
||||
*/\n\
|
||||
export function init \
|
||||
(module_or_path: RequestInfo | BufferSource | WebAssembly.Module{}): Promise<any>;
|
||||
",
|
||||
memory_doc, memory_param
|
||||
)
|
||||
}
|
||||
|
||||
fn gen_init(&mut self, module_name: &str, needs_manual_start: bool) -> (String, String) {
|
||||
let mem = self.module.memories.get(self.memory);
|
||||
let (init_memory1, init_memory2) = if mem.import.is_some() {
|
||||
let mut memory = String::from("new WebAssembly.Memory({");
|
||||
@ -862,15 +907,21 @@ impl<'a> Context<'a> {
|
||||
} else {
|
||||
(String::new(), String::new())
|
||||
};
|
||||
let init_memory_arg = if mem.import.is_some() {
|
||||
", maybe_memory"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
format!(
|
||||
let ts = Self::ts_for_init_fn(mem.import.is_some());
|
||||
let js = format!(
|
||||
"\
|
||||
function init(module_or_path, maybe_memory) {{
|
||||
function init(module{init_memory_arg}) {{
|
||||
let result;
|
||||
const imports = {{ './{module}': __exports }};
|
||||
if (module_or_path instanceof URL || typeof module_or_path === 'string' || module_or_path instanceof Request) {{
|
||||
if (module instanceof URL || typeof module === 'string' || module instanceof Request) {{
|
||||
{init_memory2}
|
||||
const response = fetch(module_or_path);
|
||||
const response = fetch(module);
|
||||
if (typeof WebAssembly.instantiateStreaming === 'function') {{
|
||||
result = WebAssembly.instantiateStreaming(response, imports)
|
||||
.catch(e => {{
|
||||
@ -890,9 +941,13 @@ impl<'a> Context<'a> {
|
||||
}}
|
||||
}} else {{
|
||||
{init_memory1}
|
||||
result = WebAssembly.instantiate(module_or_path, imports)
|
||||
.then(instance => {{
|
||||
return {{ instance, module: module_or_path }};
|
||||
result = WebAssembly.instantiate(module, imports)
|
||||
.then(result => {{
|
||||
if (result instanceof WebAssembly.Instance) {{
|
||||
return {{ instance: result, module }};
|
||||
}} else {{
|
||||
return result;
|
||||
}}
|
||||
}});
|
||||
}}
|
||||
return result.then(({{instance, module}}) => {{
|
||||
@ -903,6 +958,7 @@ impl<'a> Context<'a> {
|
||||
}});
|
||||
}}
|
||||
",
|
||||
init_memory_arg = init_memory_arg,
|
||||
module = module_name,
|
||||
init_memory1 = init_memory1,
|
||||
init_memory2 = init_memory2,
|
||||
@ -911,7 +967,9 @@ impl<'a> Context<'a> {
|
||||
} else {
|
||||
""
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
(js, ts)
|
||||
}
|
||||
|
||||
fn bind(
|
||||
@ -1306,13 +1364,12 @@ impl<'a> Context<'a> {
|
||||
while (true) {{
|
||||
const view = getUint8Memory().subarray(ptr + writeOffset, ptr + size);
|
||||
const {{ read, written }} = cachedTextEncoder.encodeInto(arg, view);
|
||||
arg = arg.substring(read);
|
||||
writeOffset += written;
|
||||
if (arg.length === 0) {{
|
||||
if (read === arg.length) {{
|
||||
break;
|
||||
}}
|
||||
ptr = wasm.__wbindgen_realloc(ptr, size, size * 2);
|
||||
size *= 2;
|
||||
arg = arg.substring(read);
|
||||
ptr = wasm.__wbindgen_realloc(ptr, size, size += arg.length * 3);
|
||||
}}
|
||||
WASM_VECTOR_LEN = writeOffset;
|
||||
return ptr;
|
||||
|
@ -42,6 +42,19 @@ enum OutputMode {
|
||||
Node { experimental_modules: bool },
|
||||
}
|
||||
|
||||
impl OutputMode {
|
||||
fn uses_es_modules(&self) -> bool {
|
||||
match self {
|
||||
OutputMode::Bundler { .. }
|
||||
| OutputMode::Web
|
||||
| OutputMode::Node {
|
||||
experimental_modules: true,
|
||||
} => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Input {
|
||||
Path(PathBuf),
|
||||
Module(Module, String),
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "wasm-bindgen-cli"
|
||||
version = "0.2.40"
|
||||
version = "0.2.42"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/cli"
|
||||
@ -25,8 +25,8 @@ serde = { version = "1.0", features = ['derive'] }
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
walrus = "0.5"
|
||||
wasm-bindgen-cli-support = { path = "../cli-support", version = "=0.2.40" }
|
||||
wasm-bindgen-shared = { path = "../shared", version = "=0.2.40" }
|
||||
wasm-bindgen-cli-support = { path = "../cli-support", version = "=0.2.42" }
|
||||
wasm-bindgen-shared = { path = "../shared", version = "=0.2.42" }
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "0.11"
|
||||
|
@ -7,13 +7,13 @@ license = "MIT/Apache-2.0"
|
||||
name = "wasm-bindgen-futures"
|
||||
repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/futures"
|
||||
readme = "./README.md"
|
||||
version = "0.3.17"
|
||||
version = "0.3.19"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
futures = "0.1.20"
|
||||
js-sys = { path = "../js-sys", version = '0.3.17' }
|
||||
wasm-bindgen = { path = "../..", version = '0.2.40' }
|
||||
js-sys = { path = "../js-sys", version = '0.3.19' }
|
||||
wasm-bindgen = { path = "../..", version = '0.2.42' }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
|
||||
wasm-bindgen-test = { path = '../test', version = '0.2.40' }
|
||||
wasm-bindgen-test = { path = '../test', version = '0.2.42' }
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "js-sys"
|
||||
version = "0.3.17"
|
||||
version = "0.3.19"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
readme = "./README.md"
|
||||
categories = ["wasm"]
|
||||
@ -19,9 +19,9 @@ test = false
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
wasm-bindgen = { path = "../..", version = "0.2.40" }
|
||||
wasm-bindgen = { path = "../..", version = "0.2.42" }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
|
||||
futures = "0.1.20"
|
||||
wasm-bindgen-test = { path = '../test', version = '=0.2.40' }
|
||||
wasm-bindgen-futures = { path = '../futures', version = '=0.3.17' }
|
||||
wasm-bindgen-test = { path = '../test', version = '=0.2.42' }
|
||||
wasm-bindgen-futures = { path = '../futures', version = '=0.3.19' }
|
||||
|
@ -126,8 +126,8 @@ extern "C" {
|
||||
// Array
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[wasm_bindgen(extends = Object, is_type_of = Array::is_array)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type Array;
|
||||
|
||||
/// Creates a new empty array
|
||||
@ -392,7 +392,7 @@ extern "C" {
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type ArrayBuffer;
|
||||
|
||||
/// The `ArrayBuffer` object is used to represent a generic,
|
||||
@ -466,14 +466,15 @@ extern "C" {
|
||||
// Boolean
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some())]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub type Boolean;
|
||||
|
||||
/// The `Boolean()` constructor creates an object wrapper for a boolean value.
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
|
||||
#[wasm_bindgen(constructor)]
|
||||
#[deprecated(note = "recommended to use `Boolean::from` instead")]
|
||||
pub fn new(value: &JsValue) -> Boolean;
|
||||
|
||||
/// The `valueOf()` method returns the primitive value of a `Boolean` object.
|
||||
@ -483,11 +484,38 @@ extern "C" {
|
||||
pub fn value_of(this: &Boolean) -> bool;
|
||||
}
|
||||
|
||||
impl From<bool> for Boolean {
|
||||
#[inline]
|
||||
fn from(b: bool) -> Boolean {
|
||||
Boolean::unchecked_from_js(JsValue::from(b))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Boolean> for bool {
|
||||
#[inline]
|
||||
fn from(b: Boolean) -> bool {
|
||||
b.value_of()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<bool> for Boolean {
|
||||
#[inline]
|
||||
fn eq(&self, other: &bool) -> bool {
|
||||
self.value_of() == *other
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Boolean {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.value_of().fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
// DataView
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type DataView;
|
||||
|
||||
/// The `DataView` view provides a low-level interface for reading and
|
||||
@ -719,7 +747,7 @@ extern "C" {
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type Error;
|
||||
|
||||
/// The Error constructor creates an error object.
|
||||
@ -758,7 +786,7 @@ extern "C" {
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object, extends = Error)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type EvalError;
|
||||
|
||||
/// The EvalError object indicates an error regarding the global eval() function. This
|
||||
@ -773,8 +801,8 @@ extern "C" {
|
||||
// Function
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type Function;
|
||||
|
||||
/// The `Function` constructor creates a new `Function` object. Calling the
|
||||
@ -869,11 +897,7 @@ impl Function {
|
||||
/// If this JS value is not an instance of a function then this returns
|
||||
/// `None`.
|
||||
pub fn try_from(val: &JsValue) -> Option<&Function> {
|
||||
if val.is_function() {
|
||||
Some(unsafe { mem::transmute(val) })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
val.dyn_ref()
|
||||
}
|
||||
}
|
||||
|
||||
@ -881,7 +905,7 @@ impl Function {
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type Generator;
|
||||
|
||||
/// The next() method returns an object with two properties done and value.
|
||||
@ -909,7 +933,7 @@ extern "C" {
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type Map;
|
||||
|
||||
/// The clear() method removes all elements from a Map object.
|
||||
@ -1001,6 +1025,7 @@ extern "C" {
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
|
||||
#[derive(Clone, Debug)]
|
||||
#[wasm_bindgen(is_type_of = Iterator::looks_like_iterator)]
|
||||
pub type Iterator;
|
||||
|
||||
/// The next method always has to return an object with appropriate
|
||||
@ -1011,6 +1036,26 @@ extern "C" {
|
||||
pub fn next(this: &Iterator) -> Result<IteratorNext, JsValue>;
|
||||
}
|
||||
|
||||
impl Iterator {
|
||||
fn looks_like_iterator(it: &JsValue) -> bool {
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
type MaybeIterator;
|
||||
|
||||
#[wasm_bindgen(method, getter)]
|
||||
fn next(this: &MaybeIterator) -> JsValue;
|
||||
}
|
||||
|
||||
if !it.is_object() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let it = it.unchecked_ref::<MaybeIterator>();
|
||||
|
||||
it.next().is_function()
|
||||
}
|
||||
}
|
||||
|
||||
/// An iterator over the JS `Symbol.iterator` iteration protocol.
|
||||
///
|
||||
/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
|
||||
@ -1099,34 +1144,20 @@ impl IterState {
|
||||
/// Create an iterator over `val` using the JS iteration protocol and
|
||||
/// `Symbol.iterator`.
|
||||
pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter>, JsValue> {
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
type MaybeIterator;
|
||||
|
||||
#[wasm_bindgen(method, getter)]
|
||||
fn next(this: &MaybeIterator) -> JsValue;
|
||||
}
|
||||
|
||||
let iter_sym = Symbol::iterator();
|
||||
let iter_fn = Reflect::get(val, iter_sym.as_ref())?;
|
||||
if !iter_fn.is_function() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let iter_fn: Function = iter_fn.unchecked_into();
|
||||
let it = iter_fn.call0(val)?;
|
||||
if !it.is_object() {
|
||||
return Ok(None);
|
||||
}
|
||||
let iter_fn: Function = match iter_fn.dyn_into() {
|
||||
Ok(iter_fn) => iter_fn,
|
||||
Err(_) => return Ok(None),
|
||||
};
|
||||
|
||||
let next = it.unchecked_ref::<MaybeIterator>().next();
|
||||
let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
|
||||
Ok(it) => it,
|
||||
Err(_) => return Ok(None),
|
||||
};
|
||||
|
||||
Ok(if next.is_function() {
|
||||
let it: Iterator = it.unchecked_into();
|
||||
Some(it.into_iter())
|
||||
} else {
|
||||
None
|
||||
})
|
||||
Ok(Some(it.into_iter()))
|
||||
}
|
||||
|
||||
// IteratorNext
|
||||
@ -1135,7 +1166,8 @@ extern "C" {
|
||||
/// The result of calling `next()` on a JS iterator.
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
|
||||
#[derive(Clone, Debug)]
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type IteratorNext;
|
||||
|
||||
/// Has the value `true` if the iterator is past the end of the iterated
|
||||
@ -1157,8 +1189,8 @@ extern "C" {
|
||||
// Math
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type Math;
|
||||
|
||||
/// The Math.abs() function returns the absolute value of a number, that is
|
||||
@ -1405,8 +1437,8 @@ extern "C" {
|
||||
// Number.
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some())]
|
||||
#[derive(Clone)]
|
||||
pub type Number;
|
||||
|
||||
/// The Number.isFinite() method determines whether the passed value is a finite number.
|
||||
@ -1441,6 +1473,7 @@ extern "C" {
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
|
||||
#[wasm_bindgen(constructor)]
|
||||
#[deprecated(note = "recommended to use `Number::from` instead")]
|
||||
pub fn new(value: &JsValue) -> Number;
|
||||
|
||||
/// The Number.parseInt() method parses a string argument and returns an
|
||||
@ -1500,11 +1533,43 @@ extern "C" {
|
||||
pub fn value_of(this: &Number) -> f64;
|
||||
}
|
||||
|
||||
macro_rules! number_from {
|
||||
($($x:ident)*) => ($(
|
||||
impl From<$x> for Number {
|
||||
#[inline]
|
||||
fn from(x: $x) -> Number {
|
||||
Number::unchecked_from_js(JsValue::from(x))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<$x> for Number {
|
||||
#[inline]
|
||||
fn eq(&self, other: &$x) -> bool {
|
||||
self.value_of() == f64::from(*other)
|
||||
}
|
||||
}
|
||||
)*)
|
||||
}
|
||||
number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
|
||||
|
||||
impl From<Number> for f64 {
|
||||
#[inline]
|
||||
fn from(n: Number) -> f64 {
|
||||
n.value_of()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Number {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.value_of().fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
// Date.
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type Date;
|
||||
|
||||
/// The getDate() method returns the day of the month for the
|
||||
@ -2091,13 +2156,22 @@ impl Object {
|
||||
/// `None`.
|
||||
pub fn try_from(val: &JsValue) -> Option<&Object> {
|
||||
if val.is_object() {
|
||||
Some(unsafe { mem::transmute(val) })
|
||||
Some(val.unchecked_ref())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Object {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Object) -> bool {
|
||||
Object::is(self.as_ref(), other.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Object {}
|
||||
|
||||
// Proxy
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
@ -2128,7 +2202,7 @@ extern "C" {
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
|
||||
#[wasm_bindgen(extends = Error, extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type RangeError;
|
||||
|
||||
/// The RangeError object indicates an error when a value is not in the set
|
||||
@ -2147,7 +2221,7 @@ extern "C" {
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
|
||||
#[wasm_bindgen(extends = Error, extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type ReferenceError;
|
||||
|
||||
/// The ReferenceError object represents an error when a non-existent
|
||||
@ -2161,8 +2235,8 @@ extern "C" {
|
||||
// Reflect
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type Reflect;
|
||||
|
||||
/// The static `Reflect.apply()` method calls a target function with
|
||||
@ -2321,7 +2395,7 @@ extern "C" {
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type RegExp;
|
||||
|
||||
/// The exec() method executes a search for a match in a specified
|
||||
@ -2498,7 +2572,7 @@ extern "C" {
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type Set;
|
||||
|
||||
/// The `add()` method appends a new element with a specified value to the
|
||||
@ -2588,7 +2662,7 @@ extern "C" {
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
|
||||
#[wasm_bindgen(extends = Error, extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type SyntaxError;
|
||||
|
||||
/// A SyntaxError is thrown when the JavaScript engine encounters tokens or
|
||||
@ -2608,7 +2682,7 @@ extern "C" {
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
|
||||
#[wasm_bindgen(extends = Error, extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type TypeError;
|
||||
|
||||
/// The TypeError object represents an error when a value is not of the
|
||||
@ -2627,7 +2701,7 @@ extern "C" {
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
|
||||
#[wasm_bindgen(extends = Error, extends = Object, js_name = URIError)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type UriError;
|
||||
|
||||
/// The URIError object represents an error when a global URI handling
|
||||
@ -2642,7 +2716,7 @@ extern "C" {
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type WeakMap;
|
||||
|
||||
/// The [`WeakMap`] object is a collection of key/value pairs in which the
|
||||
@ -2686,7 +2760,7 @@ extern "C" {
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type WeakSet;
|
||||
|
||||
/// The `WeakSet` object lets you store weakly held objects in a collection.
|
||||
@ -2773,7 +2847,7 @@ pub mod WebAssembly {
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
|
||||
#[wasm_bindgen(extends = Error, js_namespace = WebAssembly)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type CompileError;
|
||||
|
||||
/// The `WebAssembly.CompileError()` constructor creates a new
|
||||
@ -2795,7 +2869,7 @@ pub mod WebAssembly {
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
|
||||
#[wasm_bindgen(extends = Object, js_namespace = WebAssembly)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type Instance;
|
||||
|
||||
/// The `WebAssembly.Instance()` constructor function can be called to
|
||||
@ -2826,7 +2900,7 @@ pub mod WebAssembly {
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
|
||||
#[wasm_bindgen(extends = Error, js_namespace = WebAssembly)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type LinkError;
|
||||
|
||||
/// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
|
||||
@ -2847,7 +2921,7 @@ pub mod WebAssembly {
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
|
||||
#[wasm_bindgen(extends = Error, js_namespace = WebAssembly)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type RuntimeError;
|
||||
|
||||
/// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
|
||||
@ -2868,7 +2942,7 @@ pub mod WebAssembly {
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
|
||||
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type Module;
|
||||
|
||||
/// A `WebAssembly.Module` object contains stateless WebAssembly code
|
||||
@ -2910,7 +2984,7 @@ pub mod WebAssembly {
|
||||
///
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
|
||||
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type Table;
|
||||
|
||||
/// The `WebAssembly.Table()` constructor creates a new `Table` object
|
||||
@ -2956,7 +3030,7 @@ pub mod WebAssembly {
|
||||
extern "C" {
|
||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
|
||||
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type Memory;
|
||||
|
||||
/// The `WebAssembly.Memory()` constructor creates a new `Memory` object
|
||||
@ -2997,8 +3071,8 @@ extern "C" {
|
||||
/// Notation (JSON)](https://json.org/) and converting values to JSON. It
|
||||
/// can't be called or constructed, and aside from its two method
|
||||
/// properties, it has no interesting functionality of its own.
|
||||
#[derive(Clone, Debug)]
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type JSON;
|
||||
|
||||
/// The `JSON.parse()` method parses a JSON string, constructing the
|
||||
@ -3056,8 +3130,8 @@ extern "C" {
|
||||
// JsString
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_name = String, extends = Object)]
|
||||
#[derive(Clone)]
|
||||
#[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub type JsString;
|
||||
|
||||
/// The length property of a String object indicates the length of a string,
|
||||
@ -3516,11 +3590,38 @@ impl JsString {
|
||||
/// If this JS value is not an instance of a string then this returns
|
||||
/// `None`.
|
||||
pub fn try_from(val: &JsValue) -> Option<&JsString> {
|
||||
if val.is_string() {
|
||||
Some(unsafe { mem::transmute(val) })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
val.dyn_ref()
|
||||
}
|
||||
|
||||
/// Returns whether this string is a valid UTF-16 string.
|
||||
///
|
||||
/// This is useful for learning whether `String::from(..)` will return a
|
||||
/// lossless representation of the JS string. If this string contains
|
||||
/// unpaired surrogates then `String::from` will succeed but it will be a
|
||||
/// lossy representation of the JS string because unpaired surrogates will
|
||||
/// become replacement characters.
|
||||
///
|
||||
/// If this function returns `false` then to get a lossless representation
|
||||
/// of the string you'll need to manually use the `iter` method (or the
|
||||
/// `char_code_at` accessor) to view the raw character codes.
|
||||
///
|
||||
/// For more information, see the documentation on [JS strings vs Rust
|
||||
/// strings][docs]
|
||||
///
|
||||
/// [docs]: https://rustwasm.github.io/docs/wasm-bindgen/reference/types/str.html
|
||||
pub fn is_valid_utf16(&self) -> bool {
|
||||
std::char::decode_utf16(self.iter()).all(|i| i.is_ok())
|
||||
}
|
||||
|
||||
/// Returns an iterator over the `u16` character codes that make up this JS
|
||||
/// string.
|
||||
///
|
||||
/// This method will call `char_code_at` for each code in this JS string,
|
||||
/// returning an iterator of the codes in sequence.
|
||||
pub fn iter<'a>(
|
||||
&'a self,
|
||||
) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + 'a {
|
||||
(0..self.length()).map(move |i| self.char_code_at(i) as u16)
|
||||
}
|
||||
}
|
||||
|
||||
@ -3550,9 +3651,7 @@ impl<'a> PartialEq<&'a String> for JsString {
|
||||
|
||||
impl<'a> From<&'a str> for JsString {
|
||||
fn from(s: &'a str) -> Self {
|
||||
JsString {
|
||||
obj: JsValue::from_str(s),
|
||||
}
|
||||
JsString::unchecked_from_js(JsValue::from_str(s))
|
||||
}
|
||||
}
|
||||
|
||||
@ -3583,6 +3682,7 @@ impl fmt::Debug for JsString {
|
||||
// Symbol
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(is_type_of = JsValue::is_symbol)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Symbol;
|
||||
|
||||
|
@ -541,3 +541,15 @@ fn raw() {
|
||||
);
|
||||
assert!(JsString::raw_0(&JsValue::null().unchecked_into()).is_err());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn is_valid_utf16() {
|
||||
assert!(JsString::from("a").is_valid_utf16());
|
||||
assert!(JsString::from("").is_valid_utf16());
|
||||
assert!(JsString::from("🥑").is_valid_utf16());
|
||||
assert!(JsString::from("Why hello there this, 🥑, is 🥑 and is 🥑").is_valid_utf16());
|
||||
|
||||
assert!(JsString::from_char_code1(0x00).is_valid_utf16());
|
||||
assert!(!JsString::from_char_code1(0xd800).is_valid_utf16());
|
||||
assert!(!JsString::from_char_code1(0xdc00).is_valid_utf16());
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.40"
|
||||
version = "0.2.42"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/macro-support"
|
||||
@ -20,5 +20,5 @@ strict-macro = []
|
||||
syn = { version = '0.15.0', features = ['visit'] }
|
||||
quote = '0.6'
|
||||
proc-macro2 = "0.4.9"
|
||||
wasm-bindgen-backend = { path = "../backend", version = "=0.2.40" }
|
||||
wasm-bindgen-shared = { path = "../shared", version = "=0.2.40" }
|
||||
wasm-bindgen-backend = { path = "../backend", version = "=0.2.42" }
|
||||
wasm-bindgen-shared = { path = "../shared", version = "=0.2.42" }
|
||||
|
@ -45,6 +45,7 @@ macro_rules! attrgen {
|
||||
(readonly, Readonly(Span)),
|
||||
(js_name, JsName(Span, String, Span)),
|
||||
(js_class, JsClass(Span, String, Span)),
|
||||
(is_type_of, IsTypeOf(Span, syn::Expr)),
|
||||
(extends, Extends(Span, syn::Path)),
|
||||
(vendor_prefix, VendorPrefix(Span, Ident)),
|
||||
(variadic, Variadic(Span)),
|
||||
@ -241,6 +242,11 @@ impl Parse for BindgenAttr {
|
||||
return Ok(BindgenAttr::$variant(attr_span, input.parse()?));
|
||||
});
|
||||
|
||||
(@parser $variant:ident(Span, syn::Expr)) => ({
|
||||
input.parse::<Token![=]>()?;
|
||||
return Ok(BindgenAttr::$variant(attr_span, input.parse()?));
|
||||
});
|
||||
|
||||
(@parser $variant:ident(Span, String, Span)) => ({
|
||||
input.parse::<Token![=]>()?;
|
||||
let (val, span) = match input.parse::<syn::LitStr>() {
|
||||
@ -523,6 +529,7 @@ impl ConvertToAst<BindgenAttrs> for syn::ForeignItemType {
|
||||
.js_name()
|
||||
.map(|s| s.0)
|
||||
.map_or_else(|| self.ident.to_string(), |s| s.to_string());
|
||||
let is_type_of = attrs.is_type_of().cloned();
|
||||
let shim = format!("__wbg_instanceof_{}_{}", self.ident, ShortHash(&self.ident));
|
||||
let mut extends = Vec::new();
|
||||
let mut vendor_prefixes = Vec::new();
|
||||
@ -545,6 +552,7 @@ impl ConvertToAst<BindgenAttrs> for syn::ForeignItemType {
|
||||
attrs: self.attrs,
|
||||
doc_comment: None,
|
||||
instanceof_shim: shim,
|
||||
is_type_of,
|
||||
rust_name: self.ident,
|
||||
js_name,
|
||||
extends,
|
||||
@ -904,7 +912,7 @@ fn prepare_for_impl_recursion(
|
||||
pound_token: Default::default(),
|
||||
style: syn::AttrStyle::Outer,
|
||||
bracket_token: Default::default(),
|
||||
path: syn::Ident::new("__wasm_bindgen_class_marker", Span::call_site()).into(),
|
||||
path: syn::parse_quote! { wasm_bindgen::prelude::__wasm_bindgen_class_marker },
|
||||
tts: quote::quote! { (#class = #js_class) }.into(),
|
||||
},
|
||||
);
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.40"
|
||||
version = "0.2.42"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/macro"
|
||||
@ -20,5 +20,5 @@ xxx_debug_only_print_generated_code = []
|
||||
strict-macro = ["wasm-bindgen-macro-support/strict-macro"]
|
||||
|
||||
[dependencies]
|
||||
wasm-bindgen-macro-support = { path = "../macro-support", version = "=0.2.40" }
|
||||
wasm-bindgen-macro-support = { path = "../macro-support", version = "=0.2.42" }
|
||||
quote = "0.6"
|
||||
|
10
crates/macro/ui-tests/pub-not-copy.rs
Normal file
10
crates/macro/ui-tests/pub-not-copy.rs
Normal file
@ -0,0 +1,10 @@
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct A {
|
||||
pub field: String,
|
||||
}
|
15
crates/macro/ui-tests/pub-not-copy.stderr
Normal file
15
crates/macro/ui-tests/pub-not-copy.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
error[E0277]: the trait bound `std::string::String: std::marker::Copy` is not satisfied
|
||||
--> $DIR/pub-not-copy.rs:9:16
|
||||
|
|
||||
9 | pub field: String,
|
||||
| ^^^^^^ the trait `std::marker::Copy` is not implemented for `std::string::String`
|
||||
|
|
||||
note: required by `__wbg_get_a_field::assert_copy`
|
||||
--> $DIR/pub-not-copy.rs:7:1
|
||||
|
|
||||
7 | #[wasm_bindgen]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.40"
|
||||
version = "0.2.42"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/shared"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "wasm-bindgen-test-macro"
|
||||
version = "0.2.40"
|
||||
version = "0.2.42"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
description = "Internal testing macro for wasm-bindgen"
|
||||
license = "MIT/Apache-2.0"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "wasm-bindgen-test"
|
||||
version = "0.2.40"
|
||||
version = "0.2.42"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
description = "Internal testing crate for wasm-bindgen"
|
||||
license = "MIT/Apache-2.0"
|
||||
@ -10,11 +10,11 @@ edition = "2018"
|
||||
[dependencies]
|
||||
console_error_panic_hook = '0.1'
|
||||
futures = "0.1"
|
||||
js-sys = { path = '../js-sys', version = '0.3.17' }
|
||||
js-sys = { path = '../js-sys', version = '0.3.19' }
|
||||
scoped-tls = "1.0"
|
||||
wasm-bindgen = { path = '../..', version = '0.2.40' }
|
||||
wasm-bindgen-futures = { path = '../futures', version = '0.3.17' }
|
||||
wasm-bindgen-test-macro = { path = '../test-macro', version = '=0.2.40' }
|
||||
wasm-bindgen = { path = '../..', version = '0.2.42' }
|
||||
wasm-bindgen-futures = { path = '../futures', version = '0.3.19' }
|
||||
wasm-bindgen-test-macro = { path = '../test-macro', version = '=0.2.42' }
|
||||
|
||||
[lib]
|
||||
test = false
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "wasm-bindgen-threads-xform"
|
||||
version = "0.2.40"
|
||||
version = "0.2.42"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/threads-xform"
|
||||
|
@ -11,6 +11,13 @@ cargo run -p wasm-bindgen-cli --bin wasm-bindgen -- \
|
||||
--out-dir pkg \
|
||||
--typescript
|
||||
|
||||
mkdir pkg/web
|
||||
cargo run -p wasm-bindgen-cli --bin wasm-bindgen -- \
|
||||
../../target/wasm32-unknown-unknown/debug/typescript_tests.wasm \
|
||||
--out-dir pkg/web \
|
||||
--target web \
|
||||
--typescript
|
||||
|
||||
if [ ! -d node_modules ]; then
|
||||
npm install
|
||||
fi
|
||||
|
3
crates/typescript-tests/src/web/init.ts
Normal file
3
crates/typescript-tests/src/web/init.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import * as wbg from '../../pkg/web/typescript_tests';
|
||||
|
||||
const init: Promise<any> = wbg.init('.');
|
@ -9,6 +9,6 @@
|
||||
"baseUrl": "."
|
||||
},
|
||||
"include": [
|
||||
"src/*.ts"
|
||||
"src/**/*.ts"
|
||||
]
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "wasm-bindgen-wasm-interpreter"
|
||||
version = "0.2.40"
|
||||
version = "0.2.42"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/wasm-interpreter"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "web-sys"
|
||||
version = "0.3.17"
|
||||
version = "0.3.19"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
readme = "./README.md"
|
||||
homepage = "https://rustwasm.github.io/wasm-bindgen/web-sys/index.html"
|
||||
@ -22,17 +22,17 @@ test = false
|
||||
[build-dependencies]
|
||||
env_logger = "0.6.0"
|
||||
failure = "0.1.2"
|
||||
wasm-bindgen-webidl = { path = "../webidl", version = "=0.2.40" }
|
||||
wasm-bindgen-webidl = { path = "../webidl", version = "=0.2.42" }
|
||||
sourcefile = "0.1"
|
||||
|
||||
[dependencies]
|
||||
wasm-bindgen = { path = "../..", version = "0.2.40" }
|
||||
js-sys = { path = '../js-sys', version = '0.3.17' }
|
||||
wasm-bindgen = { path = "../..", version = "0.2.42" }
|
||||
js-sys = { path = '../js-sys', version = '0.3.19' }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
|
||||
futures = "0.1"
|
||||
wasm-bindgen-test = { path = '../test', version = '0.2.40' }
|
||||
wasm-bindgen-futures = { path = '../futures', version = '0.3.17' }
|
||||
wasm-bindgen-test = { path = '../test', version = '0.2.42' }
|
||||
wasm-bindgen-futures = { path = '../futures', version = '0.3.19' }
|
||||
|
||||
# This list is generated by passing `__WASM_BINDGEN_DUMP_FEATURES=foo` when
|
||||
# compiling this crate which dumps the total list of features to a file called
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "wasm-bindgen-webidl"
|
||||
version = "0.2.40"
|
||||
version = "0.2.42"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
categories = ["wasm"]
|
||||
@ -19,5 +19,5 @@ log = "0.4.1"
|
||||
proc-macro2 = "0.4.8"
|
||||
quote = '0.6'
|
||||
syn = { version = '0.15', features = ['full'] }
|
||||
wasm-bindgen-backend = { version = "=0.2.40", path = "../backend" }
|
||||
wasm-bindgen-backend = { version = "=0.2.42", path = "../backend" }
|
||||
weedle = "0.8"
|
||||
|
@ -514,6 +514,7 @@ impl<'src> FirstPassRecord<'src> {
|
||||
attrs,
|
||||
doc_comment: None,
|
||||
instanceof_shim: format!("__widl_instanceof_{}", name),
|
||||
is_type_of: None,
|
||||
extends: Vec::new(),
|
||||
vendor_prefixes: Vec::new(),
|
||||
};
|
||||
|
Reference in New Issue
Block a user