Context

open class Context : AutoCloseable

The state one run of the engine carries: the language version, the error reporter, the feature flags, and the call stack bookkeeping the interpreter needs.

Upstream keeps the current context in a ThreadLocal, one per thread. This port is single-thread confined (D-3), so there is exactly one slot. Enter a context before running anything and exit it afterwards, or use ContextFactory.call, which does both.

Gone from upstream: class shutters, wrap factories, security controllers, class loaders, the debugger hooks and the E4X and LiveConnect surfaces. None of them have a meaning off the JVM.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion
Link copied to clipboard
fun interface Runnable

A unit of deferred work, run by processMicrotasks.

Properties

Link copied to clipboard
var clock: () -> Double

Where Date.now() and new Date() get the time, as epoch milliseconds. Defaults to the system clock; a test pins it so results do not depend on when the test runs.

Link copied to clipboard

Where warnings and errors go. Defaults to a reporter that throws on error.

Link copied to clipboard
Link copied to clipboard

The version of this engine.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Always true: there is no bytecode compiler in this port (D-15).

Link copied to clipboard
Link copied to clipboard

Whether the code running right now is in strict mode.

Link copied to clipboard

The language version this context evaluates at. Changing it affects what gets compiled from then on. New code should use VERSION_ES6 or VERSION_ECMASCRIPT.

Link copied to clipboard

How deep the interpreter's call frames may go before it gives up.

Link copied to clipboard
var timeZone: TimeZone

The zone Date reads for local time. Defaults to the system's, and a test or an embedder can set it to anything. This is the only place the engine asks the platform about time zones; every other date calculation is its own arithmetic.

Link copied to clipboard

Where rejected promises with nothing to catch them are collected. Nothing is collected until trackUnhandledPromiseRejections turns it on, because what to do about them is the embedder's decision.

Functions

Link copied to clipboard
Link copied to clipboard
open override fun close()
Link copied to clipboard
fun compileFunction(scope: Scriptable, source: String, sourceName: String?, lineno: Int, securityDomain: Any? = null): Function

Compiles source, which has to hold exactly one function, into a function object.

Link copied to clipboard
fun compileString(source: String, sourceName: String?, lineno: Int, securityDomain: Any? = null): Script
Link copied to clipboard
fun decompileFunction(fun_: Function, indent: Int): String
Link copied to clipboard
Link copied to clipboard
fun decompileScript(script: Script, indent: Int): String?
Link copied to clipboard

Queues work to run after the current top-level call finishes.

Link copied to clipboard
fun evaluateString(scope: Scriptable, source: String, sourceName: String?, lineno: Int, securityDomain: Any? = null): Any?

Compiles and runs source against scope, and returns what its last expression gave.

Link copied to clipboard

The elements of an array-like object, with holes read as undefined.

Link copied to clipboard
fun getThreadLocal(key: Any): Any?

A value an embedder parks on the context under key.

Link copied to clipboard
open fun hasFeature(featureIndex: Int): Boolean

Whether an optional engine behaviour is on. The factory decides.

Link copied to clipboard

Makes a global scope with every standard object in it.


Fills scope, or a new TopLevel when null, with the standard objects.

Link copied to clipboard
Link copied to clipboard
open fun newArray(scope: Scriptable, elements: Array<Any?>): Scriptable
open fun newArray(scope: Scriptable, length: Int): Scriptable
Link copied to clipboard
open fun newObject(scope: Scriptable): Scriptable
open fun newObject(scope: Scriptable, constructorName: String): Scriptable
open fun newObject(scope: Scriptable, constructorName: String, args: Array<Any?>): Scriptable
Link copied to clipboard

Runs the queued work, including anything it queues in turn, until the queue is empty.

Link copied to clipboard
fun putThreadLocal(key: Any, value: Any?)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun seal(sealKey: Any?)

Freezes every setting. With a non-null sealKey the same key unseals it again.

Link copied to clipboard

Sets the reporter and returns the old one, the way upstream's setter does.

Link copied to clipboard
open fun setGenerateObserverCount(generateObserverCount: Boolean)
Link copied to clipboard
fun setGeneratingDebug(generatingDebug: Boolean)
Link copied to clipboard
fun setGeneratingSource(generatingSource: Boolean)
Link copied to clipboard

How many instructions the interpreter runs between calls to ContextFactory.observeInstructionCount. Zero turns the observer off.

Link copied to clipboard
fun setInterpretedMode(interpretedMode: Boolean)
Link copied to clipboard

Whether source is a complete statement, or needs more lines before it could parse.

Link copied to clipboard
fun unseal(sealKey: Any)