summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-05-02 20:28:48 +0100
committerAndreas Kling <kling@serenityos.org>2020-05-03 11:41:56 +0200
commit25cf0da2fb44d040f76dcb7ac8feddc20492ce26 (patch)
tree9099980d4f56b27f962eeb5c9dfd82eef4901062 /Libraries/LibJS/Tests
parent5e66f1900b1576f8645bb52d3ac6468ea69e7e25 (diff)
downloadserenity-25cf0da2fb44d040f76dcb7ac8feddc20492ce26.zip
LibJS: Set name of anonymous functions during assignment
Diffstat (limited to 'Libraries/LibJS/Tests')
-rw-r--r--Libraries/LibJS/Tests/function-name.js38
1 files changed, 33 insertions, 5 deletions
diff --git a/Libraries/LibJS/Tests/function-name.js b/Libraries/LibJS/Tests/function-name.js
index 163dbab8b1..9a934c01fb 100644
--- a/Libraries/LibJS/Tests/function-name.js
+++ b/Libraries/LibJS/Tests/function-name.js
@@ -1,16 +1,44 @@
load("test-common.js");
try {
- var f = function () { }
- assert(f.name === "");
- assert((f.name = "f") === "f");
- assert(f.name === "");
+ assert((function () { }).name === "");
- function foo() { }
+ var foo = function () { }
assert(foo.name === "foo");
assert((foo.name = "bar") === "bar");
assert(foo.name === "foo");
+ var a, b;
+ a = b = function () { }
+ assert(a.name === "b");
+ assert(b.name === "b");
+
+ var arr = [
+ function () { },
+ function () { },
+ function () { }
+ ];
+ assert(arr[0].name === "arr");
+ assert(arr[1].name === "arr");
+ assert(arr[2].name === "arr");
+
+ var f;
+ var o = { a: function () { } };
+ assert(o.a.name === "a");
+ f = o.a;
+ assert(f.name === "a");
+ assert(o.a.name === "a");
+ o = { ...o, b: f };
+ assert(o.a.name === "a");
+ assert(o.b.name === "a");
+ o.c = function () { };
+ assert(o.c.name === "c");
+
+ function bar() { }
+ assert(bar.name === "bar");
+ assert((bar.name = "baz") === "baz");
+ assert(bar.name === "bar");
+
assert(console.log.name === "log");
assert((console.log.name = "warn") === "warn");
assert(console.log.name === "log");