mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-16 05:59:21 +03:00
Merge pull request #1226 from Pauan/optimize-catch
Simplifying the error handling code
This commit is contained in:
commit
bf8a380264
@ -1546,6 +1546,23 @@ impl<'a> Context<'a> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn expose_handle_error(&mut self) {
|
||||||
|
if !self.should_write_global("handle_error") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.expose_uint32_memory();
|
||||||
|
self.expose_add_heap_object();
|
||||||
|
self.global(
|
||||||
|
"
|
||||||
|
function handleError(exnptr, e) {
|
||||||
|
const view = getUint32Memory();
|
||||||
|
view[exnptr / 4] = 1;
|
||||||
|
view[exnptr / 4 + 1] = addHeapObject(e);
|
||||||
|
}
|
||||||
|
",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn wasm_import_needed(&self, name: &str) -> bool {
|
fn wasm_import_needed(&self, name: &str) -> bool {
|
||||||
let imports = match self.module.import_section() {
|
let imports = match self.module.import_section() {
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
|
@ -643,23 +643,16 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if self.catch {
|
if self.catch {
|
||||||
self.cx.expose_uint32_memory();
|
self.cx.expose_handle_error();
|
||||||
self.cx.expose_add_heap_object();
|
|
||||||
let catch = "\
|
|
||||||
const view = getUint32Memory();\n\
|
|
||||||
view[exnptr / 4] = 1;\n\
|
|
||||||
view[exnptr / 4 + 1] = addHeapObject(e);\n\
|
|
||||||
";
|
|
||||||
|
|
||||||
invoc = format!(
|
invoc = format!(
|
||||||
"\
|
"\
|
||||||
try {{\n\
|
try {{\n\
|
||||||
{}
|
{}
|
||||||
}} catch (e) {{\n\
|
}} catch (e) {{\n\
|
||||||
{}
|
handleError(exnptr, e);\n\
|
||||||
}}\
|
}}\
|
||||||
",
|
",
|
||||||
&invoc, catch
|
&invoc
|
||||||
);
|
);
|
||||||
} else if self.catch_and_rethrow {
|
} else if self.catch_and_rethrow {
|
||||||
invoc = format!(
|
invoc = format!(
|
||||||
|
Loading…
Reference in New Issue
Block a user