diff options
author | Jack Karamanian <karamanian.jack@gmail.com> | 2020-05-30 00:16:42 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-30 10:33:24 +0200 |
commit | 3ffb0a4e87366b128e6d7ad749bd7083f7016975 (patch) | |
tree | 255cd76cd78a11bcc53a99bbe20d17e8edae4a49 /Libraries/LibJS | |
parent | 1110b1b444d0b9a71820d9c7520c2d81e6dcdf24 (diff) | |
download | serenity-3ffb0a4e87366b128e6d7ad749bd7083f7016975.zip |
LibJS: Throw a TypeError when an arrow function is used as a constructor
Diffstat (limited to 'Libraries/LibJS')
-rw-r--r-- | Libraries/LibJS/Runtime/ScriptFunction.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/arrow-functions.js | 7 |
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()); |