JS: fix super access to simple non-overridable properties
See KT-7653
This commit is contained in:
@@ -22,34 +22,32 @@ Kotlin.Kind = {
|
|||||||
|
|
||||||
Kotlin.callGetter = function (thisObject, klass, propertyName) {
|
Kotlin.callGetter = function (thisObject, klass, propertyName) {
|
||||||
var propertyDescriptor = Object.getOwnPropertyDescriptor(klass, propertyName);
|
var propertyDescriptor = Object.getOwnPropertyDescriptor(klass, propertyName);
|
||||||
if (propertyDescriptor != null) {
|
if (propertyDescriptor != null && propertyDescriptor.get != null) {
|
||||||
if (propertyDescriptor.get != null) {
|
return propertyDescriptor.get.call(thisObject);
|
||||||
return propertyDescriptor.get.call(thisObject);
|
|
||||||
}
|
|
||||||
else if ("value" in propertyDescriptor) {
|
|
||||||
return propertyDescriptor.value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return Kotlin.callGetter(thisObject, Object.getPrototypeOf(klass), propertyName);
|
propertyDescriptor = Object.getOwnPropertyDescriptor(thisObject, propertyName);
|
||||||
|
if (propertyDescriptor != null && "value" in propertyDescriptor) {
|
||||||
|
return thisObject[propertyName];
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
return Kotlin.callGetter(thisObject, Object.getPrototypeOf(klass), propertyName);
|
||||||
};
|
};
|
||||||
|
|
||||||
Kotlin.callSetter = function (thisObject, klass, propertyName, value) {
|
Kotlin.callSetter = function (thisObject, klass, propertyName, value) {
|
||||||
var propertyDescriptor = Object.getOwnPropertyDescriptor(klass, propertyName);
|
var propertyDescriptor = Object.getOwnPropertyDescriptor(klass, propertyName);
|
||||||
if (propertyDescriptor != null) {
|
if (propertyDescriptor != null && propertyDescriptor.set != null) {
|
||||||
if (propertyDescriptor.set != null) {
|
propertyDescriptor.set.call(thisObject, value);
|
||||||
propertyDescriptor.set.call(thisObject, value);
|
return;
|
||||||
}
|
|
||||||
else if ("value" in propertyDescriptor) {
|
|
||||||
throw new Error("Assertion failed: Kotlin compiler should not generate simple JavaScript properties for overridable " +
|
|
||||||
"Kotlin properties.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return Kotlin.callSetter(thisObject, Object.getPrototypeOf(klass), propertyName, value);
|
propertyDescriptor = Object.getOwnPropertyDescriptor(thisObject, propertyName);
|
||||||
|
if (propertyDescriptor != null && "value" in propertyDescriptor) {
|
||||||
|
thisObject[propertyName] = value;
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Kotlin.callSetter(thisObject, Object.getPrototypeOf(klass), propertyName, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
function isInheritanceFromInterface(ctor, iface) {
|
function isInheritanceFromInterface(ctor, iface) {
|
||||||
|
|||||||
@@ -8111,6 +8111,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("propertySuperAccess.kt")
|
||||||
|
public void testPropertySuperAccess() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/superCall/propertySuperAccess.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("traitSuperCall.kt")
|
@TestMetadata("traitSuperCall.kt")
|
||||||
public void testTraitSuperCall() throws Exception {
|
public void testTraitSuperCall() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/superCall/traitSuperCall.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/superCall/traitSuperCall.kt");
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// EXPECTED_REACHABLE_NODES: 1140
|
||||||
|
open class A {
|
||||||
|
val foo = "foo"
|
||||||
|
var bar = "bar"
|
||||||
|
|
||||||
|
open val boo = "A.boo"
|
||||||
|
}
|
||||||
|
|
||||||
|
class B : A() {
|
||||||
|
override val boo = "B.boo"
|
||||||
|
|
||||||
|
fun test(): String {
|
||||||
|
var r = ""
|
||||||
|
r += super.foo + ";"
|
||||||
|
r += super.bar + ";"
|
||||||
|
super.bar = "baz"
|
||||||
|
r += super.bar + ";"
|
||||||
|
|
||||||
|
r += super.boo + ";"
|
||||||
|
r += boo + ";"
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val r = B().test()
|
||||||
|
if (r != "foo;bar;baz;A.boo;B.boo;") return "fail: $r"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user