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

Fix two small issues. #107

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,6 @@ lazy val `scalajs-test-suite` = project

lazy val IgnoredTestNames: Set[String] = {
Set(
// javaLangClassGetNameRenamedThroughSemantics failed: org.junit.ComparisonFailure:
// expected:<[renamed.test.]Class> but was:<[org.scalajs.testsuite.compiler.ReflectionTest$RenamedTest]Class>
"org.scalajs.testsuite.compiler.ReflectionTest",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// wellKnownSymbolIterator/testToString failed: scala.scalajs.js.JavaScriptException: TypeError: Cannot convert a Symbol value to a string
"org.scalajs.testsuite.jsinterop.SymbolTest",
// Cannot call wasmObject.toString() from JavaScript:
// boxValueClassesGivenToJSInteropMethod failed: scala.scalajs.js.JavaScriptException: TypeError: vc.toString is not a function
"org.scalajs.testsuite.compiler.InteroperabilityTest",
Expand Down
2 changes: 1 addition & 1 deletion wasm/src/main/scala/WebAssemblyLinkerBackend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class WebAssemblyLinkerBackend(
): Future[Report] = {

val wasmModule = new WasmModule
val builder = new WasmBuilder()
val builder = new WasmBuilder(coreSpec)
implicit val context: WasmContext = new WasmContext(wasmModule)

val onlyModule = moduleSet.modules match {
Expand Down
3 changes: 2 additions & 1 deletion wasm/src/main/scala/ir2wasm/LoaderContent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ const scalaJSHelpers = {
emptyString: () => "",
stringLength: (s) => s.length,
stringCharAt: (s, i) => s.charCodeAt(i),
jsValueToString: (x) => "" + x,
jsValueToString: (x) => (x === void 0) ? "undefined" : x.toString(),
jsValueToStringForConcat: (x) => "" + x,
booleanToString: (b) => b ? "true" : "false",
charToString: (c) => String.fromCharCode(c),
intToString: (i) => "" + i,
Expand Down
14 changes: 10 additions & 4 deletions wasm/src/main/scala/ir2wasm/WasmBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import org.scalajs.ir.{Types => IRTypes}
import org.scalajs.ir.{Names => IRNames}
import org.scalajs.ir.{ClassKind, Position}

import org.scalajs.linker.standard.{LinkedClass, LinkedTopLevelExport}
import org.scalajs.linker.interface.unstable.RuntimeClassNameMapperImpl
import org.scalajs.linker.standard.{CoreSpec, LinkedClass, LinkedTopLevelExport}

import collection.mutable
import java.awt.Window.Type
import _root_.wasm4s.Defaults

import EmbeddedConstants._

class WasmBuilder {
class WasmBuilder(coreSpec: CoreSpec) {
// val module = new WasmModule()

def genPrimitiveTypeDataGlobals()(implicit ctx: WasmContext): Unit = {
Expand Down Expand Up @@ -258,8 +259,13 @@ class WasmBuilder {
ctx: WasmContext
): List[WasmInstr] = {
val nameStr = typeRef match {
case typeRef: IRTypes.PrimRef => typeRef.displayName
case IRTypes.ClassRef(className) => className.nameString
case typeRef: IRTypes.PrimRef =>
typeRef.displayName
case IRTypes.ClassRef(className) =>
RuntimeClassNameMapperImpl.map(
coreSpec.semantics.runtimeClassNameMapper,
className.nameString
)
}

val nameDataValueItems = nameStr.toList.map(c => I32_CONST(c.toInt))
Expand Down
6 changes: 3 additions & 3 deletions wasm/src/main/scala/ir2wasm/WasmExpressionBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ private class WasmExpressionBuilder private (
} // end block labelNotOurObject

// Now we have a value that is not one of our objects; the anyref is still on the stack
instrs += CALL(WasmFunctionName.jsValueToString)
instrs += CALL(WasmFunctionName.jsValueToStringForConcat)
} // end block labelDone
}
}
Expand All @@ -1264,7 +1264,7 @@ private class WasmExpressionBuilder private (
case IRTypes.DoubleType =>
instrs += CALL(WasmFunctionName.doubleToString)
case IRTypes.NullType | IRTypes.UndefType =>
instrs += CALL(WasmFunctionName.jsValueToString)
instrs += CALL(WasmFunctionName.jsValueToStringForConcat)
case IRTypes.NothingType =>
() // unreachable
case IRTypes.NoType =>
Expand All @@ -1276,7 +1276,7 @@ private class WasmExpressionBuilder private (
case IRTypes.ClassType(IRNames.BoxedStringClass) =>
// Common case for which we want to avoid the hijacked class dispatch
genTreeAuto(tree)
instrs += CALL(WasmFunctionName.jsValueToString) // for `null`
instrs += CALL(WasmFunctionName.jsValueToStringForConcat) // for `null`

case IRTypes.ClassType(className) =>
genWithDispatch(ctx.getClassInfo(className).isAncestorOfHijackedClass)
Expand Down
3 changes: 2 additions & 1 deletion wasm/src/main/scala/wasm4s/Names.scala
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ object Names {
val emptyString = helper("emptyString")
val stringLength = helper("stringLength")
val stringCharAt = helper("stringCharAt")
val jsValueToString = helper("jsValueToString")
val jsValueToString = helper("jsValueToString") // for actual toString() call
val jsValueToStringForConcat = helper("jsValueToStringForConcat")
val booleanToString = helper("booleanToString")
val charToString = helper("charToString")
val intToString = helper("intToString")
Expand Down
3 changes: 2 additions & 1 deletion wasm/src/main/scala/wasm4s/WasmContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ class WasmContext(val module: WasmModule) extends TypeDefinableWasmContext {
addHelperImport(WasmFunctionName.emptyString, List(), List(WasmRefType.any))
addHelperImport(WasmFunctionName.stringLength, List(WasmRefType.any), List(WasmInt32))
addHelperImport(WasmFunctionName.stringCharAt, List(WasmRefType.any, WasmInt32), List(WasmInt32))
addHelperImport(WasmFunctionName.jsValueToString, List(anyref), List(WasmRefType.any))
addHelperImport(WasmFunctionName.jsValueToString, List(WasmRefType.any), List(WasmRefType.any))
addHelperImport(WasmFunctionName.jsValueToStringForConcat, List(anyref), List(WasmRefType.any))
addHelperImport(WasmFunctionName.booleanToString, List(WasmInt32), List(WasmRefType.any))
addHelperImport(WasmFunctionName.charToString, List(WasmInt32), List(WasmRefType.any))
addHelperImport(WasmFunctionName.intToString, List(WasmInt32), List(WasmRefType.any))
Expand Down