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AAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EACxB,MAAM;AACR,eAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;OACpB;;;;;;;;;;;;;;;GAAA,AACH,OAAO,CAAC,IAAI,aAAW,YAAY,CAAG,CAAC;AACvC,OAAK,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjC,SAAO,KAAK,CAAC;CACd;;;;;;;;;AAUD,GAAG,CAAC,iBAAiB,CAAC,KAAK,GAAG,YAAW;AACvC,MAAI,CAAC,gBAAgB,CAAC,6BAA6B,EAAE,YAAW;AAC9D,QAAM,MAAM,GAAM,IAAI,CAAC;AACvB,QAAM,QAAQ,GAAI,MAAM,CAAC,aAAa,CAAC;;AAEvC,QAAI,MAAM,CAAC,GAAG;;AAEZ,oBAAc,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,KACnD;AACH,UAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,GAAO,QAAQ,CAAC,GAAG,UAAK,MAAM,CAAC,EAAE,GAAQ,QAAQ,CAAC,GAAG,YAAS,CAAC;;AAEzF,UAAM,cAAc,GAAG,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC;;;;;;;AAOrF,UAAI,QAAQ,CAAC,UAAU,KAAK,SAAS,EACnC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,KAEjC,cAAc,EAAE,CAAC;KACpB;;;AAGD,aAAS,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE;AAC3C,YAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;KAC5C;GACF,CAAC,CAAC;CACJ,CAAC","file":"scripts.js","sourcesContent":["// For handling JavaScript, mostly improvements to JSDOM\n\nconst DOM             = require('./index');\nconst resourceLoader  = require('jsdom/lib/jsdom/browser/resource-loader');\nconst reportException = require('jsdom/lib/jsdom/living/helpers/runtime-script-errors');\n\n\n// -- Patches to JSDOM --\n\n// If JSDOM encounters a JS error, it fires on the element.  We expect it to be\n// fires on the Window.  We also want better stack traces.\nDOM.languageProcessors.javascript = function(element, buffer, filename) {\n  const code = buffer.toString();\n  // This may be called without code, e.g. script element that has no body yet\n  if (!code)\n    return;\n\n  // Surpress JavaScript validation and execution\n  const document = element.ownerDocument;\n  const window   = document.defaultView;\n  const browser  = window.top.browser;\n  if (browser && !browser.runScripts)\n    return;\n\n  // This may be called without code, e.g. script element that has no body yet\n  try {\n    window.document._currentScript = element;\n    window._evaluate(code, filename);\n  } catch (error) {\n    enhanceStackTrace(error, document.location.href);\n    reportException(window, error);\n  } finally {\n    window.document._currentScript = null;\n  }\n};\n\nfunction enhanceStackTrace(error, document_ref) {\n  const partial = [];\n  // \"RangeError: Maximum call stack size exceeded\" doesn't have a stack trace\n  if (error.stack)\n    for (let line of error.stack.split('\\n')) {\n      if (~line.indexOf('vm.js'))\n        break;\n      partial.push(line);\n    }\n  partial.push(`    in ${document_ref}`);\n  error.stack = partial.join('\\n');\n  return error;\n}\n\n\n// HTML5 parser doesn't play well with JSDOM so we need this trickey to sort of\n// get script execution to work properly.\n//\n// Basically JSDOM listend for when the script tag is added to the DOM and\n// attemps to evaluate at, but the script has no contents at that point in\n// time.  This adds just enough delay for the inline script's content to be\n// parsed and ready for processing.\nDOM.HTMLScriptElement._init = function() {\n  this.addEventListener('DOMNodeInsertedIntoDocument', function() {\n    const script    = this;\n    const document  = script.ownerDocument;\n\n    if (script.src)\n      // Script has a src attribute, load external resource.\n      resourceLoader.load(script, script.src, script._eval);\n    else {\n      const filename = script.id ?  `${document.URL}:#${script.id}` : `${document.URL}:script`;\n      // Queue to be executed in order with all other scripts\n      const executeInOrder = resourceLoader.enqueue(script, filename, executeInlineScript);\n      // There are two scenarios:\n      // - script element added to existing document, we should evaluate it\n      //   immediately\n      // - inline script element parsed, when we get here, we still don't have\n      //   the element contents, so we have to wait before we can read and\n      //   execute it\n      if (document.readyState === 'loading')\n        process.nextTick(executeInOrder);\n      else\n        executeInOrder();\n    }\n\n    // Execute inline script\n    function executeInlineScript(code, filename) {\n      script._eval(script.textContent, filename);\n    }\n  });\n};\n"]}