public IntPtr ConvertCOMObjectToJSObject(nsISupports obj)
        {
            Guid guid = typeof(nsISupports).GUID;

            IntPtr globalObject = GetGlobalObject();

            using (var holder = new ComPtr <nsIXPConnectJSObjectHolder>(Xpcom.XPConnect.Instance.WrapNative(_cx, globalObject, (nsISupports)obj, ref guid)))
            {
                int slot        = holder.GetSlotOfComMethod(new Func <IntPtr>(holder.Instance.GetJSObject));
                var getJSObject = holder.GetComMethod <Xpcom.GetJSObjectFromHolderDelegate>(slot);
                return(getJSObject(holder.Instance));
            }
        }
        public AutoJSContext(nsIDOMWindow window)
        {
            var context = SafeJSContext;
            var go      = (nsIGlobalObject)window;

            using (var xpc = new ComPtr <nsIGlobalObject>(go, false))
            {
                int slot = xpc.GetSlotOfComMethod(new Func <IntPtr>(go.GetGlobalJSObject));
                var getGlobalJSObject = xpc.GetComMethod <GetGlobalJSObject>(Xpcom.IsLinux ? 3 : slot);
                _globalJSObject = getGlobalJSObject(go);
                if (_globalJSObject == IntPtr.Zero)
                {
                    throw new ArgumentException(
                              "Window does not have a global JSObject. Purhaps the window doesn't have an initalized document?");
                }

                _contextToGlobalDictionary[context] = _globalJSObject;
                _defaultCompartment = new JSAutoCompartment(SafeJSContext, _globalJSObject);
                _cx     = context;
                _window = window;
            }
        }
		public IntPtr ConvertCOMObjectToJSObject(nsISupports obj)
		{
			Guid guid = typeof(nsISupports).GUID;

			IntPtr globalObject = GetGlobalObject();

			using (var holder = new ComPtr<nsIXPConnectJSObjectHolder>(Xpcom.XPConnect.Instance.WrapNative(_cx, globalObject, (nsISupports)obj, ref guid)))
			{
				int slot = holder.GetSlotOfComMethod(new Func<IntPtr>(holder.Instance.GetJSObject));
				var getJSObject = holder.GetComMethod<Xpcom.GetJSObjectFromHolderDelegate>(slot);
				return getJSObject(holder.Instance);
			}

		}