From 1c121d7488a807f624105e8d41a989272d7d20d1 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Mon, 24 Jan 2022 12:43:05 +0330 Subject: [PATCH] js: Use generic reference instead of Variant As the two types are used in exactly the same way, just make the lambda generic over the type instead of explicitly moving them into a variant and then visiting with a generic lambda. --- Userland/Utilities/js.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index f98e4acc90..829c2ef0d7 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -973,17 +973,12 @@ static bool parse_and_run(JS::Interpreter& interpreter, StringView source, Strin JS::ThrowCompletionOr result { JS::js_undefined() }; - auto run_script_or_module = [&](Variant, NonnullRefPtr> script_or_module) { - auto program = script_or_module.visit( - [](auto& visitor) -> NonnullRefPtr { - return visitor->parse_node(); - }); - + auto run_script_or_module = [&](auto& script_or_module) { if (s_dump_ast) - program->dump(0); + script_or_module->parse_node().dump(0); if (JS::Bytecode::g_dump_bytecode || s_run_bytecode) { - auto executable = JS::Bytecode::Generator::generate(*program); + auto executable = JS::Bytecode::Generator::generate(script_or_module->parse_node()); executable.name = source_name; if (s_opt_bytecode) { auto& passes = JS::Bytecode::Interpreter::optimization_pipeline(); @@ -1001,10 +996,7 @@ static bool parse_and_run(JS::Interpreter& interpreter, StringView source, Strin return ReturnEarly::Yes; } } else { - result = script_or_module.visit( - [&](auto& visitor) { - return interpreter.run(*visitor); - }); + result = interpreter.run(*script_or_module); } return ReturnEarly::No; @@ -1020,7 +1012,7 @@ static bool parse_and_run(JS::Interpreter& interpreter, StringView source, Strin outln(error.to_string()); vm->throw_exception(interpreter.global_object(), error.to_string()); } else { - auto return_early = run_script_or_module(move(script_or_error.value())); + auto return_early = run_script_or_module(script_or_error.value()); if (return_early == ReturnEarly::Yes) return true; } @@ -1034,7 +1026,7 @@ static bool parse_and_run(JS::Interpreter& interpreter, StringView source, Strin outln(error.to_string()); vm->throw_exception(interpreter.global_object(), error.to_string()); } else { - auto return_early = run_script_or_module(move(module_or_error.value())); + auto return_early = run_script_or_module(module_or_error.value()); if (return_early == ReturnEarly::Yes) return true; }