/// <summary> /// Collects garbage in the specified V8 engine. /// </summary> /// <param name="engine"></param> private static void V8CollectGarbage(IJsEngine engine) { // Since JavaScriptEngineSwitcher does not expose the inner JavaScript engine, we need // to use reflection to get to it. if (_innerEngineField == null) { _innerEngineField = engine.GetType().GetField("_jsEngine", BindingFlags.NonPublic | BindingFlags.Instance); } var innerJsEngine = _innerEngineField.GetValue(engine); // Use reflection to get the garbage collection method so we don't have a hard // dependency on ClearScript. Not ideal but this will do for now. if (_collectGarbageMethod == null) { _collectGarbageMethod = innerJsEngine.GetType().GetMethod("CollectGarbage"); } _collectGarbageMethod.Invoke(innerJsEngine, new object[] { true }); }
/// <summary> /// Determines if the specified engine supports garbage collection. /// </summary> /// <param name="engine">Engine</param> /// <returns><c>true</c> if the engine supports garbage collection</returns> public static bool SupportsGarbageCollection(this IJsEngine engine) { return(engine.GetType().Name == V8_TYPE); }
/// <summary> /// Determines if the specified engine can only be used on the thread it is created on. /// </summary> /// <param name="engine">Engine</param> /// <returns><c>true</c> if the engine should be confined to a single thread</returns> public static bool NeedsOwnThread(this IJsEngine engine) { // Checking MsieJsEngine as a string so we don't need to pull in an otherwise // unneeded dependency on MsieJsEngine. return(engine.GetType().Name == MSIE_TYPE); }