From 4d7cf81ed0a80c8963801456889df410787a52d2 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Mon, 6 Mar 2023 17:25:26 +0100 Subject: [PATCH] [Wasm] Stop supporting "_export.js" in test infra, use import/export capability in relevant tests * It works slightly differently in SpiderMonkey. * It was a hack. --- .../codegen/boxWasmJsInterop/functionTypes.kt | 16 +++++++--------- .../codegen/boxWasmJsInterop/jsExport.kt | 13 ++----------- .../kotlin/wasm/test/BasicWasmBoxTest.kt | 13 ++++--------- .../jetbrains/kotlin/wasm/test/tools/WasmVM.kt | 12 +++++------- 4 files changed, 18 insertions(+), 36 deletions(-) diff --git a/compiler/testData/codegen/boxWasmJsInterop/functionTypes.kt b/compiler/testData/codegen/boxWasmJsInterop/functionTypes.kt index 8162aa33f77..abb045dc521 100644 --- a/compiler/testData/codegen/boxWasmJsInterop/functionTypes.kt +++ b/compiler/testData/codegen/boxWasmJsInterop/functionTypes.kt @@ -1,6 +1,5 @@ // Char issues // IGNORE_BACKEND: JS_IR -// WASM_FAILS_IN: SM // MODULE: main // FILE: externals.js @@ -241,16 +240,15 @@ fun box(): String { return "OK" } -// TODO: Rewrite test to use module system -fun hackNonModuleExport() { - js("globalThis.main = wasmExports;") -} +// FILE: entry.mjs -fun main() { - hackNonModuleExport() -} +import main from "./index.mjs" -// FILE: functionTypes__after.js +const boxResult = main.box(); + +if (boxResult != "OK") { + throw `Wrong box result '${boxResult}'; Expected "OK"`; +} const exportedFres = main.exportedF()(1, 20, 300)("<", ">"); if (exportedFres !== "<321>") diff --git a/compiler/testData/codegen/boxWasmJsInterop/jsExport.kt b/compiler/testData/codegen/boxWasmJsInterop/jsExport.kt index e9c0255ab9d..b59eaa1c501 100644 --- a/compiler/testData/codegen/boxWasmJsInterop/jsExport.kt +++ b/compiler/testData/codegen/boxWasmJsInterop/jsExport.kt @@ -1,4 +1,3 @@ -// WASM_FAILS_IN: SM // MODULE: main // FILE: externals.kt @@ -26,17 +25,9 @@ fun anyAsEI(any: Any): EI = any as EI fun box(): String = "OK" -// TODO: Rewrite test to use module system +// FILE: entry.mjs -fun hackNonModuleExport() { - js("globalThis.main = wasmExports;") -} - -fun main() { - hackNonModuleExport() -} - -// FILE: jsExport__after.js +import main from "./index.mjs" const c = main.makeC(300); if (main.getX(c) !== 300) { diff --git a/wasm/wasm.tests/test/org/jetbrains/kotlin/wasm/test/BasicWasmBoxTest.kt b/wasm/wasm.tests/test/org/jetbrains/kotlin/wasm/test/BasicWasmBoxTest.kt index 8d303668550..5f64283d398 100644 --- a/wasm/wasm.tests/test/org/jetbrains/kotlin/wasm/test/BasicWasmBoxTest.kt +++ b/wasm/wasm.tests/test/org/jetbrains/kotlin/wasm/test/BasicWasmBoxTest.kt @@ -68,8 +68,7 @@ abstract class BasicWasmBoxTest( val languageVersionSettings = inputFiles.firstNotNullOfOrNull { it.languageVersionSettings } val kotlinFiles = mutableListOf() - val jsFilesBefore = mutableListOf() - val jsFilesAfter = mutableListOf() + val jsFiles = mutableListOf() val mjsFiles = mutableListOf() var entryMjs: String? = "test.mjs" @@ -80,11 +79,8 @@ abstract class BasicWasmBoxTest( name.endsWith(".kt") -> kotlinFiles += name - name.endsWith("__after.js") -> - jsFilesAfter += name - name.endsWith(".js") -> - jsFilesBefore += name + jsFiles += name name.endsWith(".mjs") -> { mjsFiles += name @@ -98,7 +94,7 @@ abstract class BasicWasmBoxTest( val additionalJsFile = filePath.removeSuffix(".kt") + ".js" if (File(additionalJsFile).exists()) { - jsFilesBefore += additionalJsFile + jsFiles += additionalJsFile } val additionalMjsFile = filePath.removeSuffix(".kt") + ".mjs" if (File(additionalMjsFile).exists()) { @@ -260,8 +256,7 @@ abstract class BasicWasmBoxTest( } vm.run( "./${entryMjs}", - jsFilesBefore.map { File(it).absolutePath }, - jsFilesAfter.map { File(it).absolutePath }, + jsFiles.map { File(it).absolutePath }, workingDirectory = dir ) if (vm.shortName in failsIn) { diff --git a/wasm/wasm.tests/test/org/jetbrains/kotlin/wasm/test/tools/WasmVM.kt b/wasm/wasm.tests/test/org/jetbrains/kotlin/wasm/test/tools/WasmVM.kt index 7b09eee6280..28e2b9635db 100644 --- a/wasm/wasm.tests/test/org/jetbrains/kotlin/wasm/test/tools/WasmVM.kt +++ b/wasm/wasm.tests/test/org/jetbrains/kotlin/wasm/test/tools/WasmVM.kt @@ -17,30 +17,28 @@ internal sealed class WasmVM(val shortName: String) { val name: String = javaClass.simpleName protected val tool = ExternalTool(System.getProperty("javascript.engine.path.$name")) - abstract fun run(entryMjs: String, jsFilesBefore: List, jsFilesAfter: List, workingDirectory: File?) + abstract fun run(entryMjs: String, jsFiles: List, workingDirectory: File?) object V8 : WasmVM("V8") { - override fun run(entryMjs: String, jsFilesBefore: List, jsFilesAfter: List, workingDirectory: File?) { + override fun run(entryMjs: String, jsFiles: List, workingDirectory: File?) { tool.run( "--experimental-wasm-gc", - *jsFilesBefore.toTypedArray(), + *jsFiles.toTypedArray(), "--module", entryMjs, - *jsFilesAfter.toTypedArray(), workingDirectory = workingDirectory ) } } object SpiderMonkey : WasmVM("SM") { - override fun run(entryMjs: String, jsFilesBefore: List, jsFilesAfter: List, workingDirectory: File?) { + override fun run(entryMjs: String, jsFiles: List, workingDirectory: File?) { tool.run( "--wasm-verbose", "--wasm-gc", "--wasm-function-references", - *jsFilesBefore.flatMap { listOf("-f", it) }.toTypedArray(), + *jsFiles.flatMap { listOf("-f", it) }.toTypedArray(), "--module=$entryMjs", - *jsFilesAfter.flatMap { listOf("-f", it) }.toTypedArray(), workingDirectory = workingDirectory ) }