1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:38:10 +00:00

LibJS: Make super() in catch block work

The TryStatement handler execution creates a new LexicalEnvironment
without a current function set, which we were not accounting for when
trying to get the super constructor while executing a SuperExpression.
This makes it work but isn't pretty - this needs some refactoring to be
close to the spec for that to happen.

Fixes #7045.
This commit is contained in:
Linus Groh 2021-05-11 23:31:30 +01:00
parent d85b9fd5a0
commit 0a329d2d70
2 changed files with 30 additions and 2 deletions

View file

@ -131,3 +131,24 @@ test("super constructor call from child class with argument", () => {
expect(p.x).toBe(3);
expect(c.x).toBe(10);
});
test("issue #7045, super constructor call from child class in catch {}", () => {
class Parent {
constructor(x) {
this.x = x;
}
}
class Child extends Parent {
constructor() {
try {
throw new Error("Error in Child constructor");
} catch (e) {
super(e.message);
}
}
}
const c = new Child();
expect(c.x).toBe("Error in Child constructor");
});