abstract class ExplicitLocalJS[G <: Global with Singleton] extends PluginComponent with Transform with TypingTransformers with CompatComponent
Makes the references to local JS classes explicit and desugars calls to
js.constructorOf
.
It also makes explicit all references to inner JS classes, using the
pointers created by ExplicitInnerJS
, and otherwise makes sure the
back-end will receive all the information it needs to translate inner- and
local JS classes and objects.
Note that in this comment, by "class" we mean *only* class
es. trait
s
and object
s are not implied.
Similarly to how ExplicitInnerJS
creates explicit fields in the enclosing
templates of inner JS classes to hold the JS class values, this phase
creates local vals for local JS classes in the enclosing statement list.
For every local JS class of the form:
def outer() = { class Local extends ParentJSClass }
this phase creates a local val Local$jslass
in the body of outer()
to
hold the JS class value for Local
. The rhs of that val is a call to a
magic method, used to retain information that the back-end will need:
- A reified reference to
class Local
, in the form of aclassOf
- An explicit reference to the super JS class value, i.e., the desugaring
of
js.constructorOf[ParentJSClass]
- An array of fake
new
expressions for all overloaded constructors.
The latter will be augmented by lambdalift
with the appropriate actual
parameters for the captures of Local
, which will be needed by the
back-end. In code, this looks like:
def outer() = { class Local extends ParentJSClass val Local$jsclass: AnyRef = createLocalJSClass( classOf[Local], js.constructorOf[ParentJSClass], Array[AnyRef](new Local(), ...)) }
Since we need to insert fake new Inner()
s, this scheme does not work for
abstract local classes. We therefore reject them as implementation
restriction.
If the body of Local
references itself, then the val Local$jsclass
is
instead declared as a var
to work around the cyclic dependency:
def outer() = { var Local$jsclass: AnyRef = null class Local extends ParentJSClass { ... } Local$jsclass = createLocalJSClass(...) }
In addition to the above, ExplicitLocalJS
transforms all *call sites* of
local JS classes *and* inner JS classes, so that they refer to the
synthesized local vals and fields.
The primary transformation is the desugaring of js.constructorOf[C]
,
which depends on the nature of C
:
- If
C
is a statically accessible class, desugar toruntime.constructorOf(classOf[C])
so that the reified symbol survives erasure and reaches the back-end. - If
C
is an inner JS class, it must be of the formpath.D
for some pair (path
,D
), and we desugar it topath.D$jsclass
, using the field created byExplicitInnerJS
(it is an error ifC
is of the formEnclosing#D
). - If
C
is a local JS class, desugar toC$jsclass
, using the local val created by this phase.
The other transformations build on top of the desugaring of
js.constructorOf[C]
, and apply only to inner JS classes and local JS
classes (not for statically accessible classes):
x.isInstanceOf[C]
desugars intojs.special.instanceof(x, js.constructorOf[C])
.new C(...args)
desugars intowithContextualJSClassValue(js.constructorOf[C], new C(...args))
, so that the back-end receives a reified reference to the JS class value.- In the same spirit, for
D extends C
,D.super.m(...args)
desugars intowithContextualJSClassValue(js.constructorOf[C], D.super.m(...args))
.
Finally, for inner- and local JS *objects*, their (only) instantiation
point of the form new O.type()
is rewritten as
withContextualJSClassValue(js.constructorOf[ParentClassOfO], new O.type())
,
so that the back-end receives a reified reference to the parent class of
O
. A similar treatment is applied on anonymous JS classes, which
basically define something very similar to an object
, although without
its own JS class.
- Alphabetic
- By Inheritance
- ExplicitLocalJS
- CompatComponent
- TypingTransformers
- Transform
- PluginComponent
- SubComponent
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new ExplicitLocalJS(global: G)
Type Members
-
implicit
class
BTypesCompat extends AnyRef
- Definition Classes
- CompatComponent
-
implicit final
class
GlobalCompat extends AnyRef
- Definition Classes
- CompatComponent
-
implicit final
class
SAMFunctionCompatOps extends AnyRef
- Definition Classes
- CompatComponent
-
implicit final
class
StdTermNamesCompat extends AnyRef
- Definition Classes
- CompatComponent
-
implicit final
class
StdTypeNamesCompat extends AnyRef
- Definition Classes
- CompatComponent
-
implicit final
class
SymbolCompat extends AnyRef
- Definition Classes
- CompatComponent
- class ExplicitLocalJSTransformer extends TypingTransformer
-
class
Phase extends scala.tools.nsc.transform.Transform.StdPhase
- Definition Classes
- Transform
-
type
SAMFunctionCompat = G.SAMFunction
- Definition Classes
- CompatComponent
-
abstract
class
StdPhase extends GlobalPhase
- Definition Classes
- SubComponent
-
abstract
class
TypingTransformer extends scala.tools.nsc.Global.Transformer
- Definition Classes
- TypingTransformers
Abstract Value Members
- abstract val jsAddons: JSGlobalAddons { val global: ExplicitLocalJS.this.global.type }
-
abstract
val
runsAfter: List[String]
- Definition Classes
- SubComponent
Concrete Value Members
-
object
SAMFunctionAttachCompat
- Definition Classes
- CompatComponent
-
object
SAMFunctionAttachCompatDef
- Definition Classes
- CompatComponent
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
lazy val
SAMFunctionCompat: G.SAMFunction.type
- Definition Classes
- CompatComponent
-
final
def
afterOwnPhase[T](op: ⇒ T): T
- Definition Classes
- SubComponent
- Annotations
- @inline()
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
final
def
beforeOwnPhase[T](op: ⇒ T): T
- Definition Classes
- SubComponent
- Annotations
- @inline()
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
description: String
- Definition Classes
- ExplicitLocalJS → PluginComponent
-
def
enabled: Boolean
- Definition Classes
- SubComponent
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
val
global: G
- Definition Classes
- ExplicitLocalJS → CompatComponent → TypingTransformers → SubComponent
-
def
hashCode(): Int
- Definition Classes
- SubComponent → AnyRef → Any
-
val
initial: Boolean
- Definition Classes
- SubComponent
-
final
val
internal: Boolean(false)
- Definition Classes
- PluginComponent → SubComponent
-
def
isImplClass(sym: G.Symbol): Boolean
- Definition Classes
- CompatComponent
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
newPhase(prev: scala.tools.nsc.Phase): StdPhase
- Definition Classes
- Transform → SubComponent
-
def
newTransformer(unit: G.CompilationUnit): G.Transformer
- Attributes
- protected
- Definition Classes
- ExplicitLocalJS → Transform
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
ownPhase: scala.tools.nsc.Phase
- Definition Classes
- SubComponent
-
val
phaseName: String
- Definition Classes
- ExplicitLocalJS → SubComponent
-
def
phaseNewFlags: Long
- Definition Classes
- SubComponent
-
def
phaseNextFlags: Long
- Definition Classes
- SubComponent
-
val
requires: List[String]
- Definition Classes
- SubComponent
-
val
runsBefore: List[String]
- Definition Classes
- SubComponent
-
val
runsRightAfter: Option[String]
- Definition Classes
- PluginComponent → SubComponent
-
lazy val
scalaUsesImplClasses: Boolean
- Definition Classes
- CompatComponent
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
val
terminal: Boolean
- Definition Classes
- SubComponent
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()