is metaElements really a list? or is it a JavaScript Array (just a wild guess)
n
napperley
09/12/2018, 9:37 AM
It's a Kotlin List of org.w3c.dom.Element.
r
robstoll
09/12/2018, 9:48 AM
Well then, I would debug and see why it fails
n
napperley
09/13/2018, 3:04 AM
Did some some debugging and wasn't able to find out why the issue occurs. Would be very helpful to have someone look and see if they spot anything I haven't spotted (https://gitlab.com/webscene/webscene-core/tree/testing). All that a person needs to do is clone the project and run the tests from the project directory (./gradlew jstest). There is a single test that fails called testFetchExistingPageId.
napperley
09/13/2018, 3:12 AM
Would have thought the casting would fail after the asList function (part of Kotlin JS standard library) call but the issue doesn't occur there:
Copy code
internal fun Document.findAllElementsByTagName(tagName: String): List<Element> =
document.getElementsByTagName(tagName).asList()
napperley
09/13/2018, 3:33 AM
The asList function doesn't guarantee safe casting:
Copy code
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).unsafeCast<T>()
else -> throw IndexOutOfBoundsException("index $index is not in range [0..$lastIndex]")
}
}