LibJS: Use correct this value for tagged template literals with members

Required by creepjs, which does Date().split` `[3] to get the current
year.
This commit is contained in:
Luke Wilde 2025-01-16 17:18:19 +00:00 committed by Andreas Kling
commit a588756105
Notes: github-actions[bot] 2025-01-17 16:16:08 +00:00
2 changed files with 119 additions and 3 deletions

View file

@ -164,7 +164,7 @@ describe("tagged template literal functionality", () => {
expect(firstResult).toBe(secondResult);
});
test.xfail("this value of call comes from reference", () => {
test("this value of call comes from reference for non-computed, non-super property", () => {
let thisValue = null;
const obj = {
func() {
@ -176,4 +176,106 @@ describe("tagged template literal functionality", () => {
expect(thisValue).toBe(obj);
});
test("this value of call comes from reference for computed, non-super property", () => {
let thisValue = null;
const obj = {
func() {
thisValue = this;
},
};
obj["func"]``;
expect(thisValue).toBe(obj);
});
test("this value of call comes from reference for private property", () => {
let thisValue = null;
const obj = new (class A {
#func = () => {
thisValue = this;
};
constructor() {
this.#func``;
}
})();
expect(thisValue).toBe(obj);
});
test("this value of call comes from reference for non-computed super call property", () => {
let thisValue = null;
class A {
func() {
thisValue = this;
}
}
const obj = new (class B extends A {
constructor() {
super().func``;
}
})();
expect(thisValue).toBe(obj);
});
test("this value of call comes from reference for computed super call property", () => {
let thisValue = null;
class A {
func() {
thisValue = this;
}
}
const obj = new (class B extends A {
constructor() {
super()["func"]``;
}
})();
expect(thisValue).toBe(obj);
});
test("this value of call comes from reference for non-computed super property", () => {
let thisValue = null;
class A {
func() {
thisValue = this;
}
}
const obj = new (class B extends A {
constructor() {
super();
super.func``;
}
})();
expect(thisValue).toBe(obj);
});
test("this value of call comes from reference for computed super property", () => {
let thisValue = null;
class A {
func() {
thisValue = this;
}
}
const obj = new (class B extends A {
constructor() {
super();
super["func"]``;
}
})();
expect(thisValue).toBe(obj);
});
});