[JS IR] Add a test for external property accessor with a side effect.

This commit is contained in:
Alexander Korepanov
2022-04-19 15:36:37 +03:00
committed by Space
parent 57f16e801f
commit 9e591f3299
3 changed files with 63 additions and 9 deletions
@@ -5352,12 +5352,6 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
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
@TestMetadata("propertyAccessWithSideEffect.kt")
public void testPropertyAccessWithSideEffect() throws Exception {
@@ -5755,9 +5755,9 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
}
@Test
@TestMetadata("propertyAccessNoSideEffect.kt")
public void testPropertyAccessNoSideEffect() throws Exception {
runTest("js/js.translator/testData/box/inlineEvaluationOrder/propertyAccessNoSideEffect.kt");
@TestMetadata("propertyAccessExternalWithSideEffect.kt")
public void testPropertyAccessExternalWithSideEffect() throws Exception {
runTest("js/js.translator/testData/box/inlineEvaluationOrder/propertyAccessExternalWithSideEffect.kt");
}
@Test
@@ -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"
}