Skip to content

Commit 9584666

Browse files
committed
Fix #9785: Scala.js: Handle the typeof JSGlobalRef(_) corner case.
This is basically a forward port of the changes in the upstream commit scala-js/scala-js@b2634ea
1 parent 9b5c952 commit 9584666

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2932,7 +2932,11 @@ class JSCodeGen()(using genCtx: Context) {
29322932
case TYPEOF =>
29332933
// js.typeOf(arg)
29342934
val arg = genArgs1
2935-
genAsInstanceOf(js.JSUnaryOp(js.JSUnaryOp.typeof, arg), defn.StringType)
2935+
val typeofExpr = arg match {
2936+
case arg: js.JSGlobalRef => js.JSTypeOfGlobalRef(arg)
2937+
case _ => js.JSUnaryOp(js.JSUnaryOp.typeof, arg)
2938+
}
2939+
js.AsInstanceOf(typeofExpr, jstpe.ClassType(jsNames.BoxedStringClass))
29362940

29372941
case STRICT_EQ =>
29382942
// js.special.strictEquals(arg1, arg2)

project/Build.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,12 @@ object Build {
10091009
scalaJSLinkerConfig ~= { _.withSemantics(build.TestSuiteLinkerOptions.semantics _) },
10101010
scalaJSModuleInitializers in Test ++= build.TestSuiteLinkerOptions.moduleInitializers,
10111011

1012+
jsEnvInput in Test := {
1013+
val resourceDir = fetchScalaJSSource.value / "test-suite/js/src/test/resources"
1014+
val f = (resourceDir / "NonNativeJSTypeTestNatives.js").toPath
1015+
org.scalajs.jsenv.Input.Script(f) +: (jsEnvInput in Test).value
1016+
},
1017+
10121018
managedSources in Compile ++= {
10131019
val dir = fetchScalaJSSource.value / "test-suite/js/src/main/scala"
10141020
val filter = (
@@ -1049,7 +1055,6 @@ object Build {
10491055
-- "ExportsTest.scala" // JS exports
10501056
-- "IterableTest.scala" // non-native JS classes
10511057
-- "JSExportStaticTest.scala" // JS exports
1052-
-- "JSNativeInPackage.scala" // #9785 tests fail due to js.typeOf(globalVar) being incorrect
10531058
-- "JSOptionalTest.scala" // non-native JS classes
10541059
-- "JSSymbolTest.scala" // non-native JS classes
10551060
-- "MiscInteropTest.scala" // non-native JS classes

0 commit comments

Comments
 (0)