DeclareVariable() private method

Declares a variable or function in this scope. This will be initialized with the value of the given expression.
private DeclareVariable ( string name, Jurassic.Compiler.Expression valueAtTopOfScope = null, bool writable = true, bool deletable = false ) : DeclaredVariable
name string The name of the variable.
valueAtTopOfScope Jurassic.Compiler.Expression The value of the variable at the top of the scope.
writable bool true if the variable can be modified; false /// otherwise.
deletable bool true if the variable can be deleted; false /// otherwise.
return DeclaredVariable
Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new declarative scope for use inside a function body (and within function
        /// argument default values).
        /// </summary>
        /// <param name="parentScope"> A reference to the parent scope.  Can not be <c>null</c>. </param>
        /// <param name="functionName"> The name of the function.  Can be empty for an anonymous function. </param>
        /// <param name="argumentNames"> The names of each of the function arguments.  Can be <c>null</c>. </param>
        /// <returns> A new DeclarativeScope instance. </returns>
        internal static DeclarativeScope CreateFunctionScope(Scope parentScope, string functionName, IEnumerable <string> argumentNames)
        {
            if (parentScope == null)
            {
                throw new ArgumentNullException("parentScope", "Function scopes must have a parent scope.");
            }
            if (functionName == null)
            {
                throw new ArgumentNullException(nameof(functionName));
            }
            var result = new DeclarativeScope(parentScope, 0);

            if (string.IsNullOrEmpty(functionName) == false)
            {
                result.DeclareVariable(functionName);
            }
            result.DeclareVariable("this");
            result.DeclareVariable("arguments");
            if (argumentNames != null)
            {
                foreach (var argumentName in argumentNames)
                {
                    result.DeclareVariable(argumentName);
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new declarative scope for use inside a function body.
 /// </summary>
 /// <param name="parentScope"> A reference to the parent scope.  Can not be <c>null</c>. </param>
 /// <param name="functionName"> The name of the function.  Can be empty for an anonymous function. </param>
 /// <param name="argumentNames"> The names of each of the function arguments. </param>
 /// <returns> A new DeclarativeScope instance. </returns>
 internal static DeclarativeScope CreateFunctionScope(Scope parentScope, string functionName, IEnumerable<string> argumentNames)
 {
     if (parentScope == null)
         throw new ArgumentNullException("parentScope", "Function scopes must have a parent scope.");
     if (functionName == null)
         throw new ArgumentNullException("functionName");
     if (argumentNames == null)
         throw new ArgumentNullException("argumentNames");
     var result = new DeclarativeScope(parentScope, 0);
     if (string.IsNullOrEmpty(functionName) == false)
         result.DeclareVariable(functionName);
     result.DeclareVariable("this");
     result.DeclareVariable("arguments");
     foreach (var argumentName in argumentNames)
         result.DeclareVariable(argumentName);
     return result;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new declarative scope for use inside a catch statement.
 /// </summary>
 /// <param name="parentScope"> A reference to the parent scope.  Can not be <c>null</c>. </param>
 /// <param name="catchVariableName"> The name of the catch variable. </param>
 /// <returns> A new DeclarativeScope instance. </returns>
 internal static DeclarativeScope CreateCatchScope(Scope parentScope, string catchVariableName)
 {
     if (parentScope == null)
         throw new ArgumentNullException("parentScope", "Catch scopes must have a parent scope.");
     if (catchVariableName == null)
         throw new ArgumentNullException("catchVariableName");
     var result = new DeclarativeScope(parentScope, 0);
     result.DeclareVariable(catchVariableName);
     result.CanDeclareVariables = false;    // Only the catch variable can be declared in this scope.
     return result;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new declarative scope for use at runtime.
 /// </summary>
 /// <param name="parentScope"> A reference to the parent scope.  Can not be <c>null</c>. </param>
 /// <param name="declaredVariableNames"> The names of variables that were declared in this scope. </param>
 /// <returns> A new DeclarativeScope instance. </returns>
 public static DeclarativeScope CreateRuntimeScope(Scope parentScope, string[] declaredVariableNames)
 {
     if (parentScope == null)
         throw new ArgumentNullException("parentScope", "Function scopes must have a parent scope.");
     if (declaredVariableNames == null)
         throw new ArgumentNullException("declaredVariableNames");
     var result = new DeclarativeScope(parentScope, declaredVariableNames.Length);
     foreach (string variableName in declaredVariableNames)
         result.DeclareVariable(variableName);
     result.values = new object[result.DeclaredVariableCount];
     return result;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new declarative scope for use inside a catch statement.
        /// </summary>
        /// <param name="parentScope"> A reference to the parent scope.  Can not be <c>null</c>. </param>
        /// <param name="catchVariableName"> The name of the catch variable. </param>
        /// <returns> A new DeclarativeScope instance. </returns>
        internal static DeclarativeScope CreateCatchScope(Scope parentScope, string catchVariableName)
        {
            if (parentScope == null)
            {
                throw new ArgumentNullException("parentScope", "Catch scopes must have a parent scope.");
            }
            if (catchVariableName == null)
            {
                throw new ArgumentNullException(nameof(catchVariableName));
            }
            var result = new DeclarativeScope(parentScope, 0);

            result.DeclareVariable(catchVariableName);
            result.CanDeclareVariables = false;    // Only the catch variable can be declared in this scope.
            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new declarative scope for use at runtime.
        /// </summary>
        /// <param name="parentScope"> A reference to the parent scope.  Can not be <c>null</c>. </param>
        /// <param name="declaredVariableNames"> The names of variables that were declared in this scope. </param>
        /// <returns> A new DeclarativeScope instance. </returns>
        public static DeclarativeScope CreateRuntimeScope(Scope parentScope, string[] declaredVariableNames)
        {
            if (parentScope == null)
            {
                throw new ArgumentNullException("parentScope", "Function scopes must have a parent scope.");
            }
            if (declaredVariableNames == null)
            {
                throw new ArgumentNullException(nameof(declaredVariableNames));
            }
            var result = new DeclarativeScope(parentScope, declaredVariableNames.Length);

            foreach (string variableName in declaredVariableNames)
            {
                result.DeclareVariable(variableName);
            }
            result.values = new object[result.DeclaredVariableCount];
            return(result);
        }