summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorJack Karamanian <karamanian.jack@gmail.com>2020-05-30 00:16:42 -0500
committerAndreas Kling <kling@serenityos.org>2020-05-30 10:33:24 +0200
commit3ffb0a4e87366b128e6d7ad749bd7083f7016975 (patch)
tree255cd76cd78a11bcc53a99bbe20d17e8edae4a49 /Libraries
parent1110b1b444d0b9a71820d9c7520c2d81e6dcdf24 (diff)
downloadserenity-3ffb0a4e87366b128e6d7ad749bd7083f7016975.zip
LibJS: Throw a TypeError when an arrow function is used as a constructor
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibJS/Runtime/ScriptFunction.cpp2
-rw-r--r--Libraries/LibJS/Tests/arrow-functions.js7
2 files changed, 9 insertions, 0 deletions
diff --git a/Libraries/LibJS/Runtime/ScriptFunction.cpp b/Libraries/LibJS/Runtime/ScriptFunction.cpp
index 5828bcdde3..fddee25d2a 100644
--- a/Libraries/LibJS/Runtime/ScriptFunction.cpp
+++ b/Libraries/LibJS/Runtime/ScriptFunction.cpp
@@ -125,6 +125,8 @@ Value ScriptFunction::call(Interpreter& interpreter)
Value ScriptFunction::construct(Interpreter& interpreter)
{
+ if (m_is_arrow_function)
+ return interpreter.throw_exception<TypeError>(String::format("%s is not a constructor", m_name.characters()));
return call(interpreter);
}
diff --git a/Libraries/LibJS/Tests/arrow-functions.js b/Libraries/LibJS/Tests/arrow-functions.js
index e224415ded..add2c0a6fc 100644
--- a/Libraries/LibJS/Tests/arrow-functions.js
+++ b/Libraries/LibJS/Tests/arrow-functions.js
@@ -81,6 +81,13 @@ try {
assert(Baz.prototype === undefined);
+ assertThrowsError(() => {
+ new Baz();
+ }, {
+ error: TypeError,
+ message: "Baz is not a constructor"
+ });
+
(() => {
"use strict";
assert(isStrictMode());