public ReactRunner(string file, bool enableFileWatcher, bool enableCompilation, bool disableGlobalMembers, JsonSerializerSettings serializationSettings) { //setup assembly resolver so it can find the v8 dlls AssemblyResolver.Initialize(); JsFile = file; EnableFileWatcher = enableFileWatcher; EnableCompilation = enableCompilation; DisableGlobalMembers = disableGlobalMembers; SerializationSettings = serializationSettings; //Initialize the v8 runtime Runtime = new V8Runtime(); //Read the scripts text content ScriptRaw = File.ReadAllText(JsFile); if (EnableCompilation) { //If compilation is enabled, we compile the scripts Compiled = Runtime.Compile(ScriptRaw); CompiledShimms = Runtime.Compile(JavascriptShimms.ConsoleShim); } if (EnableFileWatcher) { fileWatcher = new FileSystemWatcher(); fileWatcher.Path = Path.GetDirectoryName(JsFile); fileWatcher.Filter = Path.GetFileName(JsFile); fileWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Attributes | NotifyFilters.Size; fileWatcher.Changed += fileWatcher_Changed; fileWatcher.EnableRaisingEvents = true; } }
/// <summary> /// Creates a new Runtime Manager. /// </summary> /// <param name="settings">Settings to apply to the Runtime Manager and the scripts it runs.</param> public RuntimeManager(IManagerSettings settings) { _settings = settings; _v8Runtime = new V8Runtime(new V8RuntimeConstraints { MaxExecutableSize = settings.MaxExecutableBytes, MaxOldSpaceSize = settings.MaxOldSpaceBytes, MaxNewSpaceSize = settings.MaxNewSpaceBytes }); _scriptCompiler = new ScriptCompiler(_v8Runtime, settings); }
private static Dictionary <string, object> TestConversion(string testJson, string code) { V8Runtime v8Runtime = new V8Runtime(); using (var context = v8Runtime.CreateScriptEngine()) { var result = JsonConvert.DeserializeObject <dynamic>(testJson); var jsValues = ScriptHelpers.ToScriptValue(result, context); context.AddHostObject("s", jsValues); Assert.IsTrue((bool)context.Evaluate(code)); return(ConvertJsToNative(jsValues)); } }
public ScriptCompiler(V8Runtime v8Runtime, IManagerSettings settings) { _settings = settings; _v8Runtime = v8Runtime; _scriptCache = new LruCache <string, CachedV8Script>(LurchTableOrder.Access, settings.ScriptCacheMaxCount); }