Skip to content

Commit a2b30c9

Browse files
committed
fix
1 parent c777973 commit a2b30c9

File tree

3 files changed

+54
-38
lines changed

3 files changed

+54
-38
lines changed

nova_cli/src/main.rs

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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
};
2020
use oxc_parser::Parser;
2121
use 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
}

nova_vm/tests/garbage_collection_tests.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,14 @@ fn garbage_collection_tests() {
7878
);
7979
agent.run_in_realm(&realm, |agent| {
8080
let realm = agent.current_realm_id();
81-
let script =
82-
parse_script(&allocator, header_contents.into_boxed_str(), realm, None).unwrap();
81+
let script = parse_script(
82+
&allocator,
83+
header_contents.into_boxed_str(),
84+
realm,
85+
false,
86+
None,
87+
)
88+
.unwrap();
8389
let _ = script_evaluation(agent, script).unwrap_or_else(|err| {
8490
panic!(
8591
"Header evaluation failed: '{}' failed: {:?}",
@@ -97,6 +103,7 @@ fn garbage_collection_tests() {
97103
&allocator,
98104
call_contents.clone().into_boxed_str(),
99105
realm,
106+
false,
100107
None,
101108
)
102109
.unwrap();

nova_vm/tests/object_prototype_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ fn object_prototype_tests() {
3030
let realm = agent.create_default_realm();
3131
agent.run_in_realm(&realm, |agent| {
3232
let realm = agent.current_realm_id();
33-
let script = parse_script(&allocator, contents.into_boxed_str(), realm, false, None).unwrap();
33+
let script =
34+
parse_script(&allocator, contents.into_boxed_str(), realm, false, None).unwrap();
3435
let _ = script_evaluation(agent, script).unwrap_or_else(|err| {
3536
panic!(
3637
"Test '{}' failed: {:?}",

0 commit comments

Comments
 (0)