Log stacks of imported JS functions that throw but are not marked catch

Particularly useful in our tests, where we don't have the regular console
logging with post-facto object inspection, and instead need to provide all this
info up front.
This commit is contained in:
Nick Fitzgerald 2019-04-16 11:50:08 -07:00
parent 10cbc789a8
commit 805aaa2273

View File

@ -716,13 +716,23 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
try {{\n\
{}
}} catch (e) {{\n\
console.error(\"wasm-bindgen: imported JS function that \
let error = (function () {{
try {{
return e instanceof Error
? `${{e.message}}\n\nStack:\n${{e.stack}}`
: e.toString();
}} catch(_) {{
return \"<failed to stringify thrown value>\";
}}
}}());
console.error(\"wasm-bindgen: imported JS function `{}` that \
was not marked as `catch` threw an error:\", \
e);
error);
throw e;
}}\
",
&invoc,
shim,
);
}