* Private Static Class Fields Implementation * Redo testing without class transform for static private * Add a call() test for private static * Use Object.defineProperty in loose mode
52 lines
944 B
JavaScript
52 lines
944 B
JavaScript
function classFactory() {
|
|
return class Foo {
|
|
#foo = "foo";
|
|
static #bar = "bar";
|
|
|
|
instance() {
|
|
return this.#foo;
|
|
}
|
|
|
|
static() {
|
|
return Foo.#bar;
|
|
}
|
|
|
|
static instance(inst) {
|
|
return inst.#foo;
|
|
}
|
|
|
|
static static() {
|
|
return Foo.#bar;
|
|
}
|
|
};
|
|
}
|
|
|
|
const Foo1 = classFactory();
|
|
const Foo2 = classFactory();
|
|
|
|
const f1 = new Foo1();
|
|
const f2 = new Foo2();
|
|
|
|
expect(f1.instance()).toBe("foo");
|
|
expect(f1.static()).toBe("bar");
|
|
expect(f2.instance()).toBe("foo");
|
|
expect(f2.static()).toBe("bar");
|
|
|
|
expect(Foo1.instance(f1)).toBe("foo");
|
|
expect(Foo1.static()).toBe("bar");
|
|
expect(Foo2.instance(f2)).toBe("foo");
|
|
expect(Foo2.static()).toBe("bar");
|
|
|
|
expect(() => {
|
|
f1.instance.call(f2), undefined;
|
|
}).toThrow();
|
|
expect(() => {
|
|
f2.instance.call(f1), undefined;
|
|
}).toThrow();
|
|
expect(() => {
|
|
Foo1.instance(f2), undefined;
|
|
}).toThrow();
|
|
expect(() => {
|
|
Foo2.instance(f1), undefined;
|
|
}).toThrow();
|