1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:57:35 +00:00

LibJS: Name functions created by "Function" "anonymous"

...as it is supposed to be.
This commit is contained in:
Linus Groh 2020-05-02 18:05:05 +01:00 committed by Andreas Kling
parent e347d6bdb8
commit ae05dc8abc
2 changed files with 5 additions and 1 deletions

View file

@ -66,7 +66,7 @@ Value FunctionConstructor::construct(Interpreter& interpreter)
parameters_source = parameters_builder.build(); parameters_source = parameters_builder.build();
body_source = interpreter.argument(interpreter.argument_count() - 1).to_string(); 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 parser = Parser(Lexer(source));
auto function_expression = parser.parse_function_node<FunctionExpression>(); auto function_expression = parser.parse_function_node<FunctionExpression>();
if (parser.has_errors()) { if (parser.has_errors()) {

View file

@ -3,8 +3,10 @@ load("test-common.js");
try { try {
assert(Function.length === 1); assert(Function.length === 1);
assert(Function.prototype.length === 0); assert(Function.prototype.length === 0);
assert(typeof Function() === "function"); assert(typeof Function() === "function");
assert(typeof new Function() === "function"); assert(typeof new Function() === "function");
assert(Function()() === undefined); assert(Function()() === undefined);
assert(new Function()() === undefined); assert(new Function()() === undefined);
assert(Function("return 42")() === 42); assert(Function("return 42")() === 42);
@ -19,6 +21,8 @@ try {
assert(new Function("return typeof Function()")() === "function"); assert(new Function("return typeof Function()")() === "function");
assert(new Function("x", "return function (y) { return x + y };")(1)(2) === 3); assert(new Function("x", "return function (y) { return x + y };")(1)(2) === 3);
assert(new Function().toString() === "function anonymous() {\n ???\n}");
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e.message); console.log("FAIL: " + e.message);