`); let content_document; try { content_document = content_window.document; } catch (error) { } assert_true(executed, 'Must synchronously instantiate a custom element'); return {window: content_window, document: content_document, exception}; } promise_test(async function () { const result = await construct_custom_element_in_parser(this, `document.open()`); assert_throws_dom('InvalidStateError', result.window.DOMException, () => { throw result.exception; }, 'Must throw an InvalidStateError'); }, 'document.open() must throw an InvalidStateError when synchronously constructing a custom element'); promise_test(async function () { const result = await construct_custom_element_in_parser(this, `document.open('text/html')`); assert_throws_dom('InvalidStateError', result.window.DOMException, () => { throw result.exception; }, 'Must throw an InvalidStateError'); }, 'document.open("text/html") must throw an InvalidStateError when synchronously constructing a custom element'); // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-open-window promise_test(async function () { let load_promise = new Promise((resolve) => window.onmessage = (event) => resolve(event.data)); const url = top.location.href.substring(0, top.location.href.lastIndexOf('/')) + '/resources/navigation-destination.html'; const result = await construct_custom_element_in_parser(this, `document.open('${url}', '_self', '')`); assert_equals(result.exception, null); assert_equals(await load_promise, 'didNavigate'); }, 'document.open(URL) must NOT throw an InvalidStateError when synchronously constructing a custom element'); promise_test(async function () { const result = await construct_custom_element_in_parser(this, `document.close()`); assert_not_equals(result.exception, null); assert_throws_dom('InvalidStateError', result.window.DOMException, () => { throw result.exception; }, 'Must throw an InvalidStateError'); }, 'document.close() must throw an InvalidStateError when synchronously constructing a custom element'); promise_test(async function () { const result = await construct_custom_element_in_parser(this, `document.write('some text')`); assert_throws_dom('InvalidStateError', result.window.DOMException, () => { throw result.exception; }, 'Must throw an InvalidStateError'); assert_equals(result.document.querySelector('b'), null, 'Must not insert new content'); assert_false(result.document.body.innerHTML.includes('some text'), 'Must not insert new content'); }, 'document.write must throw an InvalidStateError when synchronously constructing a custom element'); promise_test(async function () { const result = await construct_custom_element_in_parser(this, `document.writeln('some text')`); assert_throws_dom('InvalidStateError', result.window.DOMException, () => { throw result.exception; }, 'Must throw an InvalidStateError'); assert_equals(result.document.querySelector('b'), null, 'Must not insert new content'); assert_false(result.document.body.innerHTML.includes('some text'), 'Must not insert new content'); }, 'document.writeln must throw an InvalidStateError when synchronously constructing a custom element'); promise_test(async function () { window.another_window = await create_window_in_test_async(this, 'text/html', ''); const result = await construct_custom_element_in_parser(this, `top.another_window.document.open()`); assert_equals(result.exception, null); }, 'document.open() of another document must not throw an InvalidStateError when synchronously constructing a custom element'); promise_test(async function () { window.another_window = await create_window_in_test_async(this, 'text/html', ''); const result = await construct_custom_element_in_parser(this, `top.another_window.document.open('text/html')`); assert_equals(result.exception, null); }, 'document.open("text/html") of another document must not throw an InvalidStateError when synchronously constructing a custom element'); promise_test(async function () { window.another_window = await create_window_in_test_async(this, 'text/html', ''); const result = await construct_custom_element_in_parser(this, `top.another_window.document.close()`); assert_equals(result.exception, null); }, 'document.close() of another document must not throw an InvalidStateError when synchronously constructing a custom element'); promise_test(async function () { window.another_window = await create_window_in_test_async(this, 'text/html', ''); const result = await construct_custom_element_in_parser(this, `top.another_window.document.write('some text')`); assert_equals(result.exception, null); assert_equals(another_window.document.querySelector('b').outerHTML, 'some text'); }, 'document.write of another document must not throw an InvalidStateError when synchronously constructing a custom element'); promise_test(async function () { window.another_window = await create_window_in_test_async(this, 'text/html', ''); const result = await construct_custom_element_in_parser(this, `top.another_window.document.writeln('some text')`); assert_equals(result.exception, null); assert_equals(another_window.document.querySelector('b').outerHTML, 'some text'); }, 'document.writeln of another document must not throw an InvalidStateError when synchronously constructing a custom element'); ]]>