Skip to content

Commit 122b035

Browse files
committed
More documentation for some Scala.js-specific methods.
1 parent 9b98abf commit 122b035

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,10 @@ class JSCodeGen()(implicit ctx: Context) {
19461946
}
19471947

19481948
/** Boxes a value of the given type before `elimErasedValueType`.
1949+
*
1950+
* This should be used when sending values to a JavaScript context, which
1951+
* is erased/boxed at the IR level, although it is not erased at the
1952+
* dotty/JVM level.
19491953
*
19501954
* @param expr Tree to be boxed if needed.
19511955
* @param tpeEnteringElimErasedValueType The type of `expr` as it was
@@ -1969,6 +1973,10 @@ class JSCodeGen()(implicit ctx: Context) {
19691973
}
19701974

19711975
/** Unboxes a value typed as Any to the given type before `elimErasedValueType`.
1976+
*
1977+
* This should be used when receiving values from a JavaScript context,
1978+
* which is erased/boxed at the IR level, although it is not erased at the
1979+
* dotty/JVM level.
19721980
*
19731981
* @param expr Tree to be extracted.
19741982
* @param tpeEnteringElimErasedValueType The type of `expr` as it was

src/dotty/tools/backend/sjs/JSDefinitions.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ final class JSDefinitions()(implicit ctx: Context) {
178178
if (cls.isClass && cls.owner == ScalaJSJSPackageClass) cls.asClass.name
179179
else EmptyTypeName
180180

181+
/** Is the given `cls` a class of the form `scala.scalajs.js.prefixN` where
182+
* `N` is a number.
183+
*
184+
* This is similar to `isVarArityClass` in `Definitions.scala`.
185+
*/
181186
private def isScalaJSVarArityClass(cls: Symbol, prefix: Name): Boolean = {
182187
val name = scalajsClassName(cls)
183188
name.startsWith(prefix) && name.drop(prefix.length).forall(_.isDigit)

src/dotty/tools/backend/sjs/JSInterop.scala

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,38 @@ object JSInterop {
2424
def isScalaJSDefinedJSClass(sym: Symbol)(implicit ctx: Context): Boolean =
2525
isJSType(sym) && !sym.hasAnnotation(jsdefn.JSNativeAnnot)
2626

27-
/** Should this symbol be translated into a JS getter? */
27+
/** Should this symbol be translated into a JS getter?
28+
*
29+
* This is true for any parameterless method, i.e., defined without `()`.
30+
* Unlike `SymDenotations.isGetter`, it applies to user-defined methods as
31+
* much as *accessor* methods created for `val`s and `var`s.
32+
*/
2833
def isJSGetter(sym: Symbol)(implicit ctx: Context): Boolean = {
2934
sym.info.firstParamTypes.isEmpty && ctx.atPhase(ctx.erasurePhase) { implicit ctx =>
3035
sym.info.isParameterless
3136
}
3237
}
3338

34-
/** Should this symbol be translated into a JS setter? */
39+
/** Should this symbol be translated into a JS setter?
40+
*
41+
* This is true for any method whose name ends in `_=`.
42+
* Unlike `SymDenotations.isGetter`, it applies to user-defined methods as
43+
* much as *accessor* methods created for `var`s.
44+
*/
3545
def isJSSetter(sym: Symbol)(implicit ctx: Context): Boolean =
3646
sym.name.isSetterName && sym.is(Method)
3747

38-
/** Should this symbol be translated into a JS bracket access? */
48+
/** Should this symbol be translated into a JS bracket access?
49+
*
50+
* This is true for methods annotated with `@JSBracketAccess`.
51+
*/
3952
def isJSBracketAccess(sym: Symbol)(implicit ctx: Context): Boolean =
4053
sym.hasAnnotation(jsdefn.JSBracketAccessAnnot)
4154

42-
/** Should this symbol be translated into a JS bracket call? */
55+
/** Should this symbol be translated into a JS bracket call?
56+
*
57+
* This is true for methods annotated with `@JSBracketCall`.
58+
*/
4359
def isJSBracketCall(sym: Symbol)(implicit ctx: Context): Boolean =
4460
sym.hasAnnotation(jsdefn.JSBracketCallAnnot)
4561

0 commit comments

Comments
 (0)