@@ -199,32 +199,31 @@ impl WASMVirtualMachine {
199199 fn error ( ) -> JsValue {
200200 TypeError :: new ( "Unknown stdout option, please pass a function or 'console'" ) . into ( )
201201 }
202- let print_fn: Box < Fn ( & VirtualMachine , PyFuncArgs ) -> PyResult > =
203- if let Some ( s ) = stdout . as_string ( ) {
204- match s . as_str ( ) {
205- "console" => Box :: new ( wasm_builtins :: builtin_print_console ) ,
206- _ => return Err ( error ( ) ) ,
207- }
208- } else if stdout . is_function ( ) {
209- let func = js_sys :: Function :: from ( stdout ) ;
210- Box :: new ( move |vm : & VirtualMachine , args : PyFuncArgs | -> PyResult {
202+ let print_fn: PyObjectRef = if let Some ( s ) = stdout . as_string ( ) {
203+ match s . as_str ( ) {
204+ "console" => vm . ctx . new_rustfunc ( wasm_builtins :: builtin_print_console ) ,
205+ _ => return Err ( error ( ) ) ,
206+ }
207+ } else if stdout . is_function ( ) {
208+ let func = js_sys :: Function :: from ( stdout ) ;
209+ vm . ctx
210+ . new_rustfunc ( move |vm : & VirtualMachine , args : PyFuncArgs | -> PyResult {
211211 func. call1 (
212212 & JsValue :: UNDEFINED ,
213213 & wasm_builtins:: format_print_args ( vm, args) ?. into ( ) ,
214214 )
215215 . map_err ( |err| convert:: js_to_py ( vm, err) ) ?;
216216 Ok ( vm. get_none ( ) )
217217 } )
218- } else if stdout. is_undefined ( ) || stdout. is_null ( ) {
219- fn noop ( vm : & VirtualMachine , _args : PyFuncArgs ) -> PyResult {
220- Ok ( vm. get_none ( ) )
221- }
222- Box :: new ( noop)
223- } else {
224- return Err ( error ( ) ) ;
225- } ;
226- vm. set_attr ( & vm. builtins , "print" , vm. ctx . new_rustfunc ( print_fn) )
227- . unwrap ( ) ;
218+ } else if stdout. is_undefined ( ) || stdout. is_null ( ) {
219+ fn noop ( vm : & VirtualMachine , _args : PyFuncArgs ) -> PyResult {
220+ Ok ( vm. get_none ( ) )
221+ }
222+ vm. ctx . new_rustfunc ( noop)
223+ } else {
224+ return Err ( error ( ) ) ;
225+ } ;
226+ vm. set_attr ( & vm. builtins , "print" , print_fn) . unwrap ( ) ;
228227 Ok ( ( ) )
229228 } ) ?
230229 }
0 commit comments