예제 #1
0
 public WebSocket(JSServer server)
 {
     _server      = server;
     _application = server.Application;
     _session     = new JSSession();
     _id          = Guid.NewGuid().ToString();
 }
예제 #2
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);
        }
예제 #3
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);
     }
 }
예제 #4
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);
        }
예제 #5
0
        private JSApplication CreateApplication(HttpContext context, Action after)
        {
            var application = new JSApplication(AppDomain.CurrentDomain.BaseDirectory, (app) => {
                // Reset the websocket and http hooks
                API.WebSocket.ResetHooks();
                API.HTTPServer.ResetHooks();

                // Define the server API
                app.AddHostType(typeof(API.Request));
                app.AddHostType(typeof(API.Response));
                app.AddHostType(typeof(API.WebSocket));
                app.AddHostType(typeof(API.HTTPServer));

                var session = new JSSession();

                // Clear the compile error
                CompileError = "";

                // Run the startup file
                var require  = app.Evaluate(@"(function(file){
                    require(file);
                }).valueOf()");
                var callback = API.HTTPServer.Callback(after, context);
                var request  = new ServerRequest(require, app, callback, session, HttpContext.Current, app.Settings.Startup);
                request.Call();
            }, (exception, stage) => {
                // Get the error message
                string error = "";
                if (exception is ScriptEngineException se)
                {
                    error = se.ErrorDetails;
                }
                else
                {
                    error = exception.ToString();
                }

                // If it is a compilation error, store it in the variable "CompileError"
                if (stage == ErrorStage.Compilation)
                {
                    CompileError = error;
                }

                WriteError(context, after, error);
            });

            return(application);
        }
예제 #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();
            }
        }
예제 #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;
 }
예제 #8
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var service = new JSService();
            var session = new JSSession();

            var application = new JSApplication(null, app => {
                app.AddHostType(typeof(API.Window));
                app.AddHostType(typeof(API.Graphics));
            }, (exception, stage) => {
                if (exception is ScriptEngineException se)
                {
                    NetJS.API.Log.write(se.ErrorDetails);
                }
                else
                {
                    NetJS.API.Log.write(exception.ToString());
                }
            });

            service.RunScript(application.Settings.Startup, application, session, result => { });
        }
예제 #9
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;
        }