Changeset 102570 in webkit


Ignore:
Timestamp:
Dec 12, 2011 5:23:54 AM (12 years ago)
Author:
apavlov@chromium.org
Message:

WebKit does not enumerate over CSS properties in HTMLElement.style
https://bugs.webkit.org/show_bug.cgi?id=23946

Reviewed by Darin Adler.

Source/JavaScriptCore:

Add a few exports to follow the JSCSSStyleDeclaration.cpp changes,
introduce an std::sort() comparator function.

(WTF::codePointCompareLessThan): Used by std::sort() to sort properties.

Source/WebCore:

This change generates a list of JavaScript mirrors of the CSS properties and allows to enumerate them
using the "in" operator on the CSSStyleDeclaration object.

Test: fast/css/style-enumerate-properties.html

  • bindings/js/JSCSSStyleDeclarationCustom.cpp:

(WebCore::JSCSSStyleDeclaration::getOwnPropertyNames): Added.

  • bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp:

(WebCore::V8CSSStyleDeclaration::namedPropertyEnumerator): Added.
(WebCore::V8CSSStyleDeclaration::namedPropertyQuery): Added.
(WebCore::V8CSSStyleDeclaration::namedPropertyGetter): A small drive-by optimization (local initialization moved down).

  • css/CSSStyleDeclaration.idl: Use a custom property enumerator.
  • css/makeprop.pl: Add a function to convert CSS property names into JS ones, and a string comparator.

LayoutTests:

  • fast/css/style-enumerate-properties-expected.txt: Added.
  • fast/css/style-enumerate-properties.html: Added.
  • fast/dom/domListEnumeration-expected.txt:
  • fast/dom/script-tests/domListEnumeration.js:
