mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-26 11:34:22 +03:00
Merge pull request #740 from alexcrichton/catch-constructors
Fix the `constructor` and `catch` attributes combined
This commit is contained in:
commit
ccae331b2a
@ -486,7 +486,7 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option<String>)> for syn::ForeignItemFn
|
|||||||
|
|
||||||
ast::ImportFunctionKind::Method { class, ty, kind }
|
ast::ImportFunctionKind::Method { class, ty, kind }
|
||||||
} else if opts.constructor() {
|
} else if opts.constructor() {
|
||||||
let class = match wasm.ret {
|
let class = match js_ret {
|
||||||
Some(ref ty) => ty,
|
Some(ref ty) => ty,
|
||||||
_ => bail_span!(self, "constructor returns must be bare types"),
|
_ => bail_span!(self, "constructor returns must be bare types"),
|
||||||
};
|
};
|
||||||
|
@ -123,3 +123,11 @@ exports.run_rust_option_tests = function() {
|
|||||||
assert.strictEqual(wasm.rust_return_none(), undefined);
|
assert.strictEqual(wasm.rust_return_none(), undefined);
|
||||||
assert.strictEqual(wasm.rust_return_some() === undefined, false);
|
assert.strictEqual(wasm.rust_return_some() === undefined, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.CatchConstructors = class {
|
||||||
|
constructor(x) {
|
||||||
|
if (x == 0) {
|
||||||
|
throw new Error('bad!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -76,6 +76,10 @@ extern {
|
|||||||
fn return_undefined() -> Option<Options>;
|
fn return_undefined() -> Option<Options>;
|
||||||
fn return_some() -> Option<Options>;
|
fn return_some() -> Option<Options>;
|
||||||
fn run_rust_option_tests();
|
fn run_rust_option_tests();
|
||||||
|
|
||||||
|
type CatchConstructors;
|
||||||
|
#[wasm_bindgen(constructor, catch)]
|
||||||
|
fn new(x: u32) -> Result<CatchConstructors, JsValue>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
@ -199,3 +203,9 @@ pub fn rust_return_none() -> Option<Options> {
|
|||||||
pub fn rust_return_some() -> Option<Options> {
|
pub fn rust_return_some() -> Option<Options> {
|
||||||
Some(Options::new())
|
Some(Options::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn catch_constructors() {
|
||||||
|
assert!(CatchConstructors::new(0).is_err());
|
||||||
|
assert!(CatchConstructors::new(1).is_ok());
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user