MCPcopy Index your code
hub / github.com/RustPython/RustPython / inject_js_module

Method inject_js_module

crates/wasm/src/vm_class.rs:297–315  ·  view source on GitHub ↗
(&self, name: String, module: Object)

Source from the content-addressed store, hash-verified

295
296 #[wasm_bindgen(js_name = injectJSModule)]
297 pub fn inject_js_module(&self, name: String, module: Object) -> Result<(), JsValue> {
298 self.with_vm(|vm, _| {
299 let py_module = vm.new_module(&name, vm.ctx.new_dict(), None);
300 for entry in convert::object_entries(&module) {
301 let (key, value) = entry?;
302 let key = Object::from(key).to_string();
303 extend_module!(vm, &py_module, {
304 String::from(key) => convert::js_to_py(vm, value),
305 });
306 }
307
308 let sys_modules = vm.sys_module.get_attr("modules", vm).into_js(vm)?;
309 sys_modules
310 .set_item(&name, py_module.into(), vm)
311 .into_js(vm)?;
312
313 Ok(())
314 })?
315 }
316
317 pub(crate) fn run(
318 &self,

Callers

nothing calls this directly

Calls 8

object_entriesFunction · 0.85
with_vmMethod · 0.80
new_dictMethod · 0.80
to_stringMethod · 0.80
into_jsMethod · 0.80
new_moduleMethod · 0.45
get_attrMethod · 0.45
set_itemMethod · 0.45

Tested by

no test coverage detected