@@ -331,7 +331,7 @@ function _configure() {
331331 msg += " " ;
332332 }
333333 }
334- Module . interpreter . publish_stream ( Module . get_request_context ( ) , "stdout" , `${ msg } \n` ) ;
334+ Module . interpreter . publish_stream ( "stdout" , `${ msg } \n` ) ;
335335 }
336336 // alias
337337 globalThis . pp = globalThis . pprint ;
@@ -344,7 +344,7 @@ function _configure() {
344344 msg += " " ;
345345 }
346346 }
347- Module . interpreter . publish_stream ( Module . get_request_context ( ) , "stdout" , `${ msg } \n` ) ;
347+ Module . interpreter . publish_stream ( "stdout" , `${ msg } \n` ) ;
348348 }
349349 console . error = function ( ... args ) {
350350 let msg = ""
@@ -354,20 +354,16 @@ function _configure() {
354354 msg += " " ;
355355 }
356356 }
357- Module . interpreter . publish_stream ( Module . get_request_context ( ) , "stderr" , `${ msg } \n` ) ;
357+ Module . interpreter . publish_stream ( "stderr" , `${ msg } \n` ) ;
358358 }
359359
360360 // add ijs to global scope
361361 globalThis [ "ijs" ] = Module [ "ijs" ] ;
362362
363363 Module . interpreter = Module . _get_interpreter ( ) ;
364364
365-
366- // the execute request context
367- Module . _xrequest_context = null ;
368365}
369366
370-
371367Module . get_request_context = function ( ) {
372368 return Module . _xrequest_context ;
373369}
@@ -377,13 +373,8 @@ Module.get_interpreter = function () {
377373}
378374
379375
380- async function _call_user_code ( context , code ) {
376+ async function _call_user_code ( execution_counter , config , reply_callback , code ) {
381377
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 ;
387378
388379 try {
389380
@@ -398,17 +389,14 @@ async function _call_user_code(context, code) {
398389 let result_holder = await result_promise ;
399390 let result = result_holder [ 0 ] ;
400391 data = Module [ "ijs" ] [ "get_mime_bundle" ] ( result ) ;
392+ if ( ! config . silent ) {
393+ Module . get_interpreter ( ) . publish_execution_result ( execution_counter , data , { } ) ;
394+ }
401395 }
402396 else {
403397 await result_promise ;
404398 }
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 ( ) ;
412400 }
413401 catch ( err ) {
414402
@@ -423,35 +411,28 @@ async function _call_user_code(context, code) {
423411 if ( msg instanceof Promise ) {
424412 msg = await msg ;
425413 }
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 } ` , "" ) ;
433416 }
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 ) ;
443427 }
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 } ` ) ;
445431 }
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 ( ) ;
455436 }
456437
457438}
@@ -576,10 +557,10 @@ let ijs = {
576557 magic_imports : magic_imports ,
577558 display : {
578559 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 ) ;
580561 } ,
581562 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 ) ;
583564 } ,
584565 mime_type : function ( mime_type , data ) {
585566 this . display ( { mime_type : data } ) ;
@@ -661,7 +642,7 @@ let ijs = {
661642 }
662643 }
663644 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` ) ;
665646 }
666647 }
667648
0 commit comments