[JS IR] Add a test for external property accessor with a side effect.
This commit is contained in:
committed by
Space
parent
57f16e801f
commit
9e591f3299
@@ -5352,12 +5352,6 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/inlineEvaluationOrder/propertyAccessAndInitializer.kt");
|
runTest("js/js.translator/testData/box/inlineEvaluationOrder/propertyAccessAndInitializer.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@TestMetadata("propertyAccessNoSideEffect.kt")
|
|
||||||
public void testPropertyAccessNoSideEffect() throws Exception {
|
|
||||||
runTest("js/js.translator/testData/box/inlineEvaluationOrder/propertyAccessNoSideEffect.kt");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("propertyAccessWithSideEffect.kt")
|
@TestMetadata("propertyAccessWithSideEffect.kt")
|
||||||
public void testPropertyAccessWithSideEffect() throws Exception {
|
public void testPropertyAccessWithSideEffect() throws Exception {
|
||||||
|
|||||||
+3
-3
@@ -5755,9 +5755,9 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("propertyAccessNoSideEffect.kt")
|
@TestMetadata("propertyAccessExternalWithSideEffect.kt")
|
||||||
public void testPropertyAccessNoSideEffect() throws Exception {
|
public void testPropertyAccessExternalWithSideEffect() throws Exception {
|
||||||
runTest("js/js.translator/testData/box/inlineEvaluationOrder/propertyAccessNoSideEffect.kt");
|
runTest("js/js.translator/testData/box/inlineEvaluationOrder/propertyAccessExternalWithSideEffect.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Vendored
+60
@@ -0,0 +1,60 @@
|
|||||||
|
// DONT_TARGET_EXACT_BACKEND: JS
|
||||||
|
|
||||||
|
import kotlin.js.Console
|
||||||
|
|
||||||
|
external val consoleAccessCounter: Int
|
||||||
|
external fun resetConsoleAccessCounter(): Unit
|
||||||
|
|
||||||
|
inline fun resetCounter(): Unit { resetConsoleAccessCounter() }
|
||||||
|
|
||||||
|
fun logHelloWorld(c: Console) {
|
||||||
|
c.log("Hello")
|
||||||
|
c.log("world")
|
||||||
|
c.log("!")
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun logHelloWorldInline(c: Console) {
|
||||||
|
c.log("Hello")
|
||||||
|
c.log("world")
|
||||||
|
c.log("!")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
js("""
|
||||||
|
var consoleAccessCounter = 0;
|
||||||
|
|
||||||
|
function resetConsoleAccessCounter() {
|
||||||
|
consoleAccessCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.defineProperty(globalThis, 'console', {
|
||||||
|
get: function () {
|
||||||
|
++consoleAccessCounter;
|
||||||
|
return { log: function () {} };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
""")
|
||||||
|
|
||||||
|
logHelloWorld(console)
|
||||||
|
if (consoleAccessCounter != 1) return "Fail 1"
|
||||||
|
|
||||||
|
logHelloWorldInline(console)
|
||||||
|
if (consoleAccessCounter != 2) return "Fail 2"
|
||||||
|
|
||||||
|
console.also {
|
||||||
|
it.log("foo")
|
||||||
|
it.log("bar")
|
||||||
|
}
|
||||||
|
if (consoleAccessCounter != 3) return "Fail 3"
|
||||||
|
|
||||||
|
console.apply {
|
||||||
|
log("foo")
|
||||||
|
log("bar")
|
||||||
|
}
|
||||||
|
if (consoleAccessCounter != 4) return "Fail 4"
|
||||||
|
|
||||||
|
console.log(resetCounter())
|
||||||
|
if (consoleAccessCounter != 0) return "Fail 5"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user