summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-05-11 23:31:30 +0100
committerLinus Groh <mail@linusgroh.de>2021-05-11 23:31:30 +0100
commit0a329d2d70f636fb1d0cbe26be56ccfbd5554238 (patch)
treeef977f92098d47cec3fad3be502b4b5e44aef558 /Userland/Libraries/LibJS/Tests
parentd85b9fd5a09e451c5faa7922c3f8ab2661f0706e (diff)
downloadserenity-0a329d2d70f636fb1d0cbe26be56ccfbd5554238.zip
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.
Diffstat (limited to 'Userland/Libraries/LibJS/Tests')
-rw-r--r--Userland/Libraries/LibJS/Tests/classes/class-inheritance.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/classes/class-inheritance.js b/Userland/Libraries/LibJS/Tests/classes/class-inheritance.js
index 0e6778dbf5..421e6a0c95 100644
--- a/Userland/Libraries/LibJS/Tests/classes/class-inheritance.js
+++ b/Userland/Libraries/LibJS/Tests/classes/class-inheritance.js
@@ -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");
+});