@@ -278,13 +278,19 @@ impl WASMVirtualMachine {
278
278
} ) ?
279
279
}
280
280
281
- pub ( crate ) fn run ( & self , source : & str , mode : compile:: Mode ) -> Result < JsValue , JsValue > {
281
+ pub ( crate ) fn run (
282
+ & self ,
283
+ source : & str ,
284
+ mode : compile:: Mode ,
285
+ source_path : Option < String > ,
286
+ ) -> Result < JsValue , JsValue > {
282
287
self . assert_valid ( ) ?;
283
288
self . with_unchecked (
284
289
|StoredVirtualMachine {
285
290
ref vm, ref scope, ..
286
291
} | {
287
- let code = vm. compile ( source, mode, "<wasm>" . to_string ( ) ) ;
292
+ let source_path = source_path. unwrap_or_else ( || "<wasm>" . to_string ( ) ) ;
293
+ let code = vm. compile ( source, mode, source_path) ;
288
294
let code = code. map_err ( |err| {
289
295
let js_err = SyntaxError :: new ( & format ! ( "Error parsing Python code: {}" , err) ) ;
290
296
let _ =
@@ -302,16 +308,20 @@ impl WASMVirtualMachine {
302
308
)
303
309
}
304
310
305
- pub fn exec ( & self , source : & str ) -> Result < JsValue , JsValue > {
306
- self . run ( source, compile:: Mode :: Exec )
311
+ pub fn exec ( & self , source : & str , source_path : Option < String > ) -> Result < JsValue , JsValue > {
312
+ self . run ( source, compile:: Mode :: Exec , source_path )
307
313
}
308
314
309
- pub fn eval ( & self , source : & str ) -> Result < JsValue , JsValue > {
310
- self . run ( source, compile:: Mode :: Eval )
315
+ pub fn eval ( & self , source : & str , source_path : Option < String > ) -> Result < JsValue , JsValue > {
316
+ self . run ( source, compile:: Mode :: Eval , source_path )
311
317
}
312
318
313
319
#[ wasm_bindgen( js_name = execSingle) ]
314
- pub fn exec_single ( & self , source : & str ) -> Result < JsValue , JsValue > {
315
- self . run ( source, compile:: Mode :: Single )
320
+ pub fn exec_single (
321
+ & self ,
322
+ source : & str ,
323
+ source_path : Option < String > ,
324
+ ) -> Result < JsValue , JsValue > {
325
+ self . run ( source, compile:: Mode :: Single , source_path)
316
326
}
317
327
}
0 commit comments