CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-scala-lang--scala3-library-sjs1-3

Scala.js-specific runtime library components for Scala 3, providing JavaScript-specific functionality and bridge components between Scala 3 and the Scala.js runtime environment

Pending
Overview
Eval results
Files

runtime.mddocs/

Runtime and JavaScript Interop

JavaScript-specific runtime support and Scala.js interoperability, providing the bridge between Scala 3 language features and JavaScript runtime environment.

Capabilities

Scala.js Internal Operations

Internal operations for Unit type handling and JavaScript interoperability.

/**
 * Internal operations for Unit type under Scala.js compilation
 * Provides implicit conversions for Unit | T unions to UndefOr operations
 */
object UnitOps:
  /**
   * Convert Unit | A unions to UndefOr operations for JavaScript compatibility
   * Enables natural handling of undefined values in JavaScript contexts
   */
  given unitOrOps[A](x: A | Unit): js.UndefOrOps[A]

Usage Examples:

import scala.scalajs.js
import scala.scalajs.js.internal.UnitOps.given

// Union types with Unit automatically get UndefOr operations
val value: String | Unit = if (condition) "hello" else ()

// Can use UndefOr operations due to implicit conversion
val orElse = value.getOrElse("default")  // Works due to UnitOps conversion
val mapped = value.map(_.toUpperCase)    // Maps only if not Unit

// Function returning optional values
def maybeString(condition: Boolean): String | Unit = 
  if condition then "result" else ()

val result = maybeString(true)
// result can use UndefOr operations thanks to UnitOps

Scala.js Function Compatibility

Support for large-arity functions in Scala.js environments.

/**
 * Large arity anonymous function support for Scala.js compatibility
 * Deprecated since Scala.js 1.19 - replaced by NewLambda compilation
 * Maintained for compatibility with libraries compiled before 1.19
 */
@deprecated("used by the codegen before Scala.js 1.19", since = "3.7.0")
sealed abstract class AnonFunctionXXL extends scala.runtime.FunctionXXL

Usage Examples:

// This class is primarily used by the compiler, not directly by users
// Historical context: before Scala.js 1.19, functions with many parameters
// were compiled to AnonFunctionXXL instances

// Modern Scala.js (1.19+) uses NewLambda compilation instead
// Old compiled code referencing AnonFunctionXXL is automatically patched

// Function with many parameters (would historically use AnonFunctionXXL)
val manyParamFunction = (a: Int, b: Int, c: Int, d: Int, e: Int, 
                        f: Int, g: Int, h: Int, i: Int, j: Int) => 
  a + b + c + d + e + f + g + h + i + j

// In modern Scala.js, this compiles to efficient NewLambda representation
// Legacy AnonFunctionXXL references are handled transparently

Runtime Support Classes

Core runtime support for Scala 3 language features.

/**
 * Core runtime support for Scala 3 operations
 * Provides runtime utilities for language features
 */
object Scala3RunTime:
  /** Runtime support for pattern matching */
  def isInstanceOf[T](x: Any, clazz: Class[?]): Boolean
  /** Runtime type checking with proper variance */
  def checkCast[T](x: Any): T
  /** Dynamic method selection support */
  def selectDynamic(receiver: Any, name: String): Any

/**
 * Array utility operations
 */
object Arrays:
  /** Copy array with proper type handling */
  def copyArray[T](src: Array[T], dst: Array[T], length: Int): Unit
  /** Create array of specific type */
  def newArray[T](componentType: Class[T], length: Int): Array[T]

/**
 * Enum value support for runtime operations
 */
trait EnumValue:
  /** Get enum ordinal */
  def ordinal: Int
  /** Get enum name */  
  def productPrefix: String

/**
 * Lazy value implementation support
 */
object LazyVals:
  /** Initialize lazy value with synchronization */
  def initialize[T](target: Any, offset: Long, value: T): T
  /** Get lazy value state */
  def getState(target: Any, offset: Long): Long

/**
 * Pattern matching case support
 */
class MatchCase[T](selector: T):
  /** Test if case matches */
  def isDefinedAt(x: Any): Boolean = ???
  /** Apply case logic */  
  def apply(x: Any): T = ???

/**
 * Type boxing utilities for generic operations
 */
object TypeBox:
  /** Box primitive values for generic context */
  def box[T](value: T): AnyRef
  /** Unbox values from generic context */
  def unbox[T](value: AnyRef): T

Usage Examples:

// Runtime type checking (typically used by compiler-generated code)
val obj: Any = "hello"
val isString = Scala3RunTime.isInstanceOf[String](obj, classOf[String])  // true
val asString = Scala3RunTime.checkCast[String](obj)  // "hello"

// Dynamic method selection for structural types
type HasName = { def name: String }
def getName(obj: HasName): String = 
  Scala3RunTime.selectDynamic(obj, "name").asInstanceOf[String]

// Array operations
val source = Array(1, 2, 3, 4, 5)
val dest = new Array[Int](5)
Arrays.copyArray(source, dest, 5)

// Enum operations (used internally)
enum Color extends EnumValue:
  case Red, Green, Blue

val red = Color.Red
println(red.ordinal)       // 0 (provided by EnumValue)
println(red.productPrefix) // "Red"

// Lazy values (compiler-generated usage)
lazy val expensiveComputation = {
  println("Computing...")
  42
}
// LazyVals.initialize is used internally to ensure thread-safe initialization

// Type boxing for generic operations
val boxed = TypeBox.box(42)           // java.lang.Integer
val unboxed = TypeBox.unbox[Int](boxed) // 42

Tuple Runtime Support

Runtime support for tuple operations and large-arity tuples.

/**
 * Support for tuples with arity > 22
 */
class TupleXXL(private val elems: Array[Object]) extends Product:
  /** Get element at index */
  def productElement(n: Int): Any = elems(n)
  /** Get tuple arity */
  def productArity: Int = elems.length
  /** Check equality */
  override def equals(that: Any): Boolean = ???
  /** Hash code */  
  override def hashCode(): Int = ???

/**
 * Mirror support for tuple reflection
 */
object TupleMirror:
  /** Get mirror for tuple type */
  def apply[T <: Tuple]: Mirror.ProductOf[T] = ???

/**
 * Tuple utility operations
 */
object Tuples:
  /** Convert product to tuple */
  def fromProduct(p: Product): Tuple = ???
  /** Convert array to tuple */
  def fromArray(arr: Array[Object]): Tuple = ???
  /** Convert tuple to array */
  def toArray(t: Tuple): Array[Object] = ???

/**
 * Support for tupled function operations  
 */
object TupledFunctions:
  /** Convert function to tupled form */
  def tupled[F, G](f: F): G = ???
  /** Convert tupled function to regular form */
  def untupled[F, G](g: G): F = ???

Usage Examples:

// Large tuples (arity > 22) use TupleXXL internally
val largeTuple = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
                 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
                 21, 22, 23, 24, 25)
// Internally represented as TupleXXL

println(largeTuple.productArity)    // 25
println(largeTuple.productElement(0)) // 1

// Tuple utilities
val product = ("Alice", 30, true)
val array = Tuples.toArray(product)          // Array("Alice", 30, true)
val backToTuple = Tuples.fromArray(array)    // ("Alice", 30, true)

// Function tupling
val add3 = (x: Int, y: Int, z: Int) => x + y + z
val tupledAdd3 = TupledFunctions.tupled(add3)
val result = tupledAdd3((1, 2, 3))  // 6

Function Runtime Support

Support for large-arity functions and function operations.

/**
 * Support for functions with arity > 22
 */
abstract class FunctionXXL:
  /** Apply function with arguments array */
  def apply(args: Array[Object]): Object
  /** Get function arity */
  def arity: Int

/**
 * Exception throwing support for runtime
 */
object $throws:
  /** Mark method as potentially throwing */
  def apply[T <: Exception]: Any = ???

Usage Examples:

// Large-arity functions use FunctionXXL internally
val manyArgFunction = (a1: Int, a2: Int, a3: Int, a4: Int, a5: Int,
                      a6: Int, a7: Int, a8: Int, a9: Int, a10: Int,
                      a11: Int, a12: Int, a13: Int, a14: Int, a15: Int,
                      a16: Int, a17: Int, a18: Int, a19: Int, a20: Int,
                      a21: Int, a22: Int, a23: Int) => 
  a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 +
  a11 + a12 + a13 + a14 + a15 + a16 + a17 + a18 + a19 + a20 +
  a21 + a22 + a23

// Internally extends FunctionXXL
val args = Array.tabulate(23)(_.asInstanceOf[Object])
// Function can be called via apply(args) method

Standard Library Patches

Compatibility patches for standard library components.

/**
 * Patched Predef object for Scala 3 compatibility
 */
object Predef:
  /** Standard assertion */
  def assert(assertion: Boolean): Unit = ???
  def assert(assertion: Boolean, message: => Any): Unit = ???
  
  /** Require preconditions */
  def require(requirement: Boolean): Unit = ???
  def require(requirement: Boolean, message: => Any): Unit = ???
  
  /** Standard print operations */
  def print(x: Any): Unit = ???
  def println(x: Any): Unit = ???
  def println(): Unit = ???

/**
 * Language feature imports
 */
object language:
  /** Language features that can be imported */
  object experimental:
    /** Capture checking feature */
    given captureChecking: languageFeature = ???
    /** Named tuples support */
    given namedTuples: languageFeature = ???
  
  /** Implicit conversions */  
  given implicitConversions: languageFeature = ???
  /** Postfix operators */
  given postfixOps: languageFeature = ???

type languageFeature = Unit

Usage Examples:

// Standard operations work as expected
Predef.assert(1 + 1 == 2)
Predef.require(args.nonEmpty, "Arguments required")
Predef.println("Hello, Scala 3!")

// Language feature imports
import scala.language.experimental.captureChecking
import scala.language.implicitConversions
import scala.language.postfixOps

// Enable experimental features
import scala.language.experimental.namedTuples
val person = (name = "Alice", age = 30)  // Named tuples enabled

Coverage Support

Support for code coverage instrumentation.

/**
 * Code coverage instrumentation support
 */
object Invoker:
  /** Record coverage hit for instrumentation */
  def invoked(id: Int, count: Int): Unit = ???
  /** Initialize coverage tracking */
  def initializeInvoker(): Unit = ???

Usage Examples:

// Coverage instrumentation (typically compiler-generated)
def instrumentedMethod(): String = {
  Invoker.invoked(1, 1)  // Coverage tracking call (compiler-generated)
  "result"
}

// Coverage initialization (build tool integration)
// Invoker.initializeInvoker() called by coverage tools

Types

// Scala.js interop types
object UnitOps:
  given unitOrOps[A](x: A | Unit): js.UndefOrOps[A]

sealed abstract class AnonFunctionXXL extends scala.runtime.FunctionXXL

// Runtime support types
object Scala3RunTime
object Arrays
trait EnumValue
object LazyVals
class MatchCase[T]
object TypeBox

// Tuple support types
class TupleXXL extends Product
object TupleMirror
object Tuples
object TupledFunctions

// Function support types
abstract class FunctionXXL:
  def apply(args: Array[Object]): Object
  def arity: Int

// Standard library patches
object Predef
object language
type languageFeature = Unit

// Coverage support
object Invoker

Install with Tessl CLI

npx tessl i tessl/maven-org-scala-lang--scala3-library-sjs1-3

docs

annotations.md

capabilities.md

collections.md

core-types.md

derivation.md

index.md

metaprogramming.md

runtime.md

utilities.md

tile.json