public V8ProjectionStateHandler(
     string preludeName, string querySource, Func<string, Tuple<string, string>> getModuleSource,
     Action<string> logger)
 {
     var preludeSource = getModuleSource(preludeName);
     var prelude = new PreludeScript(preludeSource.Item1, preludeSource.Item2, getModuleSource, logger);
     QueryScript query;
     try
     {
         query = new QueryScript(prelude, querySource, "POST-BODY");
         query.Emit += QueryOnEmit;
     }
     catch
     {
         prelude.Dispose(); // clean up unmanaged resources if failed to create
         throw;
     }
     _prelude = prelude;
     _query = query;
 }
示例#2
0
        public void long_execution_of_non_v8_code_does_not_crash()
        {
            _cancelCallbackFactory = (timeout, action) => ThreadPool.QueueUserWorkItem(state =>
                {
                    Console.WriteLine("Calling a callback in " + timeout + "ms");
                    Thread.Sleep(timeout);
                    action();
                });
            Action<string> logger = Console.WriteLine;


            Func<string, Tuple<string, string>> getModuleSource = name =>
                {
                    var fullScriptFileName = Path.GetFullPath(Path.Combine(_jsPath, name + ".js"));
                    var scriptSource = File.ReadAllText(fullScriptFileName, Helper.UTF8NoBom);
                    return Tuple.Create(scriptSource, fullScriptFileName);
                };


            var preludeSource = getModuleSource("1Prelude");
            var prelude = new PreludeScript(preludeSource.Item1, preludeSource.Item2, getModuleSource, _cancelCallbackFactory, logger);
            try
            {
                //var cancelToken = 123;
                prelude.ScheduleTerminateExecution();
                Thread.Sleep(500);
                _commandHandlerRegisteredCallback = (name, handle) => { };
                _reverseCommandHandlerDelegate = (name, body) => { };
                Js1.CompileQuery(
                    prelude.GetHandle(), "log(1);", "fn", _commandHandlerRegisteredCallback,
                    _reverseCommandHandlerDelegate);

                prelude.CancelTerminateExecution();
            }
            catch
            {
                prelude.Dispose(); // clean up unmanaged resources if failed to create
                throw;
            }

        }