@@ -265,43 +265,38 @@ impl WASMVirtualMachine {
265
265
266
266
#[ wasm_bindgen( js_name = setStdout) ]
267
267
pub fn set_stdout ( & self , stdout : JsValue ) -> Result < ( ) , JsValue > {
268
- self . with (
269
- move |StoredVirtualMachine {
270
- ref mut vm,
271
- ref mut scope,
272
- ..
273
- } | {
274
- let print_fn: Box < Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > =
275
- if let Some ( selector) = stdout. as_string ( ) {
276
- Box :: new (
277
- move |vm : & mut VirtualMachine , args : PyFuncArgs | -> PyResult {
278
- wasm_builtins:: builtin_print_html ( vm, args, & selector)
279
- } ,
280
- )
281
- } else if stdout. is_function ( ) {
282
- let func = js_sys:: Function :: from ( stdout) ;
283
- Box :: new (
284
- move |vm : & mut VirtualMachine , args : PyFuncArgs | -> PyResult {
285
- func. call1 (
286
- & JsValue :: UNDEFINED ,
287
- & wasm_builtins:: format_print_args ( vm, args) ?. into ( ) ,
288
- )
289
- . map_err ( |err| convert:: js_to_py ( vm, err) ) ?;
290
- Ok ( vm. get_none ( ) )
291
- } ,
292
- )
293
- } else if stdout. is_undefined ( ) || stdout. is_null ( ) {
294
- Box :: new ( wasm_builtins:: builtin_print_console)
295
- } else {
296
- return Err ( TypeError :: new (
297
- "stdout must be null, a function or a css selector" ,
298
- )
299
- . into ( ) ) ;
300
- } ;
301
- scope. store_name ( & vm, "print" , vm. ctx . new_rustfunc ( print_fn) ) ;
302
- Ok ( ( ) )
303
- } ,
304
- ) ?
268
+ self . with ( move |StoredVirtualMachine { ref mut vm, .. } | {
269
+ let print_fn: Box < Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > =
270
+ if let Some ( selector) = stdout. as_string ( ) {
271
+ Box :: new (
272
+ move |vm : & mut VirtualMachine , args : PyFuncArgs | -> PyResult {
273
+ wasm_builtins:: builtin_print_html ( vm, args, & selector)
274
+ } ,
275
+ )
276
+ } else if stdout. is_function ( ) {
277
+ let func = js_sys:: Function :: from ( stdout) ;
278
+ Box :: new (
279
+ move |vm : & mut VirtualMachine , args : PyFuncArgs | -> PyResult {
280
+ func. call1 (
281
+ & JsValue :: UNDEFINED ,
282
+ & wasm_builtins:: format_print_args ( vm, args) ?. into ( ) ,
283
+ )
284
+ . map_err ( |err| convert:: js_to_py ( vm, err) ) ?;
285
+ Ok ( vm. get_none ( ) )
286
+ } ,
287
+ )
288
+ } else if stdout. is_undefined ( ) || stdout. is_null ( ) {
289
+ Box :: new ( wasm_builtins:: builtin_print_console)
290
+ } else {
291
+ return Err ( TypeError :: new (
292
+ "stdout must be null, a function or a css selector" ,
293
+ )
294
+ . into ( ) ) ;
295
+ } ;
296
+ let rustfunc = vm. ctx . new_rustfunc ( print_fn) ;
297
+ vm. ctx . set_attr ( & vm. builtins , "print" , rustfunc) ;
298
+ Ok ( ( ) )
299
+ } ) ?
305
300
}
306
301
307
302
#[ wasm_bindgen( js_name = injectModule) ]
@@ -391,4 +386,9 @@ impl WASMVirtualMachine {
391
386
pub fn eval ( & self , source : String ) -> Result < JsValue , JsValue > {
392
387
self . run ( source, compile:: Mode :: Eval )
393
388
}
389
+
390
+ #[ wasm_bindgen( js_name = execSingle) ]
391
+ pub fn exec_single ( & self , source : String ) -> Result < JsValue , JsValue > {
392
+ self . run ( source, compile:: Mode :: Single )
393
+ }
394
394
}
0 commit comments