diff options
author | Linus Groh <mail@linusgroh.de> | 2020-05-13 01:09:49 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-13 09:34:25 +0200 |
commit | 7b8765c311ab4a2f42c923e009216478c6c3e2d1 (patch) | |
tree | b8303a4b33986f6fbd058ae09815277c11106cdc /Libraries | |
parent | aab998e776306339ef4de2c0b6e822e4f8b00033 (diff) | |
download | serenity-7b8765c311ab4a2f42c923e009216478c6c3e2d1.zip |
LibJS: Make the Function() constructor throw a SyntaxError, not return
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibJS/Runtime/FunctionConstructor.cpp | 3 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/Function.js | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/Libraries/LibJS/Runtime/FunctionConstructor.cpp b/Libraries/LibJS/Runtime/FunctionConstructor.cpp index dc94f1a322..bb8db2d28c 100644 --- a/Libraries/LibJS/Runtime/FunctionConstructor.cpp +++ b/Libraries/LibJS/Runtime/FunctionConstructor.cpp @@ -71,7 +71,8 @@ Value FunctionConstructor::construct(Interpreter& interpreter) auto function_expression = parser.parse_function_node<FunctionExpression>(); if (parser.has_errors()) { // FIXME: The parser should expose parsing error strings rather than just fprintf()'ing them - return Error::create(interpreter.global_object(), "SyntaxError", ""); + interpreter.throw_exception<SyntaxError>(""); + return {}; } return function_expression->execute(interpreter); } diff --git a/Libraries/LibJS/Tests/Function.js b/Libraries/LibJS/Tests/Function.js index 946ff73270..146976df90 100644 --- a/Libraries/LibJS/Tests/Function.js +++ b/Libraries/LibJS/Tests/Function.js @@ -26,6 +26,12 @@ try { assert(new Function().name === "anonymous"); assert(new Function().toString() === "function anonymous() {\n ???\n}"); + assertThrowsError(() => { + new Function("["); + }, { + error: SyntaxError + }); + console.log("PASS"); } catch (e) { console.log("FAIL: " + e.message); |