@@ -15,7 +15,7 @@ use nova_vm::ecmascript::{
1515 Agent ,
1616 } ,
1717 scripts_and_modules:: script:: { parse_script, script_evaluation} ,
18- types:: { Object , Value } ,
18+ types:: Object ,
1919} ;
2020use oxc_parser:: Parser ;
2121use oxc_semantic:: { SemanticBuilder , SemanticBuilderReturn } ;
@@ -113,7 +113,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
113113 verbose,
114114 no_strict,
115115 nogc,
116- paths
116+ paths,
117117 } => {
118118 let allocator = Default :: default ( ) ;
119119
@@ -143,10 +143,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
143143 agent. run_in_realm ( & realm, |agent| -> Result < ( ) , Box < dyn std:: error:: Error > > {
144144 let realm = agent. current_realm_id ( ) ;
145145 let file = std:: fs:: read_to_string ( & path) ?;
146- let script = match parse_script ( & allocator, file. into ( ) , realm, !no_strict, None ) {
147- Ok ( script) => script,
148- Err ( ( file, errors) ) => exit_with_parse_errors ( errors, & path, & file) ,
149- } ;
146+ let script =
147+ match parse_script ( & allocator, file. into ( ) , realm, !no_strict, None ) {
148+ Ok ( script) => script,
149+ Err ( ( file, errors) ) => exit_with_parse_errors ( errors, & path, & file) ,
150+ } ;
150151 let mut result = script_evaluation ( agent, script) ;
151152
152153 if result. is_ok ( ) {
@@ -180,24 +181,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
180181 Command :: Repl { } => {
181182 let allocator = Default :: default ( ) ;
182183 let host_hooks: & CliHostHooks = & * Box :: leak ( Box :: default ( ) ) ;
183- let mut agent = Agent :: new (
184+ let mut agent = GcAgent :: new (
184185 Options {
185186 disable_gc : false ,
186187 print_internals : true ,
187188 } ,
188189 host_hooks,
189190 ) ;
190- {
191- let create_global_object: Option < fn ( & mut Realm ) -> Object > = None ;
192- let create_global_this_value: Option < fn ( & mut Realm ) -> Object > = None ;
193- initialize_host_defined_realm (
194- & mut agent,
195- create_global_object,
196- create_global_this_value,
197- Some ( initialize_global_object) ,
198- ) ;
199- }
200- let realm = agent. current_realm_id ( ) ;
191+ let create_global_object: Option < fn ( & mut Agent ) -> Object > = None ;
192+ let create_global_this_value: Option < fn ( & mut Agent ) -> Object > = None ;
193+ let realm = agent. create_realm (
194+ create_global_object,
195+ create_global_this_value,
196+ Some ( initialize_global_object) ,
197+ ) ;
201198
202199 set_theme ( DefaultTheme ) ;
203200 println ! ( "\n \n " ) ;
@@ -209,26 +206,37 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
209206
210207 if input. matches ( "exit" ) . count ( ) == 1 {
211208 std:: process:: exit ( 0 ) ;
209+ } else if input. matches ( "gc" ) . count ( ) == 1 {
210+ agent. gc ( ) ;
211+ continue ;
212212 }
213213 placeholder = input. to_string ( ) ;
214- let script = match parse_script ( & allocator, input. into ( ) , realm, true , None ) {
215- Ok ( script) => script,
216- Err ( ( file, errors) ) => {
217- exit_with_parse_errors ( errors, "<stdin>" , & file) ;
218- }
219- } ;
220- let result = script_evaluation ( & mut agent, script) ;
221- match result {
222- Ok ( result) => {
223- println ! ( "{:?}\n " , result) ;
224- }
225- Err ( error) => {
226- eprintln ! (
227- "Uncaught exception: {}" ,
228- error. value( ) . string_repr( & mut agent) . as_str( & agent)
229- ) ;
214+ agent. run_in_realm ( & realm, |agent| {
215+ let script = match parse_script (
216+ & allocator,
217+ input. into ( ) ,
218+ agent. current_realm_id ( ) ,
219+ true ,
220+ None ,
221+ ) {
222+ Ok ( script) => script,
223+ Err ( ( file, errors) ) => {
224+ exit_with_parse_errors ( errors, "<stdin>" , & file) ;
225+ }
226+ } ;
227+ let result = script_evaluation ( agent, script) ;
228+ match result {
229+ Ok ( result) => {
230+ println ! ( "{:?}\n " , result) ;
231+ }
232+ Err ( error) => {
233+ eprintln ! (
234+ "Uncaught exception: {}" ,
235+ error. value( ) . string_repr( agent) . as_str( agent)
236+ ) ;
237+ }
230238 }
231- }
239+ } ) ;
232240 }
233241 }
234242 }
0 commit comments