Skip to content

Commit

Permalink
Merge pull request #7112 from sjrd/enable-more-sjs-tests
Browse files Browse the repository at this point in the history
Enable more Scala.js tests, fix two issues
  • Loading branch information
sjrd committed Aug 28, 2019
2 parents 2bbfd17 + fd81d5c commit 524c978
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
13 changes: 13 additions & 0 deletions compiler/src/dotty/tools/backend/sjs/JSDefinitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ final class JSDefinitions()(implicit ctx: Context) {
@threadUnsafe lazy val Reflect_registerInstantiatableClassR = ReflectModule.requiredMethodRef("registerInstantiatableClass")
def Reflect_registerInstantiatableClass(implicit ctx: Context) = Reflect_registerInstantiatableClassR.symbol

private[this] var allRefClassesCache: Set[Symbol] = _
def allRefClasses(implicit ctx: Context): Set[Symbol] = {
if (allRefClassesCache == null) {
val baseNames = List("Object", "Boolean", "Character", "Byte", "Short",
"Int", "Long", "Float", "Double")
val fullNames = baseNames.flatMap { base =>
List(s"scala.runtime.${base}Ref", s"scala.runtime.Volatile${base}Ref")
}
allRefClassesCache = fullNames.map(name => ctx.requiredClass(name)).toSet
}
allRefClassesCache
}

/** If `cls` is a class in the scala package, its name, otherwise EmptyTypeName */
private def scalajsClassName(cls: Symbol)(implicit ctx: Context): TypeName =
if (cls.isClass && cls.owner == ScalaJSJSPackageClass) cls.asClass.name
Expand Down
20 changes: 11 additions & 9 deletions compiler/src/dotty/tools/backend/sjs/JSEncoding.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package dotty.tools.backend.sjs

import scala.annotation.tailrec

import scala.collection.mutable

import dotty.tools.FatalError

import dotty.tools.dotc.core._
import Decorators._
import Periods._
import SymDenotations._
import Contexts._
import Flags._
import Types._
import Symbols._
import Denotations._
Expand Down Expand Up @@ -103,13 +107,6 @@ object JSEncoding {
js.Ident(localNames.localSymbolName(sym), Some(sym.unexpandedName.decoded))
}

private def allRefClasses(implicit ctx: Context): Set[Symbol] = {
//TODO
/*(Set(ObjectRefClass, VolatileObjectRefClass) ++
refClass.values ++ volatileRefClass.values)*/
Set()
}

def encodeFieldSym(sym: Symbol)(
implicit ctx: Context, pos: ir.Position): js.Ident = {
require(sym.owner.isClass && sym.isTerm && !sym.is(Flags.Method) && !sym.is(Flags.Module),
Expand All @@ -120,14 +117,19 @@ object JSEncoding {
if (name0.charAt(name0.length()-1) != ' ') name0
else name0.substring(0, name0.length()-1)

@tailrec
def superClassCount(sym: Symbol, acc: Int): Int =
if (sym == defn.ObjectClass) acc
else superClassCount(sym.asClass.superClass, acc + 1)

/* We have to special-case fields of Ref types (IntRef, ObjectRef, etc.)
* because they are emitted as private by our .scala source files, but
* they are considered public at use site since their symbols come from
* Java-emitted .class files.
*/
val idSuffix =
if (sym.is(Flags.Private) || allRefClasses.contains(sym.owner))
sym.owner.asClass.baseClasses.size.toString
if (sym.is(Flags.Private) || jsdefn.allRefClasses.contains(sym.owner))
superClassCount(sym.owner, 0).toString
else
"f"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class LinkScala2Impls extends MiniPhase with IdentityDenotTransformer { thisPhas
def currentClass = ctx.owner.enclosingClass.asClass
app match {
case Apply(sel @ Select(Super(_, _), _), args)
if sel.symbol.owner.is(Scala2x) && currentClass.mixins.contains(sel.symbol.owner) =>
if sel.symbol.owner.is(Scala2x) && currentClass.mixins.contains(sel.symbol.owner) && !ctx.settings.scalajs.value =>
val impl = implMethod(sel.symbol)
if (impl.exists) Apply(ref(impl), This(currentClass) :: args).withSpan(app.span)
else app // could have been an abstract method in a trait linked to from a super constructor
Expand Down
1 change: 1 addition & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ object Build {
val dir = fetchScalaJSSource.value / "test-suite"
(
(dir / "shared/src/test/scala/org/scalajs/testsuite/compiler" ** "IntTest.scala").get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/javalib/lang" ** (("IntegerTest.scala": FileFilter) || "ObjectTest.scala")).get
++ (dir / "shared/src/test/require-jdk8/org/scalajs/testsuite/javalib/util" ** "Base64Test.scala").get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/utils" ** "*.scala").get
)
Expand Down

0 comments on commit 524c978

Please sign in to comment.