@@ -331,7 +331,7 @@ function _configure() {
331
331
msg += " " ;
332
332
}
333
333
}
334
- Module . interpreter . publish_stream ( Module . get_request_context ( ) , "stdout" , `${ msg } \n` ) ;
334
+ Module . interpreter . publish_stream ( "stdout" , `${ msg } \n` ) ;
335
335
}
336
336
// alias
337
337
globalThis . pp = globalThis . pprint ;
@@ -344,7 +344,7 @@ function _configure() {
344
344
msg += " " ;
345
345
}
346
346
}
347
- Module . interpreter . publish_stream ( Module . get_request_context ( ) , "stdout" , `${ msg } \n` ) ;
347
+ Module . interpreter . publish_stream ( "stdout" , `${ msg } \n` ) ;
348
348
}
349
349
console . error = function ( ... args ) {
350
350
let msg = ""
@@ -354,20 +354,16 @@ function _configure() {
354
354
msg += " " ;
355
355
}
356
356
}
357
- Module . interpreter . publish_stream ( Module . get_request_context ( ) , "stderr" , `${ msg } \n` ) ;
357
+ Module . interpreter . publish_stream ( "stderr" , `${ msg } \n` ) ;
358
358
}
359
359
360
360
// add ijs to global scope
361
361
globalThis [ "ijs" ] = Module [ "ijs" ] ;
362
362
363
363
Module . interpreter = Module . _get_interpreter ( ) ;
364
364
365
-
366
- // the execute request context
367
- Module . _xrequest_context = null ;
368
365
}
369
366
370
-
371
367
Module . get_request_context = function ( ) {
372
368
return Module . _xrequest_context ;
373
369
}
@@ -377,13 +373,8 @@ Module.get_interpreter = function () {
377
373
}
378
374
379
375
380
- async function _call_user_code ( context , code ) {
376
+ async function _call_user_code ( execution_counter , config , reply_callback , code ) {
381
377
382
- // call _xrequest_context.delete() if it exists
383
- if ( Module . _xrequest_context && Module . _xrequest_context . delete ) {
384
- Module . _xrequest_context . delete ( ) ;
385
- }
386
- Module . _xrequest_context = context ;
387
378
388
379
try {
389
380
@@ -398,17 +389,14 @@ async function _call_user_code(context, code) {
398
389
let result_holder = await result_promise ;
399
390
let result = result_holder [ 0 ] ;
400
391
data = Module [ "ijs" ] [ "get_mime_bundle" ] ( result ) ;
392
+ if ( ! config . silent ) {
393
+ Module . get_interpreter ( ) . publish_execution_result ( execution_counter , data , { } ) ;
394
+ }
401
395
}
402
396
else {
403
397
await result_promise ;
404
398
}
405
-
406
- return {
407
- has_error : false ,
408
- with_result : ret . with_return ,
409
- pub_data : data ,
410
- metadata : { } ,
411
- } ;
399
+ reply_callback . reply_success ( ) ;
412
400
}
413
401
catch ( err ) {
414
402
@@ -423,35 +411,28 @@ async function _call_user_code(context, code) {
423
411
if ( msg instanceof Promise ) {
424
412
msg = await msg ;
425
413
}
426
-
427
- return {
428
- error_type : "C++ Exception" ,
429
- error_message : `${ msg } ` ,
430
- error_stack : "" ,
431
- has_error : true
432
- }
414
+ Module . get_interpreter ( ) . publish_execution_error ( "C++ Exception" , `${ msg } ` , "" ) ;
415
+ reply_callback . reply_error ( "C++ Exception" , `${ msg } ` , "" ) ;
433
416
}
434
-
435
-
436
- // remove a bunch of noise from the stack
437
- let err_stack_str = `${ err . stack || "" } ` ;
438
- let err_stack_lines = err_stack_str . split ( "\n" ) ;
439
- let used_lines = [ ] ;
440
- for ( const line of err_stack_lines ) {
441
- if ( line . includes ( "make_async_from_code " ) ) {
442
- break ;
417
+ else {
418
+ // remove a bunch of noise from the stack
419
+ let err_stack_str = `${ err . stack || "" } ` ;
420
+ let err_stack_lines = err_stack_str . split ( "\n" ) ;
421
+ let used_lines = [ ] ;
422
+ for ( const line of err_stack_lines ) {
423
+ if ( line . includes ( "make_async_from_code " ) ) {
424
+ break ;
425
+ }
426
+ used_lines . push ( line ) ;
443
427
}
444
- used_lines . push ( line ) ;
428
+ err_stack_str = used_lines . join ( "\n" ) ;
429
+ Module . get_interpreter ( ) . publish_execution_error ( `${ err . name || "UnkwownError" } ` , `${ err . message || "" } ` , `${ err_stack_str } ` ) ;
430
+ reply_callback . reply_error ( `${ err . name || "UnkwownError" } ` , `${ err . message || "" } ` , `${ err_stack_str } ` ) ;
445
431
}
446
- err_stack_str = used_lines . join ( "\n" ) ;
447
-
448
-
449
- return {
450
- error_type : `${ err . name || "UnkwownError" } ` ,
451
- error_message : `${ err . message || "" } ` ,
452
- error_stack : `${ err_stack_str } ` ,
453
- has_error : true
454
- } ;
432
+ }
433
+ finally {
434
+ config . delete ( ) ;
435
+ reply_callback . delete ( ) ;
455
436
}
456
437
457
438
}
@@ -576,10 +557,10 @@ let ijs = {
576
557
magic_imports : magic_imports ,
577
558
display : {
578
559
display : function ( data , metadata = { } , transient = { } ) {
579
- Module . get_interpreter ( ) . display_data ( Module . get_request_context ( ) , data , metadata , transient ) ;
560
+ Module . get_interpreter ( ) . display_data ( data , metadata , transient ) ;
580
561
} ,
581
562
update_display_data : function ( data , metadata = { } , transient = { } ) {
582
- Module . get_interpreter ( ) . update_display_data ( Module . get_request_context ( ) , data , metadata , transient ) ;
563
+ Module . get_interpreter ( ) . update_display_data ( data , metadata , transient ) ;
583
564
} ,
584
565
mime_type : function ( mime_type , data ) {
585
566
this . display ( { mime_type : data } ) ;
@@ -661,7 +642,7 @@ let ijs = {
661
642
}
662
643
}
663
644
catch ( err ) {
664
- Module . interpreter . publish_stream ( Module . get_request_context ( ) , "stderr" , `display error: ${ err } \n` ) ;
645
+ Module . interpreter . publish_stream ( "stderr" , `display error: ${ err } \n` ) ;
665
646
}
666
647
}
667
648
0 commit comments