Title: [163239] trunk
Revision
163239
Author
[email protected]
Date
2014-02-01 00:10:27 -0800 (Sat, 01 Feb 2014)

Log Message

Improve the _javascript_ bindings of DatasetDOMStringMap
https://bugs.webkit.org/show_bug.cgi?id=127971

Patch by Benjamin Poulain <[email protected]> on 2014-02-01
Reviewed by Sam Weinig.

Source/WebCore: 

Instead of querying contains() followed by item(), just get the item
at once in the custom binding.

Test: fast/dom/dataset-name-getter-properties.html

* bindings/js/JSDOMStringMapCustom.cpp:
(WebCore::JSDOMStringMap::getOwnPropertySlotDelegate):
* dom/DOMStringMap.idl:
* dom/DatasetDOMStringMap.cpp:
(WebCore::DatasetDOMStringMap::item):
* dom/DatasetDOMStringMap.h:

LayoutTests: 

* fast/dom/dataset-name-getter-properties-expected.txt: Added.
* fast/dom/dataset-name-getter-properties.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (163238 => 163239)


--- trunk/LayoutTests/ChangeLog	2014-02-01 08:05:21 UTC (rev 163238)
+++ trunk/LayoutTests/ChangeLog	2014-02-01 08:10:27 UTC (rev 163239)
@@ -1,3 +1,13 @@
+2014-02-01  Benjamin Poulain  <[email protected]>
+
+        Improve the _javascript_ bindings of DatasetDOMStringMap
+        https://bugs.webkit.org/show_bug.cgi?id=127971
+
+        Reviewed by Sam Weinig.
+
+        * fast/dom/dataset-name-getter-properties-expected.txt: Added.
+        * fast/dom/dataset-name-getter-properties.html: Added.
+
 2014-01-31  Oliver Hunt  <[email protected]>
 
         Rollout r163195 and related patches

Added: trunk/LayoutTests/fast/dom/dataset-name-getter-properties-expected.txt (0 => 163239)


--- trunk/LayoutTests/fast/dom/dataset-name-getter-properties-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/dataset-name-getter-properties-expected.txt	2014-02-01 08:10:27 UTC (rev 163239)
@@ -0,0 +1,13 @@
+Test the _javascript_ property descriptor of the name getter.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Object.getOwnPropertyDescriptor(document.body.dataset, 'webkitRocks').configurable is false
+PASS Object.getOwnPropertyDescriptor(document.body.dataset, 'webkitRocks').enumerable is false
+PASS Object.getOwnPropertyDescriptor(document.body.dataset, 'webkitRocks').writable is false
+PASS Object.getOwnPropertyDescriptor(document.body.dataset, 'webkitRocks').value is "yes"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/dataset-name-getter-properties.html (0 => 163239)


--- trunk/LayoutTests/fast/dom/dataset-name-getter-properties.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/dataset-name-getter-properties.html	2014-02-01 08:10:27 UTC (rev 163239)
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body data-webkit-rocks=yes>
+<script>
+description('Test the _javascript_ property descriptor of the name getter.');
+
+shouldBe("Object.getOwnPropertyDescriptor(document.body.dataset, 'webkitRocks').configurable", 'false');
+shouldBe("Object.getOwnPropertyDescriptor(document.body.dataset, 'webkitRocks').enumerable", 'false');
+shouldBe("Object.getOwnPropertyDescriptor(document.body.dataset, 'webkitRocks').writable", 'false');
+shouldBeEqualToString("Object.getOwnPropertyDescriptor(document.body.dataset, 'webkitRocks').value", 'yes');
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (163238 => 163239)


--- trunk/Source/WebCore/ChangeLog	2014-02-01 08:05:21 UTC (rev 163238)
+++ trunk/Source/WebCore/ChangeLog	2014-02-01 08:10:27 UTC (rev 163239)
@@ -1,3 +1,22 @@
+2014-02-01  Benjamin Poulain  <[email protected]>
+
+        Improve the _javascript_ bindings of DatasetDOMStringMap
+        https://bugs.webkit.org/show_bug.cgi?id=127971
+
+        Reviewed by Sam Weinig.
+
+        Instead of querying contains() followed by item(), just get the item
+        at once in the custom binding.
+
+        Test: fast/dom/dataset-name-getter-properties.html
+
+        * bindings/js/JSDOMStringMapCustom.cpp:
+        (WebCore::JSDOMStringMap::getOwnPropertySlotDelegate):
+        * dom/DOMStringMap.idl:
+        * dom/DatasetDOMStringMap.cpp:
+        (WebCore::DatasetDOMStringMap::item):
+        * dom/DatasetDOMStringMap.h:
+
 2014-01-31  Benjamin Poulain  <[email protected]>
 
         Remove LEGACY_VIEWPORT_ADAPTION

Modified: trunk/Source/WebCore/bindings/js/JSDOMStringMapCustom.cpp (163238 => 163239)


--- trunk/Source/WebCore/bindings/js/JSDOMStringMapCustom.cpp	2014-02-01 08:05:21 UTC (rev 163238)
+++ trunk/Source/WebCore/bindings/js/JSDOMStringMapCustom.cpp	2014-02-01 08:10:27 UTC (rev 163239)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -35,17 +35,17 @@
 
 namespace WebCore {
 
-bool JSDOMStringMap::canGetItemsForName(ExecState*, DOMStringMap* impl, PropertyName propertyName)
+bool JSDOMStringMap::getOwnPropertySlotDelegate(ExecState* exec, PropertyName propertyName, PropertySlot& slot)
 {
-    return impl->contains(propertyNameToAtomicString(propertyName));
+    bool nameIsValid;
+    const AtomicString& item = impl().item(propertyNameToString(propertyName), nameIsValid);
+    if (nameIsValid) {
+        slot.setValue(this, ReadOnly | DontDelete | DontEnum, toJS(exec, globalObject(), item));
+        return true;
+    }
+    return false;
 }
 
-EncodedJSValue JSDOMStringMap::nameGetter(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName propertyName)
-{
-    JSDOMStringMap* thisObj = jsCast<JSDOMStringMap*>(JSValue::decode(slotBase));
-    return JSValue::encode(jsStringWithCache(exec, thisObj->impl().item(propertyNameToAtomicString(propertyName))));
-}
-
 void JSDOMStringMap::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
 {
     JSDOMStringMap* thisObject = jsCast<JSDOMStringMap*>(object);

Modified: trunk/Source/WebCore/dom/DOMStringMap.idl (163238 => 163239)


--- trunk/Source/WebCore/dom/DOMStringMap.idl	2014-02-01 08:05:21 UTC (rev 163238)
+++ trunk/Source/WebCore/dom/DOMStringMap.idl	2014-02-01 08:10:27 UTC (rev 163239)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,8 +28,8 @@
     CustomDeleteProperty,
     CustomEnumerateProperty,
     CustomNamedSetter,
+    JSCustomGetOwnPropertySlotAndDescriptor,
     SkipVTableValidation,
 ] interface DOMStringMap {
-    getter DOMString (DOMString name);
 };
 

Modified: trunk/Source/WebCore/dom/DatasetDOMStringMap.cpp (163238 => 163239)


--- trunk/Source/WebCore/dom/DatasetDOMStringMap.cpp	2014-02-01 08:05:21 UTC (rev 163238)
+++ trunk/Source/WebCore/dom/DatasetDOMStringMap.cpp	2014-02-01 08:10:27 UTC (rev 163239)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -144,17 +144,19 @@
     }
 }
 
-String DatasetDOMStringMap::item(const String& name)
+const AtomicString& DatasetDOMStringMap::item(const String& name, bool& isValid)
 {
-    if (!m_element.hasAttributes())
-        return String();
-
-    for (const Attribute& attribute : m_element.attributesIterator()) {
-        if (propertyNameMatchesAttributeName(name, attribute.localName()))
-            return attribute.value();
+    isValid = false;
+    if (m_element.hasAttributes()) {
+        for (const Attribute& attribute : m_element.attributesIterator()) {
+            if (propertyNameMatchesAttributeName(name, attribute.localName())) {
+                isValid = true;
+                return attribute.value();
+            }
+        }
     }
 
-    return String();
+    return nullAtom;
 }
 
 bool DatasetDOMStringMap::contains(const String& name)

Modified: trunk/Source/WebCore/dom/DatasetDOMStringMap.h (163238 => 163239)


--- trunk/Source/WebCore/dom/DatasetDOMStringMap.h	2014-02-01 08:05:21 UTC (rev 163238)
+++ trunk/Source/WebCore/dom/DatasetDOMStringMap.h	2014-02-01 08:10:27 UTC (rev 163239)
@@ -29,6 +29,7 @@
 #include "ScriptWrappable.h"
 #include <wtf/Noncopyable.h>
 #include <wtf/Vector.h>
+#include <wtf/text/AtomicString.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -48,7 +49,7 @@
     void deref();
 
     void getNames(Vector<String>&);
-    String item(const String& name);
+    const AtomicString& item(const String& name, bool& isValid);
     bool contains(const String& name);
     void setItem(const String& name, const String& value, ExceptionCode&);
     void deleteItem(const String& name, ExceptionCode&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to