Beispiel #1
0
 public WebSocket(JSServer server)
 {
     _server      = server;
     _application = server.Application;
     _session     = new JSSession();
     _id          = Guid.NewGuid().ToString();
 }
Beispiel #2
0
        public JSServer(JSService service, HttpContext context, Action after)
        {
            _service     = service;
            _application = CreateApplication(context, after);

            _sessions = new ConcurrentDictionary <string, JSSession>();
        }
Beispiel #3
0
        public static void Send(JSApplication application, JSSession session, Action <object> callback, string data)
        {
            if (_onMessage == null)
            {
                return;
            }

            var request = new FunctionRequest(_onMessage, application, callback, session, data);

            application.AddRequest(request);
        }
Beispiel #4
0
 public void ExecuteTests(JSApplication application, JSService service, JSSession session)
 {
     foreach (var test in Tests)
     {
         if (test == null)
         {
             continue;
         }
         test.Initialize();
         test.Execute(application, service, session);
     }
 }
Beispiel #5
0
        public static void OnConnection(JSApplication application, JSSession session, Action after)
        {
            if (_onConnection == null)
            {
                return;
            }

            Action <object> callback = Callback(after, HttpContext.Current);
            var             request  = new ServerRequest(_onConnection, application, callback, session, HttpContext.Current);

            application.AddRequest(request);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var application = new JSApplication("", app => {
                app.AddHostType(typeof(API.Console));
            }, (error, stage) => {
                System.Console.WriteLine(error);
            });
            var service = new JSService();
            var session = new JSSession();

            try {
                service.RunScriptSync(application.Settings.Startup, application, session, result => {
                    System.Console.WriteLine(result);
                    System.Console.ReadLine();
                });
            } catch (Exception e) {
                System.Console.WriteLine(e);
                System.Console.ReadLine();
            }
        }
Beispiel #7
0
 public ServerRequest(
     dynamic function,
     JSApplication application,
     Action <object> resultCallback,
     JSSession session,
     HttpContext context,
     object argument0 = null,
     object argument1 = null,
     object argument2 = null,
     object argument3 = null
     )
     : base(
         (object)function,
         application,
         resultCallback,
         session,
         argument0,
         argument1,
         argument2,
         argument3
         )
 {
     Context = context;
 }
Beispiel #8
0
        public void Execute(JSApplication application, JSService service, JSSession session)
        {
            if (Implemented.Count >= 1)
            {
                return;
            }
            var watch = new Stopwatch();

            watch.Start();
            var preTestOutput = "";

            if (_include != null)
            {
                foreach (var preTest in _include)
                {
                    if (!preTest.Contains(".js"))
                    {
                        continue;
                    }
                    var preTestPath = Path.GetFullPath(Program.Test262Root + "/../harness/" + preTest.Replace(",", ""))
                                      .Replace('\\', '/');
                    preTestOutput += service.RunScript(preTestPath, application, session, true, false);
                }
            }

            var strictTestOutput = "";
            var strictWatch      = new Stopwatch();

            if (UseStrict)
            {
                strictWatch.Start();
                strictTestOutput = service.RunCode("\"use strict\"\n" + _code, application, session, false, true);
                strictWatch.Stop();
            }


            var templateWatch = new Stopwatch();

            templateWatch.Start();
            var testOutput = service.RunCode(_code, application, session, false, true);

            templateWatch.Stop();

            watch.Stop();

            if (_negative != null && _negativeType != null && _negativeType.ToString().Length > 0)
            {
                var splitStrictOutput = testOutput.Split(' ');
                var splitOutput       = testOutput.Split(' ');
                var comparewith       = "";
                if (splitOutput.Length > 1)
                {
                    comparewith = splitOutput[0] + splitOutput[1][0].ToString().ToUpper() +
                                  splitOutput[1].Substring(1);
                }

                var compareStrictWith = "";
                if (splitStrictOutput.Length > 1)
                {
                    compareStrictWith = splitStrictOutput[0] + splitStrictOutput[1][0].ToString().ToUpper() +
                                        splitStrictOutput[1].Substring(1);
                }

                if (comparewith.Contains(_negativeType.ToString()))
                {
                    NonStrictResult = true;
                }

                if (compareStrictWith.Contains(_negativeType.ToString()))
                {
                    StrictResult = true;
                }
            }
            else
            {
                if (testOutput.Length < 1)
                {
                    NonStrictResult = true;
                }

                if (strictTestOutput.Length < 1)
                {
                    StrictResult = true;
                }
            }

            if (_useAsync && templateWatch.ElapsedMilliseconds > 75)
            {
                NonStrictResult   = false;
                _nonStrictOutput += "Async timeout fail | ";
            }


            if (preTestOutput.Length > 0)
            {
                _nonStrictOutput += "preTest: " + preTestOutput + " | ";
                _strictOutput    += "preTest: " + strictTestOutput + " | ";
            }


            _nonStrictOutput += testOutput;
            _strictOutput    += strictTestOutput;

            var stringTime       = Math.Round(templateWatch.Elapsed.TotalMilliseconds, 2).ToString().Split('.');
            var strictStringTime = Math.Round(strictWatch.Elapsed.TotalMilliseconds, 2).ToString().Split('.');
            var timeDecimal      = "00";

            if (stringTime.Length == 2)
            {
                timeDecimal = (int.Parse(stringTime[1]) * 6 / 10).ToString();
            }

            var timeStrictDecimal = "00";

            if (strictStringTime.Length == 2)
            {
                timeStrictDecimal = (int.Parse(strictStringTime[1]) * 6 / 10).ToString();
            }

            _nonStrictTime = stringTime[0] + "." + timeDecimal;
            _strictTime    = strictStringTime[0] + "." + timeStrictDecimal;
        }