/// <summary> /// Destroys object /// </summary> /// <param name="disposing">Flag, allowing destruction of /// managed objects contained in fields of class</param> private void Dispose(bool disposing) { if (_disposedFlag.Set()) { if (disposing) { if (_dispatcher != null) { _dispatcher.Invoke(DisposeUnmanagedResources); _dispatcher.Dispose(); _dispatcher = null; } if (_typeMapper != null) { _typeMapper.Dispose(); _typeMapper = null; } _promiseContinuationCallback = null; } else { DisposeUnmanagedResources(); } } }
/// <summary> /// Sets a promise continuation callback function that is called by the context when a task /// needs to be queued for future execution /// </summary> /// <remarks> /// <para> /// Requires an active script context. /// </para> /// </remarks> /// <param name="promiseContinuationCallback">The callback function being set</param> /// <param name="callbackState">User provided state that will be passed back to the callback</param> public static void SetPromiseContinuationCallback(JsPromiseContinuationCallback promiseContinuationCallback, IntPtr callbackState) { JsErrorHelpers.ThrowIfError(NativeMethods.JsSetPromiseContinuationCallback(promiseContinuationCallback, callbackState)); }
internal static extern JsErrorCode JsSetPromiseContinuationCallback( JsPromiseContinuationCallback promiseContinuationCallback, IntPtr callbackState);
/// <summary> /// Sets a promise continuation callback function that is called by the context when a task /// needs to be queued for future execution /// </summary> /// <remarks> /// <para> /// Requires an active script context. /// </para> /// </remarks> /// <param name="promiseContinuationCallback">The callback function being set</param> /// <param name="callbackState">User provided state that will be passed back to the callback</param> public static void SetPromiseContinuationCallback(JsPromiseContinuationCallback promiseContinuationCallback, IntPtr callbackState) { Native.ThrowIfError(Native.JsSetPromiseContinuationCallback(promiseContinuationCallback, callbackState)); }
internal static extern JsErrorCode JsSetPromiseContinuationCallback( JsPromiseContinuationCallback promiseContinuationCallback, IntPtr callbackState);
/// <summary> /// Constructs an instance of adapter for the ChakraCore JS engine /// </summary> /// <param name="settings">Settings of the ChakraCore JS engine</param> public ChakraCoreJsEngine(ChakraCoreSettings settings) { #if NETFULL Initialize(); #endif ChakraCoreSettings chakraCoreSettings = settings ?? new ChakraCoreSettings(); JsRuntimeAttributes attributes = JsRuntimeAttributes.AllowScriptInterrupt; if (chakraCoreSettings.DisableBackgroundWork) { attributes |= JsRuntimeAttributes.DisableBackgroundWork; } if (chakraCoreSettings.DisableEval) { attributes |= JsRuntimeAttributes.DisableEval; } if (chakraCoreSettings.DisableExecutablePageAllocation) { attributes |= JsRuntimeAttributes.DisableExecutablePageAllocation; } if (chakraCoreSettings.DisableFatalOnOOM) { attributes |= JsRuntimeAttributes.DisableFatalOnOOM; } if (chakraCoreSettings.DisableNativeCodeGeneration) { attributes |= JsRuntimeAttributes.DisableNativeCodeGeneration; } if (chakraCoreSettings.EnableExperimentalFeatures) { attributes |= JsRuntimeAttributes.EnableExperimentalFeatures; } #if NETSTANDARD1_3 _dispatcher = new ScriptDispatcher(); #else _dispatcher = new ScriptDispatcher(chakraCoreSettings.MaxStackSize); #endif _promiseContinuationCallback = PromiseContinuationCallback; try { _dispatcher.Invoke(() => { _jsRuntime = JsRuntime.Create(attributes, null); _jsRuntime.MemoryLimit = settings.MemoryLimit; _jsContext = _jsRuntime.CreateContext(); if (_jsContext.IsValid) { _jsContext.AddRef(); } }); } catch (DllNotFoundException e) { throw WrapDllNotFoundException(e); } catch (Exception e) { throw CoreErrorHelpers.WrapEngineLoadException(e, EngineName, EngineVersion, true); } finally { if (!_jsContext.IsValid) { Dispose(); } } }