public JsInstance GetArray(JsArguments target) { JsArray array = global.ArrayClass.New(); if (args != null) { for (int i = 0; i < args.Length; i++) { array[i.ToString()] = args[i]; } } return(array); }
public JsInstance GetLength(JsArguments target) { return global.NumberClass.New(target.length); }
public JsInstance GetArray(JsArguments target) { JsArray array = global.ArrayClass.New(); if(args!=null) { for (int i = 0; i < args.Length; i++) { array[i.ToString()] = args[i]; } } return array; }
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--; } }
public JsInstance GetLength(JsArguments target) { return(global.NumberClass.New(target.length)); }
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 JsInstance GetLength(JsArguments target) { return((JsInstance)this.global.NumberClass.New((double)target.length)); }