Skip to content

Commit 0450e48

Browse files
committed
[GR-62433] [GR-63216] Fix ClassCastException in super property access.
PullRequest: js/3455
2 parents acb62ef + bd81f1c commit 0450e48

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

graal-js/src/com.oracle.js.parser/src/com/oracle/js/parser/Parser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7561,7 +7561,7 @@ private void markSuperProperty() {
75617561
if (currentFunction.isMethod()) {
75627562
currentFunction.setFlag(FunctionNode.USES_SUPER);
75637563
addIdentifierReference(SUPER.getName());
7564-
addIdentifierReference(THIS.getName());
7564+
markThis();
75657565
}
75667566
}
75677567

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
/**
9+
* Regression test for implicit use of lexical `this` via `super` in a nested arrow function.
10+
*/
11+
new class C1 {
12+
constructor() {
13+
(() => {
14+
for (let i = (() => super.a = 0)();
15+
i >= 0;
16+
(() => (this, i--))()) {
17+
}
18+
})();
19+
}
20+
};
21+
22+
// original test case
23+
class C2 {
24+
constructor(a4, a5) {
25+
class C6 {
26+
}
27+
for (let i9 = 0, i10 = 10;
28+
i10--;
29+
(() => {
30+
for (let [i15, i16] = (() => {
31+
super.a = 0;
32+
return [0, 10];
33+
})();
34+
i16;
35+
(() => {
36+
this * Uint8Array;
37+
C6[8] = "o";
38+
i16--;
39+
})()) {
40+
}
41+
})()) {
42+
}
43+
}
44+
}
45+
new C2();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
/**
9+
* Regression test for implicit use of lexical `this` via `super` in a nested arrow function.
10+
*/
11+
class C0 {
12+
constructor() {
13+
for (let i = 0;
14+
(() => {
15+
this; // explicit use of `this`
16+
for (let j = 0;
17+
(() => {
18+
super.toString(); // implicit use of `this`
19+
return j < 1;
20+
})();
21+
j++) {
22+
}
23+
return i < 1;
24+
})();
25+
i++) {
26+
}
27+
}
28+
}
29+
new C0();
30+
31+
// bonus test case
32+
class C1 extends C0 {
33+
constructor() {
34+
for (let i = 0;
35+
(() => {
36+
for (let j = 0;
37+
(() => {
38+
super();
39+
return j < 0;
40+
})();
41+
j++) {
42+
}
43+
for (let j = 0;
44+
(() => {
45+
super.toString();
46+
return j < 0;
47+
})();
48+
j++) {
49+
}
50+
this.toString();
51+
return i < 1;
52+
})();
53+
i++) {
54+
break;
55+
}
56+
}
57+
}
58+
new C1();

0 commit comments

Comments
 (0)