diff options
Diffstat (limited to 'Userland/Libraries/LibJS/Tests')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/Object/Object.freeze.js | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/object-basic.js | 39 |
2 files changed, 47 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Object/Object.freeze.js b/Userland/Libraries/LibJS/Tests/builtins/Object/Object.freeze.js index 39d5720055..32f550548c 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Object/Object.freeze.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Object/Object.freeze.js @@ -67,3 +67,11 @@ describe("normal behavior", () => { expect(o.foo).toBe("bar"); }); }); + +test("does not override frozen function name", () => { + const func = Object.freeze(function () { + return 12; + }); + const obj = Object.freeze({ name: func }); + expect(obj.name()).toBe(12); +}); diff --git a/Userland/Libraries/LibJS/Tests/object-basic.js b/Userland/Libraries/LibJS/Tests/object-basic.js index 15b1906fbb..879a0a114a 100644 --- a/Userland/Libraries/LibJS/Tests/object-basic.js +++ b/Userland/Libraries/LibJS/Tests/object-basic.js @@ -215,3 +215,42 @@ describe("errors", () => { expect("({ ...foo: bar })").not.toEval(); }); }); + +describe("naming of anon functions", () => { + test("method has name", () => { + expect({ func() {} }.func.name).toBe("func"); + }); + + test("getter has name", () => { + expect(Object.getOwnPropertyDescriptor({ get func() {} }, "func").get.name).toBe( + "get func" + ); + }); + + test("setter has name", () => { + expect(Object.getOwnPropertyDescriptor({ set func(v) {} }, "func").set.name).toBe( + "set func" + ); + }); + + test("anon function property", () => { + expect({ func: function () {} }.func.name).toBe("func"); + }); + + test("anon function from within parenthesis", () => { + expect({ func: function () {} }.func.name).toBe("func"); + }); + + test("anon function from indirect expression", () => { + expect({ func: (0, function () {}) }.func.name).toBe(""); + }); + + test("function from function call does not get named", () => { + function f() { + return function () {}; + } + + expect(f().name).toBe(""); + expect({ func: f() }.func.name).toBe(""); + }); +}); |