From 94b95a4924416968af712b94f962f9377f90c7a1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 4 Oct 2020 23:08:49 +0200 Subject: [PATCH] LibJS: Remove Interpreter::call() Just use VM::call() directly everywhere. --- Applications/Spreadsheet/Spreadsheet.cpp | 4 ++-- Libraries/LibJS/AST.cpp | 4 ++-- Libraries/LibJS/Interpreter.h | 30 ------------------------ Userland/test-web.cpp | 4 ++-- 4 files changed, 6 insertions(+), 36 deletions(-) diff --git a/Applications/Spreadsheet/Spreadsheet.cpp b/Applications/Spreadsheet/Spreadsheet.cpp index 254b77ae71..2e871d4624 100644 --- a/Applications/Spreadsheet/Spreadsheet.cpp +++ b/Applications/Spreadsheet/Spreadsheet.cpp @@ -249,7 +249,7 @@ RefPtr Sheet::from_json(const JsonObject& object, Workbook& workbook) break; case Cell::Formula: { auto& interpreter = sheet->interpreter(); - auto value = interpreter.call(parse_function, json, JS::js_string(interpreter.heap(), obj.get("value").as_string())); + auto value = interpreter.vm().call(parse_function, json, JS::js_string(interpreter.heap(), obj.get("value").as_string())); cell = make(obj.get("source").to_string(), move(value), position, sheet->make_weak_ptr()); break; } @@ -339,7 +339,7 @@ JsonObject Sheet::to_json() const if (it.value->kind == Cell::Formula) { data.set("source", it.value->data); auto json = interpreter().global_object().get("JSON"); - auto stringified = interpreter().call(json.as_object().get("stringify").as_function(), json, it.value->evaluated_data); + auto stringified = interpreter().vm().call(json.as_object().get("stringify").as_function(), json, it.value->evaluated_data); data.set("value", stringified.to_string_without_side_effects()); } else { data.set("value", it.value->data); diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index 7ea7dedb55..e12f51e89e 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -215,7 +215,7 @@ Value CallExpression::execute(Interpreter& interpreter, GlobalObject& global_obj interpreter.current_environment()->bind_this_value(global_object, result); } else { - result = interpreter.call(function, this_value, move(arguments)); + result = interpreter.vm().call(function, this_value, move(arguments)); } if (interpreter.exception()) @@ -1760,7 +1760,7 @@ Value TaggedTemplateLiteral::execute(Interpreter& interpreter, GlobalObject& glo raw_strings->indexed_properties().append(value); } strings->define_property("raw", raw_strings, 0); - return interpreter.call(tag_function, js_undefined(), move(arguments)); + return interpreter.vm().call(tag_function, js_undefined(), move(arguments)); } void TryStatement::dump(int indent) const diff --git a/Libraries/LibJS/Interpreter.h b/Libraries/LibJS/Interpreter.h index cd67485f7a..8277313bab 100644 --- a/Libraries/LibJS/Interpreter.h +++ b/Libraries/LibJS/Interpreter.h @@ -59,21 +59,6 @@ public: static NonnullOwnPtr create_with_existing_global_object(GlobalObject&); - template - [[nodiscard]] ALWAYS_INLINE Value call(Function& function, Value this_value, Args... args) - { - // Are there any values in this argpack? - // args = [] -> if constexpr (false) - // args = [x, y, z] -> if constexpr ((void)x, true || ...) - if constexpr ((((void)args, true) || ...)) { - MarkedValueList arglist { heap() }; - (..., arglist.append(move(args))); - return call(function, this_value, move(arglist)); - } - - return call(function, this_value); - } - ~Interpreter(); Value run(GlobalObject&, const Program&); @@ -90,7 +75,6 @@ public: Value argument(size_t index) const { return vm().argument(index); } Value this_value(Object& global_object) const { return vm().this_value(global_object); } LexicalEnvironment* current_environment() { return vm().current_environment(); } - const CallFrame& call_frame() { return vm().call_frame(); } void enter_scope(const ScopeNode&, ArgumentVector, ScopeType, GlobalObject&); void exit_scope(const ScopeNode&); @@ -100,11 +84,6 @@ public: private: explicit Interpreter(VM&); - [[nodiscard]] Value call_internal(Function& function, Value this_value, Optional arguments) - { - return vm().call(function, this_value, move(arguments)); - } - void push_scope(ScopeFrame frame); Vector m_scope_stack; @@ -114,13 +93,4 @@ private: Handle m_global_object; }; -template<> -[[nodiscard]] ALWAYS_INLINE Value Interpreter::call(Function& function, Value this_value, MarkedValueList arguments) { return call_internal(function, this_value, move(arguments)); } - -template<> -[[nodiscard]] ALWAYS_INLINE Value Interpreter::call(Function& function, Value this_value, Optional arguments) { return call_internal(function, this_value, move(arguments)); } - -template<> -[[nodiscard]] ALWAYS_INLINE Value Interpreter::call(Function& function, Value this_value) { return call(function, this_value, Optional {}); } - } diff --git a/Userland/test-web.cpp b/Userland/test-web.cpp index 868d5f370f..b8c46024f2 100644 --- a/Userland/test-web.cpp +++ b/Userland/test-web.cpp @@ -363,7 +363,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path) new_interpreter.run(new_interpreter.global_object(), *file_program.value()); auto& before_initial_page_load = new_interpreter.vm().get_variable("__BeforeInitialPageLoad__", new_interpreter.global_object()).as_function(); - (void)new_interpreter.call(before_initial_page_load, JS::js_undefined()); + (void)new_interpreter.vm().call(before_initial_page_load, JS::js_undefined()); if (new_interpreter.exception()) new_interpreter.vm().clear_exception(); @@ -373,7 +373,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path) // Finally run the test by calling "__AfterInitialPageLoad__" auto& after_initial_page_load = new_interpreter.vm().get_variable("__AfterInitialPageLoad__", new_interpreter.global_object()).as_function(); - (void)new_interpreter.call(after_initial_page_load, JS::js_undefined()); + (void)new_interpreter.vm().call(after_initial_page_load, JS::js_undefined()); if (new_interpreter.exception()) new_interpreter.vm().clear_exception();