/// <summary> /// Invokes the function with the specified parameters and returns the value. /// </summary> /// <param name="args">The parameters passed to the function.</param> /// <returns>The return value of the function.</returns> /// <exception cref="ArgumentException"><paramref name="args"/> is invalid.</exception> IScriptObject IFunctionObject.Invoke(List <IScriptObject> args) { FunctionHelper.CheckArguments(Parameters, args); FunctionContext context = new FunctionContext(Closure); FunctionHelper.SetArguments(context, Parameters, args); ExecuteResult result = context.ExecuteStatements(Statements); if (result.FlowControl == FlowControl.Return) { return((IScriptObject)result.Data); } else { return(ScriptNull.Instance); } }