diff --git a/libraries/stdlib/src/kotlin/browser/Properties.kt b/libraries/stdlib/src/kotlin/browser/Properties.kt index 0554c6d04ed..ba02ef8c997 100644 --- a/libraries/stdlib/src/kotlin/browser/Properties.kt +++ b/libraries/stdlib/src/kotlin/browser/Properties.kt @@ -1,7 +1,7 @@ package kotlin.browser -import org.w3c.dom.Document import js.native +import org.w3c.dom.Document private var _document: Document? = null @@ -9,7 +9,13 @@ private var _document: Document? = null * Provides access to the current active browsers DOM for the currently visible page. */ native public var document: Document - get() = _document!! - set(value) { - _document = value - } \ No newline at end of file + get() { + // Note this code is only executed on the JVM + val answer = _document + return if (answer == null) { + kotlin.dom.createDocument() + } else answer + } + set(value) { + _document = value + }