aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Doeraene <sjrdoeraene@gmail.com>2016-03-16 12:25:08 +0100
committerSébastien Doeraene <sjrdoeraene@gmail.com>2016-03-16 12:25:08 +0100
commit122b0351e3e5d0fbacf2aab9bbcc7cd57a4f7dc9 (patch)
tree9eff842c2984d01e9195e8748b406dd8d081152f
parent9b98abf49849549eec4b2cf09e029b745abb0557 (diff)
downloaddotty-122b0351e3e5d0fbacf2aab9bbcc7cd57a4f7dc9.tar.gz
dotty-122b0351e3e5d0fbacf2aab9bbcc7cd57a4f7dc9.tar.bz2
dotty-122b0351e3e5d0fbacf2aab9bbcc7cd57a4f7dc9.zip
More documentation for some Scala.js-specific methods.
-rw-r--r--src/dotty/tools/backend/sjs/JSCodeGen.scala8
-rw-r--r--src/dotty/tools/backend/sjs/JSDefinitions.scala5
-rw-r--r--src/dotty/tools/backend/sjs/JSInterop.scala24
3 files changed, 33 insertions, 4 deletions
diff --git a/src/dotty/tools/backend/sjs/JSCodeGen.scala b/src/dotty/tools/backend/sjs/JSCodeGen.scala
index de5c8711d..0aa211bc8 100644
--- a/src/dotty/tools/backend/sjs/JSCodeGen.scala
+++ b/src/dotty/tools/backend/sjs/JSCodeGen.scala
@@ -1947,6 +1947,10 @@ class JSCodeGen()(implicit ctx: Context) {
/** Boxes a value of the given type before `elimErasedValueType`.
*
+ * This should be used when sending values to a JavaScript context, which
+ * is erased/boxed at the IR level, although it is not erased at the
+ * dotty/JVM level.
+ *
* @param expr Tree to be boxed if needed.
* @param tpeEnteringElimErasedValueType The type of `expr` as it was
* entering the `elimErasedValueType` phase.
@@ -1970,6 +1974,10 @@ class JSCodeGen()(implicit ctx: Context) {
/** Unboxes a value typed as Any to the given type before `elimErasedValueType`.
*
+ * This should be used when receiving values from a JavaScript context,
+ * which is erased/boxed at the IR level, although it is not erased at the
+ * dotty/JVM level.
+ *
* @param expr Tree to be extracted.
* @param tpeEnteringElimErasedValueType The type of `expr` as it was
* entering the `elimErasedValueType` phase.
diff --git a/src/dotty/tools/backend/sjs/JSDefinitions.scala b/src/dotty/tools/backend/sjs/JSDefinitions.scala
index f38f89987..bd0b74031 100644
--- a/src/dotty/tools/backend/sjs/JSDefinitions.scala
+++ b/src/dotty/tools/backend/sjs/JSDefinitions.scala
@@ -178,6 +178,11 @@ final class JSDefinitions()(implicit ctx: Context) {
if (cls.isClass && cls.owner == ScalaJSJSPackageClass) cls.asClass.name
else EmptyTypeName
+ /** Is the given `cls` a class of the form `scala.scalajs.js.prefixN` where
+ * `N` is a number.
+ *
+ * This is similar to `isVarArityClass` in `Definitions.scala`.
+ */
private def isScalaJSVarArityClass(cls: Symbol, prefix: Name): Boolean = {
val name = scalajsClassName(cls)
name.startsWith(prefix) && name.drop(prefix.length).forall(_.isDigit)
diff --git a/src/dotty/tools/backend/sjs/JSInterop.scala b/src/dotty/tools/backend/sjs/JSInterop.scala
index cccc1ad64..6d66c3206 100644
--- a/src/dotty/tools/backend/sjs/JSInterop.scala
+++ b/src/dotty/tools/backend/sjs/JSInterop.scala
@@ -24,22 +24,38 @@ object JSInterop {
def isScalaJSDefinedJSClass(sym: Symbol)(implicit ctx: Context): Boolean =
isJSType(sym) && !sym.hasAnnotation(jsdefn.JSNativeAnnot)
- /** Should this symbol be translated into a JS getter? */
+ /** Should this symbol be translated into a JS getter?
+ *
+ * This is true for any parameterless method, i.e., defined without `()`.
+ * Unlike `SymDenotations.isGetter`, it applies to user-defined methods as
+ * much as *accessor* methods created for `val`s and `var`s.
+ */
def isJSGetter(sym: Symbol)(implicit ctx: Context): Boolean = {
sym.info.firstParamTypes.isEmpty && ctx.atPhase(ctx.erasurePhase) { implicit ctx =>
sym.info.isParameterless
}
}
- /** Should this symbol be translated into a JS setter? */
+ /** Should this symbol be translated into a JS setter?
+ *
+ * This is true for any method whose name ends in `_=`.
+ * Unlike `SymDenotations.isGetter`, it applies to user-defined methods as
+ * much as *accessor* methods created for `var`s.
+ */
def isJSSetter(sym: Symbol)(implicit ctx: Context): Boolean =
sym.name.isSetterName && sym.is(Method)
- /** Should this symbol be translated into a JS bracket access? */
+ /** Should this symbol be translated into a JS bracket access?
+ *
+ * This is true for methods annotated with `@JSBracketAccess`.
+ */
def isJSBracketAccess(sym: Symbol)(implicit ctx: Context): Boolean =
sym.hasAnnotation(jsdefn.JSBracketAccessAnnot)
- /** Should this symbol be translated into a JS bracket call? */
+ /** Should this symbol be translated into a JS bracket call?
+ *
+ * This is true for methods annotated with `@JSBracketCall`.
+ */
def isJSBracketCall(sym: Symbol)(implicit ctx: Context): Boolean =
sym.hasAnnotation(jsdefn.JSBracketCallAnnot)