本文整理汇总了C#中Scope.SetLocalVariable方法的典型用法代码示例。如果您正苦于以下问题:C# Scope.SetLocalVariable方法的具体用法?C# Scope.SetLocalVariable怎么用?C# Scope.SetLocalVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scope
的用法示例。
在下文中一共展示了Scope.SetLocalVariable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
public override JavaScriptObject Evaluate(Scope scope, JavaScriptObject thisObject)
{
Node left = this.LeftOperand;
JavaScriptObject value = this.RightOperand.Evaluate(scope, thisObject);
if (left is VariableNode)
{
String name = ((VariableNode)left).Name;
if (isLocal)
{
scope.SetLocalVariable(name, value);
}
else
{
scope.SetVariable(name, value);
}
}
else if (left is LookupNode)
{
((LookupNode)left).Set(value, scope, thisObject);
}
else if (left is PropertyNode)
{
String name = ((PropertyNode)left).Name;
thisObject.SetProperty(name, value);
}
else
{
throw new InvalidTypeException("Left hand of assignment must be a variable.", left.Position);
}
return value;
}
示例2: SetException
public void SetException(Exception ex, Scope scope)
{
if (errorVariable != null)
{
scope.SetLocalVariable(errorVariable.Name, new JavaScriptError(ex.GetType().Name, ex.Message));
}
}
示例3: Execute
/*
* Evaluate the function.
*
* @param interpreter
* @param pos Source position of function call
* @return The result of evaluating the function.
*/
public JavaScriptObject Execute(Scope parentscope, List<JavaScriptObject> arguments, SourcePosition pos, JavaScriptObject thisObject)
{
Scope executionscope = new Scope(parentscope);
int numberMissingArgs = 0;
int numberRequiredArgs = 0;
FunctionArguments argumentsVariable = new FunctionArguments(arguments);
for (int paramIndex = 0; paramIndex < this.ArgumentCount; paramIndex++)
{
String argumentName = this.GetArgumentName(paramIndex);
JavaScriptObject value = this.GetDefaultValue(paramIndex);
if (value == null)
{
numberRequiredArgs++;
}
if (paramIndex < argumentsVariable.Count)
{
// Value provided in function call overrides the default value
value = argumentsVariable[paramIndex];
}
if (value == null)
{
numberMissingArgs++;
}
executionscope.SetLocalVariable(argumentName, value);
}
executionscope.SetLocalVariable("arguments", argumentsVariable);
if (numberMissingArgs > 0)
{
throw new TooFewArgumentsException(this.Name, numberRequiredArgs, argumentsVariable.Count, pos);
}
return this.Execute(pos, executionscope, thisObject);
}