Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

Commit bfc35ac

Browse files
authored
Merge pull request #107 from sjrd/fix-two-small-issues
Fix two small issues.
2 parents 7b1c5d5 + 3e6e35d commit bfc35ac

File tree

7 files changed

+20
-16
lines changed

7 files changed

+20
-16
lines changed

Diff for: build.sbt

-5
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,6 @@ lazy val `scalajs-test-suite` = project
226226

227227
lazy val IgnoredTestNames: Set[String] = {
228228
Set(
229-
// javaLangClassGetNameRenamedThroughSemantics failed: org.junit.ComparisonFailure:
230-
// expected:<[renamed.test.]Class> but was:<[org.scalajs.testsuite.compiler.ReflectionTest$RenamedTest]Class>
231-
"org.scalajs.testsuite.compiler.ReflectionTest",
232-
// wellKnownSymbolIterator/testToString failed: scala.scalajs.js.JavaScriptException: TypeError: Cannot convert a Symbol value to a string
233-
"org.scalajs.testsuite.jsinterop.SymbolTest",
234229
// Cannot call wasmObject.toString() from JavaScript:
235230
// boxValueClassesGivenToJSInteropMethod failed: scala.scalajs.js.JavaScriptException: TypeError: vc.toString is not a function
236231
"org.scalajs.testsuite.compiler.InteroperabilityTest",

Diff for: wasm/src/main/scala/WebAssemblyLinkerBackend.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ final class WebAssemblyLinkerBackend(
6161
): Future[Report] = {
6262

6363
val wasmModule = new WasmModule
64-
val builder = new WasmBuilder()
64+
val builder = new WasmBuilder(coreSpec)
6565
implicit val context: WasmContext = new WasmContext(wasmModule)
6666

6767
val onlyModule = moduleSet.modules match {

Diff for: wasm/src/main/scala/ir2wasm/LoaderContent.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ const scalaJSHelpers = {
121121
emptyString: () => "",
122122
stringLength: (s) => s.length,
123123
stringCharAt: (s, i) => s.charCodeAt(i),
124-
jsValueToString: (x) => "" + x,
124+
jsValueToString: (x) => (x === void 0) ? "undefined" : x.toString(),
125+
jsValueToStringForConcat: (x) => "" + x,
125126
booleanToString: (b) => b ? "true" : "false",
126127
charToString: (c) => String.fromCharCode(c),
127128
intToString: (i) => "" + i,

Diff for: wasm/src/main/scala/ir2wasm/WasmBuilder.scala

+10-4
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ import org.scalajs.ir.{Types => IRTypes}
1313
import org.scalajs.ir.{Names => IRNames}
1414
import org.scalajs.ir.{ClassKind, Position}
1515

16-
import org.scalajs.linker.standard.{LinkedClass, LinkedTopLevelExport}
16+
import org.scalajs.linker.interface.unstable.RuntimeClassNameMapperImpl
17+
import org.scalajs.linker.standard.{CoreSpec, LinkedClass, LinkedTopLevelExport}
1718

1819
import collection.mutable
1920
import java.awt.Window.Type
2021
import _root_.wasm4s.Defaults
2122

2223
import EmbeddedConstants._
2324

24-
class WasmBuilder {
25+
class WasmBuilder(coreSpec: CoreSpec) {
2526
// val module = new WasmModule()
2627

2728
def genPrimitiveTypeDataGlobals()(implicit ctx: WasmContext): Unit = {
@@ -258,8 +259,13 @@ class WasmBuilder {
258259
ctx: WasmContext
259260
): List[WasmInstr] = {
260261
val nameStr = typeRef match {
261-
case typeRef: IRTypes.PrimRef => typeRef.displayName
262-
case IRTypes.ClassRef(className) => className.nameString
262+
case typeRef: IRTypes.PrimRef =>
263+
typeRef.displayName
264+
case IRTypes.ClassRef(className) =>
265+
RuntimeClassNameMapperImpl.map(
266+
coreSpec.semantics.runtimeClassNameMapper,
267+
className.nameString
268+
)
263269
}
264270

265271
val nameDataValueItems = nameStr.toList.map(c => I32_CONST(c.toInt))

Diff for: wasm/src/main/scala/ir2wasm/WasmExpressionBuilder.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ private class WasmExpressionBuilder private (
12391239
} // end block labelNotOurObject
12401240

12411241
// Now we have a value that is not one of our objects; the anyref is still on the stack
1242-
instrs += CALL(WasmFunctionName.jsValueToString)
1242+
instrs += CALL(WasmFunctionName.jsValueToStringForConcat)
12431243
} // end block labelDone
12441244
}
12451245
}
@@ -1264,7 +1264,7 @@ private class WasmExpressionBuilder private (
12641264
case IRTypes.DoubleType =>
12651265
instrs += CALL(WasmFunctionName.doubleToString)
12661266
case IRTypes.NullType | IRTypes.UndefType =>
1267-
instrs += CALL(WasmFunctionName.jsValueToString)
1267+
instrs += CALL(WasmFunctionName.jsValueToStringForConcat)
12681268
case IRTypes.NothingType =>
12691269
() // unreachable
12701270
case IRTypes.NoType =>
@@ -1276,7 +1276,7 @@ private class WasmExpressionBuilder private (
12761276
case IRTypes.ClassType(IRNames.BoxedStringClass) =>
12771277
// Common case for which we want to avoid the hijacked class dispatch
12781278
genTreeAuto(tree)
1279-
instrs += CALL(WasmFunctionName.jsValueToString) // for `null`
1279+
instrs += CALL(WasmFunctionName.jsValueToStringForConcat) // for `null`
12801280

12811281
case IRTypes.ClassType(className) =>
12821282
genWithDispatch(ctx.getClassInfo(className).isAncestorOfHijackedClass)

Diff for: wasm/src/main/scala/wasm4s/Names.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ object Names {
179179
val emptyString = helper("emptyString")
180180
val stringLength = helper("stringLength")
181181
val stringCharAt = helper("stringCharAt")
182-
val jsValueToString = helper("jsValueToString")
182+
val jsValueToString = helper("jsValueToString") // for actual toString() call
183+
val jsValueToStringForConcat = helper("jsValueToStringForConcat")
183184
val booleanToString = helper("booleanToString")
184185
val charToString = helper("charToString")
185186
val intToString = helper("intToString")

Diff for: wasm/src/main/scala/wasm4s/WasmContext.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ class WasmContext(val module: WasmModule) extends TypeDefinableWasmContext {
420420
addHelperImport(WasmFunctionName.emptyString, List(), List(WasmRefType.any))
421421
addHelperImport(WasmFunctionName.stringLength, List(WasmRefType.any), List(WasmInt32))
422422
addHelperImport(WasmFunctionName.stringCharAt, List(WasmRefType.any, WasmInt32), List(WasmInt32))
423-
addHelperImport(WasmFunctionName.jsValueToString, List(anyref), List(WasmRefType.any))
423+
addHelperImport(WasmFunctionName.jsValueToString, List(WasmRefType.any), List(WasmRefType.any))
424+
addHelperImport(WasmFunctionName.jsValueToStringForConcat, List(anyref), List(WasmRefType.any))
424425
addHelperImport(WasmFunctionName.booleanToString, List(WasmInt32), List(WasmRefType.any))
425426
addHelperImport(WasmFunctionName.charToString, List(WasmInt32), List(WasmRefType.any))
426427
addHelperImport(WasmFunctionName.intToString, List(WasmInt32), List(WasmRefType.any))

0 commit comments

Comments
 (0)