Skip to content

Commit 100b8b3

Browse files
igoriakovlevwoainikk
authored andcommitted
Remove w3c dependencies from wasmJs target (#4097)
1 parent d82b168 commit 100b8b3

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

kotlinx-coroutines-core/wasmJs/src/CoroutineContext.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package kotlinx.coroutines
22

33
import kotlinx.coroutines.internal.*
4-
import org.w3c.dom.*
54
import kotlin.coroutines.*
65

76
internal external interface JsProcess : JsAny {
@@ -11,7 +10,7 @@ internal external interface JsProcess : JsAny {
1110
internal fun tryGetProcess(): JsProcess? =
1211
js("(typeof(process) !== 'undefined' && typeof(process.nextTick) === 'function') ? process : null")
1312

14-
internal fun tryGetWindow(): Window? =
13+
internal fun tryGetWindow(): W3CWindow? =
1514
js("(typeof(window) !== 'undefined' && window != null && typeof(window.addEventListener) === 'function') ? window : null")
1615

1716
internal actual fun createDefaultDispatcher(): CoroutineDispatcher =

kotlinx-coroutines-core/wasmJs/src/JSDispatcher.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package kotlinx.coroutines
22

3-
import org.w3c.dom.Window
43
import kotlin.js.*
54

6-
public actual typealias W3CWindow = Window
5+
public actual abstract external class W3CWindow {
6+
public fun clearTimeout(handle: Int)
7+
}
78

89
internal actual fun w3cSetTimeout(window: W3CWindow, handler: () -> Unit, timeout: Int): Int =
910
setTimeout(window, handler, timeout)
@@ -40,7 +41,7 @@ internal class NodeDispatcher(private val process: JsProcess) : SetTimeoutBasedD
4041
}
4142

4243
@Suppress("UNUSED_PARAMETER")
43-
private fun subscribeToWindowMessages(window: Window, process: () -> Unit): Unit = js("""{
44+
private fun subscribeToWindowMessages(window: W3CWindow, process: () -> Unit): Unit = js("""{
4445
const handler = (event) => {
4546
if (event.source == window && event.data == 'dispatchCoroutine') {
4647
event.stopPropagation();
@@ -51,7 +52,7 @@ private fun subscribeToWindowMessages(window: Window, process: () -> Unit): Unit
5152
}""")
5253

5354
@Suppress("UNUSED_PARAMETER")
54-
private fun createRescheduleMessagePoster(window: Window): () -> Unit =
55+
private fun createRescheduleMessagePoster(window: W3CWindow): () -> Unit =
5556
js("() => window.postMessage('dispatchCoroutine', '*')")
5657

5758
@Suppress("UNUSED_PARAMETER")
@@ -84,5 +85,5 @@ private fun clearTimeout(handle: Int): Unit =
8485
js("{ if (typeof clearTimeout !== 'undefined') clearTimeout(handle); }")
8586

8687
@Suppress("UNUSED_PARAMETER")
87-
private fun setTimeout(window: Window, handler: () -> Unit, timeout: Int): Int =
88+
private fun setTimeout(window: W3CWindow, handler: () -> Unit, timeout: Int): Int =
8889
js("window.setTimeout(handler, timeout)")

0 commit comments

Comments
 (0)