@@ -16,7 +16,7 @@ use nova_vm::{
1616 scripts_and_modules:: script:: { parse_script, script_evaluation} ,
1717 types:: { self , Object , Value } ,
1818 } ,
19- engine:: context:: GcScope ,
19+ engine:: context:: { Bindable , GcScope } ,
2020} ;
2121
2222use crate :: { Extension , HostData , MacroTask , exit_with_parse_errors} ;
@@ -130,11 +130,11 @@ impl<UserMacroTask> Runtime<UserMacroTask> {
130130 }
131131
132132 /// Run the Runtime with the specified configuration.
133- pub fn run ( & mut self ) -> JsResult < Value > {
133+ pub fn run ( mut self ) -> RuntimeOutput {
134134 // Load the builtins js sources
135135 self . agent . run_in_realm ( & self . realm_root , |agent, mut gc| {
136- let realm = agent. current_realm_id ( ) ;
137136 for builtin in & self . config . builtins {
137+ let realm = agent. current_realm ( gc. nogc ( ) ) ;
138138 let source_text = types:: String :: from_str ( agent, builtin, gc. nogc ( ) ) ;
139139 let script = match parse_script (
140140 agent,
@@ -147,22 +147,22 @@ impl<UserMacroTask> Runtime<UserMacroTask> {
147147 Ok ( script) => script,
148148 Err ( diagnostics) => exit_with_parse_errors ( diagnostics, "<runtime>" , builtin) ,
149149 } ;
150- match script_evaluation ( agent, script, gc. reborrow ( ) ) {
150+ match script_evaluation ( agent, script. unbind ( ) , gc. reborrow ( ) ) {
151151 Ok ( _) => ( ) ,
152152 Err ( _) => println ! ( "Error in runtime" ) ,
153153 }
154154 }
155155 } ) ;
156156
157- let mut final_result = Value :: Null ;
157+ let mut result = JsResult :: Ok ( Value :: Null ) ;
158158
159159 // Fetch the runtime mod.ts file using a macro and add it to the paths
160160 for path in & self . config . paths {
161161 let file = std:: fs:: read_to_string ( path) . unwrap ( ) ;
162162
163- final_result = self . agent . run_in_realm ( & self . realm_root , |agent, gc| {
163+ result = self . agent . run_in_realm ( & self . realm_root , |agent, mut gc| {
164164 let source_text = types:: String :: from_string ( agent, file, gc. nogc ( ) ) ;
165- let realm = agent. current_realm_id ( ) ;
165+ let realm = agent. current_realm ( gc . nogc ( ) ) ;
166166
167167 let script = match parse_script (
168168 agent,
@@ -176,14 +176,15 @@ impl<UserMacroTask> Runtime<UserMacroTask> {
176176 Err ( errors) => exit_with_parse_errors ( errors, path, source_text. as_str ( agent) ) ,
177177 } ;
178178
179- script_evaluation ( agent, script, gc)
180- } ) ? ;
179+ script_evaluation ( agent, script. unbind ( ) , gc. reborrow ( ) ) . unbind ( )
180+ } ) ;
181181 }
182182
183183 loop {
184184 while let Some ( job) = self . host_hooks . pop_promise_job ( ) {
185- self . agent
186- . run_in_realm ( & self . realm_root , |agent, gc| job. run ( agent, gc) ) ?;
185+ result = self . agent . run_in_realm ( & self . realm_root , |agent, mut gc| {
186+ job. run ( agent, gc. reborrow ( ) ) . unbind ( ) . map ( |_| Value :: Null )
187+ } ) ;
187188 }
188189
189190 // If both the microtasks and macrotasks queues are empty we can end the event loop
@@ -194,7 +195,11 @@ impl<UserMacroTask> Runtime<UserMacroTask> {
194195 self . handle_macro_task ( ) ;
195196 }
196197
197- Ok ( final_result)
198+ RuntimeOutput {
199+ agent : self . agent ,
200+ realm_root : self . realm_root ,
201+ result,
202+ }
198203 }
199204
200205 // Listen for pending macro tasks and resolve one by one
@@ -224,3 +229,9 @@ impl<UserMacroTask> Runtime<UserMacroTask> {
224229 }
225230 }
226231}
232+
233+ pub struct RuntimeOutput {
234+ pub agent : GcAgent ,
235+ pub realm_root : RealmRoot ,
236+ pub result : JsResult < ' static , Value < ' static > > ,
237+ }
0 commit comments