public JintEngine(Options options) { this.visitor = new ExecutionVisitor(options); this.AllowClr = true; this.permissionSet = new PermissionSet(PermissionState.None); this.MaxRecursions = 400; JsObject global = this.visitor.Global as JsObject; global["ToBoolean"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, bool>(Convert.ToBoolean)); global["ToByte"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, byte>(Convert.ToByte)); global["ToChar"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, char>(Convert.ToChar)); global["ToDateTime"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, DateTime>(Convert.ToDateTime)); global["ToDecimal"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, Decimal>(Convert.ToDecimal)); global["ToDouble"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, double>(Convert.ToDouble)); global["ToInt16"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, short>(Convert.ToInt16)); global["ToInt32"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, int>(Convert.ToInt32)); global["ToInt64"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, long>(Convert.ToInt64)); global["ToSByte"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, sbyte>(Convert.ToSByte)); global["ToSingle"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, float>(Convert.ToSingle)); global["ToString"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, string>(Convert.ToString)); global["ToUInt16"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, ushort>(Convert.ToUInt16)); global["ToUInt32"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, uint>(Convert.ToUInt32)); global["ToUInt64"] = (JsInstance)this.visitor.Global.FunctionClass.New((Delegate) new Func <object, ulong>(Convert.ToUInt64)); this.BreakPoints = new List <BreakPoint>(); }
public JintEngine(Options options) { visitor = new ExecutionVisitor(options, this as IScriptEngineContext); CurrentVisitor = visitor; AllowClr = true; //permissionSet = new PermissionSet(PermissionState.None); visitor.GlobalScope.Prototype["ToBoolean"] = visitor.Global.FunctionClass.New(new Func <object, Boolean>(Convert.ToBoolean)); visitor.GlobalScope.Prototype["ToByte"] = visitor.Global.FunctionClass.New(new Func <object, Byte>(Convert.ToByte)); visitor.GlobalScope.Prototype["ToChar"] = visitor.Global.FunctionClass.New(new Func <object, Char>(Convert.ToChar)); visitor.GlobalScope.Prototype["ToDateTime"] = visitor.Global.FunctionClass.New(new Func <object, DateTime>(Convert.ToDateTime)); visitor.GlobalScope.Prototype["ToDecimal"] = visitor.Global.FunctionClass.New(new Func <object, Decimal>(Convert.ToDecimal)); visitor.GlobalScope.Prototype["ToDouble"] = visitor.Global.FunctionClass.New(new Func <object, Double>(Convert.ToDouble)); visitor.GlobalScope.Prototype["ToInt16"] = visitor.Global.FunctionClass.New(new Func <object, Int16>(Convert.ToInt16)); visitor.GlobalScope.Prototype["ToInt32"] = visitor.Global.FunctionClass.New(new Func <object, Int32>(Convert.ToInt32)); visitor.GlobalScope.Prototype["ToInt64"] = visitor.Global.FunctionClass.New(new Func <object, Int64>(Convert.ToInt64)); visitor.GlobalScope.Prototype["ToSByte"] = visitor.Global.FunctionClass.New(new Func <object, SByte>(Convert.ToSByte)); visitor.GlobalScope.Prototype["ToSingle"] = visitor.Global.FunctionClass.New(new Func <object, Single>(Convert.ToSingle)); visitor.GlobalScope.Prototype["ToString"] = visitor.Global.FunctionClass.New(new Func <object, String>(Convert.ToString)); visitor.GlobalScope.Prototype["ToUInt16"] = visitor.Global.FunctionClass.New(new Func <object, UInt16>(Convert.ToUInt16)); visitor.GlobalScope.Prototype["ToUInt32"] = visitor.Global.FunctionClass.New(new Func <object, UInt32>(Convert.ToUInt32)); visitor.GlobalScope.Prototype["ToUInt64"] = visitor.Global.FunctionClass.New(new Func <object, UInt64>(Convert.ToUInt64)); BreakPoints = new List <BreakPoint>(); }
/// <summary> /// 15.4.4.2 /// </summary> /// <param name="target"></param> /// <param name="parameters"></param> /// <returns></returns> public JsInstance ToStringImpl(JsArray target, JsInstance[] parameters) { JsArray result = Global.ArrayClass.New(); for (int i = 0; i < target.Length; i++) { var obj = (JsDictionaryObject)target[i.ToString()]; if (ExecutionVisitor.IsNullOrUndefined(obj)) { result[i.ToString()] = Global.StringClass.New(); } else { var function = obj["toString"] as JsFunction; if (function != null) { Global.Visitor.ExecuteFunction(function, obj, parameters); result[i.ToString()] = Global.Visitor.Returned; } else { result[i.ToString()] = Global.StringClass.New(); } } } return(Global.StringClass.New(result.ToString())); }
public JsGlobal(ExecutionVisitor visitor, Options options) { this.Options = options; this.Visitor = visitor; this["null"] = JsNull.Instance; #region Global Classes this["Object"] = ObjectClass = new JsObjectConstructor(this); this["Function"] = FunctionClass = new JsFunctionConstructor(this); this["Array"] = ArrayClass = new JsArrayConstructor(this); this["Boolean"] = BooleanClass = new JsBooleanConstructor(this); this["Date"] = DateClass = new JsDateConstructor(this); this["Error"] = ErrorClass = new JsErrorConstructor(this, "Error"); this["EvalError"] = EvalErrorClass = new JsErrorConstructor(this, "EvalError"); this["RangeError"] = RangeErrorClass = new JsErrorConstructor(this, "RangeError"); this["ReferenceError"] = ReferenceErrorClass = new JsErrorConstructor(this, "ReferenceError"); this["SyntaxError"] = SyntaxErrorClass = new JsErrorConstructor(this, "SyntaxError"); this["TypeError"] = TypeErrorClass = new JsErrorConstructor(this, "TypeError"); this["URIError"] = URIErrorClass = new JsErrorConstructor(this, "URIError"); this["Number"] = NumberClass = new JsNumberConstructor(this); this["RegExp"] = RegExpClass = new JsRegExpConstructor(this); this["String"] = StringClass = new JsStringConstructor(this); this["Math"] = MathClass = new JsMathConstructor(this); this.Prototype = ObjectClass.Prototype; #endregion MathClass.Prototype = ObjectClass.Prototype; foreach (JsInstance c in this.GetValues()) { if (c is JsConstructor) { ((JsConstructor)c).InitPrototype(this); } } #region Global Properties this["NaN"] = NumberClass["NaN"]; // 15.1.1.1 this["Infinity"] = NumberClass["POSITIVE_INFINITY"]; // // 15.1.1.2 this["undefined"] = JsUndefined.Instance; // 15.1.1.3 this[JsInstance.THIS] = this; #endregion #region Global Functions this["eval"] = new JsFunctionWrapper(Eval); // 15.1.2.1 this["parseInt"] = new JsFunctionWrapper(ParseInt); // 15.1.2.2 this["parseFloat"] = new JsFunctionWrapper(ParseFloat); // 15.1.2.3 this["isNaN"] = new JsFunctionWrapper(IsNaN); this["isFinite"] = new JsFunctionWrapper(isFinite); this["decodeURI"] = new JsFunctionWrapper(DecodeURI); this["encodeURI"] = new JsFunctionWrapper(EncodeURI); this["decodeURIComponent"] = new JsFunctionWrapper(DecodeURIComponent); this["encodeURIComponent"] = new JsFunctionWrapper(EncodeURIComponent); #endregion }
public JintEngine(Options options) { visitor = new ExecutionVisitor(options); AllowClr = true; permissionSet = new PermissionSet(PermissionState.None); MaxRecursions = 400; JsObject global = visitor.Global as JsObject; global["ToBoolean"] = visitor.Global.FunctionClass.New(new JintFunc <object, Boolean>(Convert.ToBoolean)); global["ToByte"] = visitor.Global.FunctionClass.New(new JintFunc <object, Byte>(Convert.ToByte)); global["ToChar"] = visitor.Global.FunctionClass.New(new JintFunc <object, Char>(Convert.ToChar)); global["ToDateTime"] = visitor.Global.FunctionClass.New(new JintFunc <object, DateTime>(Convert.ToDateTime)); global["ToDecimal"] = visitor.Global.FunctionClass.New(new JintFunc <object, Decimal>(Convert.ToDecimal)); global["ToDouble"] = visitor.Global.FunctionClass.New(new JintFunc <object, Double>(Convert.ToDouble)); global["ToInt16"] = visitor.Global.FunctionClass.New(new JintFunc <object, Int16>(Convert.ToInt16)); global["ToInt32"] = visitor.Global.FunctionClass.New(new JintFunc <object, Int32>(Convert.ToInt32)); global["ToInt64"] = visitor.Global.FunctionClass.New(new JintFunc <object, Int64>(Convert.ToInt64)); global["ToSByte"] = visitor.Global.FunctionClass.New(new JintFunc <object, SByte>(Convert.ToSByte)); global["ToSingle"] = visitor.Global.FunctionClass.New(new JintFunc <object, Single>(Convert.ToSingle)); global["ToString"] = visitor.Global.FunctionClass.New(new JintFunc <object, String>(Convert.ToString)); global["ToUInt16"] = visitor.Global.FunctionClass.New(new JintFunc <object, UInt16>(Convert.ToUInt16)); global["ToUInt32"] = visitor.Global.FunctionClass.New(new JintFunc <object, UInt32>(Convert.ToUInt32)); global["ToUInt64"] = visitor.Global.FunctionClass.New(new JintFunc <object, UInt64>(Convert.ToUInt64)); global["StringFormat"] = visitor.Global.FunctionClass.New(new JintFunc <string, JsArray, string>(StringFormatHelper)); BreakPoints = new List <BreakPoint>(); }
internal ScriptBlockParameterBinder(ReadOnlyCollection <ParameterAst> scriptParameters, ExecutionContext context, ExecutionVisitor executionVisitor) { _scriptParameters = scriptParameters; _executionContext = context; _executionVisitor = executionVisitor; }
public JsInstance ToStringImpl(JsArray target, JsInstance[] parameters) { JsArray jsArray = this.Global.ArrayClass.New(); for (int index = 0; index < target.Length; ++index) { JsDictionaryObject _this = (JsDictionaryObject)target[index.ToString()]; if (ExecutionVisitor.IsNullOrUndefined((JsInstance)_this)) { jsArray[index.ToString()] = (JsInstance)this.Global.StringClass.New(); } else { JsFunction function = _this["toString"] as JsFunction; if (function != null) { this.Global.Visitor.ExecuteFunction(function, _this, parameters); jsArray[index.ToString()] = this.Global.Visitor.Returned; } else { jsArray[index.ToString()] = (JsInstance)this.Global.StringClass.New(); } } } return((JsInstance)this.Global.StringClass.New(jsArray.ToString())); }
public JintEngine(Options options) { visitor = new ExecutionVisitor(options); AllowClr = true; permissionSet = new PermissionSet(PermissionState.None); MaxRecursions = 400; JsObject global = visitor.Global as JsObject; global["ToBoolean"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, Boolean>(Convert.ToBoolean)); global["ToByte"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, Byte>(Convert.ToByte)); global["ToChar"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, Char>(Convert.ToChar)); global["ToDateTime"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, DateTime>(Convert.ToDateTime)); global["ToDecimal"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, Decimal>(Convert.ToDecimal)); global["ToDouble"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, Double>(Convert.ToDouble)); global["ToInt16"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, Int16>(Convert.ToInt16)); global["ToInt32"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, Int32>(Convert.ToInt32)); global["ToInt64"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, Int64>(Convert.ToInt64)); global["ToSByte"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, SByte>(Convert.ToSByte)); global["ToSingle"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, Single>(Convert.ToSingle)); global["ToString"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, String>(Convert.ToString)); global["ToUInt16"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, UInt16>(Convert.ToUInt16)); global["ToUInt32"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, UInt32>(Convert.ToUInt32)); global["ToUInt64"] = visitor.Global.FunctionClass.New(new Delegates.Func<object, UInt64>(Convert.ToUInt64)); BreakPoints = new List<BreakPoint>(); }
public JintEngine(Options options) { Visitor = new ExecutionVisitor(options); permissionSet = new PermissionSet(PermissionState.None); Visitor.AllowClr = allowClr; MaxRecursions = 400; MaxSteps = 100 * 1000; var global = Visitor.Global as JsObject; global["ToBoolean"] = Visitor.Global.FunctionClass.New(new Func <object, Boolean>(Convert.ToBoolean)); global["ToByte"] = Visitor.Global.FunctionClass.New(new Func <object, Byte>(Convert.ToByte)); global["ToChar"] = Visitor.Global.FunctionClass.New(new Func <object, Char>(Convert.ToChar)); global["ToDateTime"] = Visitor.Global.FunctionClass.New(new Func <object, DateTime>(Convert.ToDateTime)); global["ToDecimal"] = Visitor.Global.FunctionClass.New(new Func <object, Decimal>(Convert.ToDecimal)); global["ToDouble"] = Visitor.Global.FunctionClass.New(new Func <object, Double>(Convert.ToDouble)); global["ToInt16"] = Visitor.Global.FunctionClass.New(new Func <object, Int16>(Convert.ToInt16)); global["ToInt32"] = Visitor.Global.FunctionClass.New(new Func <object, Int32>(Convert.ToInt32)); global["ToInt64"] = Visitor.Global.FunctionClass.New(new Func <object, Int64>(Convert.ToInt64)); global["ToSByte"] = Visitor.Global.FunctionClass.New(new Func <object, SByte>(Convert.ToSByte)); global["ToSingle"] = Visitor.Global.FunctionClass.New(new Func <object, Single>(Convert.ToSingle)); global["ToString"] = Visitor.Global.FunctionClass.New(new Func <object, String>(Convert.ToString)); global["ToUInt16"] = Visitor.Global.FunctionClass.New(new Func <object, UInt16>(Convert.ToUInt16)); global["ToUInt32"] = Visitor.Global.FunctionClass.New(new Func <object, UInt32>(Convert.ToUInt32)); global["ToUInt64"] = Visitor.Global.FunctionClass.New(new Func <object, UInt64>(Convert.ToUInt64)); BreakPoints = new List <BreakPoint>(); }
private bool RunTests(TestOptions options, IFrontController frontController, IServiceProvider services) { var visitor = new ExecutionVisitor((services.GetService(typeof(ITestSinkFactory)) as ITestSinkFactory)?.CreateExecutionSink(services) ?? new DefaultTestExecutionSink()); frontController.RunAll(visitor, options, options); visitor.Finished.WaitOne(); return(!visitor.HasFailures); }
public Collection <PSObject> InvokeScript(string script, bool useNewScope, PipelineResultTypes writeToPipeline, IList input, params object[] args) { ScriptBlock scriptBlock = NewScriptBlock(script); var executionVisitor = new ExecutionVisitor(executionContext, commandRuntime); scriptBlock.Ast.Visit(executionVisitor); return(new Collection <PSObject>()); }
private void ExecuteSaveBreedCommand(Window window) { if (Thing != null) { World.Instance.Breeds.Remove(Thing.Id); //Temporarily remove old Breed from World } Messages = ErrorVisitor.CheckBreedScriptErrors(Script, World.Instance.ToScope()); if (Messages.Count(message => message.Severity == ErrorSeverity.Error) == 0) { var createdBreed = ExecutionVisitor.BuildBreed(Script, out var executionErrors); if (executionErrors.Count > 0 || createdBreed == null) { Messages = executionErrors; if (createdBreed != null) { World.Instance.Breeds.Remove(createdBreed.Id); //remove newly inserted breed from World } if (Thing != null) { World.Instance.Breeds.Add(Thing.Id, Thing); //Reinsert old breed to World } MessageBox.Show("Failed to save Breed."); } else { Id = createdBreed.Id; type = createdBreed.GetType().Name; Script = createdBreed.Serialize(); SpriteModel = Breeds.MainViewModel.SpriteModels.Items.FirstOrDefault(spriteModel => spriteModel.Id == createdBreed.Model.Id); if (Thing == null) { window.DialogResult = true; } else { foreach (var instance in World.Instance.Instances) { if (instance.Value.Breed == Thing) { instance.Value.Breed = createdBreed; //todo: should update $ID texts in scripts? } } NotifyReferencesOfChange(); } Thing = createdBreed; window.Close(); } } else { if (Thing != null) { World.Instance.Breeds.Add(Thing.Id, Thing); //Reinsert old breed to World } } }
private void CreateOwnScope() { _originalContext = ExecutionContext; var executionSessionState = CommandInfo.Module != null ? CommandInfo.Module.SessionState : ExecutionContext.SessionState; _scopedContext = ExecutionContext.Clone(executionSessionState, _scriptBlockInfo.ScopeUsage); _scopedExecutionVisitor = new ExecutionVisitor(_scopedContext, CommandRuntime, false); }
public override void Visit(ActivatorInstance activator) { var characterSymbol = new Symbol("Character", TypeSystem.Instance["CharacterInstance"], character.Id); ExecutionVisitor.ExecuteRunBlock(activator, "Activated", new List <Symbol>() { characterSymbol }); success = true; }
object MarshalJsFunctionHelper(JsFunction func, Type delegateType) { // create independent visitor ExecutionVisitor visitor = new ExecutionVisitor(m_global, new JsScope((JsObject)m_global)); visitor.PermissionSet = ((ExecutionVisitor)m_global.Visitor).PermissionSet; JsFunctionDelegate wrapper = new JsFunctionDelegate(visitor, func, JsNull.Instance, delegateType); return(wrapper.GetDelegate()); }
public override void Visit(CharacterInstance subjectCharacter) { var initiatorSymbol = new Symbol("Character", TypeSystem.Instance["CharacterInstance"], initiator.Id); var topicSymbol = new Symbol("Topic", TypeSystem.Instance["String"], topicId); ExecutionVisitor.ExecuteRunBlock(subjectCharacter, "TalkedTo", new List <Symbol>() { initiatorSymbol, topicSymbol }); success = true; }
public override void LoadContent() { if (worldScriptFileName != null) { World.Instance.Game = ScreenManager.Game; ExecutionVisitor.BuildWorldFromFile(worldScriptFileName, out var messages); EngineVariables.ConsoleContents.AddRange(messages.Select(message => message.ToString())); } ScreenManager.Game.ResetElapsedTime(); base.LoadContent(); }
protected override void ProcessRecord() { this.ExecutionContext.SetVariable("_", this.InputObject); var executionVisitor = new ExecutionVisitor( this.ExecutionContext, (PipelineCommandRuntime)CommandRuntime ); this.Process.Ast.Visit(executionVisitor); }
public override void Visit(EquipmentInstance equipment) { //todo: check if equipped/unequipped var characterSymbol = new Symbol("Character", TypeSystem.Instance["CharacterInstance"], equipper.Id); ExecutionVisitor.ExecuteRunBlock(equipment, "Equipped", new List <Symbol>() { characterSymbol }); success = true; }
public override void Visit(ConsumableInstance consumable) { consumer.Items.Remove(consumable); World.Instance.Instances.Remove(consumable.Id); var characterSymbol = new Symbol("Character", TypeSystem.Instance["CharacterInstance"], consumer.Id); ExecutionVisitor.ExecuteRunBlock(consumable, "Consumed", new List <Symbol>() { characterSymbol }); success = true; }
public override void Visit(ItemInstance item) { item.Region.RemoveInstance(item); picker.Items.Add(item); var characterSymbol = new Symbol("Character", TypeSystem.Instance["CharacterInstance"], picker.Id); ExecutionVisitor.ExecuteRunBlock(item, "PickedUp", new List <Symbol>() { characterSymbol }); success = true; }
protected override void ProcessRecord() { this.ExecutionContext.SetVariable("_", this.InputObject); var executionVisitor = new ExecutionVisitor( this.ExecutionContext, (PipelineCommandRuntime)CommandRuntime ); this.Process.Ast.Visit(executionVisitor); this.ExecutionContext.outputStreamWriter.Write(((PipelineCommandRuntime)CommandRuntime).outputResults.Read(), true); }
private void FilterByScript() { ExecutionContext.SetVariable("_", InputObject); var executionVisitor = new ExecutionVisitor(ExecutionContext, (PipelineCommandRuntime)CommandRuntime); object result = executionVisitor.EvaluateAst(FilterScript.Ast, true); if (IsTrue(result)) { WriteObject(InputObject); } }
public override void Visit(ItemInstance item) { dropper.Items.Remove(item); dropper.Region.AddInstance(item); item.Position = dropper.Position; var characterSymbol = new Symbol("Character", TypeSystem.Instance["CharacterInstance"], dropper.Id); ExecutionVisitor.ExecuteRunBlock(item, "Dropped", new List <Symbol>() { characterSymbol }); success = true; }
public JsGlobal(ExecutionVisitor visitor, Options options) : base((JsObject)JsNull.Instance) { this.Options = options; this.Visitor = (IJintVisitor)visitor; this["null"] = (JsInstance)JsNull.Instance; JsObject jsObject = new JsObject((JsObject)JsNull.Instance); JsFunction jsFunction = (JsFunction) new JsFunctionWrapper((Func <JsInstance[], JsInstance>)(arguments => (JsInstance)JsUndefined.Instance), jsObject); this["Function"] = (JsInstance)(this.FunctionClass = new JsFunctionConstructor((IGlobal)this, (JsObject)jsFunction)); this["Object"] = (JsInstance)(this.ObjectClass = new JsObjectConstructor((IGlobal)this, (JsObject)jsFunction, jsObject)); this.ObjectClass.InitPrototype((IGlobal)this); this["Array"] = (JsInstance)(this.ArrayClass = new JsArrayConstructor((IGlobal)this)); this["Boolean"] = (JsInstance)(this.BooleanClass = new JsBooleanConstructor((IGlobal)this)); this["Date"] = (JsInstance)(this.DateClass = new JsDateConstructor((IGlobal)this)); this["Error"] = (JsInstance)(this.ErrorClass = new JsErrorConstructor((IGlobal)this, "Error")); this["EvalError"] = (JsInstance)(this.EvalErrorClass = new JsErrorConstructor((IGlobal)this, "EvalError")); this["RangeError"] = (JsInstance)(this.RangeErrorClass = new JsErrorConstructor((IGlobal)this, "RangeError")); this["ReferenceError"] = (JsInstance)(this.ReferenceErrorClass = new JsErrorConstructor((IGlobal)this, "ReferenceError")); this["SyntaxError"] = (JsInstance)(this.SyntaxErrorClass = new JsErrorConstructor((IGlobal)this, "SyntaxError")); this["TypeError"] = (JsInstance)(this.TypeErrorClass = new JsErrorConstructor((IGlobal)this, "TypeError")); this["URIError"] = (JsInstance)(this.URIErrorClass = new JsErrorConstructor((IGlobal)this, "URIError")); this["Number"] = (JsInstance)(this.NumberClass = new JsNumberConstructor((IGlobal)this)); this["RegExp"] = (JsInstance)(this.RegExpClass = new JsRegExpConstructor((IGlobal)this)); this["String"] = (JsInstance)(this.StringClass = new JsStringConstructor((IGlobal)this)); this["Math"] = (JsInstance)(this.MathClass = new JsMathConstructor((IGlobal)this)); foreach (JsInstance jsInstance in this.GetValues()) { if (jsInstance is JsConstructor) { ((JsConstructor)jsInstance).InitPrototype((IGlobal)this); } } this[nameof(NaN)] = this.NumberClass[nameof(NaN)]; this["Infinity"] = this.NumberClass["POSITIVE_INFINITY"]; this["undefined"] = (JsInstance)JsUndefined.Instance; this[JsScope.THIS] = (JsInstance)this; this["eval"] = (JsInstance) new JsFunctionWrapper(new Func <JsInstance[], JsInstance>(this.Eval), this.FunctionClass.PrototypeProperty); this["parseInt"] = (JsInstance) new JsFunctionWrapper(new Func <JsInstance[], JsInstance>(this.ParseInt), this.FunctionClass.PrototypeProperty); this["parseFloat"] = (JsInstance) new JsFunctionWrapper(new Func <JsInstance[], JsInstance>(this.ParseFloat), this.FunctionClass.PrototypeProperty); this["isNaN"] = (JsInstance) new JsFunctionWrapper(new Func <JsInstance[], JsInstance>(this.IsNaN), this.FunctionClass.PrototypeProperty); this["isFinite"] = (JsInstance) new JsFunctionWrapper(new Func <JsInstance[], JsInstance>(this.isFinite), this.FunctionClass.PrototypeProperty); this["decodeURI"] = (JsInstance) new JsFunctionWrapper(new Func <JsInstance[], JsInstance>(this.DecodeURI), this.FunctionClass.PrototypeProperty); this["encodeURI"] = (JsInstance) new JsFunctionWrapper(new Func <JsInstance[], JsInstance>(this.EncodeURI), this.FunctionClass.PrototypeProperty); this["decodeURIComponent"] = (JsInstance) new JsFunctionWrapper(new Func <JsInstance[], JsInstance>(this.DecodeURIComponent), this.FunctionClass.PrototypeProperty); this["encodeURIComponent"] = (JsInstance) new JsFunctionWrapper(new Func <JsInstance[], JsInstance>(this.EncodeURIComponent), this.FunctionClass.PrototypeProperty); this.Marshaller = new Marshaller((IGlobal)this); this.Marshaller.InitTypes(); }
public override void Visit(CreatureInstance defender) { var damage = attacker.Damage - (defender.Breed as Creature).Protection; var damageDealt = Math.Min(damage, defender.CurrentHealth); defender.CurrentHealth -= damageDealt; var creatureSymbol = new Symbol("Creature", TypeSystem.Instance["CreatureInstance"], attacker.Id); var damageSymbol = new Symbol("Damage", TypeSystem.Instance["Number"], damageDealt.ToString()); ExecutionVisitor.ExecuteRunBlock(defender, "Attacked", new List <Symbol>() { creatureSymbol, damageSymbol }); success = true; }
public virtual ThingInstance Spawn(string instanceId = null) { ThingInstance instance = System.Activator.CreateInstance(InstanceType) as ThingInstance; instance.Breed = this; instance.Id = instanceId ?? Guid.NewGuid().ToString(); instance.IsIdGenerated = instanceId == null; foreach (var variable in Variables.Values) { instance.Variables.Add(variable.Name, new Symbol(variable)); } World.Instance.Instances.Add(instance.Id, instance); ExecutionVisitor.ExecuteRunBlock(instance, "Spawned", new List <Symbol>() { }); return(instance); }
public Collection <PSObject> InvokeScript(string script, bool useNewScope, PipelineResultTypes writeToPipeline, IList input, params object[] args) { var context = useNewScope ? executionContext.Clone(ScopeUsages.NewScriptScope) : executionContext; //Let's see on the long run if there is an easier solution for this #ExecutionContextChange //we need to change the global execution context to change the scope we are currently operating in executionContext.CurrentRunspace.ExecutionContext = context; try { ScriptBlock scriptBlock = NewScriptBlock(script); var executionVisitor = new ExecutionVisitor(context, commandRuntime); // sburnicki - handle ExitException scriptBlock.Ast.Visit(executionVisitor); } finally //make sure we set back the old execution context, no matter what happened { executionContext.CurrentRunspace.ExecutionContext = executionContext; } return(new Collection <PSObject>()); }
public CachedTypeResolver(ExecutionVisitor visitor) { _visitor = visitor; }
public JsGlobal(ExecutionVisitor visitor, Options options) : base(JsNull.Instance) { this.Options = options; this.Visitor = visitor; this["null"] = JsNull.Instance; JsObject objectProrotype = new JsObject(JsNull.Instance); JsFunction functionPrototype = new JsFunctionWrapper( delegate(JsInstance[] arguments) { return JsUndefined.Instance; }, objectProrotype ); Marshaller = new Marshaller(this); #region Global Classes this["Function"] = FunctionClass = new JsFunctionConstructor(this, functionPrototype); this["Object"] = ObjectClass = new JsObjectConstructor(this, functionPrototype, objectProrotype); ObjectClass.InitPrototype(this); this["Array"] = ArrayClass = new JsArrayConstructor(this); this["Boolean"] = BooleanClass = new JsBooleanConstructor(this); this["Date"] = DateClass = new JsDateConstructor(this); this["Error"] = ErrorClass = new JsErrorConstructor(this, "Error"); this["EvalError"] = EvalErrorClass = new JsErrorConstructor(this, "EvalError"); this["RangeError"] = RangeErrorClass = new JsErrorConstructor(this, "RangeError"); this["ReferenceError"] = ReferenceErrorClass = new JsErrorConstructor(this, "ReferenceError"); this["SyntaxError"] = SyntaxErrorClass = new JsErrorConstructor(this, "SyntaxError"); this["TypeError"] = TypeErrorClass = new JsErrorConstructor(this, "TypeError"); this["URIError"] = URIErrorClass = new JsErrorConstructor(this, "URIError"); this["Number"] = NumberClass = new JsNumberConstructor(this); this["RegExp"] = RegExpClass = new JsRegExpConstructor(this); this["String"] = StringClass = new JsStringConstructor(this); this["Math"] = MathClass = new JsMathConstructor(this); // 15.1 prototype of the global object varies on the implementation //this.Prototype = ObjectClass.PrototypeProperty; #endregion foreach (JsInstance c in this.GetValues()) { if (c is JsConstructor) { ((JsConstructor)c).InitPrototype(this); } } #region Global Properties this["NaN"] = NumberClass["NaN"]; // 15.1.1.1 this["Infinity"] = NumberClass["POSITIVE_INFINITY"]; // // 15.1.1.2 this["undefined"] = JsUndefined.Instance; // 15.1.1.3 this[JsScope.THIS] = this; #endregion #region Global Functions // every embed function should have a prototype FunctionClass.PrototypeProperty - 15. this["eval"] = new JsFunctionWrapper(Eval, FunctionClass.PrototypeProperty); // 15.1.2.1 this["parseInt"] = new JsFunctionWrapper(ParseInt, FunctionClass.PrototypeProperty); // 15.1.2.2 this["parseFloat"] = new JsFunctionWrapper(ParseFloat, FunctionClass.PrototypeProperty); // 15.1.2.3 this["isNaN"] = new JsFunctionWrapper(IsNaN, FunctionClass.PrototypeProperty); this["isFinite"] = new JsFunctionWrapper(isFinite, FunctionClass.PrototypeProperty); this["decodeURI"] = new JsFunctionWrapper(DecodeURI, FunctionClass.PrototypeProperty); this["encodeURI"] = new JsFunctionWrapper(EncodeURI, FunctionClass.PrototypeProperty); this["decodeURIComponent"] = new JsFunctionWrapper(DecodeURIComponent, FunctionClass.PrototypeProperty); this["encodeURIComponent"] = new JsFunctionWrapper(EncodeURIComponent, FunctionClass.PrototypeProperty); #endregion Marshaller.InitTypes(); }
public JsGlobal(ExecutionVisitor visitor, Options options) : base(JsNull.Instance) { this.Options = options; this.Visitor = visitor; this["null"] = JsNull.Instance; JsObject objectProrotype = new JsObject(JsNull.Instance); JsFunction functionPrototype = new JsFunctionWrapper( delegate(JsInstance[] arguments) { return(JsUndefined.Instance); }, objectProrotype ); Marshaller = new Marshaller(this); #region Global Classes this["Function"] = FunctionClass = new JsFunctionConstructor(this, functionPrototype); this["Object"] = ObjectClass = new JsObjectConstructor(this, functionPrototype, objectProrotype); ObjectClass.InitPrototype(this); this["Array"] = ArrayClass = new JsArrayConstructor(this); this["Boolean"] = BooleanClass = new JsBooleanConstructor(this); this["Date"] = DateClass = new JsDateConstructor(this); this["Error"] = ErrorClass = new JsErrorConstructor(this, "Error"); this["EvalError"] = EvalErrorClass = new JsErrorConstructor(this, "EvalError"); this["RangeError"] = RangeErrorClass = new JsErrorConstructor(this, "RangeError"); this["ReferenceError"] = ReferenceErrorClass = new JsErrorConstructor(this, "ReferenceError"); this["SyntaxError"] = SyntaxErrorClass = new JsErrorConstructor(this, "SyntaxError"); this["TypeError"] = TypeErrorClass = new JsErrorConstructor(this, "TypeError"); this["URIError"] = URIErrorClass = new JsErrorConstructor(this, "URIError"); this["Number"] = NumberClass = new JsNumberConstructor(this); this["RegExp"] = RegExpClass = new JsRegExpConstructor(this); this["String"] = StringClass = new JsStringConstructor(this); this["Math"] = MathClass = new JsMathConstructor(this); // 15.1 prototype of the global object varies on the implementation //this.Prototype = ObjectClass.PrototypeProperty; #endregion foreach (JsInstance c in this.GetValues()) { if (c is JsConstructor) { ((JsConstructor)c).InitPrototype(this); } } #region Global Properties this["NaN"] = NumberClass["NaN"]; // 15.1.1.1 this["Infinity"] = NumberClass["POSITIVE_INFINITY"]; // // 15.1.1.2 this["undefined"] = JsUndefined.Instance; // 15.1.1.3 this[JsScope.THIS] = this; #endregion #region Global Functions // every embed function should have a prototype FunctionClass.PrototypeProperty - 15. this["eval"] = new JsFunctionWrapper(Eval, FunctionClass.PrototypeProperty); // 15.1.2.1 this["parseInt"] = new JsFunctionWrapper(ParseInt, FunctionClass.PrototypeProperty); // 15.1.2.2 this["parseFloat"] = new JsFunctionWrapper(ParseFloat, FunctionClass.PrototypeProperty); // 15.1.2.3 this["isNaN"] = new JsFunctionWrapper(IsNaN, FunctionClass.PrototypeProperty); this["isFinite"] = new JsFunctionWrapper(isFinite, FunctionClass.PrototypeProperty); this["decodeURI"] = new JsFunctionWrapper(DecodeURI, FunctionClass.PrototypeProperty); this["encodeURI"] = new JsFunctionWrapper(EncodeURI, FunctionClass.PrototypeProperty); this["decodeURIComponent"] = new JsFunctionWrapper(DecodeURIComponent, FunctionClass.PrototypeProperty); this["encodeURIComponent"] = new JsFunctionWrapper(EncodeURIComponent, FunctionClass.PrototypeProperty); #endregion Marshaller.InitTypes(); }
public IMethodInvoker GetMethodInvoker(ExecutionVisitor visitor) { return(new MethodInvoker(this)); }
protected bool OnStep(ExecutionVisitor sender, DebugInformation info) { bool result = true; if (Step != null) { result = Step(this, info); } if (Break != null && result) { BreakPoint breakpoint = BreakPoints.Find(l => { bool afterStart, beforeEnd; afterStart = l.Line > info.CurrentStatement.Source.Start.Line || (l.Line == info.CurrentStatement.Source.Start.Line && l.Char >= info.CurrentStatement.Source.Start.Char); if (!afterStart) { return false; } beforeEnd = l.Line < info.CurrentStatement.Source.Stop.Line || (l.Line == info.CurrentStatement.Source.Stop.Line && l.Char <= info.CurrentStatement.Source.Stop.Char); if (!beforeEnd) { return false; } if (!String.IsNullOrEmpty(l.Condition)) { return Convert.ToBoolean(this.Run(l.Condition)); } return true; }); if (breakpoint != null) { result = Break(this, info); } } return result; }