Value for iterator property is wrong for maplike interfaces
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 May 2017 19:14:15 +0000 (19:14 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 May 2017 19:14:15 +0000 (19:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=172410

Reviewed by Sam Weinig.

Source/WebCore:

Value for iterator property was wrong for maplike interfaces. The iterator property is
supposed to have the same value as the 'entries' property but we were using the value
of the 'values' property.

Specification:
- https://heycam.github.io/webidl/#es-map-entries
- https://heycam.github.io/webidl/#es-iterator

This impacts the iterator of the RTCStatsReport interface.

No new tests, updated existing test.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation):
* bindings/scripts/test/JS/JSMapLike.cpp:
(WebCore::JSMapLikePrototype::finishCreation):
* bindings/scripts/test/JS/JSReadOnlyMapLike.cpp:
(WebCore::JSReadOnlyMapLikePrototype::finishCreation):

LayoutTests:

Extend test coverage to test the RTCStatsReport iterator.

* webrtc/video-stats.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217188 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/webrtc/video-stats.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/RTCStatsReport.idl
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSMapLike.cpp
Source/WebCore/bindings/scripts/test/JS/JSReadOnlyMapLike.cpp

index 16a459a..08c9177 100644 (file)
@@ -1,3 +1,14 @@
+2017-05-20  Chris Dumez  <cdumez@apple.com>
+
+        Value for iterator property is wrong for maplike interfaces
+        https://bugs.webkit.org/show_bug.cgi?id=172410
+
+        Reviewed by Sam Weinig.
+
+        Extend test coverage to test the RTCStatsReport iterator.
+
+        * webrtc/video-stats.html:
+
 2017-05-20  Jer Noble  <jer.noble@apple.com>
 
         [MSE][Mac] Support painting MSE video-element to canvas
index 4d19cf4..5bd4e20 100644 (file)
         <script src ="routines.js"></script>
         <script>
 
+function checkStatsReportIterator(report)
+{
+    assert_equals(Object.getOwnPropertyDescriptor(report.__proto__, Symbol.iterator).value, Object.getOwnPropertyDescriptor(report.__proto__, 'entries').value);
+    assert_equals(Object.getOwnPropertyDescriptor(report.__proto__, Symbol.iterator).value.name, "entries");
+    for (let pair of report)
+        assert_equals(pair.length, 2);
+}
+
 function getInboundRTPStats(connection)
 {
     return connection.getStats().then((report) => {
+        checkStatsReportIterator(report);
         var stats;
         report.forEach((statItem) => {
             if (statItem.type === "inbound-rtp") {
@@ -26,6 +35,7 @@ function getInboundRTPStats(connection)
 function getOutboundRTPStats(connection)
 {
     return connection.getStats().then((report) => {
+        checkStatsReportIterator(report);
         var stats;
         report.forEach((statItem) => {
             if (statItem.type === "outbound-rtp") {
index e72de56..bd9bfc9 100644 (file)
@@ -1,5 +1,31 @@
 2017-05-20  Chris Dumez  <cdumez@apple.com>
 
+        Value for iterator property is wrong for maplike interfaces
+        https://bugs.webkit.org/show_bug.cgi?id=172410
+
+        Reviewed by Sam Weinig.
+
+        Value for iterator property was wrong for maplike interfaces. The iterator property is
+        supposed to have the same value as the 'entries' property but we were using the value
+        of the 'values' property.
+
+        Specification:
+        - https://heycam.github.io/webidl/#es-map-entries
+        - https://heycam.github.io/webidl/#es-iterator
+
+        This impacts the iterator of the RTCStatsReport interface.
+
+        No new tests, updated existing test.
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateImplementation):
+        * bindings/scripts/test/JS/JSMapLike.cpp:
+        (WebCore::JSMapLikePrototype::finishCreation):
+        * bindings/scripts/test/JS/JSReadOnlyMapLike.cpp:
+        (WebCore::JSReadOnlyMapLikePrototype::finishCreation):
+
+2017-05-20  Chris Dumez  <cdumez@apple.com>
+
         Drop superfluous iterator property setting in addValueIterableMethods()
         https://bugs.webkit.org/show_bug.cgi?id=172409
 
index 37e64d2..a30a5b3 100644 (file)
@@ -23,6 +23,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: This should not be marked as [NoInterfaceObject].
 [
     NoInterfaceObject,
     Conditional=WEB_RTC,
index ce3a748..9125a0e 100644 (file)
@@ -3060,10 +3060,10 @@ sub InterfaceNeedsIterator
 {
     my ($interface) = @_;
 
-    # FIXME: This should return 1 for maplike once we support them.
+    # FIXME: This should return 1 for setlike once we support it.
     return 1 if $interface->mapLike;
-
     return 1 if $interface->iterable;
+
     if (GetIndexedGetterFunction($interface)) {
         my $lengthAttribute = GetAttributeWithName($interface, "length");
         return 1 if $lengthAttribute and $codeGenerator->IsIntegerType($lengthAttribute->type);
@@ -3466,10 +3466,8 @@ sub GenerateImplementation
 
         if (InterfaceNeedsIterator($interface)) {
             AddToImplIncludes("<builtins/BuiltinNames.h>");
-            if (IsKeyValueIterableInterface($interface)) {
+            if (IsKeyValueIterableInterface($interface) or $interface->mapLike) {
                 push(@implContent, "    putDirect(vm, vm.propertyNames->iteratorSymbol, getDirect(vm, vm.propertyNames->builtinNames().entriesPublicName()), DontEnum);\n");
-            } elsif ($interface->mapLike) {
-                push(@implContent, "    putDirect(vm, vm.propertyNames->iteratorSymbol, getDirect(vm, vm.propertyNames->builtinNames().valuesPublicName()), DontEnum);\n");
             } else {
                 push(@implContent, "    putDirect(vm, vm.propertyNames->iteratorSymbol, globalObject()->arrayPrototype()->getDirect(vm, vm.propertyNames->builtinNames().valuesPrivateName()), DontEnum);\n");
             }
index 1724c31..5315032 100644 (file)
@@ -120,7 +120,7 @@ void JSMapLikePrototype::finishCreation(VM& vm)
 {
     Base::finishCreation(vm);
     reifyStaticProperties(vm, JSMapLikePrototypeTableValues, *this);
-    putDirect(vm, vm.propertyNames->iteratorSymbol, getDirect(vm, vm.propertyNames->builtinNames().valuesPublicName()), DontEnum);
+    putDirect(vm, vm.propertyNames->iteratorSymbol, getDirect(vm, vm.propertyNames->builtinNames().entriesPublicName()), DontEnum);
 }
 
 const ClassInfo JSMapLike::s_info = { "MapLike", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMapLike) };
index 0fd530f..1a519be 100644 (file)
@@ -114,7 +114,7 @@ void JSReadOnlyMapLikePrototype::finishCreation(VM& vm)
 {
     Base::finishCreation(vm);
     reifyStaticProperties(vm, JSReadOnlyMapLikePrototypeTableValues, *this);
-    putDirect(vm, vm.propertyNames->iteratorSymbol, getDirect(vm, vm.propertyNames->builtinNames().valuesPublicName()), DontEnum);
+    putDirect(vm, vm.propertyNames->iteratorSymbol, getDirect(vm, vm.propertyNames->builtinNames().entriesPublicName()), DontEnum);
 }
 
 const ClassInfo JSReadOnlyMapLike::s_info = { "ReadOnlyMapLike", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadOnlyMapLike) };