"use strict"; function createDocument(documentType, result, inlineOrExternal, type, hasBlockingStylesheet) { return new Promise((resolve, reject) => { const iframe = document.createElement("iframe"); iframe.src = "resources/moving-between-documents-iframe.py" + "?result=" + result + "&inlineOrExternal=" + inlineOrExternal + "&type=" + type + "&hasBlockingStylesheet=" + hasBlockingStylesheet + "&cache=" + Math.random(); // As blocking stylesheets delays Document load events, we use // DOMContentLoaded here. // After that point, we expect iframe.contentDocument exists // while still waiting for blocking stylesheet loading. document.body.appendChild(iframe); window.addEventListener('message', (event) => { if (documentType === "iframe") { resolve([iframe.contentWindow, iframe.contentDocument]); } else if (documentType === "createHTMLDocument") { resolve([ iframe.contentWindow, iframe.contentDocument.implementation.createHTMLDocument("")]); } else { reject(new Error("Invalid document type: " + documentType)); } }, {once: true}); }); } window.didExecute = undefined; // For a script, there are three associated Documents that can // potentially different: // // [1] script's parser document // https://html.spec.whatwg.org/C/#parser-document // // [2] script's preparation-time document // https://html.spec.whatwg.org/C/#preparation-time-document // == script's node document at the beginning of #prepare-a-script // // [3] script's node document at the beginning of // #execute-the-script-block // // This helper is for tests where [1]/[2]/[3] are different. // In the spec, scripts are executed only if [1]/[2]/[3] are all the same // (or [1] is null and [2]==[3]). // // A check for [1]==[2] is in #prepare-a-script and // a check for [1]==[3] is in #execute-the-script-block, // but these are under debate: https://github.com/whatwg/html/issues/2137 // // A check for [2]==[3] is in #execute-the-script-block, which is added by // https://github.com/whatwg/html/pull/2673 // timing: // "before-prepare": // A