mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 11:14:38 +08:00
Remove attribute protocol from wasm.
This commit is contained in:
1 parent
26a238085f
commit
c8bdb249b0
3 files changed
+13
-10
No files matched your search
+1
-1
@@ -896,7 +896,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AttributeProtocol {
|
||||
trait AttributeProtocol {
|
||||
fn get_attr(&self, attr_name: &str) -> Option<PyObjectRef>;
|
||||
fn has_attr(&self, attr_name: &str) -> bool;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,7 @@ use rustpython_vm::import::import_module;
|
||||
use rustpython_vm::obj::objtype::PyClassRef;
|
||||
use rustpython_vm::obj::{objint, objstr};
|
||||
use rustpython_vm::pyobject::{
|
||||
AttributeProtocol, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject,
|
||||
TypeProtocol,
|
||||
PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
};
|
||||
use rustpython_vm::VirtualMachine;
|
||||
|
||||
@@ -185,9 +184,12 @@ pub fn get_promise_value(obj: &PyObjectRef) -> Promise {
|
||||
}
|
||||
|
||||
pub fn import_promise_type(vm: &VirtualMachine) -> PyResult<PyClassRef> {
|
||||
match import_module(vm, PathBuf::default(), BROWSER_NAME)?.get_attr("Promise") {
|
||||
Some(promise) => PyClassRef::try_from_object(vm, promise),
|
||||
None => Err(vm.new_not_implemented_error("No Promise".to_string())),
|
||||
match vm.get_attribute(
|
||||
import_module(vm, PathBuf::default(), BROWSER_NAME)?,
|
||||
"Promise",
|
||||
) {
|
||||
Ok(promise) => PyClassRef::try_from_object(vm, promise),
|
||||
Err(_) => Err(vm.new_not_implemented_error("No Promise".to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use wasm_bindgen::{closure::Closure, prelude::*, JsCast};
|
||||
|
||||
use rustpython_vm::function::PyFuncArgs;
|
||||
use rustpython_vm::obj::{objbytes, objint, objsequence, objtype};
|
||||
use rustpython_vm::pyobject::{AttributeProtocol, DictProtocol, PyObjectRef, PyResult};
|
||||
use rustpython_vm::pyobject::{DictProtocol, PyObjectRef, PyResult};
|
||||
use rustpython_vm::VirtualMachine;
|
||||
|
||||
use crate::browser_module;
|
||||
@@ -20,8 +20,9 @@ pub fn py_err_to_js_err(vm: &VirtualMachine, py_err: &PyObjectRef) -> JsValue {
|
||||
}
|
||||
};
|
||||
}
|
||||
let msg = match py_err
|
||||
.get_attr("msg")
|
||||
let msg = match vm
|
||||
.get_attribute(py_err.clone(), "msg")
|
||||
.ok()
|
||||
.and_then(|msg| vm.to_pystr(&msg).ok())
|
||||
{
|
||||
Some(msg) => msg,
|
||||
@@ -37,7 +38,7 @@ pub fn py_err_to_js_err(vm: &VirtualMachine, py_err: &PyObjectRef) -> JsValue {
|
||||
&vm.ctx.exceptions.name_error => js_sys::ReferenceError::new,
|
||||
&vm.ctx.exceptions.syntax_error => js_sys::SyntaxError::new,
|
||||
});
|
||||
if let Some(tb) = py_err.get_attr("__traceback__") {
|
||||
if let Ok(tb) = vm.get_attribute(py_err.clone(), "__traceback__") {
|
||||
if objtype::isinstance(&tb, &vm.ctx.list_type()) {
|
||||
let elements = objsequence::get_elements(&tb).to_vec();
|
||||
if let Some(top) = elements.get(0) {
|
||||
|
||||
Reference in new issue
Block a user