<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>150579</bug_id>
          
          <creation_ts>2015-10-26 16:18:56 -0700</creation_ts>
          <short_desc>Web Inspector: WebInspector.Object can dispatch constructor-level events multiple times</short_desc>
          <delta_ts>2015-10-26 17:26:39 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Web Inspector</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Matt Baker">mattbaker</reporter>
          <assigned_to name="Matt Baker">mattbaker</assigned_to>
          <cc>bburg</cc>
    
    <cc>commit-queue</cc>
    
    <cc>graouts</cc>
    
    <cc>joepeck</cc>
    
    <cc>mattbaker</cc>
    
    <cc>nvasilyev</cc>
    
    <cc>timothy</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1136682</commentid>
    <comment_count>0</comment_count>
    <who name="Matt Baker">mattbaker</who>
    <bug_when>2015-10-26 16:18:56 -0700</bug_when>
    <thetext>* SUMMARY
WebInspector.Object can dispatch constructor-level events multiple times. As Object.dispatchEventToListeners walks the prototype chain looking for listeners on each constructor, it should check for listeners that are a direct property of the constructor, rather than a simple &apos;in&apos; test which will pick up properties inherited down the chain.

* EXAMPLE
Assuming the following class hierarchy:
C -&gt; B -&gt; A -&gt; WebInspector.Object

and an object Foo listening for events on class A:

class Foo() {
   constructor() {
      A.addEventListener(A.Event.SomeEvent, this._handleSomeEvent, this);
   }

   _handleSomeEvent(event) {
      ...
   }
}

If an object of type C fires A.Event.SomeEvent, Foo._handleSomeEvent will be called three times, once for each constructor in the prototype chain. The expectation is that it will be called just once.

* NOTE
This has real performance implications in the Inspector UI, as constructor event handlers often perform layout updates. For example, ContentBrowser calls NavigationBar.udpateLayout (which is extremely expensive) in response to WebInspector.ContentView.Event.SelectionPathComponentsDidChange, which it listens for on the ContentView constructor.

Selecting a DOM node in the Elements tab currently generates *six* calls to NavigationBar.updateLayout (three for each deselect/select in the DOM tree content view). Fixing this issue will reduce the number to just two.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1136683</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2015-10-26 16:19:23 -0700</bug_when>
    <thetext>&lt;rdar://problem/23267238&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1136685</commentid>
    <comment_count>2</comment_count>
      <attachid>264093</attachid>
    <who name="Matt Baker">mattbaker</who>
    <bug_when>2015-10-26 16:26:45 -0700</bug_when>
    <thetext>Created attachment 264093
[Patch] Proposed Fix</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1136687</commentid>
    <comment_count>3</comment_count>
      <attachid>264093</attachid>
    <who name="Timothy Hatcher">timothy</who>
    <bug_when>2015-10-26 16:34:05 -0700</bug_when>
    <thetext>Comment on attachment 264093
[Patch] Proposed Fix

Nice find!

We might be able to keep this code as-is and just remove the loop where we walk the prototype chain and just do: dispatch(this.constructor);

I think that will do the same thing, and just take advantage of JS&apos;s inheritance. I&apos;m not sure why I didn&apos;t think of that before, unless this wasn&apos;t broken until we switched to classes with proper inheritance.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1136690</commentid>
    <comment_count>4</comment_count>
    <who name="Matt Baker">mattbaker</who>
    <bug_when>2015-10-26 16:38:52 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; Comment on attachment 264093 [details]
&gt; [Patch] Proposed Fix
&gt; 
&gt; Nice find!
&gt; 
&gt; We might be able to keep this code as-is and just remove the loop where we
&gt; walk the prototype chain and just do: dispatch(this.constructor);

That would be a nice simplification. I&apos;ll try it out.

&gt; I think that will do the same thing, and just take advantage of JS&apos;s
&gt; inheritance. I&apos;m not sure why I didn&apos;t think of that before, unless this
&gt; wasn&apos;t broken until we switched to classes with proper inheritance.

Interesting...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1136691</commentid>
    <comment_count>5</comment_count>
      <attachid>264093</attachid>
    <who name="Timothy Hatcher">timothy</who>
    <bug_when>2015-10-26 16:39:51 -0700</bug_when>
    <thetext>Comment on attachment 264093
[Patch] Proposed Fix

Nevermind! That approach wouldn&apos;t work, this is the correct fix.

My idea wont allow proper bubbling to all the classes. It would only catch event listeners registered on the concrete class of the instance, not the superclasses</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1136717</commentid>
    <comment_count>6</comment_count>
      <attachid>264093</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-10-26 17:26:35 -0700</bug_when>
    <thetext>Comment on attachment 264093
[Patch] Proposed Fix

Clearing flags on attachment: 264093

Committed r191615: &lt;http://trac.webkit.org/changeset/191615&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1136718</commentid>
    <comment_count>7</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-10-26 17:26:39 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>264093</attachid>
            <date>2015-10-26 16:26:45 -0700</date>
            <delta_ts>2015-10-26 17:26:35 -0700</delta_ts>
            <desc>[Patch] Proposed Fix</desc>
            <filename>bug-150579-20151026162557.patch</filename>
            <type>text/plain</type>
            <size>2353</size>
            <attacher name="Matt Baker">mattbaker</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMTkxNjA0CmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViSW5zcGVj
dG9yVUkvQ2hhbmdlTG9nIGIvU291cmNlL1dlYkluc3BlY3RvclVJL0NoYW5nZUxvZwppbmRleCA2
MTlkMzljOGFiYTkyZTlhZjBlNmFkNWQwNzEwYTA1Mjg5OGQ5ZDU0Li45ODc5NjY4YWIwZDVhYzY5
ODljNWU5YTFhZjk2ZTE1YmI0NDZlY2RkIDEwMDY0NAotLS0gYS9Tb3VyY2UvV2ViSW5zcGVjdG9y
VUkvQ2hhbmdlTG9nCisrKyBiL1NvdXJjZS9XZWJJbnNwZWN0b3JVSS9DaGFuZ2VMb2cKQEAgLTEs
MyArMSwxOSBAQAorMjAxNS0xMC0yNiAgTWF0dCBCYWtlciAgPG1hdHRiYWtlckBhcHBsZS5jb20+
CisKKyAgICAgICAgV2ViIEluc3BlY3RvcjogV2ViSW5zcGVjdG9yLk9iamVjdCBjYW4gZGlzcGF0
Y2ggY29uc3RydWN0b3ItbGV2ZWwgZXZlbnRzIG11bHRpcGxlIHRpbWVzCisgICAgICAgIGh0dHBz
Oi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0xNTA1NzkKKworICAgICAgICBSZXZp
ZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAgICAgICBVc2UgYGhhc093blByb3BlcnR5YCB3
aGVuIGNoZWNraW5nIGZvciBjb25zdHJ1Y3RvciBldmVudCBsaXN0ZW5lcnMgd2hlbiB3YWxraW5n
IHRoZQorICAgICAgICBwcm90b3R5cGUgY2hhaW4uIFRoaXMgcHJldmVudHMgbGlzdGVuZXJzIHJl
Z2lzdGVyZWQgd2l0aCBhIGJhc2UgY2xhc3MgY29uc3RydWN0b3IKKyAgICAgICAgZnJv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