HTMLDocumentParser.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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_start_tag() && token.tag_name() == "title") {
  187. insert_html_element(token);
  188. m_tokenizer.switch_to({}, HTMLTokenizer::State::RCDATA);
  189. m_original_insertion_mode = m_insertion_mode;
  190. m_insertion_mode = InsertionMode::Text;
  191. return;
  192. }
  193. if (token.is_start_tag() && ((token.tag_name() == "noscript" && m_scripting_enabled) || token.tag_name() == "noframes" || token.tag_name() == "style")) {
  194. parse_generic_raw_text_element(token);
  195. return;
  196. }
  197. if (token.is_start_tag() && token.tag_name() == "script") {
  198. auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
  199. auto element = create_element_for(token);
  200. auto& script_element = to<HTMLScriptElement>(*element);
  201. script_element.set_parser_document({}, document());
  202. script_element.set_non_blocking({}, false);
  203. if (m_parsing_fragment) {
  204. TODO();
  205. }
  206. if (m_invoked_via_document_write) {
  207. TODO();
  208. }
  209. adjusted_insertion_location->append_child(element, false);
  210. m_stack_of_open_elements.push(element);
  211. m_tokenizer.switch_to({}, HTMLTokenizer::State::ScriptData);
  212. m_original_insertion_mode = m_insertion_mode;
  213. m_insertion_mode = InsertionMode::Text;
  214. return;
  215. }
  216. if (token.is_start_tag() && token.tag_name() == "meta") {
  217. auto element = insert_html_element(token);
  218. m_stack_of_open_elements.pop();
  219. if (token.is_self_closing()) {
  220. ASSERT_NOT_REACHED();
  221. }
  222. return;
  223. }
  224. if (token.is_end_tag() && token.tag_name() == "head") {
  225. m_stack_of_open_elements.pop();
  226. m_insertion_mode = InsertionMode::AfterHead;
  227. return;
  228. }
  229. ASSERT_NOT_REACHED();
  230. }
  231. void HTMLDocumentParser::handle_in_head_noscript(HTMLToken&)
  232. {
  233. ASSERT_NOT_REACHED();
  234. }
  235. void HTMLDocumentParser::parse_generic_raw_text_element(HTMLToken& token)
  236. {
  237. insert_html_element(token);
  238. m_tokenizer.switch_to({}, HTMLTokenizer::State::RAWTEXT);
  239. m_original_insertion_mode = m_insertion_mode;
  240. m_insertion_mode = InsertionMode::Text;
  241. }
  242. void HTMLDocumentParser::insert_character(u32 data)
  243. {
  244. auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
  245. if (adjusted_insertion_location->is_document())
  246. return;
  247. if (adjusted_insertion_location->last_child() && adjusted_insertion_location->last_child()->is_text()) {
  248. auto& existing_text_node = to<Text>(*adjusted_insertion_location->last_child());
  249. StringBuilder builder;
  250. builder.append(existing_text_node.data());
  251. builder.append(Utf32View { &data, 1 });
  252. existing_text_node.set_data(builder.to_string());
  253. return;
  254. }
  255. StringBuilder builder;
  256. builder.append(Utf32View { &data, 1 });
  257. adjusted_insertion_location->append_child(adopt(*new Text(document(), builder.to_string())));
  258. }
  259. void HTMLDocumentParser::handle_after_head(HTMLToken& token)
  260. {
  261. if (token.is_character()) {
  262. if (token.is_parser_whitespace()) {
  263. insert_character(token.codepoint());
  264. return;
  265. }
  266. ASSERT_NOT_REACHED();
  267. }
  268. if (token.is_comment()) {
  269. ASSERT_NOT_REACHED();
  270. }
  271. if (token.is_doctype()) {
  272. ASSERT_NOT_REACHED();
  273. }
  274. if (token.is_start_tag() && token.tag_name() == "html") {
  275. ASSERT_NOT_REACHED();
  276. }
  277. if (token.is_start_tag() && token.tag_name() == "body") {
  278. insert_html_element(token);
  279. m_frameset_ok = false;
  280. m_insertion_mode = InsertionMode::InBody;
  281. return;
  282. }
  283. if (token.is_start_tag() && token.tag_name() == "frameset") {
  284. ASSERT_NOT_REACHED();
  285. }
  286. if (token.is_start_tag() && token.tag_name().is_one_of("base", "basefont", "bgsound", "link", "meta", "noframes", "script", "style", "template", "title")) {
  287. ASSERT_NOT_REACHED();
  288. }
  289. if (token.is_end_tag() && token.tag_name() == "template") {
  290. ASSERT_NOT_REACHED();
  291. }
  292. if (token.is_end_tag() && token.tag_name().is_one_of("body", "html", "br")) {
  293. goto AnythingElse;
  294. }
  295. if ((token.is_start_tag() && token.tag_name() == "head") || token.is_end_tag()) {
  296. ASSERT_NOT_REACHED();
  297. }
  298. AnythingElse:
  299. HTMLToken fake_body_token;
  300. fake_body_token.m_type = HTMLToken::Type::StartTag;
  301. fake_body_token.m_tag.tag_name.append("body");
  302. insert_html_element(fake_body_token);
  303. m_insertion_mode = InsertionMode::InBody;
  304. // FIXME: Reprocess the current token in InBody!
  305. }
  306. void HTMLDocumentParser::generate_implied_end_tags(const FlyString& exception)
  307. {
  308. while (current_node().tag_name() != exception && current_node().tag_name().is_one_of("dd", "dt", "li", "optgroup", "option", "p", "rb", "rp", "rt", "rtc"))
  309. m_stack_of_open_elements.pop();
  310. }
  311. void HTMLDocumentParser::close_a_p_element()
  312. {
  313. generate_implied_end_tags("p");
  314. if (current_node().tag_name() != "p") {
  315. PARSE_ERROR();
  316. }
  317. for (;;) {
  318. auto popped_element = m_stack_of_open_elements.pop();
  319. if (popped_element->tag_name() == "p")
  320. break;
  321. }
  322. }
  323. void HTMLDocumentParser::handle_after_body(HTMLToken& token)
  324. {
  325. if (token.is_character() && token.is_parser_whitespace()) {
  326. process_using_the_rules_for(InsertionMode::InBody, token);
  327. return;
  328. }
  329. if (token.is_end_tag() && token.tag_name() == "html") {
  330. if (m_parsing_fragment) {
  331. ASSERT_NOT_REACHED();
  332. }
  333. m_insertion_mode = InsertionMode::AfterAfterBody;
  334. return;
  335. }
  336. ASSERT_NOT_REACHED();
  337. }
  338. void HTMLDocumentParser::handle_after_after_body(HTMLToken& token)
  339. {
  340. if (token.is_doctype() || token.is_parser_whitespace() || (token.is_start_tag() && token.tag_name() == "html")) {
  341. process_using_the_rules_for(InsertionMode::InBody, token);
  342. return;
  343. }
  344. if (token.is_end_of_file()) {
  345. dbg() << "Stop parsing! :^)";
  346. return;
  347. }
  348. ASSERT_NOT_REACHED();
  349. }
  350. void HTMLDocumentParser::reconstruct_the_active_formatting_elements()
  351. {
  352. // FIXME: This needs to care about "markers"
  353. if (m_list_of_active_formatting_elements.is_empty())
  354. return;
  355. if (m_stack_of_open_elements.contains(m_list_of_active_formatting_elements.last()))
  356. return;
  357. ssize_t index = m_list_of_active_formatting_elements.size() - 1;
  358. RefPtr<Element> entry = m_list_of_active_formatting_elements.at(index);
  359. Rewind:
  360. if (m_list_of_active_formatting_elements.size() == 1) {
  361. goto Create;
  362. }
  363. --index;
  364. entry = m_list_of_active_formatting_elements.at(index);
  365. if (!m_stack_of_open_elements.contains(*entry))
  366. goto Rewind;
  367. Advance:
  368. ++index;
  369. entry = m_list_of_active_formatting_elements.at(index);
  370. Create:
  371. // FIXME: Hold on to the real token!
  372. HTMLToken fake_token;
  373. fake_token.m_type = HTMLToken::Type::StartTag;
  374. fake_token.m_tag.tag_name.append(entry->tag_name());
  375. auto new_element = insert_html_element(fake_token);
  376. m_list_of_active_formatting_elements.ptr_at(index) = *new_element;
  377. if (index != (ssize_t)m_list_of_active_formatting_elements.size() - 1)
  378. goto Advance;
  379. }
  380. void HTMLDocumentParser::handle_in_body(HTMLToken& token)
  381. {
  382. if (token.is_character()) {
  383. if (token.codepoint() == 0) {
  384. ASSERT_NOT_REACHED();
  385. }
  386. if (token.is_parser_whitespace()) {
  387. reconstruct_the_active_formatting_elements();
  388. insert_character(token.codepoint());
  389. return;
  390. }
  391. reconstruct_the_active_formatting_elements();
  392. insert_character(token.codepoint());
  393. m_frameset_ok = false;
  394. return;
  395. }
  396. if (token.is_end_tag() && token.tag_name() == "body") {
  397. if (!m_stack_of_open_elements.has_in_scope("body")) {
  398. ASSERT_NOT_REACHED();
  399. }
  400. // FIXME: Otherwise, if there is a node in the stack of open elements that is
  401. // not either a dd element, a dt element, an li element, an optgroup element,
  402. // an option element, a p element, an rb element, an rp element, an rt element,
  403. // an rtc element, a tbody element, a td element, a tfoot element, a th element,
  404. // a thead element, a tr element, the body element, or the html element,
  405. // then this is a parse error.
  406. m_insertion_mode = InsertionMode::AfterBody;
  407. return;
  408. }
  409. if (token.is_start_tag() && token.tag_name().is_one_of("h1", "h2", "h3", "h4", "h5", "h6")) {
  410. if (m_stack_of_open_elements.has_in_button_scope("p"))
  411. close_a_p_element();
  412. if (current_node().tag_name().is_one_of("h1", "h2", "h3", "h4", "h5", "h6")) {
  413. // FIXME: This is a parse error!
  414. TODO();
  415. }
  416. insert_html_element(token);
  417. return;
  418. }
  419. if (token.is_end_tag() && token.tag_name().is_one_of("h1", "h2", "h3", "h4", "h5", "h6")) {
  420. if (!m_stack_of_open_elements.has_in_scope("h1")
  421. && !m_stack_of_open_elements.has_in_scope("h2")
  422. && !m_stack_of_open_elements.has_in_scope("h3")
  423. && !m_stack_of_open_elements.has_in_scope("h4")
  424. && !m_stack_of_open_elements.has_in_scope("h5")
  425. && !m_stack_of_open_elements.has_in_scope("h6")) {
  426. TODO();
  427. }
  428. generate_implied_end_tags();
  429. if (current_node().tag_name() != token.tag_name()) {
  430. TODO();
  431. }
  432. for (;;) {
  433. auto popped_element = m_stack_of_open_elements.pop();
  434. if (popped_element->tag_name() == "h1"
  435. || popped_element->tag_name() == "h2"
  436. || popped_element->tag_name() == "h3"
  437. || popped_element->tag_name() == "h4"
  438. || popped_element->tag_name() == "h5"
  439. || popped_element->tag_name() == "h6") {
  440. break;
  441. }
  442. }
  443. return;
  444. }
  445. if (token.is_end_tag() && token.tag_name() == "p") {
  446. if (!m_stack_of_open_elements.has_in_button_scope("p")) {
  447. TODO();
  448. }
  449. close_a_p_element();
  450. return;
  451. }
  452. {
  453. if (token.is_start_tag() && token.tag_name().is_one_of("b", "big", "code", "em", "font", "i", "s", "small", "strike", "strong", "tt", "u")) {
  454. reconstruct_the_active_formatting_elements();
  455. auto element = insert_html_element(token);
  456. m_list_of_active_formatting_elements.append(*element);
  457. return;
  458. }
  459. }
  460. 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")) {
  461. // FIXME: If the stack of open elements has a p element in button scope, then close a p element.
  462. insert_html_element(token);
  463. return;
  464. }
  465. 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")) {
  466. // FIXME: If the stack of open elements has a p element in button scope, then close a p element.
  467. if (!m_stack_of_open_elements.has_in_scope(token.tag_name())) {
  468. ASSERT_NOT_REACHED();
  469. }
  470. generate_implied_end_tags();
  471. if (current_node().tag_name() != token.tag_name()) {
  472. ASSERT_NOT_REACHED();
  473. }
  474. m_stack_of_open_elements.pop();
  475. return;
  476. }
  477. if (token.is_start_tag()) {
  478. reconstruct_the_active_formatting_elements();
  479. insert_html_element(token);
  480. return;
  481. }
  482. if (token.is_end_tag()) {
  483. RefPtr<Element> node;
  484. for (ssize_t i = m_stack_of_open_elements.elements().size() - 1; i >= 0; --i) {
  485. node = m_stack_of_open_elements.elements()[i];
  486. if (node->tag_name() == token.tag_name()) {
  487. generate_implied_end_tags(token.tag_name());
  488. if (node != current_node()) {
  489. // It's a parse error
  490. TODO();
  491. }
  492. while (&current_node() != node) {
  493. m_stack_of_open_elements.pop();
  494. }
  495. m_stack_of_open_elements.pop();
  496. break;
  497. }
  498. // FIXME: Handle special elements!
  499. }
  500. return;
  501. }
  502. ASSERT_NOT_REACHED();
  503. }
  504. void HTMLDocumentParser::increment_script_nesting_level()
  505. {
  506. ++m_script_nesting_level;
  507. }
  508. void HTMLDocumentParser::decrement_script_nesting_level()
  509. {
  510. ASSERT(m_script_nesting_level);
  511. --m_script_nesting_level;
  512. }
  513. void HTMLDocumentParser::handle_text(HTMLToken& token)
  514. {
  515. if (token.is_character()) {
  516. insert_character(token.codepoint());
  517. return;
  518. }
  519. if (token.is_end_tag() && token.tag_name() == "script") {
  520. NonnullRefPtr<HTMLScriptElement> script = to<HTMLScriptElement>(current_node());
  521. m_stack_of_open_elements.pop();
  522. m_insertion_mode = m_original_insertion_mode;
  523. // FIXME: Handle tokenizer insertion point stuff here.
  524. increment_script_nesting_level();
  525. script->prepare_script({});
  526. decrement_script_nesting_level();
  527. if (script_nesting_level() == 0)
  528. m_parser_pause_flag = false;
  529. // FIXME: Handle tokenizer insertion point stuff here too.
  530. return;
  531. }
  532. if (token.is_end_tag()) {
  533. m_stack_of_open_elements.pop();
  534. m_insertion_mode = m_original_insertion_mode;
  535. return;
  536. }
  537. ASSERT_NOT_REACHED();
  538. }
  539. const char* HTMLDocumentParser::insertion_mode_name() const
  540. {
  541. switch (m_insertion_mode) {
  542. #define __ENUMERATE_INSERTION_MODE(mode) \
  543. case InsertionMode::mode: \
  544. return #mode;
  545. ENUMERATE_INSERTION_MODES
  546. #undef __ENUMERATE_INSERTION_MODE
  547. }
  548. ASSERT_NOT_REACHED();
  549. }
  550. Document& HTMLDocumentParser::document()
  551. {
  552. return *m_document;
  553. }
  554. }