HTMLDocumentParser.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <AK/Utf32View.h>
  27. #include <LibWeb/DOM/Comment.h>
  28. #include <LibWeb/DOM/Document.h>
  29. #include <LibWeb/DOM/DocumentType.h>
  30. #include <LibWeb/DOM/ElementFactory.h>
  31. #include <LibWeb/DOM/HTMLFormElement.h>
  32. #include <LibWeb/DOM/HTMLHeadElement.h>
  33. #include <LibWeb/DOM/HTMLScriptElement.h>
  34. #include <LibWeb/DOM/Text.h>
  35. #include <LibWeb/Parser/HTMLDocumentParser.h>
  36. #include <LibWeb/Parser/HTMLToken.h>
  37. #define TODO() \
  38. do { \
  39. ASSERT_NOT_REACHED(); \
  40. } while (0)
  41. #define PARSE_ERROR() \
  42. do { \
  43. dbg() << "Parse error!"; \
  44. } while (0)
  45. namespace Web {
  46. HTMLDocumentParser::HTMLDocumentParser(const StringView& input)
  47. : m_tokenizer(input)
  48. {
  49. }
  50. HTMLDocumentParser::~HTMLDocumentParser()
  51. {
  52. }
  53. void HTMLDocumentParser::run(const URL& url)
  54. {
  55. m_document = adopt(*new Document);
  56. m_document->set_url(url);
  57. for (;;) {
  58. auto optional_token = m_tokenizer.next_token();
  59. if (!optional_token.has_value())
  60. return;
  61. auto& token = optional_token.value();
  62. dbg() << "[" << insertion_mode_name() << "] " << token.to_string();
  63. process_using_the_rules_for(m_insertion_mode, token);
  64. }
  65. }
  66. void HTMLDocumentParser::process_using_the_rules_for(InsertionMode mode, HTMLToken& token)
  67. {
  68. switch (mode) {
  69. case InsertionMode::Initial:
  70. handle_initial(token);
  71. break;
  72. case InsertionMode::BeforeHTML:
  73. handle_before_html(token);
  74. break;
  75. case InsertionMode::BeforeHead:
  76. handle_before_head(token);
  77. break;
  78. case InsertionMode::InHead:
  79. handle_in_head(token);
  80. break;
  81. case InsertionMode::InHeadNoscript:
  82. handle_in_head_noscript(token);
  83. break;
  84. case InsertionMode::AfterHead:
  85. handle_after_head(token);
  86. break;
  87. case InsertionMode::InBody:
  88. handle_in_body(token);
  89. break;
  90. case InsertionMode::AfterBody:
  91. handle_after_body(token);
  92. break;
  93. case InsertionMode::AfterAfterBody:
  94. handle_after_after_body(token);
  95. break;
  96. case InsertionMode::Text:
  97. handle_text(token);
  98. break;
  99. default:
  100. ASSERT_NOT_REACHED();
  101. }
  102. }
  103. void HTMLDocumentParser::handle_initial(HTMLToken& token)
  104. {
  105. if (token.type() == HTMLToken::Type::DOCTYPE) {
  106. auto doctype = adopt(*new DocumentType(document()));
  107. doctype->set_name(token.m_doctype.name.to_string());
  108. document().append_child(move(doctype));
  109. m_insertion_mode = InsertionMode::BeforeHTML;
  110. return;
  111. }
  112. ASSERT_NOT_REACHED();
  113. }
  114. void HTMLDocumentParser::handle_before_html(HTMLToken& token)
  115. {
  116. if (token.is_character() && token.is_parser_whitespace()) {
  117. return;
  118. }
  119. if (token.is_start_tag() && token.tag_name() == "html") {
  120. auto element = create_element_for(token);
  121. document().append_child(element);
  122. m_stack_of_open_elements.push(move(element));
  123. m_insertion_mode = InsertionMode::BeforeHead;
  124. return;
  125. }
  126. ASSERT_NOT_REACHED();
  127. }
  128. Element& HTMLDocumentParser::current_node()
  129. {
  130. return m_stack_of_open_elements.current_node();
  131. }
  132. RefPtr<Node> HTMLDocumentParser::find_appropriate_place_for_inserting_node()
  133. {
  134. auto& target = current_node();
  135. if (m_foster_parenting) {
  136. ASSERT_NOT_REACHED();
  137. }
  138. return target;
  139. }
  140. NonnullRefPtr<Element> HTMLDocumentParser::create_element_for(HTMLToken& token)
  141. {
  142. auto element = create_element(document(), token.tag_name());
  143. for (auto& attribute : token.m_tag.attributes) {
  144. element->set_attribute(attribute.name_builder.to_string(), attribute.value_builder.to_string());
  145. }
  146. return element;
  147. }
  148. RefPtr<Element> HTMLDocumentParser::insert_html_element(HTMLToken& token)
  149. {
  150. auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
  151. auto element = create_element_for(token);
  152. // FIXME: Check if it's possible to insert `element` at `adjusted_insertion_location`
  153. adjusted_insertion_location->append_child(element);
  154. m_stack_of_open_elements.push(element);
  155. return element;
  156. }
  157. void HTMLDocumentParser::handle_before_head(HTMLToken& token)
  158. {
  159. if (token.is_character() && token.is_parser_whitespace()) {
  160. return;
  161. }
  162. if (token.is_start_tag() && token.tag_name() == "head") {
  163. auto element = insert_html_element(token);
  164. m_head_element = to<HTMLHeadElement>(element);
  165. m_insertion_mode = InsertionMode::InHead;
  166. return;
  167. }
  168. ASSERT_NOT_REACHED();
  169. }
  170. void HTMLDocumentParser::insert_comment(HTMLToken& token)
  171. {
  172. auto data = token.m_comment_or_character.data.to_string();
  173. auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
  174. adjusted_insertion_location->append_child(adopt(*new Comment(document(), data)));
  175. }
  176. void HTMLDocumentParser::handle_in_head(HTMLToken& token)
  177. {
  178. if (token.is_parser_whitespace()) {
  179. insert_character(token.codepoint());
  180. return;
  181. }
  182. if (token.is_comment()) {
  183. insert_comment(token);
  184. return;
  185. }
  186. if (token.is_doctype()) {
  187. PARSE_ERROR();
  188. return;
  189. }
  190. if (token.is_start_tag() && token.tag_name() == "html") {
  191. process_using_the_rules_for(InsertionMode::InBody, token);
  192. return;
  193. }
  194. if (token.is_start_tag() && token.tag_name().is_one_of("base", "basefont", "bgsound", "link")) {
  195. insert_html_element(token);
  196. m_stack_of_open_elements.pop();
  197. token.acknowledge_self_closing_flag_if_set();
  198. return;
  199. }
  200. if (token.is_start_tag() && token.tag_name() == "title") {
  201. insert_html_element(token);
  202. m_tokenizer.switch_to({}, HTMLTokenizer::State::RCDATA);
  203. m_original_insertion_mode = m_insertion_mode;
  204. m_insertion_mode = InsertionMode::Text;
  205. return;
  206. }
  207. if (token.is_start_tag() && ((token.tag_name() == "noscript" && m_scripting_enabled) || token.tag_name() == "noframes" || token.tag_name() == "style")) {
  208. parse_generic_raw_text_element(token);
  209. return;
  210. }
  211. if (token.is_start_tag() && token.tag_name() == "script") {
  212. auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
  213. auto element = create_element_for(token);
  214. auto& script_element = to<HTMLScriptElement>(*element);
  215. script_element.set_parser_document({}, document());
  216. script_element.set_non_blocking({}, false);
  217. if (m_parsing_fragment) {
  218. TODO();
  219. }
  220. if (m_invoked_via_document_write) {
  221. TODO();
  222. }
  223. adjusted_insertion_location->append_child(element, false);
  224. m_stack_of_open_elements.push(element);
  225. m_tokenizer.switch_to({}, HTMLTokenizer::State::ScriptData);
  226. m_original_insertion_mode = m_insertion_mode;
  227. m_insertion_mode = InsertionMode::Text;
  228. return;
  229. }
  230. if (token.is_start_tag() && token.tag_name() == "meta") {
  231. auto element = insert_html_element(token);
  232. m_stack_of_open_elements.pop();
  233. token.acknowledge_self_closing_flag_if_set();
  234. return;
  235. }
  236. if (token.is_end_tag() && token.tag_name() == "head") {
  237. m_stack_of_open_elements.pop();
  238. m_insertion_mode = InsertionMode::AfterHead;
  239. return;
  240. }
  241. ASSERT_NOT_REACHED();
  242. }
  243. void HTMLDocumentParser::handle_in_head_noscript(HTMLToken&)
  244. {
  245. ASSERT_NOT_REACHED();
  246. }
  247. void HTMLDocumentParser::parse_generic_raw_text_element(HTMLToken& token)
  248. {
  249. insert_html_element(token);
  250. m_tokenizer.switch_to({}, HTMLTokenizer::State::RAWTEXT);
  251. m_original_insertion_mode = m_insertion_mode;
  252. m_insertion_mode = InsertionMode::Text;
  253. }
  254. void HTMLDocumentParser::insert_character(u32 data)
  255. {
  256. auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
  257. if (adjusted_insertion_location->is_document())
  258. return;
  259. if (adjusted_insertion_location->last_child() && adjusted_insertion_location->last_child()->is_text()) {
  260. auto& existing_text_node = to<Text>(*adjusted_insertion_location->last_child());
  261. StringBuilder builder;
  262. builder.append(existing_text_node.data());
  263. builder.append(Utf32View { &data, 1 });
  264. existing_text_node.set_data(builder.to_string());
  265. return;
  266. }
  267. StringBuilder builder;
  268. builder.append(Utf32View { &data, 1 });
  269. adjusted_insertion_location->append_child(adopt(*new Text(document(), builder.to_string())));
  270. }
  271. void HTMLDocumentParser::handle_after_head(HTMLToken& token)
  272. {
  273. if (token.is_character()) {
  274. if (token.is_parser_whitespace()) {
  275. insert_character(token.codepoint());
  276. return;
  277. }
  278. ASSERT_NOT_REACHED();
  279. }
  280. if (token.is_comment()) {
  281. ASSERT_NOT_REACHED();
  282. }
  283. if (token.is_doctype()) {
  284. ASSERT_NOT_REACHED();
  285. }
  286. if (token.is_start_tag() && token.tag_name() == "html") {
  287. ASSERT_NOT_REACHED();
  288. }
  289. if (token.is_start_tag() && token.tag_name() == "body") {
  290. insert_html_element(token);
  291. m_frameset_ok = false;
  292. m_insertion_mode = InsertionMode::InBody;
  293. return;
  294. }
  295. if (token.is_start_tag() && token.tag_name() == "frameset") {
  296. ASSERT_NOT_REACHED();
  297. }
  298. if (token.is_start_tag() && token.tag_name().is_one_of("base", "basefont", "bgsound", "link", "meta", "noframes", "script", "style", "template", "title")) {
  299. ASSERT_NOT_REACHED();
  300. }
  301. if (token.is_end_tag() && token.tag_name() == "template") {
  302. ASSERT_NOT_REACHED();
  303. }
  304. if (token.is_end_tag() && token.tag_name().is_one_of("body", "html", "br")) {
  305. goto AnythingElse;
  306. }
  307. if ((token.is_start_tag() && token.tag_name() == "head") || token.is_end_tag()) {
  308. ASSERT_NOT_REACHED();
  309. }
  310. AnythingElse:
  311. HTMLToken fake_body_token;
  312. fake_body_token.m_type = HTMLToken::Type::StartTag;
  313. fake_body_token.m_tag.tag_name.append("body");
  314. insert_html_element(fake_body_token);
  315. m_insertion_mode = InsertionMode::InBody;
  316. // FIXME: Reprocess the current token in InBody!
  317. }
  318. void HTMLDocumentParser::generate_implied_end_tags(const FlyString& exception)
  319. {
  320. while (current_node().tag_name() != exception && current_node().tag_name().is_one_of("dd", "dt", "li", "optgroup", "option", "p", "rb", "rp", "rt", "rtc"))
  321. m_stack_of_open_elements.pop();
  322. }
  323. void HTMLDocumentParser::close_a_p_element()
  324. {
  325. generate_implied_end_tags("p");
  326. if (current_node().tag_name() != "p") {
  327. PARSE_ERROR();
  328. }
  329. for (;;) {
  330. auto popped_element = m_stack_of_open_elements.pop();
  331. if (popped_element->tag_name() == "p")
  332. break;
  333. }
  334. }
  335. void HTMLDocumentParser::handle_after_body(HTMLToken& token)
  336. {
  337. if (token.is_character() && token.is_parser_whitespace()) {
  338. process_using_the_rules_for(InsertionMode::InBody, token);
  339. return;
  340. }
  341. if (token.is_end_tag() && token.tag_name() == "html") {
  342. if (m_parsing_fragment) {
  343. ASSERT_NOT_REACHED();
  344. }
  345. m_insertion_mode = InsertionMode::AfterAfterBody;
  346. return;
  347. }
  348. ASSERT_NOT_REACHED();
  349. }
  350. void HTMLDocumentParser::handle_after_after_body(HTMLToken& token)
  351. {
  352. if (token.is_doctype() || token.is_parser_whitespace() || (token.is_start_tag() && token.tag_name() == "html")) {
  353. process_using_the_rules_for(InsertionMode::InBody, token);
  354. return;
  355. }
  356. if (token.is_end_of_file()) {
  357. dbg() << "Stop parsing! :^)";
  358. return;
  359. }
  360. ASSERT_NOT_REACHED();
  361. }
  362. void HTMLDocumentParser::reconstruct_the_active_formatting_elements()
  363. {
  364. // FIXME: This needs to care about "markers"
  365. if (m_list_of_active_formatting_elements.is_empty())
  366. return;
  367. if (m_stack_of_open_elements.contains(m_list_of_active_formatting_elements.last()))
  368. return;
  369. ssize_t index = m_list_of_active_formatting_elements.size() - 1;
  370. RefPtr<Element> entry = m_list_of_active_formatting_elements.at(index);
  371. Rewind:
  372. if (m_list_of_active_formatting_elements.size() == 1) {
  373. goto Create;
  374. }
  375. --index;
  376. entry = m_list_of_active_formatting_elements.at(index);
  377. if (!m_stack_of_open_elements.contains(*entry))
  378. goto Rewind;
  379. Advance:
  380. ++index;
  381. entry = m_list_of_active_formatting_elements.at(index);
  382. Create:
  383. // FIXME: Hold on to the real token!
  384. HTMLToken fake_token;
  385. fake_token.m_type = HTMLToken::Type::StartTag;
  386. fake_token.m_tag.tag_name.append(entry->tag_name());
  387. auto new_element = insert_html_element(fake_token);
  388. m_list_of_active_formatting_elements.ptr_at(index) = *new_element;
  389. if (index != (ssize_t)m_list_of_active_formatting_elements.size() - 1)
  390. goto Advance;
  391. }
  392. void HTMLDocumentParser::handle_in_body(HTMLToken& token)
  393. {
  394. if (token.is_character()) {
  395. if (token.codepoint() == 0) {
  396. ASSERT_NOT_REACHED();
  397. }
  398. if (token.is_parser_whitespace()) {
  399. reconstruct_the_active_formatting_elements();
  400. insert_character(token.codepoint());
  401. return;
  402. }
  403. reconstruct_the_active_formatting_elements();
  404. insert_character(token.codepoint());
  405. m_frameset_ok = false;
  406. return;
  407. }
  408. if (token.is_end_tag() && token.tag_name() == "body") {
  409. if (!m_stack_of_open_elements.has_in_scope("body")) {
  410. ASSERT_NOT_REACHED();
  411. }
  412. // FIXME: Otherwise, if there is a node in the stack of open elements that is
  413. // not either a dd element, a dt element, an li element, an optgroup element,
  414. // an option element, a p element, an rb element, an rp element, an rt element,
  415. // an rtc element, a tbody element, a td element, a tfoot element, a th element,
  416. // a thead element, a tr element, the body element, or the html element,
  417. // then this is a parse error.
  418. m_insertion_mode = InsertionMode::AfterBody;
  419. return;
  420. }
  421. if (token.is_start_tag() && token.tag_name().is_one_of("h1", "h2", "h3", "h4", "h5", "h6")) {
  422. if (m_stack_of_open_elements.has_in_button_scope("p"))
  423. close_a_p_element();
  424. if (current_node().tag_name().is_one_of("h1", "h2", "h3", "h4", "h5", "h6")) {
  425. // FIXME: This is a parse error!
  426. TODO();
  427. }
  428. insert_html_element(token);
  429. return;
  430. }
  431. if (token.is_end_tag() && token.tag_name().is_one_of("h1", "h2", "h3", "h4", "h5", "h6")) {
  432. if (!m_stack_of_open_elements.has_in_scope("h1")
  433. && !m_stack_of_open_elements.has_in_scope("h2")
  434. && !m_stack_of_open_elements.has_in_scope("h3")
  435. && !m_stack_of_open_elements.has_in_scope("h4")
  436. && !m_stack_of_open_elements.has_in_scope("h5")
  437. && !m_stack_of_open_elements.has_in_scope("h6")) {
  438. TODO();
  439. }
  440. generate_implied_end_tags();
  441. if (current_node().tag_name() != token.tag_name()) {
  442. TODO();
  443. }
  444. for (;;) {
  445. auto popped_element = m_stack_of_open_elements.pop();
  446. if (popped_element->tag_name() == "h1"
  447. || popped_element->tag_name() == "h2"
  448. || popped_element->tag_name() == "h3"
  449. || popped_element->tag_name() == "h4"
  450. || popped_element->tag_name() == "h5"
  451. || popped_element->tag_name() == "h6") {
  452. break;
  453. }
  454. }
  455. return;
  456. }
  457. if (token.is_end_tag() && token.tag_name() == "p") {
  458. if (!m_stack_of_open_elements.has_in_button_scope("p")) {
  459. TODO();
  460. }
  461. close_a_p_element();
  462. return;
  463. }
  464. {
  465. if (token.is_start_tag() && token.tag_name().is_one_of("b", "big", "code", "em", "font", "i", "s", "small", "strike", "strong", "tt", "u")) {
  466. reconstruct_the_active_formatting_elements();
  467. auto element = insert_html_element(token);
  468. m_list_of_active_formatting_elements.append(*element);
  469. return;
  470. }
  471. }
  472. if (token.is_start_tag() && token.tag_name().is_one_of("address", "article", "aside", "blockquote", "center", "details", "dialog", "dir", "div", "dl", "fieldset", "figcaption", "figure", "footer", "header", "hgroup", "main", "menu", "nav", "ol", "p", "section", "summary", "ul")) {
  473. // FIXME: If the stack of open elements has a p element in button scope, then close a p element.
  474. insert_html_element(token);
  475. return;
  476. }
  477. if (token.is_end_tag() && token.tag_name().is_one_of("address", "article", "aside", "blockquote", "center", "details", "dialog", "dir", "div", "dl", "fieldset", "figcaption", "figure", "footer", "header", "hgroup", "main", "menu", "nav", "ol", "p", "section", "summary", "ul")) {
  478. // FIXME: If the stack of open elements has a p element in button scope, then close a p element.
  479. if (!m_stack_of_open_elements.has_in_scope(token.tag_name())) {
  480. ASSERT_NOT_REACHED();
  481. }
  482. generate_implied_end_tags();
  483. if (current_node().tag_name() != token.tag_name()) {
  484. ASSERT_NOT_REACHED();
  485. }
  486. m_stack_of_open_elements.pop();
  487. return;
  488. }
  489. if (token.is_start_tag()) {
  490. reconstruct_the_active_formatting_elements();
  491. insert_html_element(token);
  492. return;
  493. }
  494. if (token.is_end_tag()) {
  495. RefPtr<Element> node;
  496. for (ssize_t i = m_stack_of_open_elements.elements().size() - 1; i >= 0; --i) {
  497. node = m_stack_of_open_elements.elements()[i];
  498. if (node->tag_name() == token.tag_name()) {
  499. generate_implied_end_tags(token.tag_name());
  500. if (node != current_node()) {
  501. // It's a parse error
  502. TODO();
  503. }
  504. while (&current_node() != node) {
  505. m_stack_of_open_elements.pop();
  506. }
  507. m_stack_of_open_elements.pop();
  508. break;
  509. }
  510. // FIXME: Handle special elements!
  511. }
  512. return;
  513. }
  514. ASSERT_NOT_REACHED();
  515. }
  516. void HTMLDocumentParser::increment_script_nesting_level()
  517. {
  518. ++m_script_nesting_level;
  519. }
  520. void HTMLDocumentParser::decrement_script_nesting_level()
  521. {
  522. ASSERT(m_script_nesting_level);
  523. --m_script_nesting_level;
  524. }
  525. void HTMLDocumentParser::handle_text(HTMLToken& token)
  526. {
  527. if (token.is_character()) {
  528. insert_character(token.codepoint());
  529. return;
  530. }
  531. if (token.is_end_tag() && token.tag_name() == "script") {
  532. NonnullRefPtr<HTMLScriptElement> script = to<HTMLScriptElement>(current_node());
  533. m_stack_of_open_elements.pop();
  534. m_insertion_mode = m_original_insertion_mode;
  535. // FIXME: Handle tokenizer insertion point stuff here.
  536. increment_script_nesting_level();
  537. script->prepare_script({});
  538. decrement_script_nesting_level();
  539. if (script_nesting_level() == 0)
  540. m_parser_pause_flag = false;
  541. // FIXME: Handle tokenizer insertion point stuff here too.
  542. return;
  543. }
  544. if (token.is_end_tag()) {
  545. m_stack_of_open_elements.pop();
  546. m_insertion_mode = m_original_insertion_mode;
  547. return;
  548. }
  549. ASSERT_NOT_REACHED();
  550. }
  551. const char* HTMLDocumentParser::insertion_mode_name() const
  552. {
  553. switch (m_insertion_mode) {
  554. #define __ENUMERATE_INSERTION_MODE(mode) \
  555. case InsertionMode::mode: \
  556. return #mode;
  557. ENUMERATE_INSERTION_MODES
  558. #undef __ENUMERATE_INSERTION_MODE
  559. }
  560. ASSERT_NOT_REACHED();
  561. }
  562. Document& HTMLDocumentParser::document()
  563. {
  564. return *m_document;
  565. }
  566. }