Changeset 154242 in webkit


Ignore:
Timestamp:
Aug 17, 2013 3:46:16 PM (11 years ago)
Author:
Antti Koivisto
Message:

<https://webkit.org/b/119963> Use TextNodeTraversal for getting sheet text in StyleElement

Reviewed by Andreas Kling.

  • dom/StyleElement.cpp:

(WebCore::StyleElement::process):

Use TextNodeTraversal::contentsAsString for the sheet text. The overflow check is removed as StringBuilder
(which is used by contentsAsString) does that itself. The behavior in case of overflow changes from empty
sheet to CRASH(). Thats what we do elsewhere in similar situations too (scripts for example). Continuing
with > 4GB of style sheet text nodes is probably not going to go well anyway.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r154241 r154242  
     12013-08-17  Antti Koivisto  <antti@apple.com>
     2
     3        <https://webkit.org/b/119963> Use TextNodeTraversal for getting sheet text in StyleElement
     4
     5        Reviewed by Andreas Kling.
     6
     7        * dom/StyleElement.cpp:
     8        (WebCore::StyleElement::process):
     9       
     10            Use TextNodeTraversal::contentsAsString for the sheet text. The overflow check is removed as StringBuilder
     11            (which is used by contentsAsString) does that itself. The behavior in case of overflow changes from empty
     12            sheet to CRASH(). Thats what we do elsewhere in similar situations too (scripts for example). Continuing
     13            with > 4GB of style sheet text nodes is probably not going to go well anyway.
     14
    1152013-08-17  Antti Koivisto  <antti@apple.com>
    216
  • trunk/Source/WebCore/dom/StyleElement.cpp

    r147928 r154242  
    3131#include "ScriptableDocumentParser.h"
    3232#include "StyleSheetContents.h"
     33#include "TextNodeTraversal.h"
    3334#include <wtf/text/StringBuilder.h>
    3435#include <wtf/text/TextPosition.h>
    3536
    3637namespace WebCore {
    37 
    38 static bool isValidStyleChild(Node* node)
    39 {
    40     ASSERT(node);
    41     Node::NodeType nodeType = node->nodeType();
    42     return nodeType == Node::TEXT_NODE || nodeType == Node::CDATA_SECTION_NODE;
    43 }
    4438
    4539static bool isCSS(Element* element, const AtomicString& type)
     
    111105}
    112106
    113 void StyleElement::process(Element* e)
     107void StyleElement::process(Element* element)
    114108{
    115     if (!e || !e->inDocument())
     109    if (!element || !element->inDocument())
    116110        return;
    117111
    118     unsigned resultLength = 0;
    119     for (Node* c = e->firstChild(); c; c = c->nextSibling()) {
    120         if (isValidStyleChild(c)) {
    121             unsigned length = c->nodeValue().length();
    122             if (length > std::numeric_limits<unsigned>::max() - resultLength) {
    123                 createSheet(e, m_startLineNumber, "");
    124                 return;
    125             }
    126             resultLength += length;
    127         }
    128     }
    129     StringBuilder sheetText;
    130     sheetText.reserveCapacity(resultLength);
     112    String sheetText = TextNodeTraversal::contentsAsString(element);
    131113
    132     for (Node* c = e->firstChild(); c; c = c->nextSibling()) {
    133         if (isValidStyleChild(c)) {
    134             sheetText.append(c->nodeValue());
    135         }
    136     }
    137     ASSERT(sheetText.length() == resultLength);
    138 
    139     createSheet(e, m_startLineNumber, sheetText.toString());
     114    createSheet(element, m_startLineNumber, sheetText);
    140115}
    141116
Note: See TracChangeset for help on using the changeset viewer.