@@ -8,9 +8,7 @@ use core::cell::RefCell;
88use js_sys:: { Object , TypeError } ;
99use rustpython_vm:: {
1010 Interpreter , PyObjectRef , PyPayload , PyRef , PyResult , Settings , VirtualMachine ,
11- builtins:: { PyModule , PyWeak } ,
12- compiler:: Mode ,
13- scope:: Scope ,
11+ builtins:: PyWeak , compiler:: Mode , scope:: Scope ,
1412} ;
1513use std:: collections:: HashMap ;
1614use wasm_bindgen:: prelude:: * ;
@@ -24,16 +22,17 @@ pub(crate) struct StoredVirtualMachine {
2422}
2523
2624#[ pymodule]
27- mod _window { }
28-
29- fn init_window_module ( vm : & VirtualMachine ) -> PyRef < PyModule > {
30- let module = _window:: make_module ( vm) ;
31-
32- module_exec ! ( vm, & module, {
33- "window" => js_module:: PyJsValue :: new( wasm_builtins:: window( ) ) . into_ref( & vm. ctx) ,
34- } ) ;
35-
36- module
25+ mod _window {
26+ use super :: { js_module, wasm_builtins} ;
27+ use rustpython_vm:: { Py , PyResult , VirtualMachine , builtins:: PyModule } ;
28+
29+ pub ( crate ) fn module_exec ( vm : & VirtualMachine , module : & Py < PyModule > ) -> PyResult < ( ) > {
30+ __module_exec ( vm, module) ;
31+ module_exec ! ( vm, module, {
32+ "window" => js_module:: PyJsValue :: new( wasm_builtins:: window( ) ) . into_ref( & vm. ctx) ,
33+ } ) ;
34+ Ok ( ( ) )
35+ }
3736}
3837
3938impl StoredVirtualMachine {
@@ -45,17 +44,14 @@ impl StoredVirtualMachine {
4544 #[ cfg( feature = "freeze-stdlib" ) ]
4645 vm. add_native_module_defs ( rustpython_stdlib:: get_module_defs ( ) ) ;
4746
48- #[ cfg( feature = "freeze-stdlib" ) ]
49- vm. add_native_modules ( rustpython_stdlib:: get_module_inits ( ) ) ;
50-
5147 #[ cfg( feature = "freeze-stdlib" ) ]
5248 vm. add_frozen ( rustpython_pylib:: FROZEN_STDLIB ) ;
5349
5450 vm. wasm_id = Some ( id) ;
5551
5652 js_module:: setup_js_module ( vm) ;
5753 if inject_browser_module {
58- vm. add_native_module ( "_window" . to_owned ( ) , Box :: new ( init_window_module ) ) ;
54+ vm. add_native_module_def ( "_window" . to_owned ( ) , _window :: module_def ) ;
5955 setup_browser_module ( vm) ;
6056 }
6157
0 commit comments