From 4bd187ccea1688d3cd417b9cf1b5ecae83bc091a Mon Sep 17 00:00:00 2001 From: Igor Yakovlev Date: Sat, 19 Nov 2022 12:01:04 +0100 Subject: [PATCH] [Wasm] Move ItemArrayLike w3c declarations into the right package --- .../stdlib/wasm/src/kotlin/w3cSupport.kt | 16 +-------------- .../wasm/src/kotlinx/dom/ItemArrayLike.kt | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 libraries/stdlib/wasm/src/kotlinx/dom/ItemArrayLike.kt diff --git a/libraries/stdlib/wasm/src/kotlin/w3cSupport.kt b/libraries/stdlib/wasm/src/kotlin/w3cSupport.kt index bbbac2886a3..7ba4c6cc2e8 100644 --- a/libraries/stdlib/wasm/src/kotlin/w3cSupport.kt +++ b/libraries/stdlib/wasm/src/kotlin/w3cSupport.kt @@ -12,18 +12,4 @@ internal val undefined: Nothing? = null * Exposes the JavaScript [eval function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) to Kotlin. */ @JsFun("(s) => eval(s)") -external fun js(code: String): Dynamic - -external interface ItemArrayLike { - val length: Int - fun item(index: Int): T? -} - -fun ItemArrayLike.asList(): List = object : AbstractList() { - override val size: Int get() = this@asList.length - - override fun get(index: Int): T = when (index) { - in 0..lastIndex -> this@asList.item(index) as T - else -> throw IndexOutOfBoundsException("index $index is not in range [0..$lastIndex]") - } -} \ No newline at end of file +external fun js(code: String): Dynamic \ No newline at end of file diff --git a/libraries/stdlib/wasm/src/kotlinx/dom/ItemArrayLike.kt b/libraries/stdlib/wasm/src/kotlinx/dom/ItemArrayLike.kt new file mode 100644 index 00000000000..fb5b3119b00 --- /dev/null +++ b/libraries/stdlib/wasm/src/kotlinx/dom/ItemArrayLike.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.w3c.dom + +public external interface ItemArrayLike { + val length: Int + fun item(index: Int): T? +} + +public fun ItemArrayLike.asList(): List = object : AbstractList() { + override val size: Int get() = this@asList.length + + override fun get(index: Int): T = when (index) { + in 0..lastIndex -> this@asList.item(index) as T + else -> throw IndexOutOfBoundsException("index $index is not in range [0..$lastIndex]") + } +} \ No newline at end of file