mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-28 07:51:07 +00:00
Merge pull request #1179 from alexcrichton/catch-all-errors
In debug mode log all imported uncaught exceptions
This commit is contained in:
commit
715b4f4ced
@ -2420,6 +2420,9 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
|||||||
// Build up our shim's state, and we'll use that to guide whether we
|
// Build up our shim's state, and we'll use that to guide whether we
|
||||||
// actually emit an import here or not.
|
// actually emit an import here or not.
|
||||||
let mut shim = Rust2Js::new(self.cx);
|
let mut shim = Rust2Js::new(self.cx);
|
||||||
|
if shim.cx.config.debug {
|
||||||
|
shim.catch_and_rethrow(true);
|
||||||
|
}
|
||||||
shim.catch(import.catch)
|
shim.catch(import.catch)
|
||||||
.variadic(import.variadic)
|
.variadic(import.variadic)
|
||||||
.process(descriptor.unwrap_function())?;
|
.process(descriptor.unwrap_function())?;
|
||||||
|
@ -36,6 +36,7 @@ pub struct Rust2Js<'a, 'b: 'a> {
|
|||||||
|
|
||||||
/// Whether or not we're catching JS exceptions
|
/// Whether or not we're catching JS exceptions
|
||||||
catch: bool,
|
catch: bool,
|
||||||
|
catch_and_rethrow: bool,
|
||||||
|
|
||||||
/// Whether or not the last argument is a slice representing variadic arguments.
|
/// Whether or not the last argument is a slice representing variadic arguments.
|
||||||
variadic: bool,
|
variadic: bool,
|
||||||
@ -53,6 +54,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
arg_idx: 0,
|
arg_idx: 0,
|
||||||
ret_expr: String::new(),
|
ret_expr: String::new(),
|
||||||
catch: false,
|
catch: false,
|
||||||
|
catch_and_rethrow: false,
|
||||||
variadic: false,
|
variadic: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,6 +64,11 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn catch_and_rethrow(&mut self, catch_and_rethrow: bool) -> &mut Self {
|
||||||
|
self.catch_and_rethrow = catch_and_rethrow;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn variadic(&mut self, variadic: bool) -> &mut Self {
|
pub fn variadic(&mut self, variadic: bool) -> &mut Self {
|
||||||
self.variadic = variadic;
|
self.variadic = variadic;
|
||||||
self
|
self
|
||||||
@ -505,6 +512,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
let Rust2Js {
|
let Rust2Js {
|
||||||
// fields which may affect whether we do nontrivial work
|
// fields which may affect whether we do nontrivial work
|
||||||
catch,
|
catch,
|
||||||
|
catch_and_rethrow,
|
||||||
finally,
|
finally,
|
||||||
js_arguments,
|
js_arguments,
|
||||||
prelude,
|
prelude,
|
||||||
@ -520,6 +528,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
!catch &&
|
!catch &&
|
||||||
|
!catch_and_rethrow &&
|
||||||
!variadic &&
|
!variadic &&
|
||||||
prelude.is_empty() &&
|
prelude.is_empty() &&
|
||||||
finally.is_empty() &&
|
finally.is_empty() &&
|
||||||
@ -639,7 +648,21 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
",
|
",
|
||||||
&invoc, catch
|
&invoc, catch
|
||||||
);
|
);
|
||||||
};
|
} else if self.catch_and_rethrow {
|
||||||
|
invoc = format!(
|
||||||
|
"\
|
||||||
|
try {{\n\
|
||||||
|
{}
|
||||||
|
}} catch (e) {{\n\
|
||||||
|
console.error(\"wasm-bindgen: imported JS function that \
|
||||||
|
was not marked as `catch` threw an error:\", \
|
||||||
|
e);
|
||||||
|
throw e;
|
||||||
|
}}\
|
||||||
|
",
|
||||||
|
&invoc,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if self.finally.len() > 0 {
|
if self.finally.len() > 0 {
|
||||||
invoc = format!(
|
invoc = format!(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user