diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 59d52e8d842..044e40cf271 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -213,7 +213,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: rustup update --no-self-update 1.56.0 && rustup default 1.56.0 + - run: rustup update --no-self-update 1.57.0 && rustup default 1.57.0 - run: cargo test -p wasm-bindgen-macro build_examples: diff --git a/Cargo.toml b/Cargo.toml index 1806dd98758..6e34d036770 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen" -version = "0.2.83" +version = "0.2.84" authors = ["The wasm-bindgen Developers"] license = "MIT/Apache-2.0" readme = "README.md" @@ -35,7 +35,7 @@ strict-macro = ["wasm-bindgen-macro/strict-macro"] xxx_debug_only_print_generated_code = ["wasm-bindgen-macro/xxx_debug_only_print_generated_code"] [dependencies] -wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.83" } +wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.84" } serde = { version = "1.0", optional = true } serde_json = { version = "1.0", optional = true } cfg-if = "1.0.0" diff --git a/crates/backend/Cargo.toml b/crates/backend/Cargo.toml index 56dcac338a1..9c674369341 100644 --- a/crates/backend/Cargo.toml +++ b/crates/backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen-backend" -version = "0.2.83" +version = "0.2.84" 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 @@ once_cell = "1.12" proc-macro2 = "1.0" quote = '1.0' syn = { version = '1.0', features = ['full'] } -wasm-bindgen-shared = { path = "../shared", version = "=0.2.83" } +wasm-bindgen-shared = { path = "../shared", version = "=0.2.84" } diff --git a/crates/backend/src/ast.rs b/crates/backend/src/ast.rs index 7703e2570f2..57eede5d632 100644 --- a/crates/backend/src/ast.rs +++ b/crates/backend/src/ast.rs @@ -21,7 +21,7 @@ pub struct Program { /// rust structs pub structs: Vec, /// custom typescript sections to be included in the definition file - pub typescript_custom_sections: Vec, + pub typescript_custom_sections: Vec, /// Inline JS snippets pub inline_js: Vec, } @@ -451,3 +451,14 @@ impl Function { Ok(name[4..].to_string()) } } + +/// Either the value of a string literal, or the [`proc_macro2::TokenStream`] +/// representation of a constant expression. +#[cfg_attr(feature = "extra-traits", derive(Debug))] +#[derive(Clone)] +pub enum LiteralOrExpression { + /// Literal string. + Literal(String), + /// Expression computing a constant string. + Expression(syn::Expr), +} diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index 5be0fad3350..d0f2c7602ae 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -1,6 +1,5 @@ use crate::ast; use crate::encode; -use crate::util::ShortHash; use crate::Diagnostic; use once_cell::sync::Lazy; use proc_macro2::{Ident, Literal, Span, TokenStream}; @@ -88,17 +87,8 @@ impl TryToTokens for ast::Program { shared::SCHEMA_VERSION, shared::version() ); + let prefix_json_len = prefix_json.len() as u32; let encoded = encode::encode(self)?; - let len = prefix_json.len() as u32; - let bytes = [ - &len.to_le_bytes()[..], - prefix_json.as_bytes(), - &encoded.custom_section, - ] - .concat(); - - let generated_static_length = bytes.len(); - let generated_static_value = syn::LitByteStr::new(&bytes, Span::call_site()); // We already consumed the contents of included files when generating // the custom section, but we want to make sure that updates to the @@ -113,18 +103,110 @@ impl TryToTokens for ast::Program { quote! { include_str!(#file) } }); - (quote! { - #[cfg(target_arch = "wasm32")] - #[automatically_derived] - const _: () = { - static _INCLUDED_FILES: &[&str] = &[#(#file_dependencies),*]; + let encoded_tokens = if let [encode::CustomSectionSlice::Literal(custom_section)] = + &encoded.custom_section_slices[..] + { + let custom_section_len = custom_section.len() as u32; + let bytes = [ + &prefix_json_len.to_le_bytes()[..], + prefix_json.as_bytes(), + &custom_section_len.to_le_bytes()[..], + custom_section, + ] + .concat(); + + let generated_static_length = bytes.len(); + let generated_static_value = syn::LitByteStr::new(&bytes, Span::call_site()); + + quote! { + #[cfg(target_arch = "wasm32")] + #[automatically_derived] + const _: () = { + static _INCLUDED_FILES: &[&str] = &[#(#file_dependencies),*]; + + #[link_section = "__wasm_bindgen_unstable"] + pub static _GENERATED: [u8; #generated_static_length] = + *#generated_static_value; + }; + } + } else { + let (prefix_json_literal_len, prefix_json_literal) = { + let bytes = [&prefix_json_len.to_le_bytes()[..], prefix_json.as_bytes()].concat(); - #[link_section = "__wasm_bindgen_unstable"] - pub static _GENERATED: [u8; #generated_static_length] = - *#generated_static_value; + (bytes.len(), syn::LitByteStr::new(&bytes, Span::call_site())) }; - }) - .to_tokens(tokens); + let prefix_json_literal_len_literal = + syn::LitInt::new(&prefix_json_literal_len.to_string(), Span::call_site()); + let concat_args = encoded + .custom_section_slices + .iter() + .map(|slice| match slice { + encode::CustomSectionSlice::Literal(bytes) => { + let literal = syn::LitByteStr::new(bytes, Span::call_site()); + + quote! { #literal } + } + encode::CustomSectionSlice::Expression(expr) => { + quote! { + { + // Store `#expr` into a constant first to generate + // better error messages if `#expr` isn't a string. + const _VALUE_STR: &str = #expr; + + // `const` functions cannot both evaluate the length + // they need to allocate as well as allocate that + // length, so we need to evaluate strings in two + // steps. + // Additionally, the length is encoded using + // variable-length encoding, so we don't know ahead + // of time the size of the buffer needed to encode + // the length, so we have to compute a length and + // then allocate a buffer twice in total, and then + // concatenate these values. + + const _VALUE: &[u8] = _VALUE_STR.as_bytes(); + const _VALUE_LEN: usize = _VALUE.len(); + const _VALUE_LEN_VLE_LEN: usize = + wasm_bindgen::macro_support::vle_len(_VALUE_LEN); + const _VALUE_LEN_VLE: [u8; _VALUE_LEN_VLE_LEN] = + wasm_bindgen::macro_support::vle(_VALUE_LEN); + const _TOTAL_LEN: usize = _VALUE_LEN_VLE_LEN + _VALUE_LEN; + + &wasm_bindgen::macro_support::concat::<_TOTAL_LEN>( + &[&_VALUE_LEN_VLE, _VALUE]) + } + } + } + }); + let concat_args_clone = concat_args.clone(); + + quote! { + #[cfg(target_arch = "wasm32")] + #[automatically_derived] + const _: () = { + static _INCLUDED_FILES: &[&str] = &[#(#file_dependencies),*]; + + // See comment above for why we use so many intermediate + // constants. + const _GENERATED_ARGS: &[&[u8]] = &[#(#concat_args_clone),*]; + const _GENERATED_ARGS_LEN: usize = + wasm_bindgen::macro_support::concat_len(_GENERATED_ARGS); + const _GENERATED_LEN: usize = + #prefix_json_literal_len_literal + 4 + _GENERATED_ARGS_LEN; + + #[link_section = "__wasm_bindgen_unstable"] + pub static _GENERATED: [u8; _GENERATED_LEN] = + wasm_bindgen::macro_support::concat::<_GENERATED_LEN>(&[ + #prefix_json_literal, + &_GENERATED_ARGS_LEN.to_le_bytes(), + &wasm_bindgen::macro_support::concat::<_GENERATED_ARGS_LEN>( + _GENERATED_ARGS), + ]); + }; + } + }; + + encoded_tokens.to_tokens(tokens); Ok(()) } diff --git a/crates/backend/src/encode.rs b/crates/backend/src/encode.rs index 41d3c8b773a..9f4d0dd9c88 100644 --- a/crates/backend/src/encode.rs +++ b/crates/backend/src/encode.rs @@ -1,5 +1,6 @@ use crate::util::ShortHash; use proc_macro2::{Ident, Span}; +use quote::ToTokens; use std::cell::{Cell, RefCell}; use std::collections::HashMap; use std::env; @@ -9,8 +10,13 @@ use std::path::PathBuf; use crate::ast; use crate::Diagnostic; +pub enum CustomSectionSlice { + Literal(Vec), + Expression(proc_macro2::TokenStream), +} + pub struct EncodeResult { - pub custom_section: Vec, + pub custom_section_slices: Vec, pub included_files: Vec, } @@ -18,7 +24,7 @@ pub fn encode(program: &ast::Program) -> Result { let mut e = Encoder::new(); let i = Interner::new(); shared_program(program, &i)?.encode(&mut e); - let custom_section = e.finish(); + let custom_section_slices = e.finish(); let included_files = i .files .borrow() @@ -27,7 +33,7 @@ pub fn encode(program: &ast::Program) -> Result { .cloned() .collect(); Ok(EncodeResult { - custom_section, + custom_section_slices, included_files, }) } @@ -144,7 +150,7 @@ fn shared_program<'a>( typescript_custom_sections: prog .typescript_custom_sections .iter() - .map(|x| -> &'a str { &x }) + .map(|x| shared_literal_or_expression(x, intern)) .collect(), local_modules: intern .files @@ -337,25 +343,39 @@ fn shared_struct_field<'a>(s: &'a ast::StructField, _intern: &'a Interner) -> St } } +fn shared_literal_or_expression<'a>( + s: &'a ast::LiteralOrExpression, + _intern: &'a Interner, +) -> LiteralOrExpression<'a> { + match s { + ast::LiteralOrExpression::Literal(lit) => LiteralOrExpression::Literal(lit.as_str()), + ast::LiteralOrExpression::Expression(expr) => LiteralOrExpression::Expression(expr), + } +} + trait Encode { fn encode(&self, dst: &mut Encoder); } struct Encoder { + slices: Vec, dst: Vec, } impl Encoder { fn new() -> Encoder { Encoder { - dst: vec![0, 0, 0, 0], + slices: Vec::new(), + dst: Vec::new(), } } - fn finish(mut self) -> Vec { - let len = (self.dst.len() - 4) as u32; - self.dst[..4].copy_from_slice(&len.to_le_bytes()[..]); - self.dst + fn finish(self) -> Vec { + let Self { mut slices, dst } = self; + if !dst.is_empty() { + slices.push(CustomSectionSlice::Literal(dst)); + } + slices } fn byte(&mut self, byte: u8) { @@ -363,6 +383,17 @@ impl Encoder { } } +impl Encode for syn::Expr { + fn encode(&self, dst: &mut Encoder) { + let tokens = self.to_token_stream(); + if !dst.dst.is_empty() { + dst.slices + .push(CustomSectionSlice::Literal(std::mem::take(&mut dst.dst))); + } + dst.slices.push(CustomSectionSlice::Expression(tokens)); + } +} + impl Encode for bool { fn encode(&self, dst: &mut Encoder) { dst.byte(*self as u8); diff --git a/crates/cli-support/Cargo.toml b/crates/cli-support/Cargo.toml index 99294871bc4..322eb0ba1cd 100644 --- a/crates/cli-support/Cargo.toml +++ b/crates/cli-support/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen-cli-support" -version = "0.2.83" +version = "0.2.84" authors = ["The wasm-bindgen Developers"] license = "MIT/Apache-2.0" repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/cli-support" @@ -19,12 +19,12 @@ rustc-demangle = "0.1.13" serde_json = "1.0" tempfile = "3.0" walrus = "0.19.0" -wasm-bindgen-externref-xform = { path = '../externref-xform', version = '=0.2.83' } -wasm-bindgen-multi-value-xform = { path = '../multi-value-xform', version = '=0.2.83' } -wasm-bindgen-shared = { path = "../shared", version = '=0.2.83' } -wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.83' } -wasm-bindgen-wasm-conventions = { path = '../wasm-conventions', version = '=0.2.83' } -wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.83' } +wasm-bindgen-externref-xform = { path = '../externref-xform', version = '=0.2.84' } +wasm-bindgen-multi-value-xform = { path = '../multi-value-xform', version = '=0.2.84' } +wasm-bindgen-shared = { path = "../shared", version = '=0.2.84' } +wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.84' } +wasm-bindgen-wasm-conventions = { path = '../wasm-conventions', version = '=0.2.84' } +wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.84' } wit-text = "0.8.0" wit-walrus = "0.6.0" wit-validator = "0.2.0" diff --git a/crates/cli-support/src/decode.rs b/crates/cli-support/src/decode.rs index d58b49ff06d..ab335aa2e13 100644 --- a/crates/cli-support/src/decode.rs +++ b/crates/cli-support/src/decode.rs @@ -5,7 +5,7 @@ pub trait Decode<'src>: Sized { fn decode_all(mut data: &'src [u8]) -> Self { let ret = Self::decode(&mut data); - assert!(data.len() == 0); + assert_eq!(data.len(), 0); return ret; } } @@ -154,4 +154,11 @@ macro_rules! decode_api { ); } +mod syn { + /// Alias `syn::Expr` to `str` when decoding; an expression is evaluated as + /// a Rust constant during compilation, so when we decode the buffer we can + /// expect a string instead. + pub type Expr = str; +} + wasm_bindgen_shared::shared_api!(decode_api); diff --git a/crates/cli-support/src/wit/mod.rs b/crates/cli-support/src/wit/mod.rs index f5b56e0079d..c0402a7ffd3 100644 --- a/crates/cli-support/src/wit/mod.rs +++ b/crates/cli-support/src/wit/mod.rs @@ -389,6 +389,11 @@ impl<'a> Context<'a> { self.struct_(struct_)?; } for section in typescript_custom_sections { + let section = match section { + decode::LiteralOrExpression::Literal(section) => section, + decode::LiteralOrExpression::Expression(x) => x, // match *x {}, + }; + self.aux.extra_typescript.push_str(section); self.aux.extra_typescript.push_str("\n\n"); } diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 0d914175cef..d754991020b 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen-cli" -version = "0.2.83" +version = "0.2.84" authors = ["The wasm-bindgen Developers"] license = "MIT/Apache-2.0" repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/cli" @@ -26,8 +26,8 @@ serde = { version = "1.0", features = ['derive'] } serde_derive = "1.0" serde_json = "1.0" walrus = { version = "0.19.0", features = ['parallel'] } -wasm-bindgen-cli-support = { path = "../cli-support", version = "=0.2.83" } -wasm-bindgen-shared = { path = "../shared", version = "=0.2.83" } +wasm-bindgen-cli-support = { path = "../cli-support", version = "=0.2.84" } +wasm-bindgen-shared = { path = "../shared", version = "=0.2.84" } [dev-dependencies] assert_cmd = "1.0" diff --git a/crates/externref-xform/Cargo.toml b/crates/externref-xform/Cargo.toml index 57e7d7f79cc..8bd66dea0b3 100644 --- a/crates/externref-xform/Cargo.toml +++ b/crates/externref-xform/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen-externref-xform" -version = "0.2.83" +version = "0.2.84" authors = ["The wasm-bindgen Developers"] license = "MIT/Apache-2.0" repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/externref-xform" diff --git a/crates/futures/Cargo.toml b/crates/futures/Cargo.toml index 696733eb3bd..1f11f06e25b 100644 --- a/crates/futures/Cargo.toml +++ b/crates/futures/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [dependencies] cfg-if = "1.0.0" js-sys = { path = "../js-sys", version = '0.3.60' } -wasm-bindgen = { path = "../..", version = '0.2.83' } +wasm-bindgen = { path = "../..", version = '0.2.84' } futures-core = { version = '0.3.8', default-features = false, optional = true } [features] diff --git a/crates/js-sys/Cargo.toml b/crates/js-sys/Cargo.toml index fd2efd64391..dabace55aae 100644 --- a/crates/js-sys/Cargo.toml +++ b/crates/js-sys/Cargo.toml @@ -19,7 +19,7 @@ test = false doctest = false [dependencies] -wasm-bindgen = { path = "../..", version = "0.2.83" } +wasm-bindgen = { path = "../..", version = "0.2.84" } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = { path = '../test', version = '=0.3.33' } diff --git a/crates/macro-support/Cargo.toml b/crates/macro-support/Cargo.toml index 0e393be6069..d44821c5b66 100644 --- a/crates/macro-support/Cargo.toml +++ b/crates/macro-support/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen-macro-support" -version = "0.2.83" +version = "0.2.84" 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 = '1.0.84', features = ['visit', 'full'] } quote = '1.0' proc-macro2 = "1.0" -wasm-bindgen-backend = { path = "../backend", version = "=0.2.83" } -wasm-bindgen-shared = { path = "../shared", version = "=0.2.83" } +wasm-bindgen-backend = { path = "../backend", version = "=0.2.84" } +wasm-bindgen-shared = { path = "../shared", version = "=0.2.84" } diff --git a/crates/macro-support/src/parser.rs b/crates/macro-support/src/parser.rs index d05f139f62e..9f3788b013b 100644 --- a/crates/macro-support/src/parser.rs +++ b/crates/macro-support/src/parser.rs @@ -1335,17 +1335,15 @@ impl MacroParse for syn::ItemConst { bail_span!(self, "#[wasm_bindgen] will not work on constants unless you are defining a #[wasm_bindgen(typescript_custom_section)]."); } - match get_expr(&self.expr) { - syn::Expr::Lit(syn::ExprLit { - lit: syn::Lit::Str(litstr), - .. - }) => { - program.typescript_custom_sections.push(litstr.value()); - } - expr => { - bail_span!(expr, "Expected a string literal to be used with #[wasm_bindgen(typescript_custom_section)]."); - } - } + program + .typescript_custom_sections + .push(match get_expr(&self.expr) { + syn::Expr::Lit(syn::ExprLit { + lit: syn::Lit::Str(litstr), + .. + }) => ast::LiteralOrExpression::Literal(litstr.value()), + expr => ast::LiteralOrExpression::Expression(expr.clone()), + }); opts.check_used(); diff --git a/crates/macro/Cargo.toml b/crates/macro/Cargo.toml index f7a0bbb2176..9db1e82255a 100644 --- a/crates/macro/Cargo.toml +++ b/crates/macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen-macro" -version = "0.2.83" +version = "0.2.84" authors = ["The wasm-bindgen Developers"] license = "MIT/Apache-2.0" repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/macro" @@ -20,10 +20,10 @@ 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.83" } +wasm-bindgen-macro-support = { path = "../macro-support", version = "=0.2.84" } quote = "1.0" [dev-dependencies] trybuild = "1.0" -wasm-bindgen = { path = "../..", version = "0.2.83" } +wasm-bindgen = { path = "../..", version = "0.2.84" } wasm-bindgen-futures = { path = "../futures", version = "0.4.33" } diff --git a/crates/macro/README.md b/crates/macro/README.md index 353829869f2..98c71335629 100644 --- a/crates/macro/README.md +++ b/crates/macro/README.md @@ -17,11 +17,11 @@ To add a test: * Create `ui-tests/my-awesome-test.rs` * Write an invalid `#[wasm_bindgen]` invocation, testing the error you're generating -* Execute `cargo test -p ui-tests`, the test will fail +* Execute `cargo test -p wasm-bindgen-macro`, the test will fail * From within the `ui-tests` folder, execute `./update-all-references.sh`. This should create a `my-awesome-test.stderr` file. * Inspect `my-awesome-test.stderr` to make sure it looks ok -* Rerun `cargo test -p ui-tests` and your tests should pass! +* Rerun `cargo test -p wasm-bindgen-macro` and your tests should pass! Testing here is a work in progress, see [#601](https://github.com/rustwasm/wasm-bindgen/issues/601) for more diff --git a/crates/macro/ui-tests/async-errors.stderr b/crates/macro/ui-tests/async-errors.stderr index 492492a181e..fffa205bf2d 100644 --- a/crates/macro/ui-tests/async-errors.stderr +++ b/crates/macro/ui-tests/async-errors.stderr @@ -1,68 +1,68 @@ error[E0277]: the trait bound `Result<(), ()>: IntoJsResult` is not satisfied - --> ui-tests/async-errors.rs:30:1 - | -30 | #[wasm_bindgen] - | ^^^^^^^^^^^^^^^ the trait `IntoJsResult` is not implemented for `Result<(), ()>` - | - = help: the following implementations were found: - as IntoJsResult> - as IntoJsResult> + --> ui-tests/async-errors.rs:30:1 + | +30 | #[wasm_bindgen] + | ^^^^^^^^^^^^^^^ the trait `IntoJsResult` is not implemented for `Result<(), ()>` + | + = help: the following implementations were found: + as IntoJsResult> + as IntoJsResult> note: required by `into_js_result` - --> $WORKSPACE/src/lib.rs - | - | fn into_js_result(self) -> Result; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/src/lib.rs + | + | fn into_js_result(self) -> Result; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Result<(), BadType>: IntoJsResult` is not satisfied - --> ui-tests/async-errors.rs:32:1 - | -32 | #[wasm_bindgen] - | ^^^^^^^^^^^^^^^ the trait `IntoJsResult` is not implemented for `Result<(), BadType>` - | - = help: the following implementations were found: - as IntoJsResult> - as IntoJsResult> + --> ui-tests/async-errors.rs:32:1 + | +32 | #[wasm_bindgen] + | ^^^^^^^^^^^^^^^ the trait `IntoJsResult` is not implemented for `Result<(), BadType>` + | + = help: the following implementations were found: + as IntoJsResult> + as IntoJsResult> note: required by `into_js_result` - --> $WORKSPACE/src/lib.rs - | - | fn into_js_result(self) -> Result; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/src/lib.rs + | + | fn into_js_result(self) -> Result; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `wasm_bindgen::JsValue: From` is not satisfied - --> ui-tests/async-errors.rs:34:1 - | -34 | #[wasm_bindgen] - | ^^^^^^^^^^^^^^^ the trait `From` is not implemented for `wasm_bindgen::JsValue` - | - = help: the following implementations were found: - > - > - > - > - and 73 others - = note: required because of the requirements on the impl of `Into` for `BadType` - = note: required because of the requirements on the impl of `IntoJsResult` for `BadType` + --> ui-tests/async-errors.rs:34:1 + | +34 | #[wasm_bindgen] + | ^^^^^^^^^^^^^^^ the trait `From` is not implemented for `wasm_bindgen::JsValue` + | + = help: the following implementations were found: + > + > + > + > + and $N others + = note: required because of the requirements on the impl of `Into` for `BadType` + = note: required because of the requirements on the impl of `IntoJsResult` for `BadType` note: required by `into_js_result` - --> $WORKSPACE/src/lib.rs - | - | fn into_js_result(self) -> Result; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/src/lib.rs + | + | fn into_js_result(self) -> Result; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Result: IntoJsResult` is not satisfied - --> ui-tests/async-errors.rs:36:1 - | -36 | #[wasm_bindgen] - | ^^^^^^^^^^^^^^^ the trait `IntoJsResult` is not implemented for `Result` - | - = help: the following implementations were found: - as IntoJsResult> - as IntoJsResult> + --> ui-tests/async-errors.rs:36:1 + | +36 | #[wasm_bindgen] + | ^^^^^^^^^^^^^^^ the trait `IntoJsResult` is not implemented for `Result` + | + = help: the following implementations were found: + as IntoJsResult> + as IntoJsResult> note: required by `into_js_result` - --> $WORKSPACE/src/lib.rs - | - | fn into_js_result(self) -> Result; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/src/lib.rs + | + | fn into_js_result(self) -> Result; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/macro/ui-tests/invalid-methods.stderr b/crates/macro/ui-tests/invalid-methods.stderr index a785fc1ffc2..694da760a98 100644 --- a/crates/macro/ui-tests/invalid-methods.stderr +++ b/crates/macro/ui-tests/invalid-methods.stderr @@ -1,59 +1,59 @@ error: #[wasm_bindgen] default impls are not supported - --> $DIR/invalid-methods.rs:7:1 + --> ui-tests/invalid-methods.rs:7:1 | 7 | default impl A { | ^^^^^^^ error: #[wasm_bindgen] unsafe impls are not supported - --> $DIR/invalid-methods.rs:11:1 + --> ui-tests/invalid-methods.rs:11:1 | 11 | unsafe impl A { | ^^^^^^ error: #[wasm_bindgen] trait impls are not supported - --> $DIR/invalid-methods.rs:15:6 + --> ui-tests/invalid-methods.rs:15:6 | 15 | impl Clone for A { | ^^^^^ error: #[wasm_bindgen] generic impls aren't supported - --> $DIR/invalid-methods.rs:19:5 + --> ui-tests/invalid-methods.rs:19:5 | 19 | impl A { | ^^^ error: unsupported self type in #[wasm_bindgen] impl - --> $DIR/invalid-methods.rs:23:6 + --> ui-tests/invalid-methods.rs:23:6 | 23 | impl &'static A { | ^^^^^^^^^^ error: const definitions aren't supported with #[wasm_bindgen] - --> $DIR/invalid-methods.rs:30:5 + --> ui-tests/invalid-methods.rs:30:5 | 30 | const X: u32 = 3; | ^^^^^^^^^^^^^^^^^ error: type definitions in impls aren't supported with #[wasm_bindgen] - --> $DIR/invalid-methods.rs:31:5 + --> ui-tests/invalid-methods.rs:31:5 | 31 | type Y = u32; | ^^^^^^^^^^^^^ error: macros in impls aren't supported - --> $DIR/invalid-methods.rs:32:5 + --> ui-tests/invalid-methods.rs:32:5 | 32 | x!(); | ^^^^^ error: can only #[wasm_bindgen] non-const functions - --> $DIR/invalid-methods.rs:39:9 + --> ui-tests/invalid-methods.rs:39:9 | 39 | pub const fn foo() {} | ^^^^^ warning: unused macro definition - --> $DIR/invalid-methods.rs:26:1 + --> ui-tests/invalid-methods.rs:26:1 | 26 | macro_rules! x { () => () } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/crates/macro/ui-tests/missing-catch.stderr b/crates/macro/ui-tests/missing-catch.stderr index 4c20dbe76f7..d08553b1b37 100644 --- a/crates/macro/ui-tests/missing-catch.stderr +++ b/crates/macro/ui-tests/missing-catch.stderr @@ -1,17 +1,17 @@ error[E0277]: the trait bound `Result: FromWasmAbi` is not satisfied - --> $DIR/missing-catch.rs:6:9 - | -6 | pub fn foo() -> Result; - | ^^^ the trait `FromWasmAbi` is not implemented for `Result` - | + --> ui-tests/missing-catch.rs:6:9 + | +6 | pub fn foo() -> Result; + | ^^^ the trait `FromWasmAbi` is not implemented for `Result` + | note: required by a bound in `FromWasmAbi` - --> $DIR/traits.rs:23:1 - | -23 | / pub trait FromWasmAbi: WasmDescribe { -24 | | /// The wasm ABI type that this converts from when coming back out from the -25 | | /// ABI boundary. -26 | | type Abi: WasmAbi; -... | -35 | | unsafe fn from_abi(js: Self::Abi) -> Self; -36 | | } - | |_^ required by this bound in `FromWasmAbi` + --> $WORKSPACE/src/convert/traits.rs + | + | / pub trait FromWasmAbi: WasmDescribe { + | | /// The wasm ABI type that this converts from when coming back out from the + | | /// ABI boundary. + | | type Abi: WasmAbi; +... | + | | unsafe fn from_abi(js: Self::Abi) -> Self; + | | } + | |_^ required by this bound in `FromWasmAbi` diff --git a/crates/macro/ui-tests/start-function.stderr b/crates/macro/ui-tests/start-function.stderr index 8f459863d2e..691aa63e63d 100644 --- a/crates/macro/ui-tests/start-function.stderr +++ b/crates/macro/ui-tests/start-function.stderr @@ -11,61 +11,61 @@ error: the start function cannot have generics | ^^^ error[E0277]: the trait bound `Result: wasm_bindgen::__rt::Start` is not satisfied - --> ui-tests/start-function.rs:15:1 - | -15 | #[wasm_bindgen(start)] - | ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result` - | - = help: the following implementations were found: - as wasm_bindgen::__rt::Start> + --> ui-tests/start-function.rs:15:1 + | +15 | #[wasm_bindgen(start)] + | ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result` + | + = help: the following implementations were found: + as wasm_bindgen::__rt::Start> note: required by `start` - --> $WORKSPACE/src/lib.rs - | - | fn start(self); - | ^^^^^^^^^^^^^^^ - = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/src/lib.rs + | + | fn start(self); + | ^^^^^^^^^^^^^^^ + = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Result: wasm_bindgen::__rt::Start` is not satisfied - --> ui-tests/start-function.rs:18:1 - | -18 | #[wasm_bindgen(start)] - | ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result` - | - = help: the following implementations were found: - as wasm_bindgen::__rt::Start> + --> ui-tests/start-function.rs:18:1 + | +18 | #[wasm_bindgen(start)] + | ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result` + | + = help: the following implementations were found: + as wasm_bindgen::__rt::Start> note: required by `start` - --> $WORKSPACE/src/lib.rs - | - | fn start(self); - | ^^^^^^^^^^^^^^^ - = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/src/lib.rs + | + | fn start(self); + | ^^^^^^^^^^^^^^^ + = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Result: wasm_bindgen::__rt::Start` is not satisfied - --> ui-tests/start-function.rs:27:1 - | -27 | #[wasm_bindgen(start)] - | ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result` - | - = help: the following implementations were found: - as wasm_bindgen::__rt::Start> + --> ui-tests/start-function.rs:27:1 + | +27 | #[wasm_bindgen(start)] + | ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result` + | + = help: the following implementations were found: + as wasm_bindgen::__rt::Start> note: required by `start` - --> $WORKSPACE/src/lib.rs - | - | fn start(self); - | ^^^^^^^^^^^^^^^ - = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/src/lib.rs + | + | fn start(self); + | ^^^^^^^^^^^^^^^ + = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Result: wasm_bindgen::__rt::Start` is not satisfied - --> ui-tests/start-function.rs:30:1 - | -30 | #[wasm_bindgen(start)] - | ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result` - | - = help: the following implementations were found: - as wasm_bindgen::__rt::Start> + --> ui-tests/start-function.rs:30:1 + | +30 | #[wasm_bindgen(start)] + | ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result` + | + = help: the following implementations were found: + as wasm_bindgen::__rt::Start> note: required by `start` - --> $WORKSPACE/src/lib.rs - | - | fn start(self); - | ^^^^^^^^^^^^^^^ - = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/src/lib.rs + | + | fn start(self); + | ^^^^^^^^^^^^^^^ + = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/macro/ui-tests/traits-not-implemented.stderr b/crates/macro/ui-tests/traits-not-implemented.stderr index 7b0f90f574c..aaad988af58 100644 --- a/crates/macro/ui-tests/traits-not-implemented.stderr +++ b/crates/macro/ui-tests/traits-not-implemented.stderr @@ -1,18 +1,18 @@ error[E0277]: the trait bound `A: IntoWasmAbi` is not satisfied - --> $DIR/traits-not-implemented.rs:5:1 - | -5 | #[wasm_bindgen] - | ^^^^^^^^^^^^^^^ the trait `IntoWasmAbi` is not implemented for `A` - | + --> ui-tests/traits-not-implemented.rs:5:1 + | +5 | #[wasm_bindgen] + | ^^^^^^^^^^^^^^^ the trait `IntoWasmAbi` is not implemented for `A` + | note: required by a bound in `IntoWasmAbi` - --> $DIR/traits.rs:9:1 - | -9 | / pub trait IntoWasmAbi: WasmDescribe { -10 | | /// The wasm ABI type that this converts into when crossing the ABI -11 | | /// boundary. -12 | | type Abi: WasmAbi; -... | -16 | | fn into_abi(self) -> Self::Abi; -17 | | } - | |_^ required by this bound in `IntoWasmAbi` - = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/src/convert/traits.rs + | + | / pub trait IntoWasmAbi: WasmDescribe { + | | /// The wasm ABI type that this converts into when crossing the ABI + | | /// boundary. + | | type Abi: WasmAbi; +... | + | | fn into_abi(self) -> Self::Abi; + | | } + | |_^ required by this bound in `IntoWasmAbi` + = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/macro/ui-tests/unused-attributes.stderr b/crates/macro/ui-tests/unused-attributes.stderr index c4ba32f0817..1df8f26a021 100644 --- a/crates/macro/ui-tests/unused-attributes.stderr +++ b/crates/macro/ui-tests/unused-attributes.stderr @@ -22,6 +22,12 @@ error: unused variable: `readonly` 21 | #[wasm_bindgen(readonly)] | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_readonly` +error: unused variable: `typescript_type` + --> ui-tests/unused-attributes.rs:26:28 + | +26 | #[wasm_bindgen(getter, typescript_type = "Thing[]")] + | ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_typescript_type` + error: unused variable: `getter_with_clone` --> ui-tests/unused-attributes.rs:24:16 | @@ -33,9 +39,3 @@ error: unused variable: `final` | 24 | #[wasm_bindgen(getter_with_clone, final)] | ^^^^^ help: if this is intentional, prefix it with an underscore: `_final` - -error: unused variable: `typescript_type` - --> ui-tests/unused-attributes.rs:26:28 - | -26 | #[wasm_bindgen(getter, typescript_type = "Thing[]")] - | ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_typescript_type` diff --git a/crates/multi-value-xform/Cargo.toml b/crates/multi-value-xform/Cargo.toml index 767e47d2524..ac5b6c6e3b7 100644 --- a/crates/multi-value-xform/Cargo.toml +++ b/crates/multi-value-xform/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen-multi-value-xform" -version = "0.2.83" +version = "0.2.84" authors = ["The wasm-bindgen Developers"] license = "MIT/Apache-2.0" repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/multi-value-xform" diff --git a/crates/shared/Cargo.toml b/crates/shared/Cargo.toml index 013ccd8c6c3..2cb4ed7924b 100644 --- a/crates/shared/Cargo.toml +++ b/crates/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen-shared" -version = "0.2.83" +version = "0.2.84" authors = ["The wasm-bindgen Developers"] license = "MIT/Apache-2.0" repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/shared" diff --git a/crates/shared/src/lib.rs b/crates/shared/src/lib.rs index f69d8f4a855..cbb14445877 100644 --- a/crates/shared/src/lib.rs +++ b/crates/shared/src/lib.rs @@ -6,7 +6,7 @@ mod schema_hash_approval; // This gets changed whenever our schema changes. // At this time versions of wasm-bindgen and wasm-bindgen-cli are required to have the exact same // SCHEMA_VERSION in order to work together. -pub const SCHEMA_VERSION: &str = "0.2.83"; +pub const SCHEMA_VERSION: &str = "0.2.84"; #[macro_export] macro_rules! shared_api { @@ -17,7 +17,7 @@ macro_rules! shared_api { enums: Vec>, imports: Vec>, structs: Vec>, - typescript_custom_sections: Vec<&'a str>, + typescript_custom_sections: Vec>, local_modules: Vec>, inline_js: Vec<&'a str>, unique_crate_identifier: &'a str, @@ -139,6 +139,11 @@ macro_rules! shared_api { identifier: &'a str, contents: &'a str, } + + enum LiteralOrExpression<'a> { + Literal(&'a str), + Expression(&'a syn::Expr), + } } }; // end of mac case } // end of mac definition diff --git a/crates/shared/src/schema_hash_approval.rs b/crates/shared/src/schema_hash_approval.rs index 4692a28c81e..c7b7ee58a5b 100644 --- a/crates/shared/src/schema_hash_approval.rs +++ b/crates/shared/src/schema_hash_approval.rs @@ -8,7 +8,7 @@ // If the schema in this library has changed then: // 1. Bump the version in `crates/shared/Cargo.toml` // 2. Change the `SCHEMA_VERSION` in this library to this new Cargo.toml version -const APPROVED_SCHEMA_FILE_HASH: &'static str = "17656911631008664055"; +const APPROVED_SCHEMA_FILE_HASH: &'static str = "1917474777926115096"; #[test] fn schema_version() { diff --git a/crates/test/Cargo.toml b/crates/test/Cargo.toml index a61ac6b7324..ed979b345b8 100644 --- a/crates/test/Cargo.toml +++ b/crates/test/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" console_error_panic_hook = '0.1' js-sys = { path = '../js-sys', version = '0.3.60' } scoped-tls = "1.0" -wasm-bindgen = { path = '../..', version = '0.2.83' } +wasm-bindgen = { path = '../..', version = '0.2.84' } wasm-bindgen-futures = { path = '../futures', version = '0.4.33' } wasm-bindgen-test-macro = { path = '../test-macro', version = '=0.3.33' } diff --git a/crates/threads-xform/Cargo.toml b/crates/threads-xform/Cargo.toml index 64c4b81e5b8..c2908ab5fa9 100644 --- a/crates/threads-xform/Cargo.toml +++ b/crates/threads-xform/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen-threads-xform" -version = "0.2.83" +version = "0.2.84" authors = ["The wasm-bindgen Developers"] license = "MIT/Apache-2.0" repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/threads-xform" @@ -14,7 +14,7 @@ edition = "2018" [dependencies] anyhow = "1.0" walrus = "0.19.0" -wasm-bindgen-wasm-conventions = { path = "../wasm-conventions", version = "=0.2.83" } +wasm-bindgen-wasm-conventions = { path = "../wasm-conventions", version = "=0.2.84" } [dev-dependencies] rayon = "1.0" diff --git a/crates/typescript-tests/src/custom_section.rs b/crates/typescript-tests/src/custom_section.rs index d4b602677f7..6c5b5bfac27 100644 --- a/crates/typescript-tests/src/custom_section.rs +++ b/crates/typescript-tests/src/custom_section.rs @@ -5,7 +5,21 @@ const TS_INTERFACE_EXPORT: &'static str = r" interface Height { height: number; } "; +#[wasm_bindgen(typescript_custom_section)] +const TS_INTERFACE_EXPORT_NON_LITERAL: &'static str = std::concat!( + "interface Name { name: NameString; }\n", + std::include_str!("./data/custom_section_intf.ts") +); + #[wasm_bindgen] pub struct Person { pub height: u32, } + +#[wasm_bindgen] +impl Person { + #[wasm_bindgen(getter)] + pub fn name(&self) -> String { + "Alice".into() + } +} diff --git a/crates/typescript-tests/src/custom_section.ts b/crates/typescript-tests/src/custom_section.ts index 6420ea6dd59..f453d56c71b 100644 --- a/crates/typescript-tests/src/custom_section.ts +++ b/crates/typescript-tests/src/custom_section.ts @@ -1,3 +1,3 @@ import * as wbg from '../pkg/typescript_tests'; -const height: wbg.Height = new wbg.Person(); \ No newline at end of file +const height: wbg.Height & wbg.Name = new wbg.Person(); \ No newline at end of file diff --git a/crates/typescript-tests/src/data/custom_section_intf.ts b/crates/typescript-tests/src/data/custom_section_intf.ts new file mode 100644 index 00000000000..e19b80f88f0 --- /dev/null +++ b/crates/typescript-tests/src/data/custom_section_intf.ts @@ -0,0 +1 @@ +type NameString = string; \ No newline at end of file diff --git a/crates/wasm-conventions/Cargo.toml b/crates/wasm-conventions/Cargo.toml index c677658f5da..d0c1034f26b 100644 --- a/crates/wasm-conventions/Cargo.toml +++ b/crates/wasm-conventions/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen-wasm-conventions" -version = "0.2.83" +version = "0.2.84" authors = ["The wasm-bindgen developers"] license = "MIT/Apache-2.0" repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/wasm-conventions" diff --git a/crates/wasm-interpreter/Cargo.toml b/crates/wasm-interpreter/Cargo.toml index 4635d2d1dce..a25b008a452 100644 --- a/crates/wasm-interpreter/Cargo.toml +++ b/crates/wasm-interpreter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen-wasm-interpreter" -version = "0.2.83" +version = "0.2.84" authors = ["The wasm-bindgen Developers"] license = "MIT/Apache-2.0" repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/wasm-interpreter" @@ -15,7 +15,7 @@ edition = '2018' anyhow = "1.0" log = "0.4" walrus = "0.19.0" -wasm-bindgen-wasm-conventions = { path = "../wasm-conventions", version = "0.2.83" } +wasm-bindgen-wasm-conventions = { path = "../wasm-conventions", version = "0.2.84" } [dev-dependencies] tempfile = "3" diff --git a/crates/web-sys/Cargo.toml b/crates/web-sys/Cargo.toml index e252b2d0fa6..496d46ec2b4 100644 --- a/crates/web-sys/Cargo.toml +++ b/crates/web-sys/Cargo.toml @@ -21,7 +21,7 @@ doctest = false test = false [dependencies] -wasm-bindgen = { path = "../..", version = "0.2.83" } +wasm-bindgen = { path = "../..", version = "0.2.84" } js-sys = { path = '../js-sys', version = '0.3.60' } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] diff --git a/crates/webidl/Cargo.toml b/crates/webidl/Cargo.toml index d07c4f0ab82..15519d3ad04 100644 --- a/crates/webidl/Cargo.toml +++ b/crates/webidl/Cargo.toml @@ -20,7 +20,7 @@ log = "0.4.1" proc-macro2 = "1.0" quote = '1.0' syn = { version = '1.0', features = ['full'] } -wasm-bindgen-backend = { version = "=0.2.83", path = "../backend" } +wasm-bindgen-backend = { version = "=0.2.84", path = "../backend" } weedle = { git = "https://github.com/rustwasm/weedle.git" } once_cell = "1.12" sourcefile = "0.1" diff --git a/examples/add/Cargo.toml b/examples/add/Cargo.toml index fdff38f2eef..5d524496928 100644 --- a/examples/add/Cargo.toml +++ b/examples/add/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" diff --git a/examples/canvas/Cargo.toml b/examples/canvas/Cargo.toml index 4884000626b..8842b52e759 100644 --- a/examples/canvas/Cargo.toml +++ b/examples/canvas/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] js-sys = "0.3.60" -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" [dependencies.web-sys] version = "0.3.4" diff --git a/examples/char/Cargo.toml b/examples/char/Cargo.toml index d6999023ed7..e2f335087d7 100644 --- a/examples/char/Cargo.toml +++ b/examples/char/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" diff --git a/examples/closures/Cargo.toml b/examples/closures/Cargo.toml index 57ebeceae08..2a7fb197717 100644 --- a/examples/closures/Cargo.toml +++ b/examples/closures/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" js-sys = "0.3.60" [dependencies.web-sys] diff --git a/examples/console_log/Cargo.toml b/examples/console_log/Cargo.toml index fceca22faa9..3fcaffb5bc8 100644 --- a/examples/console_log/Cargo.toml +++ b/examples/console_log/Cargo.toml @@ -8,5 +8,5 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" web-sys = { version = "0.3.60", features = ['console'] } diff --git a/examples/deno/Cargo.toml b/examples/deno/Cargo.toml index 307ed26e2e8..13b9dad8751 100644 --- a/examples/deno/Cargo.toml +++ b/examples/deno/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" diff --git a/examples/dom/Cargo.toml b/examples/dom/Cargo.toml index bb65d27f123..42b68c763c1 100644 --- a/examples/dom/Cargo.toml +++ b/examples/dom/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" [dependencies.web-sys] version = "0.3.4" diff --git a/examples/duck-typed-interfaces/Cargo.toml b/examples/duck-typed-interfaces/Cargo.toml index c51d0c4c650..c6fa54c71ad 100644 --- a/examples/duck-typed-interfaces/Cargo.toml +++ b/examples/duck-typed-interfaces/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" diff --git a/examples/fetch/Cargo.toml b/examples/fetch/Cargo.toml index 56650346a4b..bd4bdd46deb 100644 --- a/examples/fetch/Cargo.toml +++ b/examples/fetch/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" js-sys = "0.3.60" wasm-bindgen-futures = "0.4.33" diff --git a/examples/guide-supported-types-examples/Cargo.toml b/examples/guide-supported-types-examples/Cargo.toml index d5c6b5bb62f..017018b4bdb 100644 --- a/examples/guide-supported-types-examples/Cargo.toml +++ b/examples/guide-supported-types-examples/Cargo.toml @@ -8,5 +8,5 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" js-sys = "0.3.60" diff --git a/examples/hello_world/Cargo.toml b/examples/hello_world/Cargo.toml index abff0cf3fd8..0de7d193861 100644 --- a/examples/hello_world/Cargo.toml +++ b/examples/hello_world/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" diff --git a/examples/import_js/crate/Cargo.toml b/examples/import_js/crate/Cargo.toml index 34af28ff828..540bf214188 100644 --- a/examples/import_js/crate/Cargo.toml +++ b/examples/import_js/crate/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" diff --git a/examples/julia_set/Cargo.toml b/examples/julia_set/Cargo.toml index dc24bcdb4d4..d42a367055d 100644 --- a/examples/julia_set/Cargo.toml +++ b/examples/julia_set/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" [dependencies.web-sys] version = "0.3.4" diff --git a/examples/paint/Cargo.toml b/examples/paint/Cargo.toml index 904786551fa..e968f5a20ab 100644 --- a/examples/paint/Cargo.toml +++ b/examples/paint/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] js-sys = "0.3.60" -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" [dependencies.web-sys] version = "0.3.4" diff --git a/examples/performance/Cargo.toml b/examples/performance/Cargo.toml index 0c2cf684b13..1a7ba6827ef 100644 --- a/examples/performance/Cargo.toml +++ b/examples/performance/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" humantime = "2" [dependencies.web-sys] diff --git a/examples/raytrace-parallel/Cargo.toml b/examples/raytrace-parallel/Cargo.toml index c3840f119cd..836290435cb 100644 --- a/examples/raytrace-parallel/Cargo.toml +++ b/examples/raytrace-parallel/Cargo.toml @@ -15,7 +15,7 @@ rayon-core = "1.5.0" raytracer = { git = 'https://github.com/alexcrichton/raytracer', branch = 'update-deps' } serde-wasm-bindgen = "0.4.3" futures-channel-preview = "0.3.0-alpha.18" -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" wasm-bindgen-futures = "0.4.33" [dependencies.web-sys] diff --git a/examples/request-animation-frame/Cargo.toml b/examples/request-animation-frame/Cargo.toml index fff34c58d3f..d3b0aa2499f 100644 --- a/examples/request-animation-frame/Cargo.toml +++ b/examples/request-animation-frame/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" [dependencies.web-sys] version = "0.3.4" diff --git a/examples/synchronous-instantiation/Cargo.toml b/examples/synchronous-instantiation/Cargo.toml index 92fce05271b..6644b450386 100644 --- a/examples/synchronous-instantiation/Cargo.toml +++ b/examples/synchronous-instantiation/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" diff --git a/examples/todomvc/Cargo.toml b/examples/todomvc/Cargo.toml index 85f566cc59c..227009bef5a 100644 --- a/examples/todomvc/Cargo.toml +++ b/examples/todomvc/Cargo.toml @@ -12,7 +12,7 @@ askama = "0.10.0" [dependencies] js-sys = "0.3.60" -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" askama = "0.10.0" console_error_panic_hook = "0.1.5" diff --git a/examples/wasm-audio-worklet/Cargo.toml b/examples/wasm-audio-worklet/Cargo.toml index 184226d67f3..4ba4c4d15b3 100644 --- a/examples/wasm-audio-worklet/Cargo.toml +++ b/examples/wasm-audio-worklet/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] console_log = "0.2.0" js-sys = "0.3.60" -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" wasm-bindgen-futures = "0.4.33" [dependencies.web-sys] diff --git a/examples/wasm-in-wasm-imports/Cargo.toml b/examples/wasm-in-wasm-imports/Cargo.toml index f7c984fbcd3..9bad9d96ffb 100644 --- a/examples/wasm-in-wasm-imports/Cargo.toml +++ b/examples/wasm-in-wasm-imports/Cargo.toml @@ -8,6 +8,6 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" js-sys = "0.3.60" wasm-bindgen-futures = "0.4.33" diff --git a/examples/wasm-in-wasm/Cargo.toml b/examples/wasm-in-wasm/Cargo.toml index 6f0adfb80a3..feb6b6019a2 100644 --- a/examples/wasm-in-wasm/Cargo.toml +++ b/examples/wasm-in-wasm/Cargo.toml @@ -8,6 +8,6 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" js-sys = "0.3.60" wasm-bindgen-futures = "0.4.33" diff --git a/examples/wasm-in-web-worker/Cargo.toml b/examples/wasm-in-web-worker/Cargo.toml index b104a4781da..0e187a531c9 100644 --- a/examples/wasm-in-web-worker/Cargo.toml +++ b/examples/wasm-in-web-worker/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" console_error_panic_hook = { version = "0.1.6", optional = true } [dependencies.web-sys] diff --git a/examples/wasm2js/Cargo.toml b/examples/wasm2js/Cargo.toml index 68bceb4dc5d..d0cef92950b 100644 --- a/examples/wasm2js/Cargo.toml +++ b/examples/wasm2js/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" diff --git a/examples/weather_report/Cargo.toml b/examples/weather_report/Cargo.toml index a91699e7726..b64e23e3919 100644 --- a/examples/weather_report/Cargo.toml +++ b/examples/weather_report/Cargo.toml @@ -15,7 +15,7 @@ chrono = "0.4.11" reqwest = "0.10.6" wasm-bindgen-futures = "0.4.1" json= "*" -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" gloo = "0.2.1" [dependencies.web-sys] diff --git a/examples/webaudio/Cargo.toml b/examples/webaudio/Cargo.toml index 6c50bb5ce2c..a4a16ba4235 100644 --- a/examples/webaudio/Cargo.toml +++ b/examples/webaudio/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" [dependencies.web-sys] version = "0.3.4" diff --git a/examples/webgl/Cargo.toml b/examples/webgl/Cargo.toml index a5efb9f693e..bb59180c096 100644 --- a/examples/webgl/Cargo.toml +++ b/examples/webgl/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] js-sys = "0.3.60" -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" [dependencies.web-sys] version = "0.3.4" diff --git a/examples/webrtc_datachannel/Cargo.toml b/examples/webrtc_datachannel/Cargo.toml index 2c31ace92bf..5dab301ab88 100644 --- a/examples/webrtc_datachannel/Cargo.toml +++ b/examples/webrtc_datachannel/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" js-sys = "0.3" wasm-bindgen-futures = "0.4.33" diff --git a/examples/websockets/Cargo.toml b/examples/websockets/Cargo.toml index fd34117a0e8..014ad0c86e6 100644 --- a/examples/websockets/Cargo.toml +++ b/examples/websockets/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" js-sys = "0.3" [dependencies.web-sys] diff --git a/examples/webxr/Cargo.toml b/examples/webxr/Cargo.toml index 6955841341b..47f5ada4eaa 100644 --- a/examples/webxr/Cargo.toml +++ b/examples/webxr/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["cdylib"] [dependencies] futures = "0.3.4" js-sys = "0.3.60" -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" wasm-bindgen-futures = "0.4.33" [dependencies.web-sys] diff --git a/examples/without-a-bundler/Cargo.toml b/examples/without-a-bundler/Cargo.toml index 4180dafafdb..038a7829cb6 100644 --- a/examples/without-a-bundler/Cargo.toml +++ b/examples/without-a-bundler/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -wasm-bindgen = "0.2.83" +wasm-bindgen = "0.2.84" [dependencies.web-sys] version = "0.3.4" diff --git a/guide/src/contributing/testing.md b/guide/src/contributing/testing.md index fe3bca622a4..4eff646ee13 100644 --- a/guide/src/contributing/testing.md +++ b/guide/src/contributing/testing.md @@ -35,7 +35,7 @@ These tests assert that we have reasonable error messages that point to the right source spans when the `#[wasm_bindgen]` proc-macro is misused. ``` -cargo test -p ui-tests +cargo test -p wasm-bindgen-macro ``` ## The `js-sys` Tests diff --git a/src/lib.rs b/src/lib.rs index 2d6ace32639..6aaa1eaf843 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,6 +65,7 @@ pub mod prelude { pub mod convert; pub mod describe; +pub mod macro_support; mod cast; pub use crate::cast::{JsCast, JsObject}; diff --git a/src/macro_support.rs b/src/macro_support.rs new file mode 100644 index 00000000000..d35111f340c --- /dev/null +++ b/src/macro_support.rs @@ -0,0 +1,73 @@ +#![doc(hidden)] + +/// Returns the length of the buffer resulting from the concatenation of all the +/// given byte buffers. +pub const fn concat_len(strings: &[&[u8]]) -> usize { + let mut len = 0; + let mut i = 0; + + while i < strings.len() { + len += strings[i].len(); + i += 1; + } + + len +} + +/// Returns a byte buffer containing the concatenation of all the given byte +/// buffers. +pub const fn concat(strings: &[&[u8]]) -> [u8; LEN] { + let mut buf = [0; LEN]; + + let mut buf_i = 0; + let mut strings_i = 0; + + while strings_i < strings.len() { + let string = &strings[strings_i]; + let mut string_i = 0; + + while string_i < string.len() { + buf[buf_i] = string[string_i]; + buf_i += 1; + string_i += 1; + } + + strings_i += 1; + } + + assert!(buf_i == LEN); + + buf +} + +/// Returns the length in bytes it takes to encode the given value using VLE. +pub const fn vle_len(mut value: usize) -> usize { + let mut len = 1; + + while (value >> 7) != 0 { + len += 1; + value >>= 7; + } + + assert!(value >> 7 == 0); + + len +} + +/// Returns the VLE of the given value. +pub const fn vle(mut value: usize) -> [u8; LEN] { + let mut result = [0; LEN]; + let mut result_i = 0; + + while (value >> 7) != 0 { + result[result_i] = (value as u8) | 0x80; + result_i += 1; + value >>= 7; + } + + assert!(value >> 7 == 0); + assert!(result_i + 1 == LEN); + + result[result_i] = value as u8; + result +}