/// <summary> /// Creates a new JavaScript engine and adds it to the list of all available engines. /// </summary> private IJsEngine CreateEngine() { var engine = _jsEngineBuilder.Build(); _jsEngineInitializer.Initialize(engine); _metadata[engine] = new EngineMetadata(); Interlocked.Increment(ref _engineCount); return(engine); }
/// <summary> /// Gets the JavaScript engine for the current thread. It is recommended to use /// <see cref="GetEngine"/> instead, which will pool/reuse engines. /// </summary> /// <returns>The JavaScript engine</returns> public virtual IJsEngine GetEngineForCurrentThread() { EnsureValidState(); return(_engines.GetOrAdd(Thread.CurrentThread.ManagedThreadId, id => { var engine = _jsEngineBuilder.Build(); _jsEngineInitializer.Initialize(engine); EnsureValidState(); return engine; })); }