/// <summary> /// Creates a debug script context for running scripts. /// </summary> /// <remarks> /// Each script context has its own global object that is isolated from all other script /// contexts. /// </remarks> /// <returns>The created script context.</returns> public JavaScriptContext CreateContext() { JavaScriptContext reference; Native.ThrowIfError(Native.JsCreateContext(this, out reference)); return(reference); }
private JavaScriptContext CreateContext(JavaScriptRuntime runtime) { JavaScriptContext context; try { // Create an execution context. JavaScriptErrorCode errorCode = Native.JsCreateContext(runtime, out context); if (errorCode != JavaScriptErrorCode.NoError) { string errorMessage = string.Format("Failed to create JavaScriptContext with error [{0}]", errorCode); System.Diagnostics.Debug.WriteLine(errorMessage); throw new Exception(errorMessage); } // Now set the execution context as being the current one on this thread. errorCode = Native.JsSetCurrentContext(context); if (errorCode != JavaScriptErrorCode.NoError) { string errorMessage = string.Format("Failed to set current JavaScriptContext with error [{0}]", errorCode); System.Diagnostics.Debug.WriteLine(errorMessage); throw new Exception(errorMessage); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("An exception occurred when creating the javascript context with error [{0}]", ex.Message); throw; } return(context); }