TEST(HTMLTreeBuilderSimulatorTest, SelfClosingMathFollowedByScript) { HTMLParserOptions options; HTMLTreeBuilderSimulator simulator(options); std::unique_ptr<HTMLTokenizer> tokenizer = HTMLTokenizer::create(options); SegmentedString input("<math/><script></script>"); HTMLToken token; EXPECT_TRUE(tokenizer->nextToken(input, token)); EXPECT_EQ(HTMLTreeBuilderSimulator::OtherToken, simulator.simulate(CompactHTMLToken(&token, TextPosition()), tokenizer.get())); token.clear(); EXPECT_TRUE(tokenizer->nextToken(input, token)); EXPECT_EQ(HTMLTreeBuilderSimulator::ScriptStart, simulator.simulate(CompactHTMLToken(&token, TextPosition()), tokenizer.get())); EXPECT_EQ(HTMLTokenizer::ScriptDataState, tokenizer->getState()); token.clear(); EXPECT_TRUE(tokenizer->nextToken(input, token)); EXPECT_EQ(HTMLTreeBuilderSimulator::ScriptEnd, simulator.simulate(CompactHTMLToken(&token, TextPosition()), tokenizer.get())); }
void HTMLDocumentParser::constructTreeFromHTMLToken(HTMLToken& rawToken) { RefPtr<AtomicHTMLToken> token = AtomicHTMLToken::create(rawToken); // We clear the rawToken in case constructTreeFromAtomicToken // synchronously re-enters the parser. We don't clear the token immedately // for Character tokens because the AtomicHTMLToken avoids copying the // characters by keeping a pointer to the underlying buffer in the // HTMLToken. Fortunately, Character tokens can't cause us to re-enter // the parser. // // FIXME: Stop clearing the rawToken once we start running the parser off // the main thread or once we stop allowing synchronous JavaScript // execution from parseAttribute. if (rawToken.type() != HTMLTokenTypes::Character) rawToken.clear(); m_treeBuilder->constructTree(token.get()); // AtomicHTMLToken keeps a pointer to the HTMLToken's buffer instead // of copying the characters for performance. // Clear the external characters pointer before the raw token is cleared // to make sure that we won't have a dangling pointer. token->clearExternalCharacters(); if (!rawToken.isUninitialized()) { ASSERT(rawToken.type() == HTMLTokenTypes::Character); rawToken.clear(); } }
void HTMLDocumentParser::constructTreeFromHTMLToken(HTMLToken& rawToken) { AtomicHTMLToken token(rawToken); // We clear the rawToken in case constructTreeFromAtomicToken // synchronously re-enters the parser. We don't clear the token immedately // for Character tokens because the AtomicHTMLToken avoids copying the // characters by keeping a pointer to the underlying buffer in the // HTMLToken. Fortunately, Character tokens can't cause us to re-enter // the parser. // // FIXME: Stop clearing the rawToken once we start running the parser off // the main thread or once we stop allowing synchronous JavaScript // execution from parseAttribute. if (rawToken.type() != HTMLToken::Character) rawToken.clear(); m_treeBuilder->constructTree(&token); if (!rawToken.isUninitialized()) { ASSERT(rawToken.type() == HTMLToken::Character); rawToken.clear(); } }