Add EXACTLY_ONCE contract to functions that call their lambda parameter once
KT-35972
This commit is contained in:
@@ -6,19 +6,25 @@
|
||||
package kotlinx.dom
|
||||
|
||||
import org.w3c.dom.*
|
||||
import kotlin.contracts.*
|
||||
|
||||
/**
|
||||
* Creates a new element with the specified [name].
|
||||
*
|
||||
* The element is initialized with the specified [init] function.
|
||||
*/
|
||||
public fun Document.createElement(name: String, init: Element.() -> Unit): Element = createElement(name).apply(init)
|
||||
public fun Document.createElement(name: String, init: Element.() -> Unit): Element {
|
||||
contract { callsInPlace(init, InvocationKind.EXACTLY_ONCE) }
|
||||
return createElement(name).apply(init)
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a newly created element with the specified [name] to this element.
|
||||
*
|
||||
* The element is initialized with the specified [init] function.
|
||||
*/
|
||||
public fun Element.appendElement(name: String, init: Element.() -> Unit): Element =
|
||||
ownerDocument!!.createElement(name, init).also { appendChild(it) }
|
||||
public fun Element.appendElement(name: String, init: Element.() -> Unit): Element {
|
||||
contract { callsInPlace(init, InvocationKind.EXACTLY_ONCE) }
|
||||
return ownerDocument!!.createElement(name, init).also { appendChild(it) }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user