Esempio n. 1
0
        protected override JavaScriptObject Execute(SourcePosition pos, Scope scope, JavaScriptObject thisObject)
        {
            JavaScriptArray   array = (JavaScriptArray)thisObject;
            FunctionArguments args  = (FunctionArguments)scope.GetVariable("arguments", pos);

            foreach (JavaScriptObject obj in args)
            {
                array.Add(obj);
            }
            return(array);
        }
Esempio n. 2
0
        /*
         * 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));
        }