got the kotlin/Dom.kt, Preconditions.kt and AbstractIterator.kt compiling as JS; needs more testing of using these APIs from JS though...
This commit is contained in:
@@ -10,3 +10,15 @@ trait Iterable<T> {
|
||||
|
||||
library("splitString")
|
||||
public fun String.split(regex : String) : Array<String> = js.noImpl
|
||||
|
||||
library
|
||||
class IllegalArgumentException(message: String = "") : Exception() {}
|
||||
|
||||
library
|
||||
class IllegalStateException(message: String = "") : Exception() {}
|
||||
|
||||
library
|
||||
class IndexOutOfBoundsException(message: String = "") : Exception() {}
|
||||
|
||||
library
|
||||
class UnsupportedOperationException(message: String = "") : Exception() {}
|
||||
|
||||
@@ -73,6 +73,22 @@ public abstract open class AbstractCollection<erased E> : Collection<E> {
|
||||
|
||||
library
|
||||
public abstract open class AbstractList<erased E> : AbstractCollection<E>, List<E> {
|
||||
public override fun isEmpty() : Boolean = js.noImpl
|
||||
public override fun contains(o : Any?) : Boolean = js.noImpl
|
||||
public override fun iterator() : Iterator<E> = js.noImpl
|
||||
// public override fun indexOf(o : Any?) : Int = js.noImpl
|
||||
// public override fun lastIndexOf(o : Any?) : Int = js.noImpl
|
||||
// public override fun toArray() : Array<Any?> = js.noImpl
|
||||
// public override fun toArray<erased T>(a : Array<out T>) : Array<T> = js.noImpl
|
||||
public override fun set(index : Int, element : E) : E = js.noImpl
|
||||
public override fun add(e : E) : Boolean = js.noImpl
|
||||
public override fun add(index : Int, element : E) : Unit = js.noImpl
|
||||
library("removeByIndex")
|
||||
public override fun remove(index : Int) : E = js.noImpl
|
||||
public override fun remove(o : Any?) : Boolean = js.noImpl
|
||||
public override fun clear() : Unit = js.noImpl
|
||||
public override fun addAll(c : java.util.Collection<out E>) : Boolean = js.noImpl
|
||||
// public override fun addAll(index : Int, c : java.util.Collection<out E>) : Boolean = js.noImpl
|
||||
}
|
||||
|
||||
library
|
||||
|
||||
@@ -44,12 +44,10 @@ public final class StdLibToJSTest extends SingleFileTranslationTest {
|
||||
super("stdlib/");
|
||||
}
|
||||
|
||||
public void testDummy() {
|
||||
}
|
||||
|
||||
public void TODO_testCompileStandardLibraryFiles() throws Exception {
|
||||
public void testCompileStandardLibraryFiles() throws Exception {
|
||||
|
||||
generateJavaScriptFiles(MainCallParameters.noCall(), EcmaVersion.all(),
|
||||
"kotlin/Preconditions.kt",
|
||||
"kotlin/dom/Dom.kt",
|
||||
"kotlin/support/AbstractIterator.kt"
|
||||
);
|
||||
|
||||
@@ -289,8 +289,11 @@ var Kotlin;
|
||||
Kotlin.RuntimeException = Kotlin.Class.create(Kotlin.Exception);
|
||||
Kotlin.Exceptions.IndexOutOfBounds = Kotlin.Class.create(Kotlin.Exception);
|
||||
Kotlin.Exceptions.NullPointerException = Kotlin.Class.create(Kotlin.Exception);
|
||||
Kotlin.Exceptions.UnsupportedOperationException = Kotlin.Class.create(Kotlin.Exception);
|
||||
Kotlin.Exceptions.NoSuchElementException = Kotlin.Class.create(Kotlin.Exception);
|
||||
Kotlin.Exceptions.IllegalArgumentException = Kotlin.Class.create(Kotlin.Exception);
|
||||
Kotlin.Exceptions.IllegalStateException = Kotlin.Class.create(Kotlin.Exception);
|
||||
Kotlin.Exceptions.IndexOutOfBoundsException = Kotlin.Class.create(Kotlin.Exception);
|
||||
Kotlin.Exceptions.UnsupportedOperationException = Kotlin.Class.create(Kotlin.Exception);
|
||||
|
||||
Kotlin.throwNPE = function() {
|
||||
throw new Kotlin.Exceptions.NullPointerException();
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package kotlin
|
||||
|
||||
object Assertions {
|
||||
// TODO make private once KT-1528 is fixed.
|
||||
val _ENABLED = (javaClass<java.lang.System>()).desiredAssertionStatus()
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an [[AssertionError]] with an optional *message* if the *value* is false
|
||||
* and runtime assertions have been enabled on the JVM using the *-ea* JVM option.
|
||||
*/
|
||||
public inline fun assert(value: Boolean, message: Any = "Assertion failed") {
|
||||
if (Assertions._ENABLED) {
|
||||
if (!value) {
|
||||
throw AssertionError(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an [[AssertionError]] with the specified *lazyMessage* if the *value* is false
|
||||
* and runtime assertions have been enabled on the JVM using the *-ea* JVM option.
|
||||
*/
|
||||
public inline fun assert(value: Boolean, lazyMessage: () -> String) {
|
||||
if (Assertions._ENABLED) {
|
||||
if (!value) {
|
||||
val message = lazyMessage()
|
||||
throw AssertionError(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,8 @@
|
||||
package kotlin
|
||||
|
||||
object Assertions {
|
||||
// TODO make private once KT-1528 is fixed.
|
||||
val _ENABLED = (javaClass<java.lang.System>()).desiredAssertionStatus()
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an [[AssertionError]] with an optional *message* if the *value* is false
|
||||
* and runtime assertions have been enabled on the JVM using the *-ea* JVM option.
|
||||
*/
|
||||
public inline fun assert(value: Boolean, message: Any = "Assertion failed") {
|
||||
if (Assertions._ENABLED) {
|
||||
if (!value) {
|
||||
throw AssertionError(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an [[AssertionError]] with the specified *lazyMessage* if the *value* is false
|
||||
* and runtime assertions have been enabled on the JVM using the *-ea* JVM option.
|
||||
*/
|
||||
public inline fun assert(value: Boolean, lazyMessage: () -> String) {
|
||||
if (Assertions._ENABLED) {
|
||||
if (!value) {
|
||||
val message = lazyMessage()
|
||||
throw AssertionError(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO should not need this - its here for the JS stuff
|
||||
import java.lang.IllegalArgumentException
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
/**
|
||||
* Throws an [[IllegalArgumentException]] with an optional *message* if the *value* is false.
|
||||
|
||||
@@ -5,6 +5,9 @@ import kotlin.support.*
|
||||
import java.util.*
|
||||
import org.w3c.dom.*
|
||||
|
||||
// TODO should not need this - its here for the JS stuff
|
||||
import java.lang.IllegalArgumentException
|
||||
import java.lang.IndexOutOfBoundsException
|
||||
|
||||
// Properties
|
||||
|
||||
@@ -76,6 +79,66 @@ set(value) {
|
||||
this.setAttribute("class", value)
|
||||
}
|
||||
|
||||
/** Returns the children of the element as a list */
|
||||
inline fun Element?.children(): List<Node> {
|
||||
return this?.getChildNodes().toList()
|
||||
}
|
||||
|
||||
/** The child elements of this document */
|
||||
val Document?.elements : List<Element>
|
||||
get() = this?.getElementsByTagName("*").toElementList()
|
||||
|
||||
/** The child elements of this elements */
|
||||
val Element?.elements : List<Element>
|
||||
get() = this?.getElementsByTagName("*").toElementList()
|
||||
|
||||
|
||||
/** Returns all the child elements given the local element name */
|
||||
inline fun Element?.elements(localName: String): List<Element> {
|
||||
return this?.getElementsByTagName(localName).toElementList()
|
||||
}
|
||||
|
||||
/** Returns all the elements given the local element name */
|
||||
inline fun Document?.elements(localName: String): List<Element> {
|
||||
return this?.getElementsByTagName(localName).toElementList()
|
||||
}
|
||||
|
||||
/** Returns all the child elements given the namespace URI and local element name */
|
||||
inline fun Element?.elements(namespaceUri: String, localName: String): List<Element> {
|
||||
return this?.getElementsByTagNameNS(namespaceUri, localName).toElementList()
|
||||
}
|
||||
|
||||
/** Returns all the elements given the namespace URI and local element name */
|
||||
inline fun Document?.elements(namespaceUri: String, localName: String): List<Element> {
|
||||
return this?.getElementsByTagNameNS(namespaceUri, localName).toElementList()
|
||||
}
|
||||
|
||||
inline fun NodeList?.toList(): List<Node> {
|
||||
return if (this == null) {
|
||||
// TODO the following is easier to convert to JS
|
||||
//Collections.EMPTY_LIST as List<Node>
|
||||
ArrayList<Node>()
|
||||
}
|
||||
else {
|
||||
NodeListAsList(this)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun NodeList?.toElementList(): List<Element> {
|
||||
return if (this == null) {
|
||||
// TODO the following is easier to convert to JS
|
||||
//Collections.EMPTY_LIST as List<Element>
|
||||
ArrayList<Element>()
|
||||
}
|
||||
else {
|
||||
ElementListAsList(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Helper methods
|
||||
|
||||
/** TODO this approach generates compiler errors...
|
||||
|
||||
@@ -19,12 +19,6 @@ import javax.xml.transform.stream.StreamResult
|
||||
import org.w3c.dom.*
|
||||
import org.xml.sax.InputSource
|
||||
|
||||
/** Returns the children of the element as a list */
|
||||
inline fun Element?.children(): List<Node> {
|
||||
return this?.getChildNodes().toList()
|
||||
}
|
||||
|
||||
|
||||
/** Returns an [[Iterator]] of all the next [[Element]] siblings */
|
||||
fun Node.nextElements(): Iterator<Element> = nextSiblings().filterIsInstance<Node, Element>(javaClass<Element>())
|
||||
|
||||
@@ -74,36 +68,6 @@ fun Element.get(selector: String): List<Element> {
|
||||
}
|
||||
}
|
||||
|
||||
/** The child elements of this document */
|
||||
val Document?.elements : List<Element>
|
||||
get() = this?.getElementsByTagName("*").toElementList()
|
||||
|
||||
/** The child elements of this elements */
|
||||
val Element?.elements : List<Element>
|
||||
get() = this?.getElementsByTagName("*").toElementList()
|
||||
|
||||
|
||||
/** Returns all the child elements given the local element name */
|
||||
inline fun Element?.elements(localName: String?): List<Element> {
|
||||
return this?.getElementsByTagName(localName).toElementList()
|
||||
}
|
||||
|
||||
/** Returns all the elements given the local element name */
|
||||
inline fun Document?.elements(localName: String?): List<Element> {
|
||||
return this?.getElementsByTagName(localName).toElementList()
|
||||
}
|
||||
|
||||
/** Returns all the child elements given the namespace URI and local element name */
|
||||
inline fun Element?.elements(namespaceUri: String?, localName: String?): List<Element> {
|
||||
return this?.getElementsByTagNameNS(namespaceUri, localName).toElementList()
|
||||
}
|
||||
|
||||
/** Returns all the elements given the namespace URI and local element name */
|
||||
inline fun Document?.elements(namespaceUri: String?, localName: String?): List<Element> {
|
||||
return this?.getElementsByTagNameNS(namespaceUri, localName).toElementList()
|
||||
}
|
||||
|
||||
|
||||
var Element.classSet : Set<String>
|
||||
get() {
|
||||
val answer = LinkedHashSet<String>()
|
||||
@@ -156,24 +120,6 @@ fun NodeList?.toXmlString(xmlDeclaration: Boolean = false): String {
|
||||
}
|
||||
}
|
||||
|
||||
inline fun NodeList?.toList(): List<Node> {
|
||||
return if (this == null) {
|
||||
Collections.EMPTY_LIST as List<Node>
|
||||
}
|
||||
else {
|
||||
NodeListAsList(this)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun NodeList?.toElementList(): List<Element> {
|
||||
return if (this == null) {
|
||||
Collections.EMPTY_LIST as List<Element>
|
||||
}
|
||||
else {
|
||||
ElementListAsList(this)
|
||||
}
|
||||
}
|
||||
|
||||
/** Creates a new document with the given document builder*/
|
||||
public fun createDocument(builder: DocumentBuilder): Document {
|
||||
return builder.newDocument().sure()
|
||||
|
||||
@@ -2,6 +2,9 @@ package kotlin.support
|
||||
|
||||
import java.util.NoSuchElementException
|
||||
|
||||
// TODO should not need this - its here for the JS stuff
|
||||
import java.lang.UnsupportedOperationException
|
||||
|
||||
enum class State {
|
||||
Ready
|
||||
NotReady
|
||||
|
||||
@@ -41,6 +41,9 @@
|
||||
<include name="**/*.kt"/>
|
||||
<exclude name="**/*JVM.kt"/>
|
||||
</fileset>
|
||||
<fileset file="${basedir}/../../stdlib/src/kotlin">
|
||||
<include name="Preconditions.kt"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy tofile="${basedir}/target/generated-js-library/kotlin-lib.js"
|
||||
file="${kotlin-js-lib-srcdir}/../../js.translator/testFiles/kotlin_lib.js"/>
|
||||
|
||||
Reference in New Issue
Block a user