[Wasm] Move ItemArrayLike w3c declarations into the right package

This commit is contained in:
Igor Yakovlev
2022-11-19 12:01:04 +01:00
committed by teamcity
parent 950082e7f4
commit 4bd187ccea
2 changed files with 21 additions and 15 deletions
+1 -15
View File
@@ -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<out T> {
val length: Int
fun item(index: Int): T?
}
fun <T> ItemArrayLike<T>.asList(): List<T> = object : AbstractList<T>() {
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]")
}
}
external fun js(code: String): Dynamic
@@ -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<out T> {
val length: Int
fun item(index: Int): T?
}
public fun <T> ItemArrayLike<T>.asList(): List<T> = object : AbstractList<T>() {
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]")
}
}