diff options
author | davidot <davidot@serenityos.org> | 2021-10-20 21:29:47 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-20 23:19:17 +0100 |
commit | 6b2accce317e1226feaf627ddd5fbca100eb7265 (patch) | |
tree | 3a3e8a589bdb17ba630109ec3d2b4268076a6b48 /Userland/Libraries/LibJS/Tests | |
parent | 1245512c508d88e2a025d9d4e58297f76afd34bb (diff) | |
download | serenity-6b2accce317e1226feaf627ddd5fbca100eb7265.zip |
LibJS: Add static initializers to classes
Diffstat (limited to 'Userland/Libraries/LibJS/Tests')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/classes/class-static-initializers.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/classes/class-static-initializers.js b/Userland/Libraries/LibJS/Tests/classes/class-static-initializers.js new file mode 100644 index 0000000000..feb7afe76c --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/classes/class-static-initializers.js @@ -0,0 +1,48 @@ +test("basic functionality", () => { + var called = false; + class A { + static { + expect(called).toBeFalse(); + expect(this.name).toBe("A"); + called = true; + } + } + + expect(called).toBeTrue(); + new A(); + expect(called).toBeTrue(); +}); + +test("called in order", () => { + var i = 0; + class A { + static { + expect(i).toBe(0); + i++; + } + + static method() { + return 2; + } + + static { + expect(i).toBe(1); + i++; + } + } + + expect(i).toBe(2); + new A(); + expect(i).toBe(2); +}); + +test("correct this", () => { + var thisValue = null; + class A { + static { + thisValue = this; + } + } + + expect(thisValue).toBe(A); +}); |