Inheritance: JsObject
Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public JsInstance GetLength(JsArguments target)
 {
     return global.NumberClass.New(target.length);
 }
Exemplo n.º 3
0
		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;
		}
Exemplo n.º 4
0
        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--;
            }
        }
Exemplo n.º 5
0
 public JsInstance GetLength(JsArguments target)
 {
     return(global.NumberClass.New(target.length));
 }
Exemplo n.º 6
0
        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();
            }
        }
Exemplo n.º 7
0
 public JsInstance GetLength(JsArguments target)
 {
     return((JsInstance)this.global.NumberClass.New((double)target.length));
 }