/// <summary> /// Initializes a new instance of the <see cref="QuickJSContext"/>. /// </summary> /// <param name="runtime">A JavaScript runtime.</param> /// <param name="raw"> /// The value that determines that the context should be created without the default intrinsic objects. /// </param> public unsafe QuickJSContext(QuickJSRuntime runtime, bool raw) { if (runtime is null) { throw new ArgumentNullException(nameof(runtime)); } _onRuntimeInterrupt = OnRuntimeInterrupt; this.Runtime = runtime; _context = raw ? JS_NewContextRaw(runtime.NativeInstance) : JS_NewContext(runtime.NativeInstance); if (_context == JSContext.Null) { throw new InvalidOperationException(); } lock (_AllContexts) { _AllContexts.Add(_context, this); } _handle = GCHandle.Alloc(this, GCHandleType.Normal); JS_SetContextOpaque(_context, GCHandle.ToIntPtr(_handle)); runtime.Interrupt += _onRuntimeInterrupt; }
/// <summary> /// Initializes a new instance of the <see cref="QuickJSContext"/>. /// </summary> /// <param name="runtime">A JavaScript runtime.</param> public QuickJSContext(QuickJSRuntime runtime) : this(runtime, false) { }