Bug 174703 - Web Inspector: Avoid subclassing WebInspector.Object if we do not need to
Summary: Web Inspector: Avoid subclassing WebInspector.Object if we do not need to
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-20 20:08 PDT by Joseph Pecoraro
Modified: 2017-07-21 12:36 PDT (History)
5 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (49.39 KB, patch)
2017-07-20 20:10 PDT, Joseph Pecoraro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2017-07-20 20:08:16 PDT
Avoid subclassing WebInspector.Object if we do not need to
Comment 1 Joseph Pecoraro 2017-07-20 20:10:28 PDT
Created attachment 316063 [details]
[PATCH] Proposed Fix
Comment 2 Joseph Pecoraro 2017-07-20 20:11:23 PDT
Found files with:

    $ ack --files-without-matches 'Event = \{' | xargs ack 'extends WebInspector\.Object\b'

Then had to add back just a couple (TestHarness and HeapSnapshotWorkerProxy).

I didn't modify any Views / Controllers.
Comment 3 BJ Burg 2017-07-21 11:29:35 PDT
Comment on attachment 316063 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=316063&action=review

Is there any particular motivation for this? Code cleanup, correctness, performance?

> Source/WebInspectorUI/UserInterface/Models/ApplicationCacheFrame.js:26
> +WebInspector.ApplicationCacheFrame = class ApplicationCacheFrame

I guess we don't type check anywhere that the target of saveIdentityToCookie is a subclass of object?

> Source/WebInspectorUI/UserInterface/Models/DOMSearchMatchObject.js:27
>  {

Sidenote: this class needs to be cleaned up. It knows a lot of style classes for being in Models/ directory.

> Source/WebInspectorUI/UserInterface/Models/Probe.js:27
> +WebInspector.ProbeSample = class ProbeSample

r-, this class dispatches events.
Comment 4 Joseph Pecoraro 2017-07-21 11:46:14 PDT
Comment on attachment 316063 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=316063&action=review

>> Source/WebInspectorUI/UserInterface/Models/ApplicationCacheFrame.js:26
>> +WebInspector.ApplicationCacheFrame = class ApplicationCacheFrame
> 
> I guess we don't type check anywhere that the target of saveIdentityToCookie is a subclass of object?

Correct, all cases of code using `instanceof WebInspector.Object\b` were in Event related code:

> Base/EventListenerSet.js
> 49:        var emitterIsValid = emitter && (emitter instanceof WebInspector.Object || emitter instanceof Node || (typeof emitter.addEventListener === "function"));
> 
> Base/EventListener.js
> 44:        var emitterIsValid = emitter && (emitter instanceof WebInspector.Object || emitter instanceof Node || (typeof emitter.addEventListener === "function"));

>> Source/WebInspectorUI/UserInterface/Models/Probe.js:27
>> +WebInspector.ProbeSample = class ProbeSample
> 
> r-, this class dispatches events.

Where? Probe does, but I don't see where ProbeSample does. Can you point it out to me?
Comment 5 Joseph Pecoraro 2017-07-21 11:49:07 PDT
> Is there any particular motivation for this? Code cleanup, correctness, performance?

Just cleanup and clarity.

Not having a `this._listeners = null` property/value on all of these objects might be a tiny memory improvement but probably not. It will make printing these objects slightly nicer in our console not having that property around.
Comment 6 BJ Burg 2017-07-21 12:01:17 PDT
Comment on attachment 316063 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=316063&action=review

>>> Source/WebInspectorUI/UserInterface/Models/Probe.js:27
>>> +WebInspector.ProbeSample = class ProbeSample
>> 
>> r-, this class dispatches events.
> 
> Where? Probe does, but I don't see where ProbeSample does. Can you point it out to me?

Oops, didn't see the second class. I recant!
Comment 7 WebKit Commit Bot 2017-07-21 12:36:44 PDT
Comment on attachment 316063 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 316063

Committed r219734: <http://trac.webkit.org/changeset/219734>
Comment 8 WebKit Commit Bot 2017-07-21 12:36:45 PDT
All reviewed patches have been landed.  Closing bug.