Bug 80890 - Web Inspector: Introduce SnippetsScriptMapping.
Summary: Web Inspector: Introduce SnippetsScriptMapping.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (Deprecated) (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Vsevolod Vlasov
URL:
Keywords:
Depends on:
Blocks: 75094
  Show dependency treegraph
 
Reported: 2012-03-12 14:30 PDT by Vsevolod Vlasov
Modified: 2012-03-14 03:00 PDT (History)
11 users (show)

See Also:


Attachments
Patch (10.85 KB, patch)
2012-03-12 14:54 PDT, Vsevolod Vlasov
no flags Details | Formatted Diff | Diff
Patch (12.42 KB, patch)
2012-03-13 08:05 PDT, Vsevolod Vlasov
no flags Details | Formatted Diff | Diff
Patch (12.92 KB, patch)
2012-03-13 10:56 PDT, Vsevolod Vlasov
no flags Details | Formatted Diff | Diff
Patch (12.97 KB, patch)
2012-03-13 11:51 PDT, Vsevolod Vlasov
no flags Details | Formatted Diff | Diff
Patch (13.21 KB, patch)
2012-03-14 02:04 PDT, Vsevolod Vlasov
pfeldman: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vsevolod Vlasov 2012-03-12 14:30:30 PDT
Patch to follow.
Tests for this mapping will be added once snippet could be evaluated.
Comment 1 Vsevolod Vlasov 2012-03-12 14:54:20 PDT
Created attachment 131421 [details]
Patch
Comment 2 Pavel Podivilov 2012-03-13 03:34:51 PDT
Comment on attachment 131421 [details]
Patch

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

> Source/WebCore/inspector/front-end/SnippetsModel.js:227
> +    WebInspector.snippetsModel.addEventListener(WebInspector.SnippetsModel.EventTypes.SnippetDeleted, this._snippetDeleted.bind(this));

SnippetRemoved would be more consistent with other code.

> Source/WebCore/inspector/front-end/SnippetsModel.js:237
> +        var snippet = this._snippetForScriptId[rawLocation.scriptId];

Could you only store the last script in _snippetForScriptId and delete stale scripts (_snippetForLastScriptId)? There should be no need to access snippet for stale scripts.

> Source/WebCore/inspector/front-end/SnippetsModel.js:242
> +        if (!uiSourceCode)

It's guaranteed that addScript was already called for this script, so uiSourceCode should always exist here.

> Source/WebCore/inspector/front-end/SnippetsModel.js:261
> +        if (!lastScript)

There's no script for this UISourceCode. How could there be a lastScript for the snippet?

> Source/WebCore/inspector/front-end/SnippetsModel.js:262
> +            return null;

Please make sure all clients will check for null.

> Source/WebCore/inspector/front-end/SnippetsModel.js:274
> +            result.push(snippet.uiSourceCode);

Wouldn't there be duplicates?

> Source/WebCore/inspector/front-end/SnippetsModel.js:289
> +        var uiSourceCode = new WebInspector.UISourceCode(script.sourceURL, script.sourceURL, new WebInspector.ScriptContentProvider(script));

You should probably bind this script to existing snippet.uiSourceCode instead of creating a new one.

> Source/WebCore/inspector/front-end/SnippetsModel.js:294
> +        if (!snippet)

Is it possible? Maybe preventing the snippet from being deleted while it's evaluated would make the code easier to understand.

> Source/WebCore/inspector/front-end/SnippetsModel.js:310
> +        uiSourceCode.isSnippet = true;

uiSourceCode.isEditable = true?

> Source/WebCore/inspector/front-end/SnippetsModel.js:350
> +        this._lastScriptForSnippet = new Map();

Clear other maps as well?
Comment 3 Vsevolod Vlasov 2012-03-13 08:01:23 PDT
Comment on attachment 131421 [details]
Patch

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

>> Source/WebCore/inspector/front-end/SnippetsModel.js:227
>> +    WebInspector.snippetsModel.addEventListener(WebInspector.SnippetsModel.EventTypes.SnippetDeleted, this._snippetDeleted.bind(this));
> 
> SnippetRemoved would be more consistent with other code.

Done.

>> Source/WebCore/inspector/front-end/SnippetsModel.js:237
>> +        var snippet = this._snippetForScriptId[rawLocation.scriptId];
> 
> Could you only store the last script in _snippetForScriptId and delete stale scripts (_snippetForLastScriptId)? There should be no need to access snippet for stale scripts.

Done.

>> Source/WebCore/inspector/front-end/SnippetsModel.js:242
>> +        if (!uiSourceCode)
> 
> It's guaranteed that addScript was already called for this script, so uiSourceCode should always exist here.

Done.

>> Source/WebCore/inspector/front-end/SnippetsModel.js:261
>> +        if (!lastScript)
> 
> There's no script for this UISourceCode. How could there be a lastScript for the snippet?

I have removed _lastScriptForSnippet map at all and rewritten this piece of code as we discussed offline.

>> Source/WebCore/inspector/front-end/SnippetsModel.js:289
>> +        var uiSourceCode = new WebInspector.UISourceCode(script.sourceURL, script.sourceURL, new WebInspector.ScriptContentProvider(script));
> 
> You should probably bind this script to existing snippet.uiSourceCode instead of creating a new one.

Done.

>> Source/WebCore/inspector/front-end/SnippetsModel.js:310
>> +        uiSourceCode.isSnippet = true;
> 
> uiSourceCode.isEditable = true?

Done.

>> Source/WebCore/inspector/front-end/SnippetsModel.js:350
>> +        this._lastScriptForSnippet = new Map();
> 
> Clear other maps as well?

No need to clear snippet<->uiSourceCode maps, since snippet are not removed upon navigation.
Comment 4 Vsevolod Vlasov 2012-03-13 08:05:36 PDT
Created attachment 131614 [details]
Patch
Comment 5 Vsevolod Vlasov 2012-03-13 10:56:51 PDT
Created attachment 131669 [details]
Patch
Comment 6 Vsevolod Vlasov 2012-03-13 11:51:20 PDT
Created attachment 131686 [details]
Patch
Comment 7 Pavel Podivilov 2012-03-14 01:44:20 PDT
Comment on attachment 131614 [details]
Patch

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

looks good!

> Source/WebCore/inspector/front-end/ScriptMapping.js:178
> +            if (WebInspector.snippetsModel.snippetForSourceURL(script.sourceURL))

There could be no snippet at this moment. Please check that script.sourceURL starts with "snippet://" instead.

> Source/WebCore/inspector/front-end/SnippetsModel.js:391
> +        this._uiSourceCodeForScriptId = {};

Do you need to dispatch removed events here?
Comment 8 Pavel Podivilov 2012-03-14 01:47:39 PDT
Comment on attachment 131686 [details]
Patch

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

> Source/WebCore/inspector/front-end/SnippetsModel.js:307
> +    _uiSourceCodesForScripts: function()

Not uiSourceCodesForScripts actually, maybe releasedUISourceCodes?
Comment 9 Vsevolod Vlasov 2012-03-14 02:04:28 PDT
Created attachment 131808 [details]
Patch
Comment 10 Vsevolod Vlasov 2012-03-14 03:00:09 PDT
Committed r110681: <http://trac.webkit.org/changeset/110681>