1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:48:10 +00:00

LibJS: Add Interpreter::create<GlobalObjectType>()

Force Interpreter construction to go via a create() helper that takes
the global object type as a template parameter.
This commit is contained in:
Andreas Kling 2020-04-01 21:04:51 +02:00
parent aee4c1f583
commit 9d5d0261e1
3 changed files with 16 additions and 17 deletions

View file

@ -198,16 +198,15 @@ int main(int argc, char** argv)
args_parser.add_positional_argument(script_path, "Path to script file", "script", Core::ArgsParser::Required::No);
args_parser.parse(argc, argv);
JS::Interpreter interpreter;
interpreter.initialize_global_object<JS::GlobalObject>();
interpreter.heap().set_should_collect_on_every_allocation(gc_on_every_allocation);
auto interpreter = JS::Interpreter::create<JS::GlobalObject>();
interpreter->heap().set_should_collect_on_every_allocation(gc_on_every_allocation);
interpreter.global_object().put("global", &interpreter.global_object());
interpreter->global_object().put("global", &interpreter->global_object());
if (script_path == nullptr) {
editor = make<Line::Editor>();
editor->initialize();
repl(interpreter);
repl(*interpreter);
} else {
auto file = Core::File::construct(script_path);
if (!file->open(Core::IODevice::ReadOnly)) {
@ -232,7 +231,7 @@ int main(int argc, char** argv)
if (dump_ast)
program->dump(0);
auto result = interpreter.run(*program);
auto result = interpreter->run(*program);
if (print_last_result)
printf("%s\n", result.to_string().characters());