From d3b2fa6e02dd35e58d81d9261631129bcd444721 Mon Sep 17 00:00:00 2001 From: coolreader18 <33094578+coolreader18@users.noreply.github.com> Date: Wed, 8 Jan 2020 17:42:38 -0600 Subject: [PATCH 1/5] Allow serializing PyBaseExceptionRef --- vm/src/exceptions.rs | 77 +++++++++++++++++++++++++++++++++++--- vm/src/obj/objtraceback.rs | 18 +++++++++ 2 files changed, 90 insertions(+), 5 deletions(-) diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 5a7cc1d8d1..8e05859631 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -4,12 +4,13 @@ use crate::obj::objstr::{PyString, PyStringRef}; use crate::obj::objtraceback::PyTracebackRef; use crate::obj::objtuple::{PyTuple, PyTupleRef}; use crate::obj::objtype::{self, PyClass, PyClassRef}; +use crate::py_serde; use crate::pyobject::{ PyClassImpl, PyContext, PyIterable, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, }; use crate::types::create_type; -use crate::vm::VirtualMachine; +use crate::VirtualMachine; use itertools::Itertools; use std::cell::{Cell, RefCell}; use std::fmt; @@ -245,10 +246,8 @@ pub fn write_exception_inner( ) -> io::Result<()> { if let Some(tb) = exc.traceback.borrow().clone() { writeln!(output, "Traceback (most recent call last):")?; - let mut tb = Some(&tb); - while let Some(traceback) = tb { - write_traceback_entry(output, traceback)?; - tb = traceback.next.as_ref(); + for tb in tb.iter() { + write_traceback_entry(output, &tb)?; } } else { writeln!(output, "No traceback set on exception")?; @@ -662,3 +661,71 @@ pub fn init(ctx: &PyContext) { "reason" => ctx.new_property(make_arg_getter(3)), }); } + +pub struct SerializeException<'s> { + vm: &'s VirtualMachine, + exc: &'s PyBaseExceptionRef, +} + +impl<'s> SerializeException<'s> { + pub fn new(vm: &'s VirtualMachine, exc: &'s PyBaseExceptionRef) -> Self { + SerializeException { vm, exc } + } +} + +impl serde::Serialize for SerializeException<'_> { + fn serialize(&self, s: S) -> Result { + use serde::ser::*; + + let mut struc = s.serialize_struct("PyBaseException", 7)?; + struc.serialize_field("exc_type", &self.exc.class().name)?; + let tbs = { + struct Tracebacks(PyTracebackRef); + impl serde::Serialize for Tracebacks { + fn serialize(&self, s: S) -> Result { + let mut s = s.serialize_seq(None)?; + for tb in self.0.iter() { + s.serialize_element(&*tb)?; + } + s.end() + } + } + self.exc.traceback().map(Tracebacks) + }; + struc.serialize_field("traceback", &tbs)?; + struc.serialize_field( + "cause", + &self.exc.cause().as_ref().map(|e| Self::new(self.vm, e)), + )?; + struc.serialize_field( + "context", + &self.exc.context().as_ref().map(|e| Self::new(self.vm, e)), + )?; + struc.serialize_field("suppress_context", &self.exc.suppress_context.get())?; + + let args = { + struct Args<'vm>(&'vm VirtualMachine, PyTupleRef); + impl serde::Serialize for Args<'_> { + fn serialize(&self, s: S) -> Result { + s.collect_seq( + self.1 + .as_slice() + .iter() + .map(|arg| py_serde::PyObjectSerializer::new(self.0, arg)), + ) + } + } + Args(self.vm, self.exc.args()) + }; + struc.serialize_field("args", &args)?; + + let rendered = { + let mut rendered = Vec::::new(); + write_exception(&mut rendered, self.vm, &self.exc).map_err(S::Error::custom)?; + String::from_utf8(rendered).map_err(S::Error::custom)? + }; + struc.serialize_field("rendered", &rendered)?; + + struc.end() + } +} diff --git a/vm/src/obj/objtraceback.rs b/vm/src/obj/objtraceback.rs index 81664ad567..4a49bebecb 100644 --- a/vm/src/obj/objtraceback.rs +++ b/vm/src/obj/objtraceback.rs @@ -52,6 +52,24 @@ impl PyTraceback { } } +impl PyTracebackRef { + pub fn iter<'a>(&'a self) -> impl Iterator + 'a { + std::iter::successors(Some(self.clone()), |tb| tb.next.clone()) + } +} + pub fn init(context: &PyContext) { PyTraceback::extend_class(context, &context.types.traceback_type); } + +impl serde::Serialize for PyTraceback { + fn serialize(&self, s: S) -> Result { + use serde::ser::SerializeStruct; + + let mut struc = s.serialize_struct("PyTraceback", 3)?; + struc.serialize_field("name", &self.frame.code.obj_name)?; + struc.serialize_field("lineno", &self.lineno)?; + struc.serialize_field("filename", &self.frame.code.source_path)?; + struc.end() + } +} From 4a0a9167caa8ec32eb22f690c44f5c2cef4d5971 Mon Sep 17 00:00:00 2001 From: coolreader18 <33094578+coolreader18@users.noreply.github.com> Date: Wed, 8 Jan 2020 17:42:59 -0600 Subject: [PATCH 2/5] Improve wasm errors --- wasm/lib/src/convert.rs | 51 +++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/wasm/lib/src/convert.rs b/wasm/lib/src/convert.rs index ffb3240187..a1a7bc2598 100644 --- a/wasm/lib/src/convert.rs +++ b/wasm/lib/src/convert.rs @@ -5,41 +5,38 @@ use wasm_bindgen::{closure::Closure, prelude::*, JsCast}; use rustpython_vm::exceptions::PyBaseExceptionRef; use rustpython_vm::function::PyFuncArgs; use rustpython_vm::obj::{objbytes, objtype}; -use rustpython_vm::py_serde; use rustpython_vm::pyobject::{ItemProtocol, PyObjectRef, PyResult, PyValue}; use rustpython_vm::VirtualMachine; +use rustpython_vm::{exceptions, py_serde}; use crate::browser_module; use crate::vm_class::{stored_vm_from_wasm, WASMVirtualMachine}; +#[wasm_bindgen(inline_js = r" +export class PyError extends Error { + constructor(info) { + const msg = info.args[0]; + if (typeof msg === 'string') super(msg); + else super(); + this.info = info; + } + get name() { return this.info.exc_type; } + get traceback() { return this.info.traceback; } + toString() { return this.info.rendered; } +} +")] +extern "C" { + type PyError; + #[wasm_bindgen(constructor)] + fn new(info: JsValue) -> PyError; +} + pub fn py_err_to_js_err(vm: &VirtualMachine, py_err: &PyBaseExceptionRef) -> JsValue { - macro_rules! map_exceptions { - ($py_exc:ident, $msg:expr, { $($py_exc_ty:expr => $js_err_new:expr),*$(,)? }) => { - $(if objtype::isinstance($py_exc, $py_exc_ty) { - JsValue::from($js_err_new($msg)) - } else)* { - JsValue::from(js_sys::Error::new($msg)) - } - }; + let res = serde_wasm_bindgen::to_value(&exceptions::SerializeException::new(vm, py_err)); + match res { + Ok(err_info) => PyError::new(err_info).into(), + Err(e) => e.into(), } - let msg = match vm.to_str(py_err.as_object()) { - Ok(msg) => msg, - Err(_) => return js_sys::Error::new("error getting error").into(), - }; - let js_err = map_exceptions!(py_err, msg.as_str(), { - // TypeError is sort of a catch-all for "this value isn't what I thought it was like" - &vm.ctx.exceptions.type_error => js_sys::TypeError::new, - &vm.ctx.exceptions.value_error => js_sys::TypeError::new, - &vm.ctx.exceptions.index_error => js_sys::TypeError::new, - &vm.ctx.exceptions.key_error => js_sys::TypeError::new, - &vm.ctx.exceptions.attribute_error => js_sys::TypeError::new, - &vm.ctx.exceptions.name_error => js_sys::ReferenceError::new, - &vm.ctx.exceptions.syntax_error => js_sys::SyntaxError::new, - }); - if let Some(tb) = py_err.traceback() { - let _ = Reflect::set(&js_err, &"row".into(), &(tb.lineno as u32).into()); - } - js_err } pub fn js_py_typeerror(vm: &VirtualMachine, js_err: JsValue) -> PyBaseExceptionRef { From 6f43d22b560451f0c8fcea4d39b62f643cf48b5a Mon Sep 17 00:00:00 2001 From: coolreader18 <33094578+coolreader18@users.noreply.github.com> Date: Wed, 8 Jan 2020 18:06:26 -0600 Subject: [PATCH 3/5] Fix pyExec not returning errors, remove typescript hack --- wasm/demo/src/style.css | 1 + wasm/lib/src/lib.rs | 27 ++++++--------------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/wasm/demo/src/style.css b/wasm/demo/src/style.css index 8fc18ecce6..771894e491 100644 --- a/wasm/demo/src/style.css +++ b/wasm/demo/src/style.css @@ -24,6 +24,7 @@ textarea { color: tomato; margin-top: 10px; font-family: monospace; + white-space: pre; } #code-wrapper { diff --git a/wasm/lib/src/lib.rs b/wasm/lib/src/lib.rs index d6cbaae8bd..7cec6a940a 100644 --- a/wasm/lib/src/lib.rs +++ b/wasm/lib/src/lib.rs @@ -45,10 +45,6 @@ pub fn setup_console_error() { std::panic::set_hook(Box::new(panic_hook)); } -// Hack to comment out wasm-bindgen's generated typescript definitons -#[wasm_bindgen(typescript_custom_section)] -const TS_CMT_START: &'static str = "/*"; - fn run_py(source: &str, options: Option, mode: Mode) -> Result { let vm = VMStore::init(PY_EVAL_VM_ID.into(), Some(true)); let options = options.unwrap_or_else(Object::new); @@ -70,7 +66,7 @@ fn run_py(source: &str, options: Option, mode: Mode) -> Result, mode: Mode) -> Result void) | null`: A function to replace the /// native print native print function, and it will be `console.log` when giving /// `undefined` or "console", and it will be a dumb function when giving null. - +#[wasm_bindgen(js_name = pyEval)] pub fn eval_py(source: &str, options: Option) -> Result { run_py(source, options, Mode::Eval) } -#[wasm_bindgen(js_name = pyExec)] /// Evaluate Python code /// /// ```js @@ -102,11 +97,11 @@ pub fn eval_py(source: &str, options: Option) -> Result) { - let _ = run_py(source, options, Mode::Exec); +#[wasm_bindgen(js_name = pyExec)] +pub fn exec_py(source: &str, options: Option) -> Result<(), JsValue> { + run_py(source, options, Mode::Exec).map(drop) } -#[wasm_bindgen(js_name = pyExecSingle)] /// Evaluate Python code /// /// ```js @@ -116,17 +111,7 @@ pub fn exec_py(source: &str, options: Option) { /// `code`: `string`: The Python code to run in exec single mode /// /// `options`: The options are the same as eval mode +#[wasm_bindgen(js_name = pyExecSingle)] pub fn exec_single_py(source: &str, options: Option) -> Result { run_py(source, options, Mode::Single) } - -#[wasm_bindgen(typescript_custom_section)] -const TYPESCRIPT_DEFS: &'static str = r#" -*/ -export interface PyEvalOptions { - stdout: (out: string) => void; - vars: { [key: string]: any }; -} - -export function pyEval(code: string, options?: PyEvalOptions): any; -"#; From c090f457595e02075c805d6f4fce02255b0838a4 Mon Sep 17 00:00:00 2001 From: coolreader18 <33094578+coolreader18@users.noreply.github.com> Date: Wed, 8 Jan 2020 20:49:25 -0600 Subject: [PATCH 4/5] Add optional source_path argument to vm.run functions --- wasm/lib/src/lib.rs | 2 +- wasm/lib/src/vm_class.rs | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/wasm/lib/src/lib.rs b/wasm/lib/src/lib.rs index 7cec6a940a..cbc0de948b 100644 --- a/wasm/lib/src/lib.rs +++ b/wasm/lib/src/lib.rs @@ -64,7 +64,7 @@ fn run_py(source: &str, options: Option, mode: Mode) -> Result Result { + pub(crate) fn run( + &self, + source: &str, + mode: compile::Mode, + source_path: Option, + ) -> Result { self.assert_valid()?; self.with_unchecked( |StoredVirtualMachine { ref vm, ref scope, .. }| { - let code = vm.compile(source, mode, "".to_string()); + let source_path = source_path.unwrap_or_else(|| "".to_string()); + let code = vm.compile(source, mode, source_path); let code = code.map_err(|err| { let js_err = SyntaxError::new(&format!("Error parsing Python code: {}", err)); let _ = @@ -302,16 +308,20 @@ impl WASMVirtualMachine { ) } - pub fn exec(&self, source: &str) -> Result { - self.run(source, compile::Mode::Exec) + pub fn exec(&self, source: &str, source_path: Option) -> Result { + self.run(source, compile::Mode::Exec, source_path) } - pub fn eval(&self, source: &str) -> Result { - self.run(source, compile::Mode::Eval) + pub fn eval(&self, source: &str, source_path: Option) -> Result { + self.run(source, compile::Mode::Eval, source_path) } #[wasm_bindgen(js_name = execSingle)] - pub fn exec_single(&self, source: &str) -> Result { - self.run(source, compile::Mode::Single) + pub fn exec_single( + &self, + source: &str, + source_path: Option, + ) -> Result { + self.run(source, compile::Mode::Single, source_path) } } From c5264c942dd27c706cbe68551e34c9a7a046d9b0 Mon Sep 17 00:00:00 2001 From: coolreader18 <33094578+coolreader18@users.noreply.github.com> Date: Fri, 10 Jan 2020 17:04:45 -0600 Subject: [PATCH 5/5] Update wasm-bindgen, export PyError to JS --- Cargo.lock | 90 ++++++++++++++++++++++------------------- wasm/lib/src/convert.rs | 2 +- wasm/lib/src/lib.rs | 1 + 3 files changed, 50 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1107855cfc..0bdeb029d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,6 +30,11 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "anyhow" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "arr_macro" version = "0.1.2" @@ -208,7 +213,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bumpalo" -version = "2.6.0" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -259,12 +264,12 @@ name = "chrono" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "js-sys 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -632,10 +637,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "js-sys" -version = "0.3.28" +version = "0.3.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "wasm-bindgen 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1396,7 +1401,7 @@ dependencies = [ "unic-common 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-casing 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode_names2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "wtf8 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1407,15 +1412,15 @@ version = "0.1.0-pre-alpha.2" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", "rustpython-compiler 0.1.1", "rustpython-parser 0.1.1", "rustpython-vm 0.1.1", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde-wasm-bindgen 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)", - "web-sys 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1466,9 +1471,9 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2048,25 +2053,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasm-bindgen" -version = "0.2.51" +version = "0.2.58" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-macro 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-macro 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.51" +version = "0.2.58" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bumpalo 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bumpalo 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-shared 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2076,62 +2081,62 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "web-sys 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.51" +version = "0.2.58" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-macro-support 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-macro-support 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.51" +version = "0.2.58" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-backend 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-backend 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-shared 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.51" +version = "0.2.58" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasm-bindgen-webidl" -version = "0.2.51" +version = "0.2.58" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "anyhow 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-backend 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-backend 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "weedle 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "web-sys" -version = "0.3.28" +version = "0.3.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", + "anyhow 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", "sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-webidl 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-webidl 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2188,6 +2193,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" "checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum anyhow 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "7825f6833612eb2414095684fcf6c635becf3ce97fe48cf6421321e93bfbd53c" "checksum arr_macro 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d262b83f2f573121554ad6e764cd444303df85d86e5fcebc81903ddcf8dd3a97" "checksum arr_macro_impl 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8decbe97ffec939e44228d91e5d0829ceb1616c6ed0984c09df164b1e7ebaafc" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" @@ -2210,7 +2216,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09" "checksum bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8d6c2c5b58ab920a4f5aeaaca34b4488074e8cc7596af94e6f8c6ff247c60245" "checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" -"checksum bumpalo 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad807f2fc2bf185eeb98ff3a901bd46dc5ad58163d0fa4577ba0d25674d71708" +"checksum bumpalo 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5fb8038c1ddc0a5f73787b130f4cc75151e96ed33e417fde765eb5a81e3532f4" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" @@ -2263,7 +2269,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum is-macro 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9a8b41b34ff4371fb34c500c9d5a5b39548f51efbc278c4a53195e73961cea" "checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" -"checksum js-sys 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)" = "2cc9a97d7cec30128fd8b28a7c1f9df1c001ceb9b441e2b755e24130a6b43c79" +"checksum js-sys 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)" = "7889c7c36282151f6bf465be4700359318aef36baa951462382eae49e9577cf9" "checksum keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" "checksum lalrpop 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)" = "64dc3698e75d452867d9bd86f4a723f452ce9d01fe1d55990b79f0c790aa67db" "checksum lalrpop-util 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c277d18683b36349ab5cd030158b54856fca6bb2d5dc5263b06288f486958b7c" @@ -2412,14 +2418,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" -"checksum wasm-bindgen 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "cd34c5ba0d228317ce388e87724633c57edca3e7531feb4e25e35aaa07a656af" -"checksum wasm-bindgen-backend 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "927196b315c23eed2748442ba675a4c54a1a079d90d9bdc5ad16ce31cf90b15b" +"checksum wasm-bindgen 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "5205e9afdf42282b192e2310a5b463a6d1c1d774e30dc3c791ac37ab42d2616c" +"checksum wasm-bindgen-backend 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "11cdb95816290b525b32587d76419facd99662a07e59d3cdb560488a819d9a45" "checksum wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)" = "83420b37346c311b9ed822af41ec2e82839bfe99867ec6c54e2da43b7538771c" -"checksum wasm-bindgen-macro 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "92c2442bf04d89792816650820c3fb407af8da987a9f10028d5317f5b04c2b4a" -"checksum wasm-bindgen-macro-support 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "9c075d27b7991c68ca0f77fe628c3513e64f8c477d422b859e03f28751b46fc5" -"checksum wasm-bindgen-shared 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "83d61fe986a7af038dd8b5ec660e5849cbd9f38e7492b9404cc48b2b4df731d1" -"checksum wasm-bindgen-webidl 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "9b979afb0535fe4749906a674082db1211de8aef466331d43232f63accb7c07c" -"checksum web-sys 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)" = "c84440699cd02ca23bed6f045ffb1497bc18a3c2628bd13e2093186faaaacf6b" +"checksum wasm-bindgen-macro 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "574094772ce6921576fb6f2e3f7497b8a76273b6db092be18fc48a082de09dc3" +"checksum wasm-bindgen-macro-support 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "e85031354f25eaebe78bb7db1c3d86140312a911a106b2e29f9cc440ce3e7668" +"checksum wasm-bindgen-shared 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e7e61fc929f4c0dddb748b102ebf9f632e2b8d739f2016542b4de2965a9601" +"checksum wasm-bindgen-webidl 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "ef012a0d93fc0432df126a8eaf547b2dce25a8ce9212e1d3cbeef5c11157975d" +"checksum web-sys 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)" = "aaf97caf6aa8c2b1dac90faf0db529d9d63c93846cca4911856f78a83cebf53b" "checksum weedle 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3bb43f70885151e629e2a19ce9e50bd730fd436cfd4b666894c9ce4de9141164" "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" diff --git a/wasm/lib/src/convert.rs b/wasm/lib/src/convert.rs index a1a7bc2598..736a4386d5 100644 --- a/wasm/lib/src/convert.rs +++ b/wasm/lib/src/convert.rs @@ -26,7 +26,7 @@ export class PyError extends Error { } ")] extern "C" { - type PyError; + pub type PyError; #[wasm_bindgen(constructor)] fn new(info: JsValue) -> PyError; } diff --git a/wasm/lib/src/lib.rs b/wasm/lib/src/lib.rs index cbc0de948b..a349f8968a 100644 --- a/wasm/lib/src/lib.rs +++ b/wasm/lib/src/lib.rs @@ -18,6 +18,7 @@ use rustpython_compiler::compile::Mode; use std::panic; use wasm_bindgen::prelude::*; +pub use crate::convert::PyError; pub use crate::vm_class::*; const PY_EVAL_VM_ID: &str = "__py_eval_vm";