REGRESSION (r195305): Web Inspector: WebInspector.Object can dispatch constructor...
authornvasilyev@apple.com <nvasilyev@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Jan 2016 05:54:31 +0000 (05:54 +0000)
committernvasilyev@apple.com <nvasilyev@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Jan 2016 05:54:31 +0000 (05:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=153269
<rdar://problem/24253106>

Reviewed by Timothy Hatcher.

Source/WebInspectorUI:

Bring back object.hasOwnProperty("_listeners") check.

* UserInterface/Base/Object.js:
(WebInspector.Object.prototype.dispatchEventToListeners.dispatch):
(WebInspector.Object.prototype.dispatchEventToListeners):
(WebInspector.Object):
Check !object._listeners before !object.hasOwnProperty("_listeners")
because !object._listeners is more common case thus we can exit earlier
most of the time.

LayoutTests:

* inspector/unit-tests/object-expected.txt: Added.
* inspector/unit-tests/object.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/inspector/unit-tests/object-expected.txt [new file with mode: 0644]
LayoutTests/inspector/unit-tests/object.html [new file with mode: 0644]
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/Object.js

index 1564047..32751f0 100644 (file)
@@ -1,3 +1,14 @@
+2016-01-21  Nikita Vasilyev  <nvasilyev@apple.com>
+
+        REGRESSION (r195305): Web Inspector: WebInspector.Object can dispatch constructor-level events multiple times
+        https://bugs.webkit.org/show_bug.cgi?id=153269
+        <rdar://problem/24253106>
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/unit-tests/object-expected.txt: Added.
+        * inspector/unit-tests/object.html: Added.
+
 2016-01-21  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         [ES6] Catch parameter should accept BindingPattern
 2016-01-21  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         [ES6] Catch parameter should accept BindingPattern
diff --git a/LayoutTests/inspector/unit-tests/object-expected.txt b/LayoutTests/inspector/unit-tests/object-expected.txt
new file mode 100644 (file)
index 0000000..76784c9
--- /dev/null
@@ -0,0 +1,7 @@
+Testing WebInspector.Object.
+
+
+== Running test suite: Object
+-- Running test case: Events propagation
+Dispatch count: 1
+
diff --git a/LayoutTests/inspector/unit-tests/object.html b/LayoutTests/inspector/unit-tests/object.html
new file mode 100644 (file)
index 0000000..19c3e8c
--- /dev/null
@@ -0,0 +1,36 @@
+<!doctype html>
+<html>
+<head>
+<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
+<script>
+function test()
+{
+    let suite = InspectorTest.createSyncSuite("Object");
+
+    suite.addTestCase({
+        name: "Events propagation",
+        description: "WebInspector.Object shouldn't dispatch constructor-level events multiple times",
+        test: function() {
+            class Parent extends WebInspector.Object {}
+            class Child extends Parent {}
+
+            const eventName = "clicked";
+            let dispatchCount = 0;
+
+            Parent.addEventListener(eventName, () => dispatchCount++);
+
+            let child = new Child;
+            child.dispatchEventToListeners(eventName);
+
+            InspectorTest.log("Dispatch count: " + dispatchCount);
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body onload="runTest()">
+    <p>Testing WebInspector.Object.</p>
+</body>
+</html>
index 6ce7509..653d351 100644 (file)
@@ -1,3 +1,21 @@
+2016-01-21  Nikita Vasilyev  <nvasilyev@apple.com>
+
+        REGRESSION (r195305): Web Inspector: WebInspector.Object can dispatch constructor-level events multiple times
+        https://bugs.webkit.org/show_bug.cgi?id=153269
+        <rdar://problem/24253106>
+
+        Reviewed by Timothy Hatcher.
+
+        Bring back object.hasOwnProperty("_listeners") check.
+
+        * UserInterface/Base/Object.js:
+        (WebInspector.Object.prototype.dispatchEventToListeners.dispatch):
+        (WebInspector.Object.prototype.dispatchEventToListeners):
+        (WebInspector.Object):
+        Check !object._listeners before !object.hasOwnProperty("_listeners")
+        because !object._listeners is more common case thus we can exit earlier
+        most of the time.
+
 2016-01-21  Devin Rousso  <dcrousso+webkit@gmail.com>
 
         Web Inspector: Add toggle-able list of classes for each element
 2016-01-21  Devin Rousso  <dcrousso+webkit@gmail.com>
 
         Web Inspector: Add toggle-able list of classes for each element
index a271640..e29022c 100644 (file)
@@ -139,12 +139,16 @@ WebInspector.Object = class WebInspectorObject
 
         function dispatch(object)
         {
 
         function dispatch(object)
         {
-            if (!object || !object._listeners || event._stoppedPropagation)
+            if (!object || event._stoppedPropagation)
                 return;
 
                 return;
 
-            console.assert(object._listeners instanceof Map);
+            let listenerTypesMap = object._listeners;
+            if (!listenerTypesMap || !object.hasOwnProperty("_listeners"))
+                return;
+
+            console.assert(listenerTypesMap instanceof Map);
 
 
-            let listenersTable = object._listeners.get(eventType);
+            let listenersTable = listenerTypesMap.get(eventType);
             if (!listenersTable)
                 return;
 
             if (!listenersTable)
                 return;