Skip to content

Commit 62e4f88

Browse files
committed
improve super put processing
Found somewhere the hint that super is more or less about starting the property search at super but calling the final setter on this. Therefore this changes the put implementation like that and 'magically' the super.__proto__ handling works now and all the other tests are still green.
1 parent b1af731 commit 62e4f88

3 files changed

Lines changed: 5 additions & 31 deletions

File tree

rhino/src/main/java/org/mozilla/javascript/IRFactory.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,31 +2025,6 @@ private Node createPropertyGet(
20252025
}
20262026
parser.checkActivationName(name, Token.GETPROP);
20272027

2028-
if (target.getType() == Token.SUPER && NativeObject.PROTO_PROPERTY.equals(name)) {
2029-
// We have access to super.__proto__.
2030-
// This needs to behave in the same way as this.__proto__ - it really is not
2031-
// obvious why, but you can test it in v8 or any other engine. So, we just
2032-
// replace SUPER with THIS in the AST. It's a bit hacky, but it works - see the
2033-
// test cases in SuperTest!
2034-
if (!(target instanceof KeywordLiteral)) {
2035-
throw Kit.codeBug();
2036-
}
2037-
KeywordLiteral oldTarget = (KeywordLiteral) target;
2038-
target =
2039-
new KeywordLiteral(
2040-
oldTarget.getPosition(), oldTarget.getLength(), Token.THIS);
2041-
target.setLineColumnNumber(oldTarget.getLineno(), oldTarget.getColumn());
2042-
2043-
Node ref = new Node(Token.REF_SPECIAL, target);
2044-
ref.putProp(Node.NAME_PROP, name);
2045-
Node getRef = new Node(Token.GET_REF, ref);
2046-
if (type == Token.QUESTION_DOT) {
2047-
ref.putIntProp(Node.OPTIONAL_CHAINING, 1);
2048-
getRef.putIntProp(Node.OPTIONAL_CHAINING, 1);
2049-
}
2050-
return getRef;
2051-
}
2052-
20532028
if (parser.compilerEnv.getLanguageVersion() < Context.VERSION_ES6
20542029
&& ScriptRuntime.isSpecialProperty(name)) {
20552030
Node ref = new Node(Token.REF_SPECIAL, target);

rhino/src/main/java/org/mozilla/javascript/ScriptableObject.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,10 @@ public static void putProperty(Scriptable obj, String name, Object value) {
24902490
/** Variant of putProperty to handle super.name = value */
24912491
public static void putSuperProperty(
24922492
Scriptable superObj, Scriptable thisObj, String name, Object value) {
2493-
superObj.put(name, thisObj, value);
2493+
// in contrast to putProperty we start searching at superObj
2494+
Scriptable base = getBase(superObj, name);
2495+
if (base == null) base = superObj;
2496+
base.put(name, thisObj, value);
24942497
}
24952498

24962499
/** This is a version of putProperty for Symbol keys. */

tests/src/test/java/org/mozilla/javascript/tests/es6/ProtoProperty2Test.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,12 +546,8 @@ public void protoSuperSet() {
546546
+ "c.f();"
547547
+ "res;";
548548

549-
// this is only partially supported
550-
// see org.mozilla.javascript.IRFactory.createPropertyGet()
551-
// Utils.assertWithAllModes_ES6("truetrue-truetrue / truetrue-truetrue / truetrue-truetrue",
552-
// script);
553549
Utils.assertWithAllModes_ES6(
554-
"truetrue-truetrue / truefalse-truetrue / truefalse-truetrue", script);
550+
"truetrue-truetrue / truetrue-truetrue / truetrue-truetrue", script);
555551
}
556552

557553
@Test

0 commit comments

Comments
 (0)