summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests
diff options
context:
space:
mode:
authordavidot <davidot@serenityos.org>2021-10-20 21:29:47 +0200
committerLinus Groh <mail@linusgroh.de>2021-10-20 23:19:17 +0100
commit6b2accce317e1226feaf627ddd5fbca100eb7265 (patch)
tree3a3e8a589bdb17ba630109ec3d2b4268076a6b48 /Userland/Libraries/LibJS/Tests
parent1245512c508d88e2a025d9d4e58297f76afd34bb (diff)
downloadserenity-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.js48
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);
+});