Skip to content

Commit 9630c5c

Browse files
Merge pull request RustPython#727 from RustPython/wasm_no_attribute_protocol
Remove attribute protocol from wasm.
2 parents 8fa3151 + c8bdb24 commit 9630c5c

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

vm/src/pyobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ where
896896
}
897897
}
898898

899-
pub trait AttributeProtocol {
899+
trait AttributeProtocol {
900900
fn get_attr(&self, attr_name: &str) -> Option<PyObjectRef>;
901901
fn has_attr(&self, attr_name: &str) -> bool;
902902
}

wasm/lib/src/browser_module.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ use rustpython_vm::import::import_module;
1212
use rustpython_vm::obj::objtype::PyClassRef;
1313
use rustpython_vm::obj::{objint, objstr};
1414
use rustpython_vm::pyobject::{
15-
AttributeProtocol, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject,
16-
TypeProtocol,
15+
PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol,
1716
};
1817
use rustpython_vm::VirtualMachine;
1918

@@ -185,9 +184,12 @@ pub fn get_promise_value(obj: &PyObjectRef) -> Promise {
185184
}
186185

187186
pub fn import_promise_type(vm: &VirtualMachine) -> PyResult<PyClassRef> {
188-
match import_module(vm, PathBuf::default(), BROWSER_NAME)?.get_attr("Promise") {
189-
Some(promise) => PyClassRef::try_from_object(vm, promise),
190-
None => Err(vm.new_not_implemented_error("No Promise".to_string())),
187+
match vm.get_attribute(
188+
import_module(vm, PathBuf::default(), BROWSER_NAME)?,
189+
"Promise",
190+
) {
191+
Ok(promise) => PyClassRef::try_from_object(vm, promise),
192+
Err(_) => Err(vm.new_not_implemented_error("No Promise".to_string())),
191193
}
192194
}
193195

wasm/lib/src/convert.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use wasm_bindgen::{closure::Closure, prelude::*, JsCast};
44

55
use rustpython_vm::function::PyFuncArgs;
66
use rustpython_vm::obj::{objbytes, objint, objsequence, objtype};
7-
use rustpython_vm::pyobject::{AttributeProtocol, DictProtocol, PyObjectRef, PyResult};
7+
use rustpython_vm::pyobject::{DictProtocol, PyObjectRef, PyResult};
88
use rustpython_vm::VirtualMachine;
99

1010
use crate::browser_module;
@@ -20,8 +20,9 @@ pub fn py_err_to_js_err(vm: &VirtualMachine, py_err: &PyObjectRef) -> JsValue {
2020
}
2121
};
2222
}
23-
let msg = match py_err
24-
.get_attr("msg")
23+
let msg = match vm
24+
.get_attribute(py_err.clone(), "msg")
25+
.ok()
2526
.and_then(|msg| vm.to_pystr(&msg).ok())
2627
{
2728
Some(msg) => msg,
@@ -37,7 +38,7 @@ pub fn py_err_to_js_err(vm: &VirtualMachine, py_err: &PyObjectRef) -> JsValue {
3738
&vm.ctx.exceptions.name_error => js_sys::ReferenceError::new,
3839
&vm.ctx.exceptions.syntax_error => js_sys::SyntaxError::new,
3940
});
40-
if let Some(tb) = py_err.get_attr("__traceback__") {
41+
if let Ok(tb) = vm.get_attribute(py_err.clone(), "__traceback__") {
4142
if objtype::isinstance(&tb, &vm.ctx.list_type()) {
4243
let elements = objsequence::get_elements(&tb).to_vec();
4344
if let Some(top) = elements.get(0) {

0 commit comments

Comments
 (0)