summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/ScriptFunction.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-08-25 12:52:32 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-25 18:30:31 +0200
commit9ea6ef4ed1450590ad02f6d501c7345eab779439 (patch)
treecf6827af2c346e2051229b55d49de2f90792b18c /Libraries/LibJS/Runtime/ScriptFunction.cpp
parent98dd034c2926c61b4fae47172a89b4e68a6eb43c (diff)
downloadserenity-9ea6ef4ed1450590ad02f6d501c7345eab779439.zip
LibJS: Make Interpreter::throw_exception() a void function
The motivation for this change is twofold: - Returning a JS::Value is misleading as one would expect it to carry some meaningful information, like maybe the error object that's being created, but in fact it is always empty. Supposedly to serve as a shortcut for the common case of "throw and return empty value", but that's just leading us to my second point. - Inconsistent usage / coding style: as of this commit there are 114 uses of throw_exception() discarding its return value and 55 uses directly returning the call result (in LibJS, not counting LibWeb); with the first style often having a more explicit empty value (or nullptr in some cases) return anyway. One more line to always make the return value obvious is should be worth it. So now it's basically always these steps, which is already being used in the majority of cases (as outlined above): - Throw an exception. This mutates interpreter state by updating m_exception and unwinding, but doesn't return anything. - Let the caller explicitly return an empty value, nullptr or anything else itself.
Diffstat (limited to 'Libraries/LibJS/Runtime/ScriptFunction.cpp')
-rw-r--r--Libraries/LibJS/Runtime/ScriptFunction.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/Libraries/LibJS/Runtime/ScriptFunction.cpp b/Libraries/LibJS/Runtime/ScriptFunction.cpp
index 7a7a78dc92..1a5b607de9 100644
--- a/Libraries/LibJS/Runtime/ScriptFunction.cpp
+++ b/Libraries/LibJS/Runtime/ScriptFunction.cpp
@@ -135,8 +135,10 @@ Value ScriptFunction::call(Interpreter& interpreter)
Value ScriptFunction::construct(Interpreter& interpreter, Function&)
{
- if (m_is_arrow_function)
- return interpreter.throw_exception<TypeError>(ErrorType::NotAConstructor, m_name.characters());
+ if (m_is_arrow_function) {
+ interpreter.throw_exception<TypeError>(ErrorType::NotAConstructor, m_name.characters());
+ return {};
+ }
return call(interpreter);
}