MsieJavaScriptEngine.JsRt.Ie.IeJsRuntime.CreateContext C# (CSharp) Method

CreateContext() public method

Creates a script context for running scripts
Each script context has its own global object that is isolated from all other script contexts.
public CreateContext ( ) : IeJsContext
return IeJsContext
        public IeJsContext CreateContext()
        {
            IeJsContext reference;
            IeJsErrorHelpers.ThrowIfError(Utils.Is64BitProcess() ?
                IeNativeMethods.JsCreateContext(this, (IDebugApplication64)null, out reference)
                :
                IeNativeMethods.JsCreateContext(this, (IDebugApplication32)null, out reference)
            );

            return reference;
        }

Same methods

IeJsRuntime::CreateContext ( IDebugApplication32 debugApplication ) : IeJsContext
IeJsRuntime::CreateContext ( IDebugApplication64 debugApplication ) : IeJsContext

Usage Example

Example #1
0
        /// <summary>
        /// Constructs an instance of the Chakra “IE” JsRT JavaScript engine
        /// </summary>
        /// <param name="enableDebugging">Flag for whether to enable script debugging features</param>
        public ChakraIeJsRtJsEngine(bool enableDebugging)
            : base(JsEngineMode.ChakraIeJsRt, 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_IeJsEngineNotLoaded,
                                                     _engineModeName, LOWER_IE_VERSION, e.Message);
                    }

                    throw new JsEngineLoadException(errorMessage, _engineModeName);
                }
                catch (Exception e)
                {
                    throw new JsEngineLoadException(
                        string.Format(CommonStrings.Runtime_IeJsEngineNotLoaded,
                                      _engineModeName, LOWER_IE_VERSION, e.Message), _engineModeName);
                }
            });
        }