From 310d9267470877b684b496543139694ba82e206c Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Mon, 13 Aug 2012 16:10:51 +0400 Subject: [PATCH] Test for KT-2388: if function passed as setTimeout callback, all "this" references will be point to HTML window instead of real object. #KT-2388 fixed --- .../test/semantics/NativeInteropTest.java | 4 ++++ .../testFiles/native/cases/Kt2388.kt | 20 +++++++++++++++++++ .../testFiles/native/native/Kt2388.js | 3 +++ 3 files changed, 27 insertions(+) create mode 100644 js/js.translator/testFiles/native/cases/Kt2388.kt create mode 100644 js/js.translator/testFiles/native/native/Kt2388.js diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/NativeInteropTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/NativeInteropTest.java index aaf68d3835f..6d50f14f77b 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/NativeInteropTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/NativeInteropTest.java @@ -75,4 +75,8 @@ public final class NativeInteropTest extends SingleFileTranslationTest { public void testKt2209() throws Exception { fooBoxTest(); } + + public void testKt2388() throws Exception { + fooBoxTest(); + } } diff --git a/js/js.translator/testFiles/native/cases/Kt2388.kt b/js/js.translator/testFiles/native/cases/Kt2388.kt new file mode 100644 index 00000000000..1938b7044a5 --- /dev/null +++ b/js/js.translator/testFiles/native/cases/Kt2388.kt @@ -0,0 +1,20 @@ +package foo + +native +fun _setTimeout(callback:()->Unit):Unit = noImpl + +var done = false + +object foo { + var timeoutId: Long = 1 + + val callbackWrapper = { + timeoutId = -1 as Long + done = true + } +} + +fun box(): Boolean { + _setTimeout(foo.callbackWrapper) + return foo.timeoutId == -1 as Long +} diff --git a/js/js.translator/testFiles/native/native/Kt2388.js b/js/js.translator/testFiles/native/native/Kt2388.js new file mode 100644 index 00000000000..9593fd9db39 --- /dev/null +++ b/js/js.translator/testFiles/native/native/Kt2388.js @@ -0,0 +1,3 @@ +function _setTimeout(callback) { + callback.call({}); +}