Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove w3c usages from wasmJs implementation #4097

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions kotlinx-coroutines-core/wasmJs/src/CoroutineContext.kt
@@ -1,7 +1,6 @@
package kotlinx.coroutines

import kotlinx.coroutines.internal.*
import org.w3c.dom.*
import kotlin.coroutines.*

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

internal fun tryGetWindow(): Window? =
internal fun tryGetWindow(): W3CWindow? =
js("(typeof(window) !== 'undefined' && window != null && typeof(window.addEventListener) === 'function') ? window : null")

internal actual fun createDefaultDispatcher(): CoroutineDispatcher =
Expand Down
12 changes: 6 additions & 6 deletions kotlinx-coroutines-core/wasmJs/src/JSDispatcher.kt
@@ -1,9 +1,8 @@
package kotlinx.coroutines

import org.w3c.dom.Window
import kotlin.js.*

public actual typealias W3CWindow = Window
public actual abstract external class W3CWindow

internal actual fun w3cSetTimeout(window: W3CWindow, handler: () -> Unit, timeout: Int): Int =
setTimeout(window, handler, timeout)
Expand All @@ -12,7 +11,7 @@ internal actual fun w3cSetTimeout(handler: () -> Unit, timeout: Int): Int =
setTimeout(handler, timeout)

internal actual fun w3cClearTimeout(window: W3CWindow, handle: Int) =
window.clearTimeout(handle)
clearTimeout(handle)

internal actual fun w3cClearTimeout(handle: Int) =
clearTimeout(handle)
Expand Down Expand Up @@ -40,7 +39,7 @@ internal class NodeDispatcher(private val process: JsProcess) : SetTimeoutBasedD
}

@Suppress("UNUSED_PARAMETER")
private fun subscribeToWindowMessages(window: Window, process: () -> Unit): Unit = js("""{
private fun subscribeToWindowMessages(window: W3CWindow, process: () -> Unit): Unit = js("""{
const handler = (event) => {
if (event.source == window && event.data == 'dispatchCoroutine') {
event.stopPropagation();
Expand All @@ -51,7 +50,7 @@ private fun subscribeToWindowMessages(window: Window, process: () -> Unit): Unit
}""")

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

@Suppress("UNUSED_PARAMETER")
Expand Down Expand Up @@ -84,5 +83,6 @@ private fun clearTimeout(handle: Int): Unit =
js("{ if (typeof clearTimeout !== 'undefined') clearTimeout(handle); }")

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