diff --git a/crates/macro-support/src/parser.rs b/crates/macro-support/src/parser.rs index 18b198a6a..a3de4d17c 100644 --- a/crates/macro-support/src/parser.rs +++ b/crates/macro-support/src/parser.rs @@ -486,7 +486,7 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option)> for syn::ForeignItemFn ast::ImportFunctionKind::Method { class, ty, kind } } else if opts.constructor() { - let class = match wasm.ret { + let class = match js_ret { Some(ref ty) => ty, _ => bail_span!(self, "constructor returns must be bare types"), }; diff --git a/tests/wasm/import_class.js b/tests/wasm/import_class.js index 6154d9ce3..fa60847c7 100644 --- a/tests/wasm/import_class.js +++ b/tests/wasm/import_class.js @@ -123,3 +123,11 @@ exports.run_rust_option_tests = function() { assert.strictEqual(wasm.rust_return_none(), undefined); assert.strictEqual(wasm.rust_return_some() === undefined, false); }; + +exports.CatchConstructors = class { + constructor(x) { + if (x == 0) { + throw new Error('bad!'); + } + } +}; diff --git a/tests/wasm/import_class.rs b/tests/wasm/import_class.rs index 06083ea2c..64c97d142 100644 --- a/tests/wasm/import_class.rs +++ b/tests/wasm/import_class.rs @@ -76,6 +76,10 @@ extern { fn return_undefined() -> Option; fn return_some() -> Option; fn run_rust_option_tests(); + + type CatchConstructors; + #[wasm_bindgen(constructor, catch)] + fn new(x: u32) -> Result; } #[wasm_bindgen] @@ -199,3 +203,9 @@ pub fn rust_return_none() -> Option { pub fn rust_return_some() -> Option { Some(Options::new()) } + +#[wasm_bindgen_test] +fn catch_constructors() { + assert!(CatchConstructors::new(0).is_err()); + assert!(CatchConstructors::new(1).is_ok()); +}