Location:
trunk
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r102567 r102570  
     12011-11-30  Alexander Pavlov  <apavlov@chromium.org>
     2
     3        WebKit does not enumerate over CSS properties in HTMLElement.style
     4        https://bugs.webkit.org/show_bug.cgi?id=23946
     5
     6        Reviewed by Darin Adler.
     7
     8        * fast/css/style-enumerate-properties-expected.txt: Added.
     9        * fast/css/style-enumerate-properties.html: Added.
     10        * fast/dom/domListEnumeration-expected.txt:
     11        * fast/dom/script-tests/domListEnumeration.js:
     12
    1132011-12-12  Philippe Normand  <pnormand@igalia.com>
    214
  • trunk/LayoutTests/fast/dom/domListEnumeration-expected.txt

    r97925 r102570  
    6767
    6868[object CSSStyleDeclaration]
    69 PASS resultArray.length is 14
    7069PASS resultArray[0].i is '0'
    7170PASS resultArray[0].item is cssStyleDeclaration.item(0)
  • trunk/LayoutTests/fast/dom/script-tests/domListEnumeration.js

    r100369 r102570  
    174174var cssStyleDeclaration = document.styleSheets[2].cssRules[0].style;
    175175resultArray = iterateList(cssStyleDeclaration);
    176 shouldBe("resultArray.length", "14");
    177176shouldBe("resultArray[0].i", "'0'");
    178177shouldBe("resultArray[0].item", "cssStyleDeclaration.item(0)");
  • trunk/Source/JavaScriptCore/ChangeLog

    r102564 r102570  
     12011-12-09  Alexander Pavlov  <apavlov@chromium.org>
     2
     3        WebKit does not enumerate over CSS properties in HTMLElement.style
     4        https://bugs.webkit.org/show_bug.cgi?id=23946
     5
     6        Reviewed by Darin Adler.
     7
     8        Add a few exports to follow the JSCSSStyleDeclaration.cpp changes,
     9        introduce an std::sort() comparator function.
     10
     11        * JavaScriptCore.exp:
     12        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
     13        * wtf/text/WTFString.h:
     14        (WTF::codePointCompareLessThan): Used by std::sort() to sort properties.
     15
    1162011-12-12  Carlos Garcia Campos  <cgarcia@igalia.com>
    217
  • trunk/Source/JavaScriptCore/JavaScriptCore.exp

    r102534 r102570  
    156156__ZN3JSC12SamplingTool5setupEv
    157157__ZN3JSC12SmallStrings17createEmptyStringEPNS_12JSGlobalDataE
     158__ZN3JSC12SmallStrings24singleCharacterStringRepEh
    158159__ZN3JSC12SmallStrings27createSingleCharacterStringEPNS_12JSGlobalDataEh
    159160__ZN3JSC12StringObject14finishCreationERNS_12JSGlobalDataEPNS_8JSStringE
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r102534 r102570  
    5454    ?add@AtomicString@WTF@@CA?AV?$PassRefPtr@VStringImpl@WTF@@@2@PBD@Z
    5555    ?add@Identifier@JSC@@SA?AV?$PassRefPtr@VStringImpl@WTF@@@WTF@@PAVExecState@2@PBD@Z
     56    ?add@Identifier@JSC@@CA?AV?$PassRefPtr@VStringImpl@WTF@@@WTF@@PAVJSGlobalData@2@PAVStringImpl@4@@Z
    5657    ?add@PropertyNameArray@JSC@@QAEXPAVStringImpl@WTF@@@Z
    5758    ?addBytes@MD5@WTF@@QAEXPBEI@Z
     
    6364    ?addPropertyWithoutTransition@Structure@JSC@@QAEIAAVJSGlobalData@2@ABVIdentifier@2@IPAVJSCell@2@@Z
    6465    ?addSlowCase@Identifier@JSC@@CA?AV?$PassRefPtr@VStringImpl@WTF@@@WTF@@PAVExecState@2@PAVStringImpl@4@@Z
     66    ?addSlowCase@Identifier@JSC@@CA?AV?$PassRefPtr@VStringImpl@WTF@@@WTF@@PAVJSGlobalData@2@PAVStringImpl@4@@Z
    6567    ?addStaticGlobals@JSGlobalObject@JSC@@IAEXPAUGlobalPropertyInfo@12@H@Z
    6668    ?allocatePropertyStorage@JSObject@JSC@@QAEXAAVJSGlobalData@2@II@Z
     
    132134    ?currentThreadIsHoldingLock@JSLock@JSC@@SA_NXZ
    133135    ?currentTime@WTF@@YANXZ
    134         ?execute@ParallelEnvironment@WTF@@QAEXPAX@Z
     136    ?execute@ParallelEnvironment@WTF@@QAEXPAX@Z
    135137    ?data@CString@WTF@@QBEPBDXZ
    136138    ?dateToDaysFrom1970@WTF@@YANHHH@Z
     
    314316    ?shrinkToFit@StringBuilder@WTF@@QAEXXZ
    315317    ?signal@ThreadCondition@WTF@@QAEXXZ
     318    ?singleCharacterStringRep@SmallStrings@JSC@@QAEPAVStringImpl@WTF@@E@Z
    316319    ?size@Heap@JSC@@QAEIXZ
    317320    ?slowAppend@MarkedArgumentBuffer@JSC@@AAEXVJSValue@2@@Z
  • trunk/Source/JavaScriptCore/wtf/text/WTFString.h

    r102059 r102570  
    506506
    507507WTF_EXPORT_PRIVATE int codePointCompare(const String&, const String&);
     508
     509inline bool codePointCompareLessThan(const String& a, const String& b)
     510{
     511    return codePointCompare(a.impl(), b.impl()) < 0;
     512}
    508513
    509514inline size_t find(const LChar* characters, unsigned length, LChar matchCharacter, unsigned index = 0)
  • trunk/Source/WebCore/ChangeLog

    r102569 r102570  
     12011-11-25  Alexander Pavlov  <apavlov@chromium.org>
     2
     3        WebKit does not enumerate over CSS properties in HTMLElement.style
     4        https://bugs.webkit.org/show_bug.cgi?id=23946
     5
     6        Reviewed by Darin Adler.
     7
     8        This change generates a list of JavaScript mirrors of the CSS properties and allows to enumerate them
     9        using the "in" operator on the CSSStyleDeclaration object.
     10
     11        Test: fast/css/style-enumerate-properties.html
     12
     13        * bindings/js/JSCSSStyleDeclarationCustom.cpp:
     14        (WebCore::JSCSSStyleDeclaration::getOwnPropertyNames): Added.
     15        * bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp:
     16        (WebCore::V8CSSStyleDeclaration::namedPropertyEnumerator): Added.
     17        (WebCore::V8CSSStyleDeclaration::namedPropertyQuery): Added.
     18        (WebCore::V8CSSStyleDeclaration::namedPropertyGetter): A small drive-by optimization (local initialization moved down).
     19        * css/CSSStyleDeclaration.idl: Use a custom property enumerator.
     20        * css/makeprop.pl: Add a function to convert CSS property names into JS ones, and a string comparator.
     21
    1222011-12-09  Yury Semikhatsky  <yurys@chromium.org>
    223
  • trunk/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp

    r102262 r102570  
    2929#include "CSSMutableStyleDeclaration.h"
    3030#include "CSSPrimitiveValue.h"
     31#include "CSSPropertyNames.h"
    3132#include "CSSValue.h"
    3233#include "JSCSSValue.h"
     
    3839#include <wtf/text/StringBuilder.h>
    3940#include <wtf/text/StringConcatenate.h>
     41#include <wtf/text/WTFString.h>
    4042
    4143using namespace JSC;
    4244using namespace WTF;
     45using namespace std;
    4346
    4447namespace WebCore {
     
    140143}
    141144
    142 // FIXME: You can get these properties, and set them (see putDelegate below),
    143 // but you should also be able to enumerate them.
    144145JSValue JSCSSStyleDeclaration::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
    145146{
     
    196197}
    197198
     199void JSCSSStyleDeclaration::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
     200{
     201    JSCSSStyleDeclaration* thisObject = jsCast<JSCSSStyleDeclaration*>(object);
     202    ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
     203
     204    unsigned length = thisObject->impl()->length();
     205    for (unsigned i = 0; i < length; ++i)
     206        propertyNames.add(Identifier::from(exec, i));
     207
     208    static Identifier* propertyIdentifiers = 0;
     209    if (!propertyIdentifiers) {
     210        Vector<String, numCSSProperties> jsPropertyNames;
     211        for (int id = firstCSSProperty; id < firstCSSProperty + numCSSProperties; ++id)
     212            jsPropertyNames.append(getJSPropertyName(static_cast<CSSPropertyID>(id)));
     213        sort(jsPropertyNames.begin(), jsPropertyNames.end(), WTF::codePointCompareLessThan);
     214
     215        propertyIdentifiers = new Identifier[numCSSProperties];
     216        for (int i = 0; i < numCSSProperties; ++i)
     217            propertyIdentifiers[i] = Identifier(exec, jsPropertyNames[i].impl());
     218    }
     219
     220    for (int i = 0; i < numCSSProperties; ++i)
     221        propertyNames.add(propertyIdentifiers[i]);
     222
     223    Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
     224}
     225
    198226} // namespace WebCore
  • trunk/Source/WebCore/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp

    r102262 r102570  
    3333
    3434#include "CSSParser.h"
     35#include "CSSPropertyNames.h"
    3536#include "CSSStyleDeclaration.h"
    3637#include "CSSValue.h"
     
    4849#include <wtf/StdLibExtras.h>
    4950#include <wtf/Vector.h>
     51
     52using namespace WTF;
     53using namespace std;
    5054
    5155namespace WebCore {
     
    153157}
    154158
     159v8::Handle<v8::Array> V8CSSStyleDeclaration::namedPropertyEnumerator(const v8::AccessorInfo& info)
     160{
     161    typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector;
     162    DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ());
     163    DEFINE_STATIC_LOCAL(String, filterString, ("filter"));
     164    static unsigned propertyNamesLength = 0;
     165
     166    if (propertyNames.isEmpty()) {
     167        for (int id = firstCSSProperty; id < firstCSSProperty + numCSSProperties; ++id) {
     168            String jsPropertyName = getJSPropertyName(static_cast<CSSPropertyID>(id));
     169            // The "filter" property is present in the list but should not be provided in the enumeration.
     170            // See a comment in the V8CSSStyleDeclaration::namedPropertyGetter() implementation.
     171            // FIXME: this should be removed (see bug 73426).
     172            if (jsPropertyName != filterString)
     173                propertyNames.append(jsPropertyName);
     174        }
     175        sort(propertyNames.begin(), propertyNames.end(), codePointCompareLessThan);
     176        propertyNamesLength = propertyNames.size();
     177    }
     178
     179    v8::Handle<v8::Array> properties = v8::Array::New(propertyNamesLength);
     180    for (unsigned i = 0; i < propertyNamesLength; ++i) {
     181        String key = propertyNames.at(i);
     182        ASSERT(!key.isNull());
     183        properties->Set(v8::Integer::New(i), v8String(key));
     184    }
     185
     186    return properties;
     187}
     188
     189v8::Handle<v8::Integer> V8CSSStyleDeclaration::namedPropertyQuery(v8::Local<v8::String> v8Name, const v8::AccessorInfo& info)
     190{
     191    INC_STATS("DOM.CSSStyleDeclaration.NamedPropertyQuery");
     192    return v8::Integer::New(v8::None);
     193}
     194
    155195v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
    156196{
     
    161201
    162202    // Search the style declaration.
    163     CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder());
    164203    CSSPropertyInfo* propInfo = cssPropertyInfo(name);
    165204
     
    168207        return notHandledByInterceptor();
    169208
    170 
     209    CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder());
    171210    RefPtr<CSSValue> cssValue = imp->getPropertyCSSValue(propInfo->propID);
    172211    if (cssValue) {
  • trunk/Source/WebCore/css/CSSStyleDeclaration.idl

    r92236 r102570  
    2828        HasNameGetter,
    2929        HasIndexGetter,
     30        CustomGetPropertyNames,
    3031        V8DependentLifetime
    3132    ] CSSStyleDeclaration {
  • trunk/Source/WebCore/css/makeprop.pl

    r89362 r102570  
    6363%{
    6464/* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
     65#include "config.h"
    6566#include \"CSSPropertyNames.h\"
    6667#include \"HashTools.h\"
    6768#include <string.h>
     69
     70#include <wtf/ASCIICType.h>
     71#include <wtf/text/WTFString.h>
    6872
    6973namespace WebCore {
     
    115119}
    116120
     121WTF::String getJSPropertyName(CSSPropertyID id)
     122{
     123    char result[maxCSSPropertyNameLength + 1];
     124    const char* cssPropertyName = getPropertyName(id);
     125    const char* propertyNamePointer = cssPropertyName;
     126    if (!propertyNamePointer)
     127        return emptyString();
     128
     129    char* resultPointer = result;
     130    while (char character = *propertyNamePointer++) {
     131        if (character == '-') {
     132            char nextCharacter = *propertyNamePointer++;
     133            if (!nextCharacter)
     134                break;
     135            character = (propertyNamePointer - 2 != cssPropertyName) ? toASCIIUpper(nextCharacter) : nextCharacter;
     136        }
     137        *resultPointer++ = character;
     138    }
     139    *resultPointer = '\\0';
     140    return WTF::String(result);
     141}
     142
    117143} // namespace WebCore
    118144EOF
     
    126152
    127153#include <string.h>
     154
     155namespace WTF {
     156class String;
     157}
    128158
    129159namespace WebCore {
     
    161191
    162192const char* getPropertyName(CSSPropertyID);
     193WTF::String getJSPropertyName(CSSPropertyID);
    163194
    164195} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.