Changeset 63998 in webkit
- Timestamp:
- Jul 23, 2010 3:14:02 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r63995 r63998 1 2010-07-23 Adam Barth <abarth@webkit.org> 2 3 Reviewed by Eric Seidel. 4 5 HTML5 Parser: document.write in a asynchronous script which is specified to load before page finish blows away document 6 https://bugs.webkit.org/show_bug.cgi?id=42365 7 8 * http/tests/misc/write-from-dom-script-expected.txt: Added. 9 * http/tests/misc/write-from-dom-script.html: Added. 10 - Test the scenario where a script added to the DOM asynchronously 11 while the nesting level is >0. It's supposed to have its calls to 12 document.write blocked. 13 * http/tests/misc/write-while-waiting.html: 14 - Writes are only prevented from scripts that are added to the DOM. 15 Scripts that run via setTimeout do not have their writes blocked. 16 1 17 2010-07-23 Shinichiro Hamaji <hamaji@chromium.org> 2 18 -
trunk/LayoutTests/http/tests/misc/write-while-waiting.html
r63165 r63998 1 1 <html> 2 2 <body> 3 PASS 3 FAIL 4 4 <script> 5 5 if (window.layoutTestController) 6 6 layoutTestController.dumpAsText(); 7 7 8 setTimeout("document.write(' FAIL');document.close();", 100);8 setTimeout("document.write('PASS');document.close();", 100); 9 9 </script> 10 10 <script src="resources/script-slow1.pl"></script> -
trunk/WebCore/ChangeLog
r63996 r63998 1 2010-07-23 Adam Barth <abarth@webkit.org> 2 3 Reviewed by Eric Seidel. 4 5 HTML5 Parser: document.write in a asynchronous script which is specified to load before page finish blows away document 6 https://bugs.webkit.org/show_bug.cgi?id=42365 7 8 This patch implements the changes Ian made to HTML5 to address these 9 issues. Let's try it and see how well it works. 10 11 Test: http/tests/misc/write-from-dom-script.html 12 13 * dom/Document.cpp: 14 (WebCore::Document::Document): 15 (WebCore::Document::write): 16 * dom/Document.h: 17 (WebCore::Document::writeDisabled): 18 (WebCore::Document::setWriteDisabled): 19 * dom/DocumentParser.h: 20 (WebCore::DocumentParser::hasInsertionPoint): 21 * dom/ScriptElement.cpp: 22 (WebCore::ScriptElement::insertedIntoDocument): 23 (WebCore::ScriptElementData::ScriptElementData): 24 (WebCore::ScriptElementData::evaluateScript): 25 * dom/ScriptElement.h: 26 (WebCore::ScriptElementData::writeDisabled): 27 (WebCore::ScriptElementData::setWriteDisabled): 28 * html/HTMLDocumentParser.cpp: 29 (WebCore::HTMLDocumentParser::hasInsertionPoint): 30 (WebCore::HTMLDocumentParser::insert): 31 * html/HTMLDocumentParser.h: 32 1 33 2010-07-23 Patrick Gansterer <paroga@paroga.com> 2 34 -
trunk/WebCore/dom/Document.cpp
r63165 r63998 364 364 , m_containsValidityStyleRules(false) 365 365 , m_updateFocusAppearanceRestoresSelection(false) 366 , m_writeDisabled(false) 366 367 , m_title("") 367 368 , m_rawTitle("") … … 2017 2018 #endif 2018 2019 2019 if (!m_parser) 2020 // If the insertion point is undefined and the Document has the 2021 // "write-neutralised" flag set, then abort these steps. 2022 bool hasInsertionPoint = m_parser && m_parser->hasInsertionPoint(); 2023 if (!hasInsertionPoint && writeDisabled()) 2024 return; 2025 2026 if (!hasInsertionPoint) 2020 2027 open(ownerDocument); 2021 2028 -
trunk/WebCore/dom/Document.h
r62693 r63998 1003 1003 const QualifiedName& idAttributeName() const { return m_idAttributeName; } 1004 1004 1005 bool writeDisabled() const { return m_writeDisabled; } 1006 void setWriteDisabled(bool flag) { m_writeDisabled = flag; } 1007 1005 1008 protected: 1006 1009 Document(Frame*, const KURL&, bool isXHTML, bool isHTML); … … 1156 1159 bool m_updateFocusAppearanceRestoresSelection; 1157 1160 1161 // http://www.whatwg.org/specs/web-apps/current-work/#write-neutralised 1162 bool m_writeDisabled; 1163 1158 1164 String m_title; 1159 1165 String m_rawTitle; -
trunk/WebCore/dom/DocumentParser.h
r61985 r63998 41 41 virtual ScriptableDocumentParser* asScriptableDocumentParser() { return 0; } 42 42 43 // http://www.whatwg.org/specs/web-apps/current-work/#insertion-point 44 virtual bool hasInsertionPoint() { return true; } 45 43 46 // insert is used by document.write 44 47 virtual void insert(const SegmentedString&) = 0; -
trunk/WebCore/dom/ScriptElement.cpp
r61518 r63998 28 28 #include "DocLoader.h" 29 29 #include "Document.h" 30 #include "DocumentParser.h" 30 31 #include "Frame.h" 31 32 #include "FrameLoader.h" … … 54 55 return; 55 56 57 // http://www.whatwg.org/specs/web-apps/current-work/#script 58 59 // If the element's Document has an active parser, and the parser's script 60 // nesting level is non-zero, but this script element does not have the 61 // "parser-inserted" flag set, the user agent must set the element's 62 // "write-neutralised" flag. 63 DocumentParser* parser = data.element()->document()->parser(); 64 if (parser && parser->hasInsertionPoint()) 65 data.setWriteDisabled(true); 66 56 67 if (!sourceUrl.isEmpty()) { 57 68 data.requestScript(sourceUrl); … … 83 94 if (element->inDocument() && element->firstChild()) 84 95 data.evaluateScript(ScriptSourceCode(data.scriptContent(), element->document()->url())); // FIXME: Provide a real starting line number here 85 }86 87 static inline bool useHTML5Parser(Document* document)88 {89 ASSERT(document);90 Settings* settings = document->page() ? document->page()->settings() : 0;91 return settings && settings->html5ParserEnabled();92 96 } 93 97 … … 138 142 , m_cachedScript(0) 139 143 , m_createdByParser(false) 144 , m_writeDisabled(false) 140 145 , m_requested(false) 141 146 , m_evaluated(false) … … 192 197 m_evaluated = true; 193 198 199 // http://www.whatwg.org/specs/web-apps/current-work/#script 200 201 // If the script element's "write-neutralised" flag is set, then flag 202 // the Document the script element was in when the "write-neutralised" 203 // flag was set as being itself "write-neutralised". Let neutralised doc 204 // be that Document. 205 if (m_writeDisabled) { 206 ASSERT(!m_element->document()->writeDisabled()); 207 m_element->document()->setWriteDisabled(true); 208 } 209 210 // Create a script from the script element node, using the script 211 // block's source and the script block's type. 212 // Note: This is where the script is compiled and actually executed. 194 213 frame->script()->evaluate(sourceCode); 214 215 // Remove the "write-neutralised" flag from neutralised doc, if it was 216 // set in the earlier step. 217 if (m_writeDisabled) { 218 ASSERT(m_element->document()->writeDisabled()); 219 m_element->document()->setWriteDisabled(false); 220 } 221 195 222 Document::updateStyleForAllDocuments(); 196 223 } -
trunk/WebCore/dom/ScriptElement.h
r61518 r63998 83 83 bool createdByParser() const { return m_createdByParser; } 84 84 void setCreatedByParser(bool value) { m_createdByParser = value; } 85 bool writeDisabled() const { return m_writeDisabled; } 86 void setWriteDisabled(bool value) { m_writeDisabled = value; } 85 87 bool haveFiredLoadEvent() const { return m_firedLoad; } 86 88 void setHaveFiredLoadEvent(bool firedLoad) { m_firedLoad = firedLoad; } … … 100 102 CachedResourceHandle<CachedScript> m_cachedScript; 101 103 bool m_createdByParser; // HTML5: "parser-inserted" 104 bool m_writeDisabled; // http://www.whatwg.org/specs/web-apps/current-work/#write-neutralised 102 105 bool m_requested; 103 106 bool m_evaluated; // HTML5: "already started" -
trunk/WebCore/html/HTMLDocumentParser.cpp
r63165 r63998 214 214 } 215 215 216 bool HTMLDocumentParser::hasInsertionPoint() 217 { 218 return m_input.hasInsertionPoint(); 219 } 220 216 221 void HTMLDocumentParser::insert(const SegmentedString& source) 217 222 { 218 223 if (m_parserStopped) 219 224 return; 220 221 if (m_scriptRunner && !m_scriptRunner->inScriptExecution() && m_input.haveSeenEndOfFile()) {222 // document.write was called without a current insertion point.223 // According to the spec, we're supposed to implicitly open the224 // document. Unfortunately, that behavior isn't sufficiently compatible225 // with the web. The working group is mulling over what exactly to226 // do. In the meantime, we're going to try one of the potential227 // solutions, which is to ignore the write.228 // http://www.w3.org/Bugs/Public/show_bug.cgi?id=9767229 return;230 }231 225 232 226 { … … 325 319 if (!m_scriptRunner) 326 320 return false; 327 return m_scriptRunner->i nScriptExecution();321 return m_scriptRunner->isExecutingScript(); 328 322 } 329 323 … … 403 397 if (!m_scriptRunner->hasScriptsWaitingForStylesheets()) 404 398 return; 405 ASSERT(!m_scriptRunner->i nScriptExecution());399 ASSERT(!m_scriptRunner->isExecutingScript()); 406 400 ASSERT(m_treeBuilder->isPaused()); 407 401 // Note: We only ever wait on one script at a time, so we always know this -
trunk/WebCore/html/HTMLDocumentParser.h
r62033 r63998 65 65 private: 66 66 // DocumentParser 67 virtual bool hasInsertionPoint(); 67 68 virtual void insert(const SegmentedString&); 68 69 virtual void append(const SegmentedString&); -
trunk/WebCore/html/HTMLInputStream.h
r62168 r63998 65 65 } 66 66 67 bool hasInsertionPoint() const 68 { 69 if (&m_first != m_last) 70 return true; 71 if (!haveSeenEndOfFile()) { 72 // FIXME: Somehow we need to understand the difference between 73 // input streams that are coming off the network and streams that 74 // were created with document.open(). In the later case, we always 75 // have an isertion point at the end of the stream until someone 76 // calls document.close(). 77 return true; 78 } 79 return false; 80 } 81 67 82 void markEndOfFile() 68 83 { … … 74 89 } 75 90 76 bool haveSeenEndOfFile() 91 bool haveSeenEndOfFile() const 77 92 { 78 93 return m_last->isClosed(); -
trunk/WebCore/html/HTMLScriptRunner.cpp
r61940 r63998 155 155 if (!scriptElement->shouldExecuteAsJavaScript()) 156 156 return; 157 ASSERT(i nScriptExecution());157 ASSERT(isExecutingScript()); 158 158 if (!m_document->frame()) 159 159 return; -
trunk/WebCore/html/HTMLScriptRunner.h
r61940 r63998 54 54 bool executeScriptsWaitingForStylesheets(); 55 55 56 bool i nScriptExecution() { return !!m_scriptNestingLevel; }56 bool isExecutingScript() { return !!m_scriptNestingLevel; } 57 57 58 58 private:
Note: See TracChangeset
for help on using the changeset viewer.