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CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC;AAC9D,QAAI,CAAC,cAAc,GAAG,UAAU,CAAC;AAC/B,UAAI,EAAM,IAAI,CAAC,IAAI;AACnB,SAAG,EAAO,cAAc,CAAC,kBAAkB,CAAC,cAAc,EAAE,GAAG,CAAC;AAChE,YAAM,EAAI,YAAY;AACtB,cAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,IAAI;KACrC,CAAC,CAAC;GACJ;AACD,SAAO,IAAI,CAAC,cAAc,CAAC;CAC5B,CAAC,CAAC","file":"iframe.js","sourcesContent":["// Support for iframes.\n\n\nconst DOM             = require('./index');\nconst resourceLoader  = require('jsdom/lib/jsdom/browser/resource-loader');\n\n\nfunction loadFrame(frame) {\n  // Close current content window in order to open a new one\n  if (frame._contentWindow) {\n    frame._contentWindow.close();\n    delete frame._contentWindow;\n  }\n\n  function onload() {\n    frame.contentWindow.removeEventListener('load', onload);\n    const parentDocument = frame._ownerDocument;\n    const loadEvent = parentDocument.createEvent('HTMLEvents');\n    loadEvent.initEvent('load', false, false);\n    frame.dispatchEvent(loadEvent);\n  }\n\n  // This is both an accessor to the contentWindow and a side-effect of creating\n  // the window and loading the document based on the value of frame.src\n  //\n  // Not happy about this hack\n  frame.contentWindow.addEventListener('load', onload);\n}\n\n\nfunction refreshAccessors(document) {\n  const window = document._defaultView;\n  const frames = document.querySelectorAll('iframe,frame');\n  for (let i = 0; i < window._length; ++i)\n    delete window[i];\n  window._length = frames.length;\n  Array.prototype.forEach.call(frames, function (frame, i) {\n    window.__defineGetter__(i, ()=> frame.contentWindow );\n  });\n}\n\nfunction refreshNameAccessor(frame) {\n  const name = frame.getAttribute('name');\n  // https://html.spec.whatwg.org/multipage/browsers.html#named-access-on-the-window-object:supported-property-names\n  if (name) {\n    // I do not know why this only works with _global and not with _defaultView :(\n    const window = frame._ownerDocument._global;\n    delete window[name];\n    if (isInDocument(frame))\n      window.__defineGetter__(name, ()=> frame.contentWindow );\n  }\n}\n\nfunction isInDocument(el) {\n  const document = el._ownerDocument;\n  let   current = el;\n  while ((current = current.parentNode))\n    if (current === document)\n      return true;\n  return false;\n}\n\n\nDOM.HTMLFrameElement.prototype._attrModified = function (name, value, oldVal) {\n  DOM.HTMLElement.prototype._attrModified.call(this, name, value, oldVal);\n  if (name === 'name') {\n    if (oldVal)\n      // I do not know why this only works with _global and not with _defaultView :(\n      delete this._ownerDocument._global[oldVal];\n    refreshNameAccessor(this);\n  } else if (name === 'src' && value !== oldVal && isInDocument(this))\n    loadFrame(this);\n};\n\nDOM.HTMLFrameElement.prototype._detach = function () {\n  DOM.HTMLElement.prototype._detach.call(this);\n  if (this.contentWindow)\n    this.contentWindow.close();\n  refreshAccessors(this._ownerDocument);\n  refreshNameAccessor(this);\n};\n\nDOM.HTMLFrameElement.prototype._attach = function () {\n  DOM.HTMLElement.prototype._attach.call(this);\n  loadFrame(this);\n  refreshAccessors(this._ownerDocument);\n  refreshNameAccessor(this);\n};\n\nDOM.HTMLFrameElement.prototype.__defineGetter__('contentDocument', function() {\n  return this.contentWindow.document;\n});\n\nDOM.HTMLFrameElement.prototype.__defineGetter__('contentWindow', function() {\n  if (!this._contentWindow) {\n    const createHistory   = require('../history');\n    const parentDocument  = this._ownerDocument;\n    const parentWindow    = parentDocument.defaultView;\n\n    // Need to bypass JSDOM's window/document creation and use ours\n    const openWindow = createHistory(parentWindow.browser, (active)=> {\n      // Change the focus from window to active.\n      this._contentWindow = active;\n    });\n\n    const src = this.src.trim() === '' ? 'about:blank' : this.src;\n    this._contentWindow = openWindow({\n      name:     this.name,\n      url:      resourceLoader.resolveResourceUrl(parentDocument, src),\n      parent:   parentWindow,\n      referrer: parentWindow.location.href\n    });\n  }\n  return this._contentWindow;\n});\n"]}