| 69 | } |
| 70 | |
| 71 | pub fn js_err_to_py_err(vm: &VirtualMachine, js_err: &JsValue) -> PyBaseExceptionRef { |
| 72 | match js_err.dyn_ref::<js_sys::Error>() { |
| 73 | Some(err) => { |
| 74 | let exc_type = match String::from(err.name()).as_str() { |
| 75 | "TypeError" => vm.ctx.exceptions.type_error, |
| 76 | "ReferenceError" => vm.ctx.exceptions.name_error, |
| 77 | "SyntaxError" => vm.ctx.exceptions.syntax_error, |
| 78 | _ => vm.ctx.exceptions.exception_type, |
| 79 | } |
| 80 | .to_owned(); |
| 81 | vm.new_exception_msg(exc_type, String::from(err.message()).into()) |
| 82 | } |
| 83 | None => vm.new_exception_msg( |
| 84 | vm.ctx.exceptions.exception_type.to_owned(), |
| 85 | format!("{js_err:?}").into(), |
| 86 | ), |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | pub fn py_to_js(vm: &VirtualMachine, py_obj: PyObjectRef) -> JsValue { |
| 91 | if let Some(ref wasm_id) = vm.wasm_id |