[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.
This commit is contained in:
Zalim Bashorov
2023-03-06 17:25:26 +01:00
parent bec827b654
commit 4d7cf81ed0
4 changed files with 18 additions and 36 deletions
@@ -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>")
+2 -11
View File
@@ -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) {
@@ -68,8 +68,7 @@ abstract class BasicWasmBoxTest(
val languageVersionSettings = inputFiles.firstNotNullOfOrNull { it.languageVersionSettings }
val kotlinFiles = mutableListOf<String>()
val jsFilesBefore = mutableListOf<String>()
val jsFilesAfter = mutableListOf<String>()
val jsFiles = mutableListOf<String>()
val mjsFiles = mutableListOf<String>()
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) {
@@ -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<String>, jsFilesAfter: List<String>, workingDirectory: File?)
abstract fun run(entryMjs: String, jsFiles: List<String>, workingDirectory: File?)
object V8 : WasmVM("V8") {
override fun run(entryMjs: String, jsFilesBefore: List<String>, jsFilesAfter: List<String>, workingDirectory: File?) {
override fun run(entryMjs: String, jsFiles: List<String>, 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<String>, jsFilesAfter: List<String>, workingDirectory: File?) {
override fun run(entryMjs: String, jsFiles: List<String>, 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
)
}