Class: DynamicEvaluator

DynamicEvaluator(compiledopt)

Provides dynamic expression and statement evaluation within a given scope.

Constructor

new DynamicEvaluator(compiledopt)

Parameters:
Name Type Attributes Default Description
compiled object <optional>
null

The compiled tables the compiler emitted for the owning class.

Properties
Name Type Attributes Description
expressions Object:.<string:, function(object:): any:> <optional>

Value expressions, keyed by their source text.

statements Object:.<string:, function(object:): any:> <optional>

Handler and action bodies, keyed by their source text.

Source:

Classes

DynamicEvaluator

Members

compiledExpressions :Object:.<string:, function(object:): any:>|null

Expressions the compiler already turned into closures.

When an entry exists it is used, and neither the parser nor the interpreter is reached. That is the whole point: a build in which every expression compiled never executes the interpreter, which is what allows it to be dropped from a production bundle.

Type:
  • Object:.<string:, function(object:): any:> | null
Source:

compiledStatements :Object:.<string:, function(object:): any:>|null

Statement bodies the compiler already turned into closures.

Type:
  • Object:.<string:, function(object:): any:> | null
Source:

indexedExpressions :Array:.<function(object:): any:>|null

Compiled closures addressed by index, for the render program.

Separate from the source-keyed table rather than overloading it. A program op carries an index and a legacy binding carries source text; one table serving both would have to guess which it was handed, and a numeric string key is a real expression source.

Type:
  • Array:.<function(object:): any:> | null
Source:

indexedStatements :Array:.<function(object:): any:>|null

Compiled statement closures addressed by index, for event ops.

Type:
  • Array:.<function(object:): any:> | null
Source:

Methods

createMethodMap(methodsopt, getScope, getThisArg, contextopt) → {object}

Creates a map of executable methods from string definitions.

Parameters:
Name Type Attributes Default Description
methods object <optional>

An object containing method name and source code pairs.

getScope function

Function to retrieve the scope for a method.

getThisArg function

Function to retrieve the 'this' context for methods.

context object <optional>
null

Trace context describing who owns these methods.

Properties
Name Type Attributes Description
owner string <optional>

The component or page name, used in traces.

kind string <optional>

What sort of unit these are, e.g. action or resource.

contracts Array:.<string:> <optional>

Compiler contracts the owner declared.

atomic Object:.<string:, {onConflict:: string:=}> <optional>

Actions the compiler saw declared atomic, keyed by name. Each one runs inside a Rewind transaction: its writes are journaled and undone if it fails.

compiled Object:.<string:, function(object:): any:> <optional>

Bodies the compiler already turned into functions, keyed by action name. Keyed by name rather than by source so an action's text does not have to be in the bundle at all to find its implementation, and so a call does not hash a multi-line string to look one up.

Source:
Returns:

A map of functions.

Type
object

evaluateExpression(expression, scopeopt, thisArgopt) → {any}

Evaluates a JavaScript expression within a scope.

Parameters:
Name Type Attributes Description
expression string

The expression to evaluate.

scope object <optional>

The scope variables.

thisArg object <optional>

The 'this' context for evaluation.

Source:
Returns:

The result of evaluation.

Type
any

evaluateIndexed(index, scopeopt, thisArgopt) → {any}

Evaluates a compiled expression by index.

There is no interpreter fallback here, and that is deliberate. An index names a closure and nothing else -- the source it came from is not in the bundle -- so a missing entry is a program and a table that disagree, which is a build fault rather than a template the runtime could still render. The compiler refuses to emit a program whose expressions did not all compile, so this cannot be reached by an application that built.

Parameters:
Name Type Attributes Description
index number

The expression index.

scope object <optional>

The scope variables.

thisArg object <optional>

The this context.

Source:
Returns:

The value.

Type
any

executeIndexed(index, scopeopt, thisArgopt) → {any}

Runs a compiled statement body by index.

Parameters:
Name Type Attributes Description
index number

The statement index.

scope object <optional>

The scope variables.

thisArg object <optional>

The this context.

Source:
Returns:

Whatever the body returned.

Type
any

executeStatement(source, scopeopt, thisArgopt) → {any}

Executes a JavaScript statement within a scope.

This used to accept a pre-compiled function as well, for handlers EventExecutor had already built with new Function, and ran those against the source-text sandbox rather than the AST evaluator. Nothing produces such a function any more, and accepting one would be a door back into the sandbox the evaluator exists to replace.

Parameters:
Name Type Attributes Description
source string

The statement(s) to execute.

scope object <optional>

The scope variables.

thisArg object <optional>

The 'this' context for execution.

Source:
Returns:

The result of execution.

Type
any

sanitizeHTML(value, optionsopt) → {string}

Sanitizes an HTML string using the Sanitizer utility with optional custom policy configuration.

Parameters:
Name Type Attributes Description
value any

The HTML string or value to sanitize.

options object <optional>

Optional custom policy configuration for Sanitizer.

Source:
Returns:

The sanitized HTML string.

Type
string