Source/WebCore/ChangeLog

 12011-03-02 Emil A Eklund <eae@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 DatasetDOMStringMap::item and ::contains copies attribute name string
 6 https://bugs.webkit.org/show_bug.cgi?id=55645
 7
 8 Change propertyNameMatchesAttributeName to match without creating a copy
 9 of the string.
 10
 11 * dom/DatasetDOMStringMap.cpp:
 12 (WebCore::propertyNameMatchesAttributeName):
 13
1142011-03-02 Levi Weintraub <leviw@chromium.org>
215
316 Reviewed by Ryosuke Niwa.
80196

Source/WebCore/dom/DatasetDOMStringMap.cpp

@@static String convertAttributeNameToProp
7272
7373static bool propertyNameMatchesAttributeName(const String& propertyName, const String& attributeName)
7474{
75  // FIXME: This should be able to match without creating a new string.
76 
77  if (!isValidAttributeName(attributeName))
 75 if (!attributeName.startsWith("data-"))
7876 return false;
7977
80  String convertedName = convertAttributeNameToPropertyName(attributeName);
81  return (convertedName == propertyName);
 78 const UChar* property = propertyName.characters();
 79 const UChar* attribute = attributeName.characters();
 80 unsigned propertyLength = propertyName.length();
 81 unsigned attributeLength = attributeName.length();
 82
 83 unsigned a = 5;
 84 unsigned p = 0;
 85 bool wordBoundary = false;
 86 while (a < attributeLength && p < propertyLength) {
 87 if (attribute[a] == '-' && a + 1 < attributeLength && attribute[a + 1] != '-')
 88 wordBoundary = true;
 89 else {
 90 if ((wordBoundary ? toASCIIUpper(attribute[a]) : attribute[a]) != property[p])
 91 return false;
 92 p++;
 93 wordBoundary = false;
 94 }
 95 a++;
 96 }
 97
 98 return (a == attributeLength && p == propertyLength);
8299}
83100
84101static bool isValidPropertyName(const String& name)
80179

LayoutTests/ChangeLog

 12011-03-02 Emil A Eklund <eae@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 DatasetDOMStringMap::item and ::contains copies attribute name string
 6 https://bugs.webkit.org/show_bug.cgi?id=55645
 7
 8 * fast/dom/script-tests/dataset-expected.txt:
 9 * fast/dom/script-tests/dataset.js:
 10 Added extra test cases for getting fields by property name.
 11
1122011-03-02 Mihai Parparita <mihaip@chromium.org>
213
314 Reviewed by Tony Gentilcore.
80196

LayoutTests/fast/dom/dataset-expected.txt

@@PASS testGet('data-foo-bar', 'fooBar') i
88PASS testGet('data--', '-') is true
99PASS testGet('data--foo', 'Foo') is true
1010PASS testGet('data---foo', '-Foo') is true
 11PASS testGet('data---foo--bar', '-Foo-Bar') is true
 12PASS testGet('data---foo---bar', '-Foo--Bar') is true
 13PASS testGet('data-foo-', 'foo-') is true
 14PASS testGet('data-foo--', 'foo--') is true
1115PASS testGet('data-Foo', 'foo') is true
1216PASS testGet('data-', '') is true
1317PASS testGet('data-à', 'à') is true
80179

LayoutTests/fast/dom/script-tests/dataset.js

@@shouldBeTrue("testGet('data-foo-bar', 'f
1212shouldBeTrue("testGet('data--', '-')");
1313shouldBeTrue("testGet('data--foo', 'Foo')");
1414shouldBeTrue("testGet('data---foo', '-Foo')");
 15shouldBeTrue("testGet('data---foo--bar', '-Foo-Bar')");
 16shouldBeTrue("testGet('data---foo---bar', '-Foo--Bar')");
 17shouldBeTrue("testGet('data-foo-', 'foo-')");
 18shouldBeTrue("testGet('data-foo--', 'foo--')");
1519shouldBeTrue("testGet('data-Foo', 'foo')"); // HTML lowercases all attributes.
1620shouldBeTrue("testGet('data-', '')");
1721shouldBeTrue("testGet('data-\xE0', '\xE0')");
80179