diff --git a/js/js.libraries/src/core/domEvents.kt b/js/js.libraries/src/core/domEvents.kt deleted file mode 100644 index 90fd35e0c94..00000000000 --- a/js/js.libraries/src/core/domEvents.kt +++ /dev/null @@ -1,84 +0,0 @@ - -package org.w3c.dom.events - -import org.w3c.dom.* -import org.w3c.dom.views.* - - -// -// NOTE THIS FILE IS AUTO-GENERATED by the GenerateJavaScriptStubs.kt -// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib -// - -// Contains stub APIs for the W3C DOM API so we can delegate to the platform DOM instead - -deprecated("Use org.w3c.dom instead") -native public trait DocumentEvent { - public fun createEvent(arg1: String?): Event = noImpl -} - -deprecated("Use org.w3c.dom instead") -native public trait Event { - public val bubbles: Boolean - public val cancelable: Boolean - public val currentTarget: EventTarget - public val eventPhase: Short - public val target: EventTarget - public val timeStamp: Long - public val type: String - public fun initEvent(arg1: String?, arg2: Boolean, arg3: Boolean): Unit = noImpl - public fun preventDefault(): Unit = noImpl - public fun stopPropagation(): Unit = noImpl - - public companion object { - public val AT_TARGET: Short = 2 - public val BUBBLING_PHASE: Short = 3 - public val CAPTURING_PHASE: Short = 1 - } -} - -deprecated("Use org.w3c.dom instead") -native public trait EventTarget { - public fun addEventListener(arg1: String?, arg2: EventListener, arg3: Boolean): Unit = noImpl - public fun dispatchEvent(arg1: Event?): Boolean = noImpl - public fun removeEventListener(arg1: String?, arg2: EventListener, arg3: Boolean): Unit = noImpl -} - -deprecated("Use org.w3c.dom instead") -native public trait MouseEvent: UIEvent { - public val altKey: Boolean - public val button: Short - public val clientX: Int - public val clientY: Int - public val ctrlKey: Boolean - public val metaKey: Boolean - public val relatedTarget: EventTarget - public val screenX: Int - public val screenY: Int - public val shiftKey: Boolean - public fun initMouseEvent(arg1: String?, arg2: Boolean, arg3: Boolean, arg4: AbstractView, arg5: Int, arg6: Int, arg7: Int, arg8: Int, arg9: Int, arg10: Boolean, arg11: Boolean, arg12: Boolean, arg13: Boolean, arg14: Short, arg15: EventTarget): Unit = noImpl -} - -deprecated("Use org.w3c.dom instead") -native public trait MutationEvent: Event { - public val attrChange: Short - public val attrName: String - public val newValue: String - public val prevValue: String - public val relatedNode: Node - public fun initMutationEvent(arg1: String?, arg2: Boolean, arg3: Boolean, arg4: Node, arg5: String?, arg6: String?, arg7: String?, arg8: Short): Unit = noImpl - - public companion object { - public val ADDITION: Short = 2 - public val MODIFICATION: Short = 1 - public val REMOVAL: Short = 3 - } -} - -deprecated("Use org.w3c.dom instead") -native public trait UIEvent: Event { - public val detail: Int - public val view: AbstractView - public fun initUIEvent(arg1: String?, arg2: Boolean, arg3: Boolean, arg4: AbstractView, arg5: Int): Unit = noImpl -} - diff --git a/js/js.libraries/src/core/domEventsCode.kt b/js/js.libraries/src/core/domEventsCode.kt deleted file mode 100644 index 114cca270e3..00000000000 --- a/js/js.libraries/src/core/domEventsCode.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.w3c.dom.events - -import org.w3c.dom.* -import org.w3c.dom.views.* - -/* - TODO we should maybe update GeneratedJavaScriptStubs.kt to auto-create this file - too so that we can have the implementation code generated for JS - - See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib -*/ - -deprecated("Use org.w3c.dom instead") -public trait EventListener { - public fun handleEvent(arg1: Event): Unit -} diff --git a/js/js.libraries/src/core/domExts.kt b/js/js.libraries/src/core/domExts.kt index e4337144058..2cfbbadc7b4 100644 --- a/js/js.libraries/src/core/domExts.kt +++ b/js/js.libraries/src/core/domExts.kt @@ -31,15 +31,28 @@ public val localStorage: Storage = noImpl native public val sessionStorage: Storage = noImpl - private class HTMLCollectionListView(val collection: HTMLCollection) : AbstractList() { - override fun size(): Int = collection.length.toInt() + override fun size(): Int = collection.length override fun get(index: Int): HTMLElement = - if (index in 0..size() - 1) collection.item(index) as HTMLElement - else throw IndexOutOfBoundsException("index $index is not in range [0 .. ${size() - 1})") + when { + index in 0..size() - 1 -> collection.item(index) as HTMLElement + else -> throw IndexOutOfBoundsException("index $index is not in range [0 .. ${size() - 1})") + } } public fun HTMLCollection.asList(): List = HTMLCollectionListView(this) -public fun HTMLCollection?.toElementList() : List = this?.asList() ?: emptyList() \ No newline at end of file +public fun HTMLCollection?.toElementList(): List = this?.asList() ?: emptyList() + +private class DOMTokenListView(val delegate: DOMTokenList) : AbstractList() { + override fun size(): Int = delegate.length + + override fun get(index: Int) = + when { + index in 0..size() - 1 -> delegate.item(index)!! + else -> throw IndexOutOfBoundsException("index $index is not in range [0 .. ${size() - 1})") + } +} + +public fun DOMTokenList.asList(): List = DOMTokenListView(this) \ No newline at end of file diff --git a/js/js.translator/testData/stdlib/cases/browserDocumentAccess.kt b/js/js.translator/testData/stdlib/cases/browserDocumentAccess.kt index bd6065c0906..9f4c6967a28 100644 --- a/js/js.translator/testData/stdlib/cases/browserDocumentAccess.kt +++ b/js/js.translator/testData/stdlib/cases/browserDocumentAccess.kt @@ -9,5 +9,5 @@ fun box(): String { element.appendChild(textNode) if (textNode.nodeType != Node.TEXT_NODE) return "The type of the node is ${textNode.nodeType}, ${Node.TEXT_NODE} was expected" if (element.nodeType != Node.ELEMENT_NODE) return "The type of the node is ${element.nodeType}, ${Node.ELEMENT_NODE} was expected" - return element.textContent + return element.textContent!! } diff --git a/libraries/stdlib/src/kotlin/dom/DomEvents.kt b/libraries/stdlib/src/kotlin/dom/DomEvents.kt index 758a2337af8..1d4d2c4a752 100644 --- a/libraries/stdlib/src/kotlin/dom/DomEvents.kt +++ b/libraries/stdlib/src/kotlin/dom/DomEvents.kt @@ -1,7 +1,7 @@ package kotlin.dom import java.io.Closeable -import org.w3c.dom.Node +import org.w3c.dom.* import org.w3c.dom.events.* /** diff --git a/libraries/stdlib/test/js/JsDomTest.kt b/libraries/stdlib/test/js/JsDomTest.kt index 57ec600978d..8349bc82c1b 100644 --- a/libraries/stdlib/test/js/JsDomTest.kt +++ b/libraries/stdlib/test/js/JsDomTest.kt @@ -1,7 +1,6 @@ package test.js import kotlin.* -import kotlin.browser.* import kotlin.dom.* import kotlin.test.* import org.w3c.dom.*