JSCodeGen

class JSCodeGen(using genCtx: Context)

Main codegen for Scala.js IR.

GenSJSIR creates one instance of JSCodeGen per compilation unit. The run() method processes the whole compilation unit and generates .sjsir files for it.

There are 4 main levels of translation:

  • genCompilationUnit() iterates through all the type definitions in the compilation unit. Each generated js.ClassDef is serialized to an .sjsir file.
  • genScalaClass() and other similar methods generate the skeleton of classes.
  • genMethod() and similar methods generate the declarations of methods.
  • genStatOrExpr() and everything else generate the bodies of methods.
Companion
object
class Object
trait Matchable
class Any

Value members

Concrete methods

def box(expr: Tree, tpeEnteringElimErasedValueType: Type)(pos: Position): Tree

Boxes a value of the given type before elimErasedValueType.

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.

Value Params
expr

Tree to be boxed if needed.

tpeEnteringElimErasedValueType

The type of expr as it was entering the elimErasedValueType phase.

Returns a new fresh local identifier.

Returns a new fresh local identifier.

def genApplyJSClassMethod(receiver: Tree, method: Symbol, arguments: List[Tree])(pos: Position): Tree

Gen a call to a non-exposed method of a non-native JS class.

Gen a call to a non-exposed method of a non-native JS class.

def genApplyMethod(receiver: Tree, method: Symbol, arguments: List[Tree])(pos: Position): Tree

Gen a dynamically linked call to a Scala method.

Gen a dynamically linked call to a Scala method.

def genApplyMethodStatically(receiver: Tree, method: Symbol, arguments: List[Tree])(pos: Position): Tree

Gen a statically linked call to an instance method.

Gen a statically linked call to an instance method.

def genExpr(name: JSName)(pos: SourcePosition): Tree

Gen JS code for a tree in expression position (in the IR) or the global scope.

Gen JS code for a tree in expression position (in the IR) or the global scope.

def genIsInstanceOf(value: Tree, to: Type)(pos: SourcePosition): Tree

Gen JS code for an isInstanceOf test (for reference types only)

Gen JS code for an isInstanceOf test (for reference types only)

Wraps a js.Array to use as varargs.

Wraps a js.Array to use as varargs.

Generates the JSNativeMemberDef.

Generates the JSNativeMemberDef.

Generate loading of a module value.

Generate loading of a module value.

Can be given either the module symbol or its module class symbol.

If the module we load refers to the global scope (i.e., it is annotated with @JSGlobalScope), report a compile error specifying that a global scope object should only be used as the qualifier of a .-selection.

Generate loading of a module value or the global scope.

Generate loading of a module value or the global scope.

Can be given either the module symbol of its module class symbol.

Unlike genLoadModule, this method does not fail if the module we load refers to the global scope.

def genMatch(tree: Tree, isStat: Boolean): Tree

Gen JS code for a switch-Match, which is translated into an IR js.Match.

Gen JS code for a switch-Match, which is translated into an IR js.Match.

Gen the static forwarders to the members of a class or interface for methods of its companion object.

Gen the static forwarders to the members of a class or interface for methods of its companion object.

This is only done if there exists a companion object and it is not a JS type.

Precondition: isCandidateForForwarders(sym) is true

Gen the static forwarders for the methods of a module class.

Gen the static forwarders for the methods of a module class.

Precondition: isCandidateForForwarders(moduleClass) is true

Is the given Scala class, interface or module class a candidate for static forwarders?

Is the given Scala class, interface or module class a candidate for static forwarders?

  • the flag -XnoForwarders is not set to true, and
  • the symbol is static, and
  • either of both of the following is true:
    • the flag -scalajsGenStaticForwardersForNonTopLevelObjects is set to true, or
    • the symbol was originally at the package level

Other than the Scala.js-specific flag, and the fact that we also consider interfaces, this performs the same tests as the JVM back-end.

def run(): Unit
def unbox(expr: Tree, tpeEnteringElimErasedValueType: Type)(pos: Position): Tree

Unboxes a value typed as Any to the given type before elimErasedValueType.

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.

Value Params
expr

Tree to be extracted.

tpeEnteringElimErasedValueType

The type of expr as it was entering the elimErasedValueType phase.

def withNewLocalNameScope[A](body: => A): A

Implicits

Implicits

Implicitly materializes the current local name generator.

Implicitly materializes the current local name generator.