Repository navigation
[WASM] Add a JsValue class - #1039
Conversation
8d3defa to
3569068
Compare
|
Ok, I think this is good for review as an initial implementation; everything works that did before, and although it's not all converted to the new system, I think that's best done in follow-up PRs. |
c848ac0 to
658b6ca
Compare
| pub use rustpython_compiler::*; | ||
|
|
||
| #[doc(hidden)] | ||
| pub mod __exports { |
There was a problem hiding this comment.
I think the same can be achieved by using extern crate bincode. Cargo will make sure that both the vm and the wasm crate use the same version of the bincode crate, so no need to import the bincode crate via the rustpython_vm.
There was a problem hiding this comment.
I did this here because this pattern is used by other macros in the ecosystem, here are a few examples:
| pub type StdlibInitFunc = Box<dyn Fn(&VirtualMachine) -> PyObjectRef>; | ||
|
|
||
| pub fn get_module_inits() -> HashMap<String, StdlibInitFunc> { | ||
| #[allow(unused_mut)] |
There was a problem hiding this comment.
Why was this added? We're returning an immutable HashMap here right?
There was a problem hiding this comment.
A little bit downwards there are some #[cfg]s that conditionally add modules to the map, and if your target matches neither of those cfgs, you get an unused mut warning.
There was a problem hiding this comment.
Ah, I understand now. Thanks!
windelbouwman
left a comment
There was a problem hiding this comment.
Looks good to me, except a few comments.
|
@rmliddle could you take a view on this change? |
Attempt number 2, after #848. Here's the design for this implementation:
_jsmodule - contains theJsValueclass which wraps awasm_bindgen::JsValueand provides methods likeget_prop(),set_prop(), andtypeof()._window- provides a single export, aJsValuewrappingwindow. Can be disabled by the JS code usingrustpython_wasm.browser- a (eventually) Python frozen module that importswindowfrom_windowand uses it to provide all the functionality that thebrowsernative module does now.jslib- a frozen module that provides a JsProxy similar in functionality to theJsValuediscussed in How should JS values bind into Python? #808 among some other things (like a Promise wrapper).Closes #808.