diff --git a/Libraries/LibJS/Runtime/FunctionConstructor.cpp b/Libraries/LibJS/Runtime/FunctionConstructor.cpp index 0ed6fd1185..dc94f1a322 100644 --- a/Libraries/LibJS/Runtime/FunctionConstructor.cpp +++ b/Libraries/LibJS/Runtime/FunctionConstructor.cpp @@ -66,7 +66,7 @@ Value FunctionConstructor::construct(Interpreter& interpreter) parameters_source = parameters_builder.build(); body_source = interpreter.argument(interpreter.argument_count() - 1).to_string(); } - auto source = String::format("function (%s) { %s }", parameters_source.characters(), body_source.characters()); + auto source = String::format("function anonymous(%s) { %s }", parameters_source.characters(), body_source.characters()); auto parser = Parser(Lexer(source)); auto function_expression = parser.parse_function_node(); if (parser.has_errors()) { diff --git a/Libraries/LibJS/Tests/Function.js b/Libraries/LibJS/Tests/Function.js index c46ba99aaa..8ddcb691d6 100644 --- a/Libraries/LibJS/Tests/Function.js +++ b/Libraries/LibJS/Tests/Function.js @@ -3,8 +3,10 @@ load("test-common.js"); try { assert(Function.length === 1); assert(Function.prototype.length === 0); + assert(typeof Function() === "function"); assert(typeof new Function() === "function"); + assert(Function()() === undefined); assert(new Function()() === undefined); assert(Function("return 42")() === 42); @@ -19,6 +21,8 @@ try { assert(new Function("return typeof Function()")() === "function"); assert(new Function("x", "return function (y) { return x + y };")(1)(2) === 3); + assert(new Function().toString() === "function anonymous() {\n ???\n}"); + console.log("PASS"); } catch (e) { console.log("FAIL: " + e.message);