Skip to content

Commit 263965a

Browse files
committed
Add workaround for wasm d8 print issue
1 parent a67a507 commit 263965a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

runtime/wasmMain/src/kotlinx/benchmark/D8EngineSupport.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,24 @@ private external fun d8ReadFile(path: String): String
88
@JsFun("() => globalThis.arguments.join(' ')")
99
private external fun d8Arguments(): String
1010

11+
private const val maxStringLength = 65_536 / 4
12+
1113
internal object D8EngineSupport : JsEngineSupport() {
1214
override fun writeFile(path: String, text: String) {
1315
//WORKAROUND: D8 cannot write into files, this format will be parsed on gradle plugin side
1416
if (text.isEmpty()) {
1517
print("<FILE:$path><ENDFILE>")
1618
} else {
1719
print("<FILE:$path>")
18-
print(text)
20+
//TODO("Workaround for kotlin/wasm issue in 1.7.20 and below. This should be removed for kotlin 1.8.0 or above")
21+
var srcStartIndex = 0
22+
var srcEndIndex = srcStartIndex + maxStringLength
23+
while (srcEndIndex < text.length) {
24+
print(text.substring(srcStartIndex, srcEndIndex))
25+
srcStartIndex = srcEndIndex
26+
srcEndIndex += maxStringLength
27+
}
28+
print(text.substring(srcStartIndex))
1929
print("<ENDFILE>")
2030
}
2131
}

0 commit comments

Comments
 (0)