/// <summary> /// Invokes the constructor on the specified target with the specified parameters and returns the value. /// </summary> /// <param name="target">The target on which the constructor is invoked.</param> /// <param name="args">The parameters passed to the constructor.</param> /// <exception cref="ArgumentException"><paramref name="args"/> is invalid.</exception> public void Invoke(InstanceObject target, List <IScriptObject> args) { try { FunctionHelper.CheckArguments(Parameters, args); } catch (ArgumentException) { throw new ArgumentException( string.Format(ExceptionResource.ConstructorParemetersNotMatch, Class.Name)); } MethodContext context = new MethodContext(Class, target, Closure); FunctionHelper.SetArguments(context, Parameters, args); if (Class.Super != null && Class.Super.Constructor != null) { var list = new List <IScriptObject>(); if (Parameters != null) { foreach (var p in SuperCall) { list.Add(context.EvaluateExpression(p)); } } Class.Super.Constructor.Invoke(target, list); } IScriptObject value; foreach (var field in Class.FieldInitializers) { if (field.Value != null) { value = Closure.EvaluateExpression(field.Value); } else { value = ScriptNull.Instance; } if (target.Fields.ContainsKey(field.Key)) { target.Fields.Add(field.Key, value); } else { target.Fields[field.Key] = value; } } if (Statements != null) { context.ExecuteStatements(Statements); } }
/// <summary> /// Invokes the method on the specified target with the specified parameters and returns the value. /// </summary> /// <param name="target">The target on which the method is invoked. It should be <see langword="null"/> if the method is a static method.</param> /// <param name="args">The parameters passed to the method.</param> /// <exception cref="ArgumentException"><paramref name="args"/> is invalid.</exception> public override IScriptObject Invoke(IScriptObject target, List <IScriptObject> args) { FunctionHelper.CheckArguments(Parameters, args); MethodContext context = new MethodContext(Class, target, Closure); FunctionHelper.SetArguments(context, Parameters, args); ExecuteResult result = context.ExecuteStatements(Statements); if (result.FlowControl == FlowControl.Return) { return((IScriptObject)result.Data); } else { return(ScriptNull.Instance); } }