Changeset 143797 in webkit


Ignore:
Timestamp:
Feb 22, 2013 2:17:49 PM (11 years ago)
Author:
abarth@webkit.org
Message:

Threaded HTML parser should pass fast/parser/iframe-sets-parent-to-javascript-url.html
https://bugs.webkit.org/show_bug.cgi?id=110637

Reviewed by Eric Seidel.

With the main thread parser, we always parse the first chunk of content
returned as the result of evaluating a JavaScript URL synchronously. In
particular, if the first chunk has an inline script, we'll execute it
synchronously.

Previous to this patch, the threaded parser would always parse this
content asynchronously. It's conceivable that there could be some
content relying on the synchronous behavior, so this patch introduces
the notion of "pinning" a parser to the main thread and uses that
concept to force the result of JavaScript URLs to be parsed on the main
thread (which is probably desirable anyway because they're likely to be
quite short).

This patch fixes fast/parser/iframe-sets-parent-to-javascript-url.html
and fast/dom/javascript-url-crash-function.html with the threaded
parser with --enable-threaded-html-parser.

  • dom/DocumentParser.h:

(WebCore::DocumentParser::pinToMainThread):
(DocumentParser):

  • html/parser/HTMLDocumentParser.cpp:

(WebCore::HTMLDocumentParser::HTMLDocumentParser):
(WebCore):
(WebCore::HTMLDocumentParser::pinToMainThread):

  • html/parser/HTMLDocumentParser.h:

(HTMLDocumentParser):
(WebCore::HTMLDocumentParser::shouldUseThreading):

  • loader/DocumentWriter.cpp:

(WebCore::DocumentWriter::replaceDocument):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r143796 r143797  
     12013-02-22  Adam Barth  <abarth@webkit.org>
     2
     3        Threaded HTML parser should pass fast/parser/iframe-sets-parent-to-javascript-url.html
     4        https://bugs.webkit.org/show_bug.cgi?id=110637
     5
     6        Reviewed by Eric Seidel.
     7
     8        With the main thread parser, we always parse the first chunk of content
     9        returned as the result of evaluating a JavaScript URL synchronously. In
     10        particular, if the first chunk has an inline script, we'll execute it
     11        synchronously.
     12
     13        Previous to this patch, the threaded parser would always parse this
     14        content asynchronously. It's conceivable that there could be some
     15        content relying on the synchronous behavior, so this patch introduces
     16        the notion of "pinning" a parser to the main thread and uses that
     17        concept to force the result of JavaScript URLs to be parsed on the main
     18        thread (which is probably desirable anyway because they're likely to be
     19        quite short).
     20
     21        This patch fixes fast/parser/iframe-sets-parent-to-javascript-url.html
     22        and fast/dom/javascript-url-crash-function.html with the threaded
     23        parser with --enable-threaded-html-parser.
     24
     25        * dom/DocumentParser.h:
     26        (WebCore::DocumentParser::pinToMainThread):
     27        (DocumentParser):
     28        * html/parser/HTMLDocumentParser.cpp:
     29        (WebCore::HTMLDocumentParser::HTMLDocumentParser):
     30        (WebCore):
     31        (WebCore::HTMLDocumentParser::pinToMainThread):
     32        * html/parser/HTMLDocumentParser.h:
     33        (HTMLDocumentParser):
     34        (WebCore::HTMLDocumentParser::shouldUseThreading):
     35        * loader/DocumentWriter.cpp:
     36        (WebCore::DocumentWriter::replaceDocument):
     37
    1382013-02-22  Joe Mason  <jmason@rim.com>
    239
  • trunk/Source/WebCore/dom/DocumentParser.h

    r140036 r143797  
    4949    virtual void appendBytes(DocumentWriter*, const char* bytes, size_t length) = 0;
    5050    virtual void flush(DocumentWriter*) = 0;
     51
     52    virtual void pinToMainThread() { }
    5153
    5254    // FIXME: append() should be private, but DocumentWriter::replaceDocument
  • trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp

    r143685 r143797  
    9090#endif
    9191    , m_preloader(adoptPtr(new HTMLResourcePreloader(document)))
     92    , m_isPinnedToMainThread(false)
    9293    , m_endWasDelayed(false)
    9394    , m_haveBackgroundParser(false)
     
    109110    , m_weakFactory(this)
    110111#endif
     112    , m_isPinnedToMainThread(true)
    111113    , m_endWasDelayed(false)
    112114    , m_haveBackgroundParser(false)
     
    126128    ASSERT(!m_haveBackgroundParser);
    127129}
     130
     131#if ENABLE(THREADED_HTML_PARSER)
     132void HTMLDocumentParser::pinToMainThread()
     133{
     134    ASSERT(!m_haveBackgroundParser);
     135    ASSERT(!m_tokenizer);
     136    ASSERT(!m_token);
     137    ASSERT(!m_isPinnedToMainThread);
     138    m_isPinnedToMainThread = true;
     139    m_token = adoptPtr(new HTMLToken);
     140    m_tokenizer = HTMLTokenizer::create(m_options);
     141}
     142#endif
    128143
    129144void HTMLDocumentParser::detach()
  • trunk/Source/WebCore/html/parser/HTMLDocumentParser.h

    r143661 r143797  
    9797
    9898protected:
    99     virtual void insert(const SegmentedString&);
    100     virtual void append(const SegmentedString&);
    101     virtual void finish();
     99    virtual void insert(const SegmentedString&) OVERRIDE;
     100    virtual void append(const SegmentedString&) OVERRIDE;
     101    virtual void finish() OVERRIDE;
    102102
    103103    HTMLDocumentParser(HTMLDocument*, bool reportErrors);
     
    115115
    116116    // DocumentParser
    117     virtual void detach();
    118     virtual bool hasInsertionPoint();
    119     virtual bool processingData() const;
    120     virtual void prepareToStopParsing();
    121     virtual void stopParsing();
    122     virtual bool isWaitingForScripts() const;
    123     virtual bool isExecutingScript() const;
    124     virtual void executeScriptsWaitingForStylesheets();
     117#if ENABLE(THREADED_HTML_PARSER)
     118    virtual void pinToMainThread() OVERRIDE;
     119#endif
     120    virtual void detach() OVERRIDE;
     121    virtual bool hasInsertionPoint() OVERRIDE;
     122    virtual bool processingData() const OVERRIDE;
     123    virtual void prepareToStopParsing() OVERRIDE;
     124    virtual void stopParsing() OVERRIDE;
     125    virtual bool isWaitingForScripts() const OVERRIDE;
     126    virtual bool isExecutingScript() const OVERRIDE;
     127    virtual void executeScriptsWaitingForStylesheets() OVERRIDE;
    125128
    126129    // HTMLScriptRunnerHost
    127     virtual void watchForLoad(CachedResource*);
    128     virtual void stopWatchingForLoad(CachedResource*);
     130    virtual void watchForLoad(CachedResource*) OVERRIDE;
     131    virtual void stopWatchingForLoad(CachedResource*) OVERRIDE;
    129132    virtual HTMLInputStream& inputStream() { return m_input; }
    130133    virtual bool hasPreloadScanner() const { return m_preloadScanner.get() && !shouldUseThreading(); }
    131     virtual void appendCurrentInputStreamToPreloadScannerAndScan();
     134    virtual void appendCurrentInputStreamToPreloadScannerAndScan() OVERRIDE;
    132135
    133136    // CachedResourceClient
     
    164167    void end();
    165168
    166     bool shouldUseThreading() const { return m_options.useThreading && !isParsingFragment(); }
     169    bool shouldUseThreading() const { return m_options.useThreading && !m_isPinnedToMainThread; }
    167170
    168171    bool isParsingFragment() const;
     
    196199    OwnPtr<HTMLResourcePreloader> m_preloader;
    197200
     201    bool m_isPinnedToMainThread;
    198202    bool m_endWasDelayed;
    199203    bool m_haveBackgroundParser;
  • trunk/Source/WebCore/loader/DocumentWriter.cpp

    r125613 r143797  
    7979        // FIXME: This should call DocumentParser::appendBytes instead of append
    8080        // to support RawDataDocumentParsers.
    81         if (DocumentParser* parser = m_frame->document()->parser())
     81        if (DocumentParser* parser = m_frame->document()->parser()) {
     82            parser->pinToMainThread();
    8283            parser->append(source);
     84        }
    8385    }
    8486
Note: See TracChangeset for help on using the changeset viewer.