Skip to content

[WASM] Add a JsValue class - #1039

Merged
windelbouwman merged 10 commits into
masterfrom
coolreader18/wasm-_js-module
Jun 23, 2019
Merged

windelbouwman merged 10 commits into
masterfrom
coolreader18/wasm-_js-module

Conversation

@coolreader18

Copy link
Copy Markdown
Member

Attempt number 2, after #848. Here's the design for this implementation:

  • _js module - contains the JsValue class which wraps a wasm_bindgen::JsValue and provides methods like get_prop(), set_prop(), and typeof().
  • _window - provides a single export, a JsValue wrapping window. Can be disabled by the JS code using rustpython_wasm.
  • browser - a (eventually) Python frozen module that imports window from _window and uses it to provide all the functionality that the browser native module does now.
  • (eventually) jslib - a frozen module that provides a JsProxy similar in functionality to the JsValue discussed in How should JS values bind into Python? #808 among some other things (like a Promise wrapper).

Closes #808.

@coolreader18
coolreader18 force-pushed the coolreader18/wasm-_js-module branch 4 times, most recently from 8d3defa to 3569068 Compare June 19, 2019 04:22
@coolreader18
coolreader18 marked this pull request as ready for review June 22, 2019 01:16
@coolreader18

Copy link
Copy Markdown
Member Author

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.

@coolreader18
coolreader18 force-pushed the coolreader18/wasm-_js-module branch from c848ac0 to 658b6ca Compare June 22, 2019 01:20
Comment thread vm/src/lib.rs
pub use rustpython_compiler::*;

#[doc(hidden)]
pub mod __exports {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread vm/src/stdlib/mod.rs
pub type StdlibInitFunc = Box<dyn Fn(&VirtualMachine) -> PyObjectRef>;

pub fn get_module_inits() -> HashMap<String, StdlibInitFunc> {
#[allow(unused_mut)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added? We're returning an immutable HashMap here right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I understand now. Thanks!

@windelbouwman windelbouwman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, except a few comments.

@windelbouwman
windelbouwman requested a review from rmliddle June 22, 2019 11:47
@windelbouwman

Copy link
Copy Markdown
Contributor

@rmliddle could you take a view on this change?

@windelbouwman
windelbouwman merged commit eeb7551 into master Jun 23, 2019
@coolreader18
coolreader18 deleted the coolreader18/wasm-_js-module branch June 23, 2019 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How should JS values bind into Python?

3 participants