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

Function run_py

crates/wasm/src/lib.rs:54–74  ·  view source on GitHub ↗
(source: &str, options: Option<Object>, mode: Mode)

Source from the content-addressed store, hash-verified

52 const PY_EVAL_VM_ID: &str = "__py_eval_vm";
53
54 fn run_py(source: &str, options: Option<Object>, mode: Mode) -> Result<JsValue, JsValue> {
55 let vm = VMStore::init(PY_EVAL_VM_ID.into(), Some(true));
56 let options = options.unwrap_or_default();
57 let js_vars = {
58 let prop = Reflect::get(&options, &"vars".into())?;
59 if prop.is_undefined() {
60 None
61 } else if prop.is_object() {
62 Some(Object::from(prop))
63 } else {
64 return Err(TypeError::new("vars must be an object").into());
65 }
66 };
67
68 vm.set_stdout(Reflect::get(&options, &"stdout".into())?)?;
69
70 if let Some(js_vars) = js_vars {
71 vm.add_to_scope("js_vars".into(), js_vars.into())?;
72 }
73 vm.run(source, mode, None)
74 }
75
76 /// Evaluate Python code
77 ///

Callers 3

eval_pyFunction · 0.85
exec_pyFunction · 0.85
exec_single_pyFunction · 0.85

Calls 9

getFunction · 0.85
newFunction · 0.85
is_objectMethod · 0.80
set_stdoutMethod · 0.80
add_to_scopeMethod · 0.80
initFunction · 0.50
SomeClass · 0.50
ErrClass · 0.50
runMethod · 0.45

Tested by

no test coverage detected