public JsFunction() { Arguments = new List<string>(); Statement = new EmptyStatement(); Scope = new JsScope(); DeclaringScopes = new List<JsDictionaryObject>(); }
public JsFunction() { Arguments = new List <string>(); Statement = new EmptyStatement(); Scope = new JsScope(); DeclaringScopes = new List <JsDictionaryObject>(); }
/// <summary> /// Creates a new scope inside the specified scope /// </summary> /// <param name="outer">Scope inside which the new scope should be created</param> public JsScope(JsScope outer) : base(outer) { if (outer == null) throw new ArgumentNullException("outer"); globalScope = outer.Global; }
public JsScope(JsScope outer, JsDictionaryObject bag) : base(outer) { if (outer == null) throw new ArgumentNullException("outer"); if (bag == null) throw new ArgumentNullException("bag"); globalScope = outer.Global; this.bag = bag; }
public JsScope(JsScope outer) : base((JsDictionaryObject)outer) { if (outer == null) { throw new ArgumentNullException(nameof(outer)); } this.globalScope = outer.Global; }
/// <summary> /// Creates a new scope inside the specified scope /// </summary> /// <param name="outer">Scope inside which the new scope should be created</param> public JsScope(JsScope outer) : base(outer) { if (outer == null) { throw new ArgumentNullException("outer"); } globalScope = outer.Global; }
public ExecutionVisitor(Options options) { typeResolver = CachedTypeResolver.Default; Global = new JsGlobal(this, options); GlobalScope = new JsScope(Global as JsObject); EnterScope(GlobalScope); CallStack = new Stack<string>(); }
public JsScope(JsScope outer, JsDictionaryObject bag) : base(outer) { if (outer == null) { throw new ArgumentNullException("outer"); } if (bag == null) { throw new ArgumentNullException("bag"); } globalScope = outer.Global; this.bag = bag; }
public ExecutionVisitor(IGlobal GlobalObject, JsScope Scope) { if (GlobalObject == null) throw new ArgumentNullException("GlobalObject"); if (Scope == null) throw new ArgumentNullException("Scope"); typeResolver = CachedTypeResolver.Default; Global = GlobalObject; GlobalScope = Scope.Global; MaxRecursions = 500; EnterScope(Scope); CallStack = new Stack<string>(); }
/// <summary> /// Creates a new Global scope /// </summary> public JsScope() : base(JsNull.Instance) { globalScope = null; }
public void ExecuteFunction(JsFunction function, JsDictionaryObject that, JsInstance[] parameters, Type[] genericParameters) { if (function == null) { return; } if (recursionLevel++ > MaxRecursions) { throw new JsException(Global.ErrorClass.New("Too many recursions in the script.")); } // ecma chapter 10. // TODO: move creation of the activation object to the JsFunction // create new argument object and instantinate arguments into it JsArguments args = new JsArguments(Global, function, parameters); // create new activation object and copy instantinated arguments to it // Activation should be before the function.Scope hierarchy JsScope functionScope = new JsScope(function.Scope ?? GlobalScope); for (int i = 0; i < function.Arguments.Count; i++) if (i < parameters.Length) functionScope.DefineOwnProperty( new LinkedDescriptor( functionScope, function.Arguments[i], args.GetDescriptor(i.ToString()), args ) ); else functionScope.DefineOwnProperty( new ValueDescriptor( functionScope, function.Arguments[i], JsUndefined.Instance ) ); // define arguments variable if (HasOption(Options.Strict)) functionScope.DefineOwnProperty(JsScope.ARGUMENTS, args); else args.DefineOwnProperty(JsScope.ARGUMENTS, args); // set this variable if (that != null) functionScope.DefineOwnProperty(JsScope.THIS, that); else functionScope.DefineOwnProperty(JsScope.THIS, that = Global as JsObject); // enter activation object EnterScope(functionScope); try { PermissionSet.PermitOnly(); if (genericParameters != null && genericParameters.Length > 0) Result = function.Execute(this, that, parameters, genericParameters); else Result = function.Execute(this, that, parameters); // Resets the return flag if (exit) { exit = false; } } finally { // return to previous execution state ExitScope(); CodeAccessPermission.RevertPermitOnly(); recursionLevel--; } }
protected void EnterScope(JsScope scope) { Scopes.Push(scope); }
public void Visit(JsonExpression json) { JsObject instance = Global.ObjectClass.New(); JsScope scope = new JsScope() { Prototype = CurrentScope }; scope.DefineOwnProperty(JsInstance.THIS, instance); EnterScope(scope); try { foreach (var item in json.Values) { item.Value.Accept(this); instance.DefineOwnProperty(item.Key, Result); } } finally { ExitScope(); } Result = instance; }
public void ExecuteFunction(JsFunction function, JsDictionaryObject that, JsInstance[] parameters) { if (function == null) { return; } JsScope functionScope = new JsScope(); JsArguments args = new JsArguments(Global, function, parameters); functionScope.Prototype = args; if (HasOption(Options.Strict)) functionScope.DefineOwnProperty(JsInstance.ARGUMENTS, args); else functionScope.Prototype.DefineOwnProperty(JsInstance.ARGUMENTS, args); if (that != null) functionScope.DefineOwnProperty(JsInstance.THIS, that); functionScope.Extensible = false; //for (int i = function.DeclaringScopes.Count - 1; i >= 0; i--) //{ // EnterScope(function.DeclaringScopes[i]); //} EnterScope(function); EnterScope(functionScope); try { PermissionSet.PermitOnly(); Result = function.Execute(this, that, parameters); // Resets the return flag if (exit) { exit = false; } } finally { ExitScope(); ExitScope(); CodeAccessPermission.RevertPermitOnly(); } }
public JsScope() : base((JsDictionaryObject)JsNull.Instance) { this.globalScope = (JsScope)null; }