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 | |
deletable | bool | |
리턴 | DeclaredVariable |
/// <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); }
/// <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; }
/// <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; }
/// <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; }
/// <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); }
/// <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); }