mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:47:34 +00:00
LibJS: Make the Function() constructor throw a SyntaxError, not return
This commit is contained in:
parent
aab998e776
commit
7b8765c311
2 changed files with 8 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue