summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/ScriptFunction.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-11-11 21:37:40 +0000
committerAndreas Kling <kling@serenityos.org>2020-11-12 10:14:00 +0100
commit1b0c862f3af03e42e039c7e6639d365e22ee6463 (patch)
treeee7a401c4db44a590ce5dcf4da4beb1ac4809b98 /Libraries/LibJS/Runtime/ScriptFunction.cpp
parentb07c7f589f995ce057e28e75d60b3a14962d39e4 (diff)
downloadserenity-1b0c862f3af03e42e039c7e6639d365e22ee6463.zip
LibJS: Throw TypeError when calling class constructor without 'new'
Diffstat (limited to 'Libraries/LibJS/Runtime/ScriptFunction.cpp')
-rw-r--r--Libraries/LibJS/Runtime/ScriptFunction.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/Libraries/LibJS/Runtime/ScriptFunction.cpp b/Libraries/LibJS/Runtime/ScriptFunction.cpp
index d3275425a1..4fd0ac399b 100644
--- a/Libraries/LibJS/Runtime/ScriptFunction.cpp
+++ b/Libraries/LibJS/Runtime/ScriptFunction.cpp
@@ -110,7 +110,7 @@ LexicalEnvironment* ScriptFunction::create_environment()
return environment;
}
-Value ScriptFunction::call()
+Value ScriptFunction::execute_function_body()
{
auto& vm = this->vm();
@@ -150,13 +150,22 @@ Value ScriptFunction::call()
return interpreter->execute_statement(global_object(), m_body, move(arguments), ScopeType::Function);
}
+Value ScriptFunction::call()
+{
+ if (m_is_class_constructor) {
+ vm().throw_exception<TypeError>(global_object(), ErrorType::ClassConstructorWithoutNew, m_name);
+ return {};
+ }
+ return execute_function_body();
+}
+
Value ScriptFunction::construct(Function&)
{
if (m_is_arrow_function) {
vm().throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, m_name);
return {};
}
- return call();
+ return execute_function_body();
}
JS_DEFINE_NATIVE_GETTER(ScriptFunction::length_getter)