aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/backend/sjs
diff options
context:
space:
mode:
authorSébastien Doeraene <sjrdoeraene@gmail.com>2016-03-23 12:19:14 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2016-04-18 14:44:23 +0200
commit88baa04f2bc6b89d3e65226973d7b72fdf715095 (patch)
tree5155594073ca194ec33140f47de6a4671f6a39c6 /src/dotty/tools/backend/sjs
parent8c9a3f7ce5fa7548f9611dc2a14900a5bd42c105 (diff)
downloaddotty-88baa04f2bc6b89d3e65226973d7b72fdf715095.tar.gz
dotty-88baa04f2bc6b89d3e65226973d7b72fdf715095.tar.bz2
dotty-88baa04f2bc6b89d3e65226973d7b72fdf715095.zip
Implement loading static fields in the Scala.js back-end.
Diffstat (limited to 'src/dotty/tools/backend/sjs')
-rw-r--r--src/dotty/tools/backend/sjs/JSCodeGen.scala24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/dotty/tools/backend/sjs/JSCodeGen.scala b/src/dotty/tools/backend/sjs/JSCodeGen.scala
index ec75a1c4d..70c5af1e7 100644
--- a/src/dotty/tools/backend/sjs/JSCodeGen.scala
+++ b/src/dotty/tools/backend/sjs/JSCodeGen.scala
@@ -718,9 +718,9 @@ class JSCodeGen()(implicit ctx: Context) {
if (sym.is(Module)) {
assert(!sym.is(Package), "Cannot use package as value: " + tree)
genLoadModule(sym)
- } else /*if (sym.isStaticMember) {
- genStaticMember(sym)
- } else if (paramAccessorLocals contains sym) {
+ } else if (sym.is(JavaStatic)) {
+ genLoadStaticField(sym)
+ } else /*if (paramAccessorLocals contains sym) {
paramAccessorLocals(sym).ref
} else if (isScalaJSDefinedJSClass(sym.owner)) {
val genQual = genExpr(qualifier)
@@ -2328,6 +2328,24 @@ class JSCodeGen()(implicit ctx: Context) {
}
}
+ /** Gen JS code for loading a Java static field.
+ */
+ private def genLoadStaticField(sym: Symbol)(implicit pos: Position): js.Tree = {
+ /* Actually, there is no static member in Scala.js. If we come here, that
+ * is because we found the symbol in a Java-emitted .class in the
+ * classpath. But the corresponding implementation in Scala.js will
+ * actually be a val in the companion module.
+ */
+
+ if (sym == defn.BoxedUnit_UNIT) {
+ js.Undefined()
+ } else {
+ val instance = genLoadModule(sym.owner)
+ val method = encodeStaticMemberSym(sym)
+ js.Apply(instance, method, Nil)(toIRType(sym.info))
+ }
+ }
+
/** Gen JS code for loading a module.
*
* Can be given either the module symbol, or its module class symbol.