File tree 3 files changed +25
-16
lines changed 3 files changed +25
-16
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ ast = ["rustpython-ast"]
23
23
codegen = [" rustpython-codegen" , " ast" ]
24
24
parser = [" rustpython-parser" , " ast" ]
25
25
serde = [" dep:serde" ]
26
+ wasmbind = [" chrono/wasmbind" , " getrandom/js" ]
27
+
26
28
27
29
[dependencies ]
28
30
rustpython-compiler = { workspace = true , optional = true }
Original file line number Diff line number Diff line change @@ -104,15 +104,19 @@ mod decl {
104
104
105
105
#[ cfg( all( target_arch = "wasm32" , not( target_os = "wasi" ) ) ) ]
106
106
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 ) ;
113
118
}
114
- // Date.now returns unix time in milliseconds, we want it in seconds
115
- Ok ( Date :: now ( ) / 1000.0 )
119
+ panic ! ( "Date not available" )
116
120
}
117
121
118
122
#[ pyfunction]
Original file line number Diff line number Diff line change @@ -21,15 +21,18 @@ impl VirtualMachine {
21
21
}
22
22
#[ cfg( all( target_arch = "wasm32" , not( target_os = "wasi" ) ) ) ]
23
23
{
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) ;
29
35
}
30
- let mut s = String :: new ( ) ;
31
- self . write_exception ( & mut s, & exc) . unwrap ( ) ;
32
- error ( & s) ;
33
36
panic ! ( "{}; exception backtrace above" , msg)
34
37
}
35
38
}
You can’t perform that action at this time.
0 commit comments