Files
ladybird/Tests/LibJS/Runtime/classes/class-expressions.js
Shannon Booth adabc5cedb LibJS: Handle empty UTF-16 strings in Rust FFI
Treat zero length UTF-16 slices from Rust as empty views at the FFI
boundary instead of assuming a non null backing pointer.

Add a regression test which crashed before these changes. Fixes
a crash loading github.com/ladybirdbrowser/ladybird.
2026-03-31 22:33:36 +02:00

80 lines
1.4 KiB
JavaScript

test("basic functionality", () => {
const A = class {
constructor(x) {
this.x = x;
}
getX() {
return this.x * 2;
}
};
expect(new A(10).getX()).toBe(20);
});
test("inline instantiation", () => {
// prettier-ignore
const a = new class {
constructor() {
this.x = 10;
}
getX() {
return this.x * 2;
}
};
expect(a.getX()).toBe(20);
});
test("inline instantiation with argument", () => {
// prettier-ignore
const a = new class {
constructor(x) {
this.x = x;
}
getX() {
return this.x * 2;
}
}(10);
expect(a.getX()).toBe(20);
});
test("extending class expressions", () => {
class A extends class {
constructor(x) {
this.x = x;
}
} {
constructor(y) {
super(y);
this.y = y * 2;
}
}
const a = new A(10);
expect(a.x).toBe(10);
expect(a.y).toBe(20);
});
test("class expression name", () => {
let A = class {};
expect(A.name).toBe("A");
let B = class C {};
expect(B.name).toBe("C");
});
test("empty string literal field initializers", () => {
const A = class {
x = "";
static y = "";
};
const a = new A();
expect(a.x).toBe("");
expect(A.y).toBe("");
});