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

Method set_stdout

crates/wasm/src/vm_class.rs:222–250  ·  view source on GitHub ↗
(&self, stdout: JsValue)

Source from the content-addressed store, hash-verified

220
221 #[wasm_bindgen(js_name = setStdout)]
222 pub fn set_stdout(&self, stdout: JsValue) -> Result<(), JsValue> {
223 self.with_vm(|vm, _| {
224 fn error() -> JsValue {
225 TypeError::new("Unknown stdout option, please pass a function or 'console'").into()
226 }
227 use wasm_builtins::make_stdout_object;
228 let stdout: PyObjectRef = if let Some(s) = stdout.as_string() {
229 match s.as_str() {
230 "console" => make_stdout_object(vm, wasm_builtins::sys_stdout_write_console),
231 _ => return Err(error()),
232 }
233 } else if stdout.is_function() {
234 let func = js_sys::Function::from(stdout);
235 make_stdout_object(vm, move |data, vm| {
236 func.call1(&JsValue::UNDEFINED, &data.into())
237 .map_err(|err| convert::js_py_typeerror(vm, err))?;
238 Ok(())
239 })
240 } else if stdout.is_null() {
241 make_stdout_object(vm, |_, _| Ok(()))
242 } else if stdout.is_undefined() {
243 make_stdout_object(vm, wasm_builtins::sys_stdout_write_console)
244 } else {
245 return Err(error());
246 };
247 vm.sys_module.set_attr("stdout", stdout, vm).unwrap();
248 Ok(())
249 })?
250 }
251
252 #[wasm_bindgen(js_name = injectModule)]
253 pub fn inject_module(

Callers 1

run_pyFunction · 0.80

Calls 9

make_stdout_objectFunction · 0.85
js_py_typeerrorFunction · 0.85
with_vmMethod · 0.80
ErrClass · 0.50
errorFunction · 0.50
as_stringMethod · 0.45
as_strMethod · 0.45
unwrapMethod · 0.45
set_attrMethod · 0.45

Tested by

no test coverage detected