mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 13:02:09 +02:00
LibJS: Throw TypeError when calling class constructor without 'new'
This commit is contained in:
committed by
Andreas Kling
parent
b07c7f589f
commit
1b0c862f3a
Notes:
sideshowbarker
2024-07-19 01:26:14 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/1b0c862f3af Pull-request: https://github.com/SerenityOS/serenity/pull/4050
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user