“Edge” Chakra runtime

Each Chakra runtime has its own independent execution engine, JIT compiler, and garbage collected heap. As such, each runtime is completely isolated from other runtimes.

Runtimes can be used on any thread, but only one thread can call into a runtime at any time.

NOTE: A EdgeJsRuntime, unlike other objects in the Chakra hosting API, is not garbage collected since it contains the garbage collected heap itself. A runtime will continue to exist until Dispose is called.

        /// <summary>
        /// Constructs an instance of the Chakra “Edge” JsRT engine
        /// </summary>
        /// <param name="enableDebugging">Flag for whether to enable script debugging features</param>
        public ChakraEdgeJsRtJsEngine(bool enableDebugging)
            : base(JsEngineMode.ChakraEdgeJsRt, enableDebugging)
        {
            _dispatcher.Invoke(() =>
            {
                try
                {
                    _jsRuntime = CreateJsRuntime();
                    _jsContext = _jsRuntime.CreateContext();
                }
                catch (JsUsageException e)
                {
                    string errorMessage;
                    if (e.ErrorCode == JsErrorCode.WrongThread)
                    {
                        errorMessage = CommonStrings.Runtime_JsEnginesConflictOnMachine;
                    }
                    else
                    {
                        errorMessage = string.Format(CommonStrings.Runtime_EdgeJsEngineNotLoaded, e.Message);
                    }

                    throw new JsEngineLoadException(errorMessage, _engineModeName);
                }
                catch (Exception e)
                {
                    throw new JsEngineLoadException(
                        string.Format(CommonStrings.Runtime_EdgeJsEngineNotLoaded, e.Message), _engineModeName);
                }
            });
        }
		internal static extern JsErrorCode JsDisposeRuntime(EdgeJsRuntime handle);
		internal static extern JsErrorCode JsCollectGarbage(EdgeJsRuntime handle);
		internal static extern JsErrorCode JsCreateRuntime(JsRuntimeAttributes attributes, JsThreadServiceCallback threadService, out EdgeJsRuntime runtime);
 internal static extern JsErrorCode JsIsRuntimeExecutionDisabled(EdgeJsRuntime runtime, out bool isDisabled);
		internal static extern JsErrorCode JsCreateContext(EdgeJsRuntime runtime, out EdgeJsContext newContext);
		internal static extern JsErrorCode JsSetRuntimeMemoryAllocationCallback(EdgeJsRuntime runtime, IntPtr callbackState, JsMemoryAllocationCallback allocationCallback);
		internal static extern JsErrorCode JsIsRuntimeExecutionDisabled(EdgeJsRuntime runtime, out bool isDisabled);
 internal static extern JsErrorCode JsSetRuntimeBeforeCollectCallback(EdgeJsRuntime runtime,
                                                                      IntPtr callbackState, JsBeforeCollectCallback beforeCollectCallback);
 internal static extern JsErrorCode JsSetRuntimeMemoryAllocationCallback(EdgeJsRuntime runtime,
                                                                         IntPtr callbackState, JsMemoryAllocationCallback allocationCallback);
 internal static extern JsErrorCode JsSetRuntimeMemoryLimit(EdgeJsRuntime runtime, UIntPtr memoryLimit);
 internal static extern JsErrorCode JsGetRuntimeMemoryUsage(EdgeJsRuntime runtime, out UIntPtr memoryUsage);
 internal static extern JsErrorCode JsDisposeRuntime(EdgeJsRuntime handle);
 internal static extern JsErrorCode JsCollectGarbage(EdgeJsRuntime handle);
 internal static extern JsErrorCode JsCreateRuntime(JsRuntimeAttributes attributes,
                                                    JsThreadServiceCallback threadService, out EdgeJsRuntime runtime);
		internal static extern JsErrorCode JsGetRuntimeMemoryUsage(EdgeJsRuntime runtime, out UIntPtr memoryUsage);
		internal static extern JsErrorCode JsEnableRuntimeExecution(EdgeJsRuntime runtime);
 internal static extern JsErrorCode JsCreateContext(EdgeJsRuntime runtime, out EdgeJsContext newContext);
		internal static extern JsErrorCode JsSetRuntimeMemoryLimit(EdgeJsRuntime runtime, UIntPtr memoryLimit);
 internal static extern JsErrorCode JsGetRuntime(EdgeJsContext context, out EdgeJsRuntime runtime);
		internal static extern JsErrorCode JsSetRuntimeBeforeCollectCallback(EdgeJsRuntime runtime, IntPtr callbackState, JsBeforeCollectCallback beforeCollectCallback);
 /// <summary>
 /// Creates a instance of JS runtime with special settings
 /// </summary>
 /// <returns>Instance of JS runtime with special settings</returns>
 private static EdgeJsRuntime CreateJsRuntime()
 {
     return(EdgeJsRuntime.Create(JsRuntimeAttributes.None, null));
 }
		internal static extern JsErrorCode JsGetRuntime(EdgeJsContext context, out EdgeJsRuntime runtime);
 internal static extern JsErrorCode JsEnableRuntimeExecution(EdgeJsRuntime runtime);