Skip to content

Instantly share code, notes, and snippets.

@sjrd
Created July 18, 2017 11:06
Show Gist options
  • Save sjrd/1ceffe2d62146b2f9b954551903296e3 to your computer and use it in GitHub Desktop.
Save sjrd/1ceffe2d62146b2f9b954551903296e3 to your computer and use it in GitHub Desktop.
diff --cc compiler/src/main/scala/org/scalajs/core/compiler/GenJSCode.scala
index 08efc4c,502a57b..0000000
--- a/compiler/src/main/scala/org/scalajs/core/compiler/GenJSCode.scala
+++ b/compiler/src/main/scala/org/scalajs/core/compiler/GenJSCode.scala
@@@ -4302,22 -4265,55 +4291,55 @@@ abstract class GenJSCode extends plugin
}
}
- def genSelectGet(propName: js.Tree): js.Tree =
+ def genSelectGet(propName: js.Tree): js.Tree = {
- if (superIn.exists(isScalaJSDefinedAnonJSClass(_))) {
++ if (superIn.exists(isAnonJSClass(_))) {
+ // #3055
+ genApplyMethod(
+ genLoadModule(RuntimePackageModule),
+ Runtime_jsObjectSuperGet,
- List(receiver, propName))
++ List(ruleOutGlobalScope(receiver), propName))
+ } else {
genSuperReference(propName)
+ }
+ }
- def genSelectSet(propName: js.Tree, value: js.Tree): js.Tree =
+ def genSelectSet(propName: js.Tree, value: js.Tree): js.Tree = {
- if (superIn.exists(isScalaJSDefinedAnonJSClass(_))) {
++ if (superIn.exists(isAnonJSClass(_))) {
+ // #3055
+ genApplyMethod(
+ genLoadModule(RuntimePackageModule),
+ Runtime_jsObjectSuperSet,
- List(receiver, propName, value))
++ List(ruleOutGlobalScope(receiver), propName, value))
+ } else {
js.Assign(genSuperReference(propName), value)
+ }
+ }
def genCall(methodName: js.Tree, args: List[js.Tree]): js.Tree = {
superIn.fold[js.Tree] {
- js.JSBracketMethodApply(
+ genJSBracketMethodApplyOrGlobalRefApply(
receiver, methodName, args)
} { superInSym =>
- if (isScalaJSDefinedAnonJSClass(superInSym)) {
++ if (isAnonJSClass(superInSym)) {
+ // #3055
+ val superClassType =
+ jstpe.ClassType(encodeClassFullName(superInSym.superClass))
+ val superProto = js.JSBracketSelect(
+ js.LoadJSConstructor(superClassType),
+ js.StringLiteral("prototype"))
+ val superMethod =
+ js.JSBracketSelect(superProto, methodName)
+ js.JSBracketMethodApply(
+ superMethod,
+ js.StringLiteral("call"),
- receiver :: args)
++ ruleOutGlobalScope(receiver) :: args)
+ } else {
js.JSSuperBracketCall(
jstpe.ClassType(encodeClassFullName(superInSym)),
- receiver, methodName, args)
+ ruleOutGlobalScope(receiver), methodName, args)
}
}
+ }
if (jsInterop.isJSGetter(sym)) {
assert(noSpread && argc == 0)
diff --cc project/Build.scala
index 0eb2be6,8a09597..0000000
--- a/project/Build.scala
+++ b/project/Build.scala
@@@ -620,40 -619,34 +620,45 @@@ object Build
) ++ (
parallelCollectionsDependencies(scalaVersion.value)
)
- )
).dependsOn(irProject).enableScalastyleInSharedSources
- lazy val toolsJS: Project = Project(
- id = "toolsJS",
- base = file("tools/js"),
- settings = myScalaJSSettings ++ commonToolsSettings ++ Seq(
+ lazy val toolsJS: Project = (project in file("tools/js")).enablePlugins(
+ MyScalaJSPlugin
+ ).settings(
+ commonToolsSettings,
crossVersion := ScalaJSCrossVersion.binary,
+ /* We need RuntimeClassNameMapper.custom() in QuickLinker
+ * TODO Remove this in 1.x.
+ */
+ scalacOptions in Test -= "-Xfatal-warnings",
+
- resourceGenerators in Test += Def.task {
- val base = (resourceManaged in Compile).value
- IO.createDirectory(base)
- val outFile = base / "js-test-definitions.js"
+ scalaJSLinkerConfig in Test ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
+
+ jsExecutionFiles in Test := {
+ val frameworks = (loadedTestFrameworks in testSuite in Test).value
+ val frameworkImplClassNames =
+ frameworks.toList.map(_._1.implClassNames.toList)
+
+ val taskDefs = for (td <- (definedTests in testSuite in Test).value) yield {
+ new sbt.testing.TaskDef(td.name, td.fingerprint,
+ td.explicitlySpecified, td.selectors)
+ }
val testDefinitions = {
- org.scalajs.build.HTMLRunnerTemplateAccess.renderTestDefinitions(
- (loadedTestFrameworks in testSuite in Test).value,
- (definedTests in testSuite in Test).value)
+ org.scalajs.build.HTMLRunnerBuilderAccess.renderTestDefinitions(
+ frameworkImplClassNames, taskDefs.toList)
}
- IO.write(outFile, testDefinitions)
- Seq(outFile)
- }.taskValue,
+ val testDefinitionsFile = {
+ new MemVirtualJSFile("js-test-definitions.js")
+ .withContent(testDefinitions)
+ }
+
+ testDefinitionsFile +: (jsExecutionFiles in Test).value
+ },
+
+ testSuiteJSExecutionFilesSetting,
// Give more memory to Node.js, and deactivate source maps
jsEnv := {
@@@ -1460,18 -1498,31 +1465,32 @@@
val testDir = (sourceDirectory in Test).value
includeIf(testDir / "require-modules",
- scalaJSModuleKind.value != ModuleKind.NoModule)
+ scalaJSLinkerConfig.value.moduleKind != ModuleKind.NoModule)
},
- jsDependencies += ProvidedJS / "ScalaJSDefinedTestNatives.js" % "test",
- skip in packageJSDependencies in Test := false,
+ testSuiteJSExecutionFilesSetting,
- scalaJSSemantics ~= { sems =>
+ scalaJSLinkerConfig ~= { prevConfig =>
- prevConfig.withSemantics(_.withRuntimeClassName(_.fullName match {
+ import Semantics.RuntimeClassNameMapper
+
++ prevConfig.withSemantics { sems =>
+ sems.withRuntimeClassNameMapper(
+ RuntimeClassNameMapper.custom(_.fullName match {
case "org.scalajs.testsuite.compiler.ReflectionTest$RenamedTestClass" =>
"renamed.test.Class"
case fullName =>
fullName
- }))
+ }).andThen(
+ RuntimeClassNameMapper.regexReplace(
+ raw"""^org\.scalajs\.testsuite\.compiler\.ReflectionTest\$$Prefix""".r,
+ "renamed.test.byprefix.")
+ ).andThen(
+ RuntimeClassNameMapper.regexReplace(
+ raw"""^org\.scalajs\.testsuite\.compiler\.ReflectionTest\$$OtherPrefix""".r,
+ "renamed.test.byotherprefix.")
+ )
+ )
++ }
},
javaOptions in Test += "-Dscalajs.scalaVersion=" + scalaVersion.value,
diff --cc tools/shared/src/main/scala/org/scalajs/core/tools/linker/backend/emitter/ClassEmitter.scala
index d9d08b4,111ef24..0000000
--- a/tools/shared/src/main/scala/org/scalajs/core/tools/linker/backend/emitter/ClassEmitter.scala
+++ b/tools/shared/src/main/scala/org/scalajs/core/tools/linker/backend/emitter/ClassEmitter.scala
@@@ -813,11 -805,10 +813,11 @@@ private[emitter] final class ClassEmitt
}
}
+ for (isInstanceFun <- isInstanceFunWithGlobals) yield {
val allParams = List(
- js.ObjectConstr(List(classIdent -> js.IntLiteral(0))),
+ js.ObjectConstr(List(js.Ident(className) -> js.IntLiteral(0))),
js.BooleanLiteral(kind == ClassKind.Interface),
- js.StringLiteral(semantics.runtimeClassName(tree)),
+ js.StringLiteral(semantics.runtimeClassNameMapper(tree)),
ancestorsRecord,
isRawJSTypeParam,
parentData,
diff --cc tools/shared/src/main/scala/org/scalajs/core/tools/sem/Semantics.scala
index 4b92a01,96b4a5d..0000000
--- a/tools/shared/src/main/scala/org/scalajs/core/tools/sem/Semantics.scala
+++ b/tools/shared/src/main/scala/org/scalajs/core/tools/sem/Semantics.scala
@@@ -111,5 -245,23 +226,5 @@@ object Semantics
moduleInit = Unchecked,
strictFloats = false,
productionMode = false,
- runtimeClassName = _.fullName)
+ runtimeClassNameMapper = RuntimeClassNameMapper.keepAll())
-
- def compliantTo(semantics: Traversable[String]): Semantics = {
- import Defaults._
-
- val semsSet = semantics.toSet
-
- def sw[T](name: String, compliant: T, default: T): T =
- if (semsSet.contains(name)) compliant else default
-
- new Semantics(
- asInstanceOfs = sw("asInstanceOfs", Compliant, asInstanceOfs),
- arrayIndexOutOfBounds =
- sw("arrayIndexOutOfBounds", Compliant, arrayIndexOutOfBounds),
- moduleInit = sw("moduleInit", Compliant, moduleInit),
- strictFloats = sw("strictFloats", true, strictFloats),
- productionMode = false,
- runtimeClassNameMapper = RuntimeClassNameMapper.keepAll())
- }
}
diff --git a/compiler/src/main/scala/org/scalajs/core/compiler/GenJSExports.scala b/compiler/src/main/scala/org/scalajs/core/compiler/GenJSExports.scala
index a73037d..f491848 100644
--- a/compiler/src/main/scala/org/scalajs/core/compiler/GenJSExports.scala
+++ b/compiler/src/main/scala/org/scalajs/core/compiler/GenJSExports.scala
@@ -556,7 +556,7 @@ trait GenJSExports extends SubComponent { self: GenJSCode =>
}
val kind =
- if (isScalaJSDefinedJSClass(currentClass)) "method"
+ if (isNonNativeJSClass(currentClass)) "method"
else "exported method"
val name = alts.head.name
@@ -823,7 +823,7 @@ trait GenJSExports extends SubComponent { self: GenJSCode =>
genApplyForSym(minArgc, hasRestParam, sym, static)
def name: String =
- if (isScalaJSDefinedJSClass(sym.owner)) jsNameOf(sym).displayName
+ if (isNonNativeJSClass(sym.owner)) jsNameOf(sym).displayName
else sym.name.toString
def typeInfo: String = sym.tpe.toString
diff --git a/compiler/src/test/scala/org/scalajs/core/compiler/test/NonNativeJSTypeTest.scala b/compiler/src/test/scala/org/scalajs/core/compiler/test/NonNativeJSTypeTest.scala
index cfbbfa0..47d7e25 100644
--- a/compiler/src/test/scala/org/scalajs/core/compiler/test/NonNativeJSTypeTest.scala
+++ b/compiler/src/test/scala/org/scalajs/core/compiler/test/NonNativeJSTypeTest.scala
@@ -115,7 +115,6 @@ class NonNativeJSTypeTest extends DirectTest with TestHelpers {
@Test
def noCollapseOverloadsOnJSName: Unit = {
"""
- @ScalaJSDefined
class A extends js.Object {
@JSName("bar")
def foo(): Int = 42
@@ -124,7 +123,7 @@ class NonNativeJSTypeTest extends DirectTest with TestHelpers {
}
""" hasErrors
"""
- |newSource1.scala:10: error: Cannot disambiguate overloads for method bar with types
+ |newSource1.scala:9: error: Cannot disambiguate overloads for method bar with types
| ()Int
| ()Int
| def bar(): Int = 24
@@ -132,7 +131,6 @@ class NonNativeJSTypeTest extends DirectTest with TestHelpers {
"""
"""
- @ScalaJSDefined
class A extends js.Object {
def bar(): Int = 24
@@ -141,7 +139,7 @@ class NonNativeJSTypeTest extends DirectTest with TestHelpers {
}
""" hasErrors
"""
- |newSource1.scala:10: error: Cannot disambiguate overloads for method bar with types
+ |newSource1.scala:9: error: Cannot disambiguate overloads for method bar with types
| ()Int
| ()Int
| def foo(): Int = 42
@@ -149,19 +147,17 @@ class NonNativeJSTypeTest extends DirectTest with TestHelpers {
"""
"""
- @ScalaJSDefined
class A extends js.Object {
@JSName("bar")
def foo(): Int = 42
}
- @ScalaJSDefined
class B extends A {
def bar(): Int = 24
}
""" hasErrors
"""
- |newSource1.scala:13: error: Cannot disambiguate overloads for method bar with types
+ |newSource1.scala:11: error: Cannot disambiguate overloads for method bar with types
| ()Int
| ()Int
| def bar(): Int = 24
@@ -176,13 +172,12 @@ class NonNativeJSTypeTest extends DirectTest with TestHelpers {
def foo(): Int = js.native
}
- @ScalaJSDefined
class B extends A {
def bar(): Int = 24
}
""" hasErrors
"""
- |newSource1.scala:14: error: Cannot disambiguate overloads for method bar with types
+ |newSource1.scala:13: error: Cannot disambiguate overloads for method bar with types
| ()Int
| ()Int
| def bar(): Int = 24
@@ -199,13 +194,12 @@ class NonNativeJSTypeTest extends DirectTest with TestHelpers {
def bar(x: Int): Int = js.native
}
- @ScalaJSDefined
class Bar extends Foo {
def foo(): Int = 42
}
""" hasErrors
"""
- |newSource1.scala:15: error: Cannot disambiguate overloads for method bar with types
+ |newSource1.scala:14: error: Cannot disambiguate overloads for method bar with types
| (x: Int)Int
| (x: Int)Int
| class Bar extends Foo {
diff --git a/test-suite/js/src/test/scala/org/scalajs/testsuite/compiler/RegressionJSTest.scala b/test-suite/js/src/test/scala/org/scalajs/testsuite/compiler/RegressionJSTest.scala
index f89670a..8555f14 100644
--- a/test-suite/js/src/test/scala/org/scalajs/testsuite/compiler/RegressionJSTest.scala
+++ b/test-suite/js/src/test/scala/org/scalajs/testsuite/compiler/RegressionJSTest.scala
@@ -87,7 +87,6 @@ object RegressionJSTest {
class B extends A1 with A2 {
override def f(): String = "B"
- @ScalaJSDefined
class C extends js.Object {
def t1(): String = B.super[A1].f()
def t2(): String = B.super[A2].f()
diff --git a/test-suite/js/src/test/scala/org/scalajs/testsuite/jsinterop/NonNativeJSTypeTest.scala b/test-suite/js/src/test/scala/org/scalajs/testsuite/jsinterop/NonNativeJSTypeTest.scala
index 1a3133a..e713cf2 100644
--- a/test-suite/js/src/test/scala/org/scalajs/testsuite/jsinterop/NonNativeJSTypeTest.scala
+++ b/test-suite/js/src/test/scala/org/scalajs/testsuite/jsinterop/NonNativeJSTypeTest.scala
@@ -715,7 +715,6 @@ class NonNativeJSTypeTest {
}
@Test def simple_overloaded_methods_anon_js_class_issue_3054(): Unit = {
- @ScalaJSDefined
trait SimpleOverloadedMethodsAnonJSClass extends js.Object {
def foo(): Int
def foo(x: Int): Int
@@ -753,7 +752,6 @@ class NonNativeJSTypeTest {
}
@Test def overloaded_methods_with_varargs(): Unit = {
- @ScalaJSDefined
class OverloadedMethodsWithVarargs extends js.Object {
def foo(x: Int): Int = x * 2
def foo(strs: String*): Int = strs.foldLeft(0)(_ + _.length)
@@ -774,7 +772,6 @@ class NonNativeJSTypeTest {
}
@Test def overloaded_methods_with_varargs_anon_js_class_issue_3054(): Unit = {
- @ScalaJSDefined
trait OverloadedMethodsWithVarargsAnonJSClass extends js.Object {
def foo(x: Int): Int
def foo(strs: String*): Int
@@ -1187,7 +1184,6 @@ class NonNativeJSTypeTest {
}
@Test def super_method_call_in_anon_JS_class_issue_3055(): Unit = {
- @ScalaJSDefined
class Foo extends js.Object {
def bar(msg: String): String = "super: " + msg
}
@@ -1354,7 +1350,6 @@ class NonNativeJSTypeTest {
}
@Test def super_property_get_set_in_anon_JS_class_issue_3055(): Unit = {
- @ScalaJSDefined
class Foo extends js.Object {
var x: Int = 1
var lastSetValue: Int = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment