Update sys module when stdlib_inits is changed

Provide `update_sysmodule` in vm to update sys when update_sysmodule
changed
This commit is contained in:
yanganto
2019-11-29 11:30:33 +08:00
parent 97b8a7bf32
commit 241d3c5370
2 changed files with 9 additions and 0 deletions

View File

@@ -209,6 +209,12 @@ impl VirtualMachine {
vm
}
/// `update_sysmodule` should be called when the `vm.stdlib_inits` are changed,
/// and then the `builtin_module_names` of `sys` module will be updated.
pub fn update_sysmodule(&self) {
sysmodule::make_module(self, self.sys_module.clone(), self.builtins.clone());
}
pub fn run_code_obj(&self, code: PyCodeRef, scope: Scope) -> PyResult {
let frame = Frame::new(code, scope).into_ref(self);
self.run_frame_full(frame)

View File

@@ -44,6 +44,9 @@ impl StoredVirtualMachine {
setup_browser_module(&vm);
}
// sys module needs to be updated because js_module and browser_module is setted
vm.update_sysmodule();
import::init_importlib(&vm, false).unwrap();
StoredVirtualMachine {