File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ ast = ["rustpython-ast"]
2323codegen = [" rustpython-codegen" , " ast" ]
2424parser = [" rustpython-parser" , " ast" ]
2525serde = [" dep:serde" ]
26+ wasmbind = [" chrono/wasmbind" , " getrandom/js" ]
27+
2628
2729[dependencies ]
2830rustpython-compiler = { workspace = true , optional = true }
Original file line number Diff line number Diff line change @@ -104,15 +104,19 @@ mod decl {
104104
105105 #[ cfg( all( target_arch = "wasm32" , not( target_os = "wasi" ) ) ) ]
106106 fn _time ( _vm : & VirtualMachine ) -> PyResult < f64 > {
107- use wasm_bindgen:: prelude:: * ;
108- #[ wasm_bindgen]
109- extern "C" {
110- type Date ;
111- #[ wasm_bindgen( static_method_of = Date ) ]
112- fn now ( ) -> f64 ;
107+ #[ cfg( feature = "wasmbind" ) ]
108+ {
109+ use wasm_bindgen:: prelude:: * ;
110+ #[ wasm_bindgen]
111+ extern "C" {
112+ type Date ;
113+ #[ wasm_bindgen( static_method_of = Date ) ]
114+ fn now ( ) -> f64 ;
115+ }
116+ // Date.now returns unix time in milliseconds, we want it in seconds
117+ return Ok ( Date :: now ( ) / 1000.0 ) ;
113118 }
114- // Date.now returns unix time in milliseconds, we want it in seconds
115- Ok ( Date :: now ( ) / 1000.0 )
119+ panic ! ( "Date not available" )
116120 }
117121
118122 #[ pyfunction]
Original file line number Diff line number Diff line change @@ -21,15 +21,18 @@ impl VirtualMachine {
2121 }
2222 #[ cfg( all( target_arch = "wasm32" , not( target_os = "wasi" ) ) ) ]
2323 {
24- use wasm_bindgen:: prelude:: * ;
25- #[ wasm_bindgen]
26- extern "C" {
27- #[ wasm_bindgen( js_namespace = console) ]
28- fn error ( s : & str ) ;
24+ #[ cfg( feature = "wasmbind" ) ]
25+ {
26+ use wasm_bindgen:: prelude:: * ;
27+ #[ wasm_bindgen]
28+ extern "C" {
29+ #[ wasm_bindgen( js_namespace = console) ]
30+ fn error ( s : & str ) ;
31+ }
32+ let mut s = String :: new ( ) ;
33+ self . write_exception ( & mut s, & exc) . unwrap ( ) ;
34+ error ( & s) ;
2935 }
30- let mut s = String :: new ( ) ;
31- self . write_exception ( & mut s, & exc) . unwrap ( ) ;
32- error ( & s) ;
3336 panic ! ( "{}; exception backtrace above" , msg)
3437 }
3538 }
You can’t perform that action at this time.
0 commit comments