import { Identifier } from "../lexer"; import { BrsType, RoAssociativeArray, BrsInvalid, RoSGNode, Callable } from "../brsTypes"; import { ComponentDefinition } from "../scenegraph"; /** The logical region from a particular variable or function that defines where it may be accessed from. */ export declare enum Scope { /** The set of native functions that are always accessible, e.g. `RebootSystem`. */ Global = 0, /** The set of named functions accessible from a set of files compiled together. */ Module = 1, /** The set of variables (including anonymous functions) accessible *only* from within a function body. */ Function = 2 } /** An error thrown when attempting to access an uninitialized variable. */ export declare class NotFound extends Error { constructor(reason: string); } /** Holds a set of values in multiple scopes and provides access operations to them. */ export declare class Environment { constructor(rootM?: RoAssociativeArray); /** * Functions that are always accessible. * @see Scope.Global */ private global; /** * Named functions that are compiled together into a single module. * @see Scope.Module */ private module; /** * Variables and anonymous functions accessible only within a function's body. * @see Scope.Function */ private function; /** * Mocked objects */ private mockObjects; /** * Unscoped mock functions. These mocks are used across all components and files. */ private unscopedMockFunctions; /** * Scoped mock functions. These mocks are only used in this component. */ private scopedMockFunctions; /** The BrightScript `m` pointer, analogous to JavaScript's `this` pointer. */ private mPointer; private rootM; /** * The one true focus of the scenegraph app, only one component can have focus at a time. * Note: this focus is only meaningful if the node being set focus to * is a child of the main scene graph tree. Otherwise, it will not follow the rule * of stealing focus away from another node if a new node got focus. */ private focusedNode; /** Map holding component definitions of all parsed xml component files */ nodeDefMap: Map; /** The node in which field-change observers are registered. */ hostNode: RoSGNode | undefined; /** * Stores a `value` for the `name`d variable in the provided `scope`. * @param scope The logical region from a particular variable or function that defines where it may be accessed from * @param name the name of the variable to define (in the form of an `Identifier`) * @param value the value of the variable to define */ define(scope: Scope, name: string, value: BrsType): void; /** * Sets the value of the special `m` variable, which is analogous to JavaScript's `this`. * @param newMPointer the new value to be used for the `m` pointer */ setM(newMPointer: RoAssociativeArray): void; /** * Retrieves the current value of the special `m` variable, which is analogous to JavaScript's `this`. * @returns the current value used for the `m` pointer. */ getM(): RoAssociativeArray; /** * Retrieves the the special `m` variable from the root Environment. * @returns the current value used for the root `m` pointer. */ getRootM(): RoAssociativeArray; /** * Sets the the special `m` variable from the root Environment. * @param newMPointer the new value to be used for the `m` pointer */ setRootM(newMPointer: RoAssociativeArray): void; /** * Removes a variable from this environment's function scope. * @param name the name of the variable to remove (in the form of an `Identifier`) * @param scope the scope to remove this variable from (defaults to "function") */ remove(name: string, scope?: Scope): void; /** * Retrieves a variable from this environment, checking each internal scope in order of precedence. * @param name the name of the variable to retrieve (in the form of an `Identifier`) * @returns the value stored for `name` if any exist * @throws a `NotFound` error if no value is stored for `name` */ get(name: Identifier): BrsType; /** * Determines whether or not a variable exists in this environment. * @param name the name of the variable to search for (in the form of an `Identifier`) * @param scopeFilter the set of scopes with which to limit searches for `name` * @returns `true` if this environment contains `name`, otherwise `false` */ has(name: Identifier, scopeFilter?: Scope[]): boolean; /** * Returns list of variables of a specific in this environment. * @param scope the scope to return variables map * @returns the map of variables for the requested scope */ getList(scope: Scope): Map; /** * Creates a clone of the current environment, but without its function-scoped * values. Useful for creating sub-environments. * * The Reference BrightScript Implementation (RBI) doesn't currently create closures when * functions are created. When a function is called, it has access only to: * * 1. Globally-defined functions (e.g. `RebootSystem`, `UCase`, et. al.) * 2. Named functions compiled together into a single "module" * 3. Parameters passed into the function * 4. The `m` pointer, defined by the way in which a function was called * 5. Currently focused node object that reacts to onKey button presses * @param includeModuleScope whether or not to includer caller's module scope into * the cloned environment. * * @returns a copy of this environment but with no function-scoped values. */ createSubEnvironment(includeModuleScope?: boolean): Environment; /** * returns true if the variable has a mocked object * @param objName the object to mock */ isMockedObject(objName: string): boolean; /** * retrieves mocked object if it exists * @param objName the object to mock */ getMockObject(objName: string): BrsType; /** * places the mockValue object into list of mocks * @param objName the object we are mocking * @param mockValue the mock to return */ setMockObject(objName: string, mockValue: RoAssociativeArray): void; /** * places the mockValue function into list of mocks * @param functionName the function we are mocking * @param mockValue the mock to return * @param isScoped whether this function should be scoped to this module or universally mocked. */ setMockFunction(functionName: string, mockValue: Callable, isScoped?: boolean): void; /** * Retrieves mocked function if it exists. If there is a scoped and unscoped function * by the same name, it will return the scoped. * @param functionName the function to mock */ getMockFunction(functionName: string): Callable | BrsInvalid; /** * returns true if the variable has a mocked function * @param possibleMockFunction the variable that may be mocked * @param possibleMockName the identifier/name for the mocked function */ private isMockedFunction; /** * resets all of the mocked functions and objects in this environment */ resetMocks(): void; /** * resets all of the mocked objects in this environment */ resetMockObjects(): void; /** * resets a single mocked object in this environment */ resetMockObject(name: string): void; /** * reset the unscoped (globally mocked) function that matches the given name */ resetUnscopedMockFunction(name: string): void; /** * resets all of the unscoped (globally mocked) functions */ resetUnscopedMockFunctions(): void; /** * reset the scoped (this environment only) function that matches the given name */ resetScopedMockFunction(name: string): void; /** * resets all of the mocked functions *in this environment* */ resetScopedMockFunctions(): void; /** * Sets the currently focused node, which reacts to onKey button presses * @param node either node object or invalid */ setFocusedNode(node: RoSGNode | BrsInvalid): void; /** * Gets the currently focused node, which reacts to onKey button presses * @returns currently focused node */ getFocusedNode(): RoSGNode | BrsInvalid; }