Esempio n. 1
0
		public void CheckinScript(ScriptedPatchRequest request, Jint.JintEngine context)
		{
			CachedResult value;
			if (cacheDic.TryGetValue(request, out value))
			{
				if (value.Queue.Count > 20)
					return;
				value.Queue.Enqueue(context);
				return;
			}
			cacheDic.AddOrUpdate(request, patchRequest =>
			{
				var queue = new ConcurrentQueue<Jint.JintEngine>();
				queue.Enqueue(context);
				return new CachedResult
				{
					Queue = queue,
					Timestamp = SystemTime.UtcNow,
					Usage = 1
				};
			}, (patchRequest, result) =>
			{
				result.Queue.Enqueue(context);
				return result;
			});
		}
		public static JScriptAliasCommand Create(string AliasName, string Cost, int CooldownSeconds, string PermissionNeeded, Jint.Native.JsValue func)
		{
			return new JScriptAliasCommand() {
				CommandAlias = AliasName,
				CommandsToExecute = null,
				CooldownSeconds = CooldownSeconds,
				Permissions = PermissionNeeded,
				func = func
			};
		}
Esempio n. 3
0
 public bool TryGet(string name, out Jint.Native.Descriptor descriptor)
 {
     int index = keys.IndexOf(name);
     if (index < 0)
     {
         descriptor = null;
         return false;
     }
     descriptor = values[index];
     return true;
 }
Esempio n. 4
0
 public Jint.Native.Descriptor Put(string name, Jint.Native.Descriptor descriptor)
 {
     Stack<Descriptor> stack;
     if (!bag.TryGetValue(name, out stack))
     {
         stack = new Stack<Descriptor>();
         bag.Add(name, stack);
     }
     stack.Push(descriptor);
     currentScope.Add(stack);
     return descriptor;
 }
Esempio n. 5
0
 public bool TryGet(string name, out Jint.Native.Descriptor descriptor)
 {
     if (lastAccessed != null && lastAccessed.Name == name)
     {
         descriptor = lastAccessed;
         return true;
     }
     bool result = bag.TryGet(name, out descriptor);
     if (result)
         lastAccessed = descriptor;
     return result;
 }
Esempio n. 6
0
        public static JsValue[] ToJsValueArray(this object[] args, Jint.Engine jsEngine)
        {
            JsValue[] jsValues = null;
            if (args == null) {
                return new JsValue[] { JsValue.Undefined };
            }

            jsValues = new JsValue[args.Length];

            for (int i = 0; i < args.Length; i++) {
                jsValues[i] = JsValue.FromObject(jsEngine, args[i]);
            }

            return jsValues;
        }
Esempio n. 7
0
 public void AddRecurring(int Hours, int Minutes, int Seconds, Jint.Native.JsValue Func)
 {
     lock (__recurringLock) {
         recurList.Add(new RecurringFunction(Hours, Minutes, Seconds, Func));
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Error handler wrapping for calling of JS functions.
        /// </summary>
        public static object CallJSFunction(Jint.Native.JsFunction func, params object[] funcParameters) {

            try {
                return scriptEngine.CallFunction(func, funcParameters);
            } catch (Jint.Native.JsException jsex ) {
                TShockAPI.Log.ConsoleError("aliascmd js: Javascript parse error: " + jsex.Value);
            } catch (Jint.JintException jex) {
                TShockAPI.Log.ConsoleError("aliascmd js: Javascript runtime error: " + jex.Message);
            } catch (Exception ex) {
                TShockAPI.Log.ConsoleError("aliascmd js: CLR error: " + ex.ToString());
            }

            return null;
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a JavaScript recurring function, with the specified 
        /// hours minutes and seconds which runs the supplied function.
        /// </summary>
        public RecurringFunction(int Hours, int Minutes, int Seconds, Jint.Native.JsValue Func)
        {
            this.RecurrenceID = Guid.NewGuid();
            this.Function = Func;

            this.Seconds += Hours * 3600;
            this.Seconds += Minutes * 60;
            this.Seconds += Seconds;

            this.NextRunTime = DateTime.UtcNow.Add(TimeSpan.FromSeconds(this.Seconds));
            //Console.WriteLine("jist recurring: Recurring Func {0}: next run time {1}", this.RecurrenceID, this.NextRunTime);
        }
Esempio n. 10
0
 public void AddAt(int Hours, int Minutes, Jint.Native.JsValue Func)
 {
     lock (__runAtLock) {
         runAtList.Add(new RunAt(Hours, Minutes, Func));
     }
 }
Esempio n. 11
0
 public override void Visit(Jint.Expressions.Program expression)
 {
     //all global vars are in fact closed on
 }
Esempio n. 12
0
 public bool TryGet(string name, out Jint.Native.Descriptor descriptor)
 {
     descriptor = Get(name);
     return descriptor != null;
 }
Esempio n. 13
0
 public override void Visit(Jint.Expressions.FunctionExpression expression)
 {
     //Look for identifiers
     Visit(expression.Statement);
 }
Esempio n. 14
0
 void Analyze(Jint.Expressions.Statement Stmt)
 {
     SetCurrentLineAndCharNos(Stmt);
     Type T = Stmt.GetType();
     switch (T.Name)
     {
         case("ArrayDeclaration"):
             ArrayDeclaration AD = (ArrayDeclaration)Stmt;
             Analyze(AD);
             break;
         case ("AssignmentExpression"):
             AssignmentExpression AE = (AssignmentExpression)Stmt;
             Analyze(AE);
             break;
         case ("BinaryExpression"):
             BinaryExpression BE = (BinaryExpression)Stmt;
             Analyze(BE);
             break;
         case ("BlockStatement"):
             BlockStatement BS = (BlockStatement)Stmt;
             Analyze(BS);
             break;
         case ("BreakStatement"):
             BreakStatement BrS = (BreakStatement)Stmt;
             Analyze(BrS);
             break;
         case ("CaseClause"):
             CaseClause CC = new CaseClause();
             try
             {
                 CC.Expression = (Expression)Stmt;
                 Analyze(CC);
             }
             catch { }
             break;
         case ("CatchClause"):
             try
             {
                 CatchClause CaC = new CatchClause("a", Stmt);
                 Analyze(CaC);
             }
             catch { }
             break;
         case ("ClrIdentifier"):
             ClrIdentifier CI = (ClrIdentifier)Stmt;
             Analyze(CI);
             break;
         case ("CommaOperatorStatement"):
             CommaOperatorStatement COS = (CommaOperatorStatement)Stmt;
             Analyze(COS);
             break;
         case ("ContinueStatement"):
             ContinueStatement CS = (ContinueStatement)Stmt;
             Analyze(CS);
             break;
         case ("DoWhileStatement"):
             DoWhileStatement DWS = (DoWhileStatement)Stmt;
             Analyze(DWS);
             break;
         case ("EmptyStatement"):
             EmptyStatement ES = (EmptyStatement)Stmt;
             Analyze(ES);
             break;
         case ("ExpressionStatement"):
             ExpressionStatement ExS = (ExpressionStatement)Stmt;
             Analyze(ExS);
             break;
         case ("FinallyClause"):
             try
             {
                 FinallyClause FC = new FinallyClause(Stmt);
                 Analyze(FC);
             }
             catch { }
             break;
         case ("ForEachInStatement"):
             ForEachInStatement FEIS = (ForEachInStatement)Stmt;
             Analyze(FEIS);
             break;
         case ("ForStatement"):
             ForStatement FoS = (ForStatement)Stmt;
             Analyze(FoS);
             break;
         case ("FunctionDeclarationStatement"):
             FunctionDeclarationStatement FDS = (FunctionDeclarationStatement)Stmt;
             Analyze(FDS);
             break;
         case ("FunctionExpression"):
             FunctionExpression FE = (FunctionExpression)Stmt;
             Analyze(FE);
             break;
         case ("Identifier"):
             Identifier Id = (Identifier)Stmt;
             Analyze(Id);
             break;
         case ("IfStatement"):
             IfStatement IS = (IfStatement)Stmt;
             Analyze(IS);
             break;
         case ("Indexer"):
             Indexer Ind = (Indexer)Stmt;
             Analyze(Ind);
             break;
         case ("JsonExpression"):
             JsonExpression JE = (JsonExpression)Stmt;
             Analyze(JE);
             break;
         case ("MemberExpression"):
             MemberExpression ME = (MemberExpression)Stmt;
             Analyze(ME);
             break;
         case ("MethodCall"):
             MethodCall MC = (MethodCall)Stmt;
             Analyze(MC);
             break;
         case ("NewExpression"):
             NewExpression NE = (NewExpression)Stmt;
             Analyze(NE);
             break;
         case ("Program"):
             Jint.Expressions.Program Pr = (Jint.Expressions.Program)Stmt;
             Analyze(Pr);
             break;
         case ("PropertyDeclarationExpression"):
             PropertyDeclarationExpression PDP = (PropertyDeclarationExpression)Stmt;
             Analyze(PDP);
             break;
         case ("PropertyExpression"):
             PropertyExpression PE = (PropertyExpression)Stmt;
             Analyze(PE);
             break;
         case ("RegexpExpression"):
             RegexpExpression RE = (RegexpExpression)Stmt;
             Analyze(RE);
             break;
         case ("ReturnStatement"):
             ReturnStatement RS = (ReturnStatement)Stmt;
             Analyze(RS);
             break;
         case ("SwitchStatement"):
             SwitchStatement SS = (SwitchStatement)Stmt;
             Analyze(SS);
             break;
         case ("TernaryExpression"):
             TernaryExpression TE = (TernaryExpression)Stmt;
             Analyze(TE);
             break;
         case ("ThrowStatement"):
             ThrowStatement TS = (ThrowStatement)Stmt;
             Analyze(TS);
             break;
         case ("TryStatement"):
             TryStatement TrS = (TryStatement)Stmt;
             Analyze(TrS);
             break;
         case ("UnaryExpression"):
             UnaryExpression UE = (UnaryExpression)Stmt;
             Analyze(UE);
             break;
         case ("ValueExpression"):
             ValueExpression VE = (ValueExpression)Stmt;
             Analyze(VE);
             break;
         case ("VariableDeclarationStatement"):
             VariableDeclarationStatement VDS = (VariableDeclarationStatement)Stmt;
             Analyze(VDS);
             break;
         case ("WhileStatement"):
             WhileStatement WS = (WhileStatement)Stmt;
             Analyze(WS);
             break;
         case ("WithStatement"):
             WithStatement WiS = (WithStatement)Stmt;
             Analyze(WiS);
             break;
     }
 }
Esempio n. 15
0
 int AddToJintStack(Jint.Debugger.SourceCodeDescriptor Source, JintState State, string Value)
 {
     JintStack.Add(new JintItem(Source, State, Value, this));
     return (JintStack.Count - 1);
 }
Esempio n. 16
0
 int AddToJintStack(Jint.Debugger.SourceCodeDescriptor Source, JintState State)
 {
     return AddToJintStack(Source, State, "");
 }
Esempio n. 17
0
 void Analyze(Jint.Expressions.Program Stmt)
 {
     SetCurrentLineAndCharNos(Stmt);
     if (Stmt.Statements != null) Analyze(Stmt.Statements);
 }
Esempio n. 18
0
 public override void Visit(Jint.Expressions.FunctionDeclarationStatement expression)
 {
     //all global vars are in fact closed on, so we don't care if this func refers to them
 }
Esempio n. 19
0
 public Jint.Native.Descriptor Put(string name, Jint.Native.Descriptor descriptor)
 {
     keys.Add(name, descriptor);
     return descriptor;
 }
Esempio n. 20
0
 void engine_Break(object sender, Jint.Debugger.DebugInformation e)
 {
     if (Break != null) Break(sender, e);
 }
Esempio n. 21
0
 void templateService_PrepareEngine(Jint.Engine engine)
 {
     engine.SetValue("write2", new Action<string>(s => engine.GetValue("write").As<Jint.Native.Function.FunctionInstance>().Call(engine.Global, new[] { new Jint.Native.JsValue(s) })));
 }
Esempio n. 22
0
        void jint_Step(object sender, Jint.Debugger.DebugInformation e)
        {
            if (!e.CurrentStatement.Source.Code.StartsWith("FindProxyForURL"))
            {
                listBox1.Invoke(new Action(delegate
                {
                    listBox1.Items.Add(string.Format("{0}: {1}\n", e.CurrentStatement.Source, e.CurrentStatement.Source.Code));
                    listBox1.SelectedIndex = listBox1.Items.Count - 1;
                    string source = e.CurrentStatement.Source.ToString();
                    if (source.Contains(" "))
                    {
                        string lineNumber = source.Split(' ')[1];
                        int line;
                        if (Int32.TryParse(lineNumber, out line))
                        {
                            textEditor1.HighlightActiveLine = true;
                            textEditor1.GotoLine(line - 1);
                        }
                    }

                }));
            }
            
        }
 protected override void RemoveEngineCustomizations(Jint.JintEngine jintEngine)
 {
     jintEngine.RemoveParameter("DeleteDocument");
 }
Esempio n. 24
0
 public void Trigger(Jint.Native.JsValue[] Arguments)
 {
     Function.Invoke(Arguments);
 }
 protected override void CustomizeEngine(Jint.JintEngine jintEngine)
 {
     jintEngine.SetFunction("DeleteDocument", ((Action<string>)(document => DocumentsToDelete.Remove(document))));
 }
Esempio n. 26
0
 public CommentWrapper(Jint.Parser.Comment orig)
 {
     Spelling = orig.Value;
     StartLine = orig.Location.Start.Line;
     EndLine = orig.Location.End.Line;
 }
Esempio n. 27
0
 public bool TryGet(string name, out Jint.Native.Descriptor descriptor)
 {
    return bag.TryGetValue(name, out descriptor);
 }
Esempio n. 28
0
 public override JsInstance Execute(Jint.Expressions.IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
 {
     visitor.Return( m_impl(visitor.Global, that, parameters) );
     return that;
 }
Esempio n. 29
-1
 public override void Visit(Jint.Expressions.Identifier expression)
 {
     if (_currFuncImp.GetDeclaration(expression.Text) != null)
         return; //It is a local var, so nothing to do!
     var funcImp = _currFuncImp.ParentFunction;
     while (funcImp != null)
     {
         var decl = funcImp.GetDeclaration(expression.Text);
         if (decl != null)
         {
             decl.IsClosedOn = true;
             return;
         }
     }
 }
Esempio n. 30
-1
        static bool CommandLoop(Jint.Expressions.Program program, DebugInformation information, JdbEngine debugger)
        {
            Console.ForegroundColor = ConsoleColor.White;
            Console.BackgroundColor = ConsoleColor.Black;

            if (information == null)
            {
                information = new DebugInformation();
                information.CallStack = new Stack<string>();
                information.Locals = new JsObject(JsNull.Instance);

                foreach (var property in debugger.CurrentScope.GetKeys())
                    information.Locals[property] = debugger.CurrentScope[property];
            }
            else
            {
                Console.WriteLine("{0}:{1} => {2}", information.CurrentStatement.Source.Start.Line,
                                  information.CurrentStatement.Source.Start.Char,
                                  information.CurrentStatement.Source.Code);
            }

            try
            {
                while (true)
                {
                    Console.Write(">");
                    var command = Console.ReadLine().ToLowerInvariant();

                    if (command == "bt")
                    {
                        // backtrace
                        int frame = 0;
                        foreach (string stackframe in information.CallStack)
                        {
                            Console.WriteLine("[{0}] {1}", frame++, stackframe);
                        }
                    }
                    else if (command.StartsWith("p "))
                    {
                        // find value for next word and print it
                        string varname = command.Substring(command.IndexOf(" ") + 1);
                        Console.WriteLine("{0} => {1}", varname, information.Locals[varname].Value);
                    }
                    else if (command == "l")
                    {
                        // locals
                        foreach (string key in information.Locals.GetKeys())
                        {
                            Console.WriteLine("{0} => {1}", key, information.Locals[key].Value);
                        }
                    }
                    else if (command == "n")
                    {
                        // Step
                        stepping = true;
                        return true;
                    }
                    else if (command == "c" || command == "r")
                    {
                        // continue
                        stepping = false;
                        return true;
                    }
                    else if (command == "q")
                    {
                        // quit
                        return false;
                    }
                    else if (command.StartsWith("bp "))
                    {
                        // set a breakpoint
                        string[] split = command.Split(new string[] {" "}, StringSplitOptions.RemoveEmptyEntries);
                        int line = 0;
                        int chr = 0;
                        string expr = null;
                        if (split.Length > 1)
                        {
                            line = int.Parse(split[1]);

                            if (split.Length > 2)
                            {
                                chr = int.Parse(split[2]);

                                if (split.Length > 3)
                                    expr = split[3];
                            }

                            debugger.BreakPoints.Add(new BreakPoint(line, chr, expr));
                        }
                    }
                    else if (command == "lbp")
                    {
                        // list breakpoints
                        int bpcount = 0;
                        foreach (BreakPoint bp in debugger.BreakPoints)
                        {
                            Console.WriteLine("{0} => {1}:{2} {3}", bpcount++, bp.Line, bp.Char, bp.Condition);
                        }
                    }
                    else if (command.StartsWith("dbp "))
                    {
                        // delete break point
                        int bpi = int.Parse(command.Substring(command.IndexOf(" ") + 1));
                        debugger.BreakPoints.RemoveAt(bpi);
                    }
                    else
                    {
                        // try to eval as an immediate
                        Console.WriteLine("{0}", debugger.Immediate(command));
                    }
                }
            }
            finally
            {
                Console.ResetColor();
            }
        }