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

Commit 11dcef3

Browse files
authored
Merge pull request #94 from sjrd/getclass-char-long-box
Fix #77: Fix getClass() for the Box classes.
2 parents 782d6ca + ad49ca9 commit 11dcef3

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

Diff for: build.sbt

-3
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,6 @@ lazy val IgnoredTestNames: Set[String] = {
242242
"org.scalajs.testsuite.compiler.ReflectionTest",
243243
"org.scalajs.testsuite.compiler.RuntimeTypeTestsJSTest",
244244
"org.scalajs.testsuite.jsinterop.ModulesTest",
245-
// getClass for Box classes
246-
"org.scalajs.testsuite.javalib.lang.ClassTest",
247-
"org.scalajs.testsuite.javalib.lang.ObjectTest",
248245
// eqEqJLFloat/eqEqJLDouble failed: java.lang.AssertionError: null
249246
"org.scalajs.testsuite.compiler.RegressionTest",
250247
// TypeError: WebAssembly objects are opaque

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

+23-1
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ object HelperFunctions {
10771077
val typeDataLocal = fctx.addLocal("typeData", typeDataType)
10781078
val doubleValueLocal = fctx.addLocal("doubleValue", WasmFloat64)
10791079
val intValueLocal = fctx.addLocal("intValue", WasmInt32)
1080+
val ourObjectLocal = fctx.addLocal("ourObject", WasmRefType(WasmHeapType.ObjectType))
10801081

10811082
def getHijackedClassTypeDataInstr(className: IRNames.ClassName): WasmInstr =
10821083
GLOBAL_GET(WasmGlobalName.forVTable(className))
@@ -1192,7 +1193,28 @@ object HelperFunctions {
11921193
instrs += BR(gotTypeDataLabel)
11931194
}
11941195

1195-
instrs += STRUCT_GET(WasmStructTypeName.forClass(IRNames.ObjectClass), WasmFieldIdx.vtable)
1196+
/* Now we have one of our objects. Normally we only have to get the
1197+
* vtable, but there are two exceptions. If the value is an instance of
1198+
* `jl.CharacterBox` or `jl.LongBox`, we must use the typeData of
1199+
* `jl.Character` or `jl.Long`, respectively.
1200+
*/
1201+
instrs += LOCAL_TEE(ourObjectLocal)
1202+
instrs += REF_TEST(WasmRefType(WasmStructTypeName.forClass(SpecialNames.CharBoxClass)))
1203+
fctx.ifThenElse(typeDataType) {
1204+
instrs += getHijackedClassTypeDataInstr(IRNames.BoxedCharacterClass)
1205+
} {
1206+
instrs += LOCAL_GET(ourObjectLocal)
1207+
instrs += REF_TEST(WasmRefType(WasmStructTypeName.forClass(SpecialNames.LongBoxClass)))
1208+
fctx.ifThenElse(typeDataType) {
1209+
instrs += getHijackedClassTypeDataInstr(IRNames.BoxedLongClass)
1210+
} {
1211+
instrs += LOCAL_GET(ourObjectLocal)
1212+
instrs += STRUCT_GET(
1213+
WasmStructTypeName.forClass(IRNames.ObjectClass),
1214+
WasmFieldIdx.vtable
1215+
)
1216+
}
1217+
}
11961218
}
11971219

11981220
instrs += CALL(WasmFunctionName.getClassOf)

0 commit comments

Comments
 (0)