[Wasm] Migrate usages of @JsFun to js("code")
This commit is contained in:
committed by
Space Team
parent
7a04999e4a
commit
7175b9f31c
@@ -242,8 +242,9 @@ fun box(): String {
|
||||
}
|
||||
|
||||
// TODO: Rewrite test to use module system
|
||||
@JsFun("() => { globalThis.main = wasmExports; }")
|
||||
external fun hackNonModuleExport()
|
||||
fun hackNonModuleExport() {
|
||||
js("globalThis.main = wasmExports;")
|
||||
}
|
||||
|
||||
fun main() {
|
||||
hackNonModuleExport()
|
||||
|
||||
+3
-3
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR, JS
|
||||
// WASM_FAILS_IN: SM
|
||||
// MODULE: main
|
||||
// FILE: externals.kt
|
||||
@@ -29,8 +28,9 @@ fun box(): String = "OK"
|
||||
|
||||
// TODO: Rewrite test to use module system
|
||||
|
||||
@JsFun("() => { globalThis.main = wasmExports; }")
|
||||
external fun hackNonModuleExport()
|
||||
fun hackNonModuleExport() {
|
||||
js("globalThis.main = wasmExports;")
|
||||
}
|
||||
|
||||
fun main() {
|
||||
hackNonModuleExport()
|
||||
|
||||
@@ -11,17 +11,13 @@ inline fun checkNPE(body: () -> Unit) {
|
||||
check(throwed)
|
||||
}
|
||||
|
||||
@JsFun("() => 'abc'")
|
||||
external fun notNullString(): String
|
||||
fun notNullString(): String = js("'abc'")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun notNull2String(): String
|
||||
fun notNull2String(): String = js("null")
|
||||
|
||||
@JsFun("() => 'abc'")
|
||||
external fun nullString(): String?
|
||||
fun nullString(): String? = js("'abc'")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun null2String(): String?
|
||||
fun null2String(): String? = js("null")
|
||||
|
||||
fun testString() {
|
||||
check(notNullString() == "abc")
|
||||
@@ -32,17 +28,13 @@ fun testString() {
|
||||
|
||||
external interface ExternRef
|
||||
|
||||
@JsFun("() => 'abc'")
|
||||
external fun notNullExternRef(): ExternRef
|
||||
fun notNullExternRef(): ExternRef = js("'abc'")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun notNull2ExternRef(): ExternRef
|
||||
fun notNull2ExternRef(): ExternRef = js("null")
|
||||
|
||||
@JsFun("() => 'abc'")
|
||||
external fun nullExternRef(): ExternRef?
|
||||
fun nullExternRef(): ExternRef? = js("'abc'")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun null2ExternRef(): ExternRef?
|
||||
fun null2ExternRef(): ExternRef? = js("null")
|
||||
|
||||
|
||||
fun testExterRef() {
|
||||
@@ -54,17 +46,13 @@ fun testExterRef() {
|
||||
|
||||
class DataRef
|
||||
|
||||
@JsFun("(x) => x")
|
||||
external fun notNullDataRef(x: DataRef): DataRef
|
||||
fun notNullDataRef(x: DataRef): DataRef = js("x")
|
||||
|
||||
@JsFun("(x) => null")
|
||||
external fun notNull2DataRef(x: DataRef): DataRef
|
||||
fun notNull2DataRef(x: DataRef): DataRef = js("null")
|
||||
|
||||
@JsFun("(x) => x")
|
||||
external fun nullDataRef(x: DataRef): DataRef?
|
||||
fun nullDataRef(x: DataRef): DataRef? = js("x")
|
||||
|
||||
@JsFun("(x) => null")
|
||||
external fun null2DataRef(x: DataRef): DataRef?
|
||||
fun null2DataRef(x: DataRef): DataRef? = js("null")
|
||||
|
||||
fun testDataRef() {
|
||||
val dataRef = DataRef()
|
||||
@@ -74,17 +62,13 @@ fun testDataRef() {
|
||||
check (null2DataRef(dataRef) == null)
|
||||
}
|
||||
|
||||
@JsFun("() => 123")
|
||||
external fun notNullInt(): Int
|
||||
fun notNullInt(): Int = js("123")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun notNull2Int(): Int
|
||||
fun notNull2Int(): Int = js("null")
|
||||
|
||||
@JsFun("() => 123")
|
||||
external fun nullInt(): Int?
|
||||
fun nullInt(): Int? = js("123")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun null2Int(): Int?
|
||||
fun null2Int(): Int? = js("null")
|
||||
|
||||
fun testInt() {
|
||||
check(notNullInt() == 123)
|
||||
@@ -93,17 +77,13 @@ fun testInt() {
|
||||
check(null2Int() == null)
|
||||
}
|
||||
|
||||
@JsFun("() => true")
|
||||
external fun notNullBoolean(): Boolean
|
||||
fun notNullBoolean(): Boolean = js("true")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun notNull2Boolean(): Boolean
|
||||
fun notNull2Boolean(): Boolean = js("null")
|
||||
|
||||
@JsFun("() => true")
|
||||
external fun nullBoolean(): Boolean?
|
||||
fun nullBoolean(): Boolean? = js("true")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun null2Boolean(): Boolean?
|
||||
fun null2Boolean(): Boolean? = js("null")
|
||||
|
||||
fun testBoolean() {
|
||||
check(notNullBoolean() == true)
|
||||
@@ -112,17 +92,13 @@ fun testBoolean() {
|
||||
check(null2Boolean() == null)
|
||||
}
|
||||
|
||||
@JsFun("() => 123")
|
||||
external fun notNullShort(): Short
|
||||
fun notNullShort(): Short = js("123")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun notNull2Short(): Short
|
||||
fun notNull2Short(): Short = js("null")
|
||||
|
||||
@JsFun("() => 123")
|
||||
external fun nullShort(): Short?
|
||||
fun nullShort(): Short? = js("123")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun null2Short(): Short?
|
||||
fun null2Short(): Short? = js("null")
|
||||
|
||||
fun testShort() {
|
||||
check(notNullShort() == 123.toShort())
|
||||
@@ -131,17 +107,13 @@ fun testShort() {
|
||||
check(null2Short() == null)
|
||||
}
|
||||
|
||||
@JsFun("() => 123.5")
|
||||
external fun notNullFloat(): Float
|
||||
fun notNullFloat(): Float = js("123.5")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun notNull2Float(): Float
|
||||
fun notNull2Float(): Float = js("null")
|
||||
|
||||
@JsFun("() => 123.5")
|
||||
external fun nullFloat(): Float?
|
||||
fun nullFloat(): Float? = js("123.5")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun null2Float(): Float?
|
||||
fun null2Float(): Float? = js("null")
|
||||
|
||||
fun testFloat() {
|
||||
check(notNullFloat() == 123.5f)
|
||||
@@ -151,17 +123,13 @@ fun testFloat() {
|
||||
}
|
||||
|
||||
|
||||
@JsFun("() => 123.5")
|
||||
external fun notNullNumber(): Number
|
||||
fun notNullNumber(): Number = js("123.5")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun notNull2Number(): Number
|
||||
fun notNull2Number(): Number = js("null")
|
||||
|
||||
@JsFun("() => 123.5")
|
||||
external fun nullNumber(): Number?
|
||||
fun nullNumber(): Number? = js("123.5")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun null2Number(): Number?
|
||||
fun null2Number(): Number? = js("null")
|
||||
|
||||
fun testNumber() {
|
||||
check(notNullNumber() == 123.5)
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
// IGNORE_BACKEND: JS_IR, JS
|
||||
// WASM_FAILS_IN: SM
|
||||
|
||||
@JsFun("(x) => { if (x !== 'abc') throw 'error' }")
|
||||
external fun notNullString(x: String)
|
||||
fun notNullString(x: String) {
|
||||
js("if (x !== 'abc') throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== 'abc') throw 'error' }")
|
||||
external fun nullString(x: String?)
|
||||
fun nullString(x: String?) {
|
||||
js("if (x !== 'abc') throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== null) throw 'error' }")
|
||||
external fun null2String(x: String?)
|
||||
fun null2String(x: String?) {
|
||||
js("if (x !== null) throw 'error'")
|
||||
}
|
||||
|
||||
fun testString() {
|
||||
notNullString("abc")
|
||||
@@ -18,17 +20,20 @@ fun testString() {
|
||||
|
||||
external interface ExternRef
|
||||
|
||||
@JsFun("(x) => { if (x !== 'abc') throw 'error' }")
|
||||
external fun notNullExternRef(x: ExternRef)
|
||||
fun notNullExternRef(x: ExternRef) {
|
||||
js("if (x !== 'abc') throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== 'abc') throw 'error' }")
|
||||
external fun nullExternRef(x: ExternRef?)
|
||||
fun nullExternRef(x: ExternRef?) {
|
||||
js("if (x !== 'abc') throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== null) throw 'error' }")
|
||||
external fun null2ExternRef(x: ExternRef?)
|
||||
fun null2ExternRef(x: ExternRef?) {
|
||||
js("if (x !== null) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("() => 'abc'")
|
||||
external fun getExternRef(): ExternRef
|
||||
fun getExternRef(): ExternRef =
|
||||
js("'abc'")
|
||||
|
||||
fun testExterRef() {
|
||||
val externRef = getExternRef()
|
||||
@@ -39,14 +44,17 @@ fun testExterRef() {
|
||||
|
||||
class DataRef
|
||||
|
||||
@JsFun("(x, y) => { if (x === null) throw 'error' }")
|
||||
external fun notNullDataRef(x: DataRef)
|
||||
fun notNullDataRef(x: DataRef) {
|
||||
js("if (x === null) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x, y) => { if (x === null) throw 'error' }")
|
||||
external fun nullDataRef(x: DataRef?)
|
||||
fun nullDataRef(x: DataRef?) {
|
||||
js("if (x === null) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x, y) => { if (x !== null) throw 'error' }")
|
||||
external fun null2DataRef(x: DataRef?)
|
||||
fun null2DataRef(x: DataRef?) {
|
||||
js("if (x !== null) throw 'error'")
|
||||
}
|
||||
|
||||
fun testDataRef() {
|
||||
val dataRef = DataRef()
|
||||
@@ -55,14 +63,17 @@ fun testDataRef() {
|
||||
null2DataRef(null)
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== 123) throw 'error' }")
|
||||
external fun notNullInt(x: Int)
|
||||
fun notNullInt(x: Int) {
|
||||
js("if (x !== 123) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== 123) throw 'error' }")
|
||||
external fun nullInt(x: Int?)
|
||||
fun nullInt(x: Int?) {
|
||||
js("if (x !== 123) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== null) throw 'error' }")
|
||||
external fun null2Int(x: Int?)
|
||||
fun null2Int(x: Int?) {
|
||||
js("if (x !== null) throw 'error'")
|
||||
}
|
||||
|
||||
fun testInt() {
|
||||
notNullInt(123)
|
||||
@@ -70,14 +81,17 @@ fun testInt() {
|
||||
null2Int(null)
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== true) throw 'error' }")
|
||||
external fun notNullBoolean(x: Boolean)
|
||||
fun notNullBoolean(x: Boolean) {
|
||||
js("if (x !== true) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== true) throw 'error' }")
|
||||
external fun nullBoolean(x: Boolean?)
|
||||
fun nullBoolean(x: Boolean?) {
|
||||
js("if (x !== true) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== null) throw 'error' }")
|
||||
external fun null2Boolean(x: Boolean?)
|
||||
fun null2Boolean(x: Boolean?) {
|
||||
js("if (x !== null) throw 'error'")
|
||||
}
|
||||
|
||||
fun testBoolean() {
|
||||
notNullBoolean(true)
|
||||
@@ -85,14 +99,17 @@ fun testBoolean() {
|
||||
null2Boolean(null)
|
||||
}
|
||||
|
||||
@JsFun("(x) => { x == 123 }")
|
||||
external fun notNullShort(x: Short)
|
||||
fun notNullShort(x: Short) {
|
||||
js("x == 123")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== 123) throw 'error' }")
|
||||
external fun nullShort(x: Short?)
|
||||
fun nullShort(x: Short?) {
|
||||
js("if (x !== 123) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== null) throw 'error' }")
|
||||
external fun null2Short(x: Short?)
|
||||
fun null2Short(x: Short?) {
|
||||
js("if (x !== null) throw 'error'")
|
||||
}
|
||||
|
||||
fun testShort() {
|
||||
notNullShort(123.toShort())
|
||||
@@ -100,14 +117,17 @@ fun testShort() {
|
||||
null2Short(null)
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== 123.5) throw 'error' }")
|
||||
external fun notNullFloat(x: Float)
|
||||
fun notNullFloat(x: Float) {
|
||||
js("if (x !== 123.5) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== 123.5) throw 'error' }")
|
||||
external fun nullFloat(x: Float?)
|
||||
fun nullFloat(x: Float?) {
|
||||
js("if (x !== 123.5) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== null) throw 'error' }")
|
||||
external fun null2Float(x: Float?)
|
||||
fun null2Float(x: Float?) {
|
||||
js("if (x !== null) throw 'error'")
|
||||
}
|
||||
|
||||
fun testFloat() {
|
||||
notNullFloat(123.5f)
|
||||
@@ -115,23 +135,29 @@ fun testFloat() {
|
||||
null2Float(null)
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== 123.5) throw 'error' }")
|
||||
external fun notNullNumber(x: Number)
|
||||
fun notNullNumber(x: Number) {
|
||||
js("if (x !== 123.5) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== 123.5) throw 'error' }")
|
||||
external fun nullNumber(x: Number?)
|
||||
fun nullNumber(x: Number?) {
|
||||
js("if (x !== 123.5) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== null) throw 'error' }")
|
||||
external fun null2Number(x: Number?)
|
||||
fun null2Number(x: Number?) {
|
||||
js("if (x !== null) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== 123) throw 'error' }")
|
||||
external fun byte2Number(x: Number)
|
||||
fun byte2Number(x: Number) {
|
||||
js("if (x !== 123) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== 123) throw 'error' }")
|
||||
external fun notNullByte2Number(x: Number?)
|
||||
fun notNullByte2Number(x: Number?) {
|
||||
js("if (x !== 123) throw 'error'")
|
||||
}
|
||||
|
||||
@JsFun("(x) => { if (x !== null) throw 'error' }")
|
||||
external fun nullByte2Number(x: Number?)
|
||||
fun nullByte2Number(x: Number?) {
|
||||
js("if (x !== null) throw 'error'")
|
||||
}
|
||||
|
||||
fun testNumber() {
|
||||
notNullNumber(123.5)
|
||||
|
||||
@@ -19,23 +19,23 @@ fun assertFalse(x: Boolean) {
|
||||
|
||||
external interface EI
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun getNull(): EI?
|
||||
fun getNull(): EI? =
|
||||
js("null")
|
||||
|
||||
@JsFun("() => undefined")
|
||||
external fun getUndefined(): EI?
|
||||
fun getUndefined(): EI? =
|
||||
js("undefined")
|
||||
|
||||
@JsFun("(ref) => ref === null")
|
||||
external fun isJsNull(ref: EI?): Boolean
|
||||
fun isJsNull(ref: EI?): Boolean =
|
||||
js("ref === null")
|
||||
|
||||
@JsFun("(ref) => ref === undefined")
|
||||
external fun isJsUndefined(ref: EI?): Boolean
|
||||
fun isJsUndefined(ref: EI?): Boolean =
|
||||
js("ref === undefined")
|
||||
|
||||
@JsFun("() => null")
|
||||
external fun getJsNullAsNonNullable(): EI
|
||||
fun getJsNullAsNonNullable(): EI =
|
||||
js("null")
|
||||
|
||||
@JsFun("() => undefined")
|
||||
external fun getJsUndefinedAsNonNullable(): EI
|
||||
fun getJsUndefinedAsNonNullable(): EI =
|
||||
js("undefined")
|
||||
|
||||
inline fun checkNPE(body: () -> Unit) {
|
||||
var throwed = false
|
||||
|
||||
Reference in New Issue
Block a user