(id: String, inject_browser_module: bool)
| 37 | |
| 38 | impl StoredVirtualMachine { |
| 39 | fn new(id: String, inject_browser_module: bool) -> StoredVirtualMachine { |
| 40 | let mut settings = Settings::default(); |
| 41 | settings.allow_external_library = false; |
| 42 | |
| 43 | let mut builder = Interpreter::builder(settings); |
| 44 | |
| 45 | #[cfg(feature = "freeze-stdlib")] |
| 46 | { |
| 47 | let defs = rustpython_stdlib::stdlib_module_defs(&builder.ctx); |
| 48 | builder = builder |
| 49 | .add_native_modules(&defs) |
| 50 | .add_frozen_modules(rustpython_pylib::FROZEN_STDLIB); |
| 51 | } |
| 52 | |
| 53 | // Add wasm-specific modules |
| 54 | let js_def = js_module::module_def(&builder.ctx); |
| 55 | builder = builder.add_native_module(js_def); |
| 56 | |
| 57 | if inject_browser_module { |
| 58 | let window_def = _window::module_def(&builder.ctx); |
| 59 | let browser_def = browser_module::module_def(&builder.ctx); |
| 60 | builder = builder |
| 61 | .add_native_modules(&[window_def, browser_def]) |
| 62 | .add_frozen_modules(rustpython_vm::py_freeze!(dir = "../Lib")); |
| 63 | } |
| 64 | |
| 65 | let interp = builder |
| 66 | .init_hook(move |vm| { |
| 67 | vm.wasm_id = Some(id); |
| 68 | }) |
| 69 | .build(); |
| 70 | |
| 71 | let scope = interp.enter(|vm| vm.new_scope_with_builtins()); |
| 72 | |
| 73 | StoredVirtualMachine { |
| 74 | interp, |
| 75 | scope, |
| 76 | held_objects: RefCell::new(Vec::new()), |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // It's fine that it's thread local, since WASM doesn't even have threads yet. thread_local! |
nothing calls this directly
no test coverage detected