MCPcopy Index your code
hub / github.com/RustPython/RustPython / js_err_to_py_err

Function js_err_to_py_err

crates/wasm/src/convert.rs:71–88  ·  view source on GitHub ↗
(vm: &VirtualMachine, js_err: &JsValue)

Source from the content-addressed store, hash-verified

69}
70
71pub 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
90pub fn py_to_js(vm: &VirtualMachine, py_obj: PyObjectRef) -> JsValue {
91 if let Some(ref wasm_id) = vm.wasm_id

Callers 1

js_to_pyFunction · 0.85

Calls 5

new_exception_msgMethod · 0.80
messageMethod · 0.80
to_ownedMethod · 0.45
as_strMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected