Bug 139426 - Web Inspector: Abstract common functions from TypeTokenAnnotator into a parent class and introduce an AnnotatorManager
Summary: Web Inspector: Abstract common functions from TypeTokenAnnotator into a paren...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Saam Barati
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2014-12-08 20:41 PST by Saam Barati
Modified: 2015-01-09 17:56 PST (History)
5 users (show)

See Also:


Attachments
path (24.63 KB, patch)
2014-12-09 11:34 PST, Saam Barati
no flags Details | Formatted Diff | Diff
patch (24.26 KB, patch)
2014-12-09 15:08 PST, Saam Barati
joepeck: review-
Details | Formatted Diff | Diff
patch (26.59 KB, patch)
2014-12-19 12:48 PST, Saam Barati
no flags Details | Formatted Diff | Diff
patch (25.80 KB, patch)
2014-12-19 12:56 PST, Saam Barati
timothy: review+
Details | Formatted Diff | Diff
patch (25.72 KB, patch)
2015-01-07 00:40 PST, Saam Barati
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Saam Barati 2014-12-08 20:41:34 PST
These changes are in preparation for the soon to be finished Basic Block Annotator.

- This patch will create a parent class that will be shared by both TypeTokenAnnaotor and BasicBlockAnnotator.
- This patch will also create an AnnotatorManager that is responsible for keeping track of a group annotators.
Comment 1 Radar WebKit Bug Importer 2014-12-08 20:41:45 PST
<rdar://problem/19186398>
Comment 2 Saam Barati 2014-12-09 11:34:07 PST
Created attachment 242948 [details]
path
Comment 3 Saam Barati 2014-12-09 15:08:00 PST
Created attachment 242969 [details]
patch

Fix whitespace alteration in previous patch.
Comment 4 Joseph Pecoraro 2014-12-10 12:53:27 PST
Comment on attachment 242969 [details]
patch

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

I think this is good, but I want to see another patch with the changes mentioned here, and then I'll look more closely at the other details!

> Source/WebInspectorUI/ChangeLog:15
> +        This patch also introduces JavaScriptAnnotatorManager which controls a
> +        set of JavaScriptAnnotators and provides a single interface for
> +        controlling them.

From the description it sounds like these objects have little that is JavaScript specific. The Annotators hold "SourceCode"TextEditors, it would be great to abstract this to be SourceCodes if we ever wanted to use something similar for CSS.

> Source/WebInspectorUI/UserInterface/Controllers/JavaScriptAnnotator.js:31
> +    console.assert(sourceCodeTextEditor && sourceCodeTextEditor instanceof WebInspector.SourceCodeTextEditor, sourceCodeTextEditor);

Nit: The "sourceCodeTextEditor &&" part is implied by the second condition so it can be removed.

> Source/WebInspectorUI/UserInterface/Controllers/JavaScriptAnnotator.js:32
> +    console.assert(script, script);

Nit: The second arguments to this asserts seems unnecessary, since it would almost certainly just be "null".

That said, the Annotator doesn't need to hold the script/sourceCode object. The sourceCodeTextEditor already has it. No need for the argument / instance variable.

> Source/WebInspectorUI/UserInterface/Controllers/JavaScriptAnnotatorManager.js:31
> +    this._annotators = {};

Lets make this a "Map". <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map>

    this._annotators = new Map;
    this._annotators.set(key, annotator);
    return this._annotators.get(key) || null;

> Source/WebInspectorUI/UserInterface/Controllers/JavaScriptAnnotatorManager.js:62
> +        for (var annotator of this._getAnnotators())

If "this._annotators" is an array, then you can iterate it directly:

    // Key and value
    for (var [key, annotator] of this._annotators) { ... }

    // Just values (order or insertion I believe)
    for (var annotator of this._annotators.values()) { ... }

Or, you can do the normal forEach.

    this._annotators.forEach(function(key, value) { ... });

> Source/WebInspectorUI/UserInterface/Controllers/TypeTokenAnnotator.js:63
>              this._script.requestScriptSyntaxTree(function(syntaxTree) {

Now that this is a subclass we wouldn't want to access "this._script" directly.

You could create:

- Assert it is a script in the constructor:

    console.assert(this.sourceCodeTextEditor.sourceCode instanceof WebInspector.Script);

- Add a convenience getter

    get script()
    {
        return this.sourceCodeTextEditor.sourceCode;
    }

- And use "this.script" instead
Comment 5 Saam Barati 2014-12-19 12:48:22 PST
Created attachment 243566 [details]
patch

Made recommended changes.
Comment 6 Saam Barati 2014-12-19 12:56:18 PST
Created attachment 243568 [details]
patch

Move TextEditor argument back to SourceCodeTextEditor.
Comment 7 Timothy Hatcher 2015-01-06 13:46:00 PST
Comment on attachment 243568 [details]
patch

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

> Source/WebInspectorUI/UserInterface/Controllers/AnnotatorManager.js:103
> +    _getAnnotators: function()
> +    {
> +        return this._annotators.values();
> +    }

Not sure this adds any thing. this._getAnnotators() isn't much better than this._annotators.values().
Comment 8 Saam Barati 2015-01-07 00:40:36 PST
Created attachment 244145 [details]
patch
Comment 9 WebKit Commit Bot 2015-01-07 02:34:49 PST
Comment on attachment 244145 [details]
patch

Clearing flags on attachment: 244145

Committed r178030: <http://trac.webkit.org/changeset/178030>
Comment 10 WebKit Commit Bot 2015-01-07 02:34:53 PST
All reviewed patches have been landed.  Closing bug.
Comment 11 Joseph Pecoraro 2015-01-09 17:56:05 PST
Comment on attachment 244145 [details]
patch

Nit: 2015