JS: fix some code in stdlib that attempts to to is check against native interface

This commit is contained in:
Alexey Andreev
2016-09-30 19:29:42 +03:00
parent 2eb54f234c
commit e17321e1f6
+7 -3
View File
@@ -40,9 +40,13 @@ public fun Node.on(name: String, capture: Boolean, handler: (Event) -> Unit): Cl
* Registers an [EventListener] on the named event * Registers an [EventListener] on the named event
*/ */
public fun Node?.on(name: String, capture: Boolean, listener: EventListener): Closeable? { public fun Node?.on(name: String, capture: Boolean, listener: EventListener): Closeable? {
return if (this is EventTarget) { // TODO: instanceof EventTarget is a very bad idea!
addEventListener(name, listener, capture) // TODO: nullable target is a very bad idea!
CloseableEventListener(this, listener, name, capture) // TODO: receiver should be EventTarget
val target = this as? EventTarget
return if (target != null) {
target.addEventListener(name, listener, capture)
CloseableEventListener(target, listener, name, capture)
} else { } else {
null null
} }