Changeset 147102 in webkit


Ignore:
Timestamp:
Mar 28, 2013 6:06:25 AM (11 years ago)
Author:
vsevik@chromium.org
Message:

Web Inspector: ResourceScriptFile should check if resource content really matches VM script when determining hasDiverged state.
https://bugs.webkit.org/show_bug.cgi?id=113488

Reviewed by Pavel Feldman.

Source/WebCore:

Enabled support for checking that file content matches VM script in ResourceScriptFile (For script resources only).
This check is never done before content is loaded in corresponding editor to avoid regressing performance.
File - script content matching is done bearing in mind sourceURLs.
Live edit keeps sourceURL in script content now even if it is not present in file's content.

  • inspector/front-end/JavaScriptSourceFrame.js:

(WebInspector.JavaScriptSourceFrame.prototype._updateScriptFile):
(WebInspector.JavaScriptSourceFrame.prototype.onTextEditorContentLoaded):

  • inspector/front-end/LiveEditSupport.js:

(WebInspector.LiveEditScriptFile.prototype.checkMapping):

  • inspector/front-end/ResourceScriptMapping.js:

(WebInspector.ResourceScriptMapping.prototype._bindUISourceCodeToScripts):
(WebInspector.ScriptFile.prototype.checkMapping):
(WebInspector.ResourceScriptFile):
(WebInspector.ResourceScriptFile.prototype._workingCopyCommitted):
(WebInspector.ResourceScriptFile.prototype._isDiverged):
(WebInspector.ResourceScriptFile.prototype._sourceMatchesScriptSource):
(WebInspector.ResourceScriptFile.prototype._sourceEndsWithSourceURL):
(WebInspector.ResourceScriptFile.prototype.checkMapping.callback):
(WebInspector.ResourceScriptFile.prototype.checkMapping):

  • inspector/front-end/ScriptSnippetModel.js:

(WebInspector.SnippetScriptFile.prototype.checkMapping):

LayoutTests:

  • http/tests/inspector/debugger-test.js:
  • inspector/debugger/file-system-project-mapping-expected.txt:
  • inspector/debugger/file-system-project-mapping.html:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r147101 r147102  
     12013-03-28  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: ResourceScriptFile should check if resource content really matches VM script when determining hasDiverged state.
     4        https://bugs.webkit.org/show_bug.cgi?id=113488
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * http/tests/inspector/debugger-test.js:
     9        * inspector/debugger/file-system-project-mapping-expected.txt:
     10        * inspector/debugger/file-system-project-mapping.html:
     11
    1122013-03-28  Ádám Kallai  <kadam@inf.u-szeged.hu>
    213
  • trunk/LayoutTests/http/tests/inspector/debugger-test.js

    r144467 r147102  
    285285    var endLine = startLine + lineCount - 1;
    286286    var endColumn = lineCount === 1 ? startColumn + source.length : source.length - source.lineEndings()[lineCount - 2];
    287     var script = new WebInspector.Script(scriptId, url, startLine, startColumn, endLine, endColumn, isContentScript);
     287    var hasSourceURL = !!source.match(/\/\/@\ssourceURL=\s*(\S*?)\s*$/m);
     288    var script = new WebInspector.Script(scriptId, url, startLine, startColumn, endLine, endColumn, isContentScript, null, hasSourceURL);
    288289    script.requestContent = function(callback) { callback(source, false, "text/javascript"); };
    289290    WebInspector.debuggerModel._registerScript(script);
  • trunk/LayoutTests/inspector/debugger/file-system-project-mapping-expected.txt

    r145539 r147102  
    2121Running: testScriptFileOnReloadWithDirtyFile
    2222Adding file system.
     23Dumping uiSourceCode and script content:
     24    uiSourceCode: <foo content>
     25    script: <foo content>
     26  //@ sourceURL=http://localhost/html/foo.js 
     27 
    2328 - hasDivergedFromVM: false
    2429Editing uiSourceCode:
    2530 - hasDivergedFromVM: true
    2631Committing uiSourceCode with live edit failure:
     32Dumping uiSourceCode and script content:
     33    uiSourceCode: <foo content edited>
     34    script: <foo content>
     35  //@ sourceURL=http://localhost/html/foo.js 
     36 
     37 - hasDivergedFromVM: true
     38Reloading with saved but diverged uiSourceCode:
     39Dumping uiSourceCode and script content:
     40    uiSourceCode: <foo content edited>
     41    script: <foo content>
     42  //@ sourceURL=http://localhost/html/foo.js 
     43 
    2744 - hasDivergedFromVM: true
    2845Editing uiSourceCode again:
    2946 - hasDivergedFromVM: true
    3047Committing uiSourceCode again (with live edit success now):
     48Dumping uiSourceCode and script content:
     49    uiSourceCode: <foo content edited again>
     50    script: <foo content edited again>
     51 //@ sourceURL=http://localhost/html/foo.js
    3152 - hasDivergedFromVM: false
    3253Reloading page:
  • trunk/LayoutTests/inspector/debugger/file-system-project-mapping.html

    r145539 r147102  
    9191        function testScriptFileOnReloadWithDirtyFile(next)
    9292        {
     93            var originalFileContent = "<foo content>";
     94            var scriptURL = "http://localhost/html/foo.js";
     95            var scriptContent = originalFileContent + "\n  //@ sourceURL=" + scriptURL + "  \n ";
    9396            function uiSourceCodeAdded(uiSourceCode) { }
    9497
     
    97100                resourceScriptMapping._debuggerReset();
    98101                defaultScriptMapping._debuggerReset();
    99                 script = InspectorTest.createScriptMock("http://localhost/html/foo.js", 0, 0, false, "<foo content>");
     102                script = InspectorTest.createScriptMock(scriptURL, 0, 0, false, scriptContent);
    100103                InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded, 1);
    101104                defaultScriptMapping.addScript(script);
     
    105108            var fileSystemPath = "/var/www";
    106109            var fileSystemProjectId = WebInspector.FileSystemProjectDelegate.projectId(fileSystemPath);
    107             var files = {"/html/foo.js": "<foo content>", "/bar.js": "<bar content>"};
     110            var files = {"/html/foo.js": originalFileContent, "/bar.js": "<bar content>"};
    108111            createObjects();
    109112            var entry1 = new WebInspector.FileMapping.Entry("http://localhost/", "/var/www/");
     
    116119
    117120            var uiSourceCode = InspectorTest.testWorkspace.uiSourceCode(fileSystemProjectId, ["html", "foo.js"]);
    118             InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
    119             InspectorTest.addResult("Editing uiSourceCode:");
    120             uiSourceCode.setWorkingCopy("<foo content edited>");
    121             InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
     121            InspectorTest.showUISourceCode(uiSourceCode, didShowScriptSource);
    122122
    123             function setScriptSourceOverrideFailure(scriptId, newContent, callback)
     123            function dumpUISourceCodeAndScriptContents()
    124124            {
    125                 callback("error");
     125                InspectorTest.addResult("Dumping uiSourceCode and script content:");
     126                InspectorTest.addResult("    uiSourceCode: " + uiSourceCode.workingCopy());
     127                InspectorTest.addResult("    script: " + scriptContent);
    126128            }
    127             InspectorTest.override(WebInspector.debuggerModel, "setScriptSource", setScriptSourceOverrideFailure);
    128             InspectorTest.addResult("Committing uiSourceCode with live edit failure:");
    129             uiSourceCode.commitWorkingCopy(function() { });
    130             InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
    131129
    132             InspectorTest.addResult("Editing uiSourceCode again:");
    133             uiSourceCode.setWorkingCopy("<foo content edited again>");
    134             InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
     130            function didShowScriptSource(sourceFrame)
     131            {
     132                dumpUISourceCodeAndScriptContents();
     133                InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
    135134
    136             function setScriptSourceOverrideSuccess(scriptId, newContent, callback)
    137             {
    138                 callback();
     135                InspectorTest.addResult("Editing uiSourceCode:");
     136                uiSourceCode.setWorkingCopy("<foo content edited>");
     137                InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
     138
     139                function setScriptSourceOverrideFailure(scriptId, newContent, callback)
     140                {
     141                    callback("error");
     142                }
     143                InspectorTest.override(WebInspector.debuggerModel, "setScriptSource", setScriptSourceOverrideFailure);
     144
     145                InspectorTest.addResult("Committing uiSourceCode with live edit failure:");
     146                uiSourceCode.commitWorkingCopy(function() { });
     147                dumpUISourceCodeAndScriptContents();
     148                InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
     149
     150                InspectorTest.addResult("Reloading with saved but diverged uiSourceCode:");
     151                reload();
     152                dumpUISourceCodeAndScriptContents();
     153                InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
     154
     155                InspectorTest.addResult("Editing uiSourceCode again:");
     156                uiSourceCode.setWorkingCopy("<foo content edited again>");
     157                InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
     158
     159                function setScriptSourceOverrideSuccess(scriptId, newContent, callback)
     160                {
     161                    scriptContent = newContent;
     162                    callback();
     163                }
     164                InspectorTest.override(WebInspector.debuggerModel, "setScriptSource", setScriptSourceOverrideSuccess);
     165
     166                InspectorTest.addResult("Committing uiSourceCode again (with live edit success now):");
     167                uiSourceCode.commitWorkingCopy(function() { });
     168                dumpUISourceCodeAndScriptContents();
     169                InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
     170
     171                InspectorTest.addResult("Reloading page:");
     172                reload();
     173                InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
     174
     175                InspectorTest.addResult("Editing uiSourceCode again and reloading while it is dirty:");
     176                uiSourceCode.setWorkingCopy("<foo content edited and dirty>");
     177                reload();
     178                InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
     179                next();
    139180            }
    140             InspectorTest.override(WebInspector.debuggerModel, "setScriptSource", setScriptSourceOverrideSuccess);
    141             InspectorTest.addResult("Committing uiSourceCode again (with live edit success now):");
    142             uiSourceCode.commitWorkingCopy(function() { });
    143             InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
    144 
    145             InspectorTest.addResult("Reloading page:");
    146             reload();
    147             InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
    148 
    149             InspectorTest.addResult("Editing uiSourceCode again and reloading while it is dirty:");
    150             uiSourceCode.setWorkingCopy("<foo content edited and dirty>");
    151             reload();
    152             InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM());
    153             next();
    154181        }
    155182    ]);
  • trunk/Source/WebCore/ChangeLog

    r147099 r147102  
     12013-03-28  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: ResourceScriptFile should check if resource content really matches VM script when determining hasDiverged state.
     4        https://bugs.webkit.org/show_bug.cgi?id=113488
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Enabled support for checking that file content matches VM script in ResourceScriptFile (For script resources only).
     9        This check is never done before content is loaded in corresponding editor to avoid regressing performance.
     10        File - script content matching is done bearing in mind sourceURLs.
     11        Live edit keeps sourceURL in script content now even if it is not present in file's content.
     12
     13        * inspector/front-end/JavaScriptSourceFrame.js:
     14        (WebInspector.JavaScriptSourceFrame.prototype._updateScriptFile):
     15        (WebInspector.JavaScriptSourceFrame.prototype.onTextEditorContentLoaded):
     16        * inspector/front-end/LiveEditSupport.js:
     17        (WebInspector.LiveEditScriptFile.prototype.checkMapping):
     18        * inspector/front-end/ResourceScriptMapping.js:
     19        (WebInspector.ResourceScriptMapping.prototype._bindUISourceCodeToScripts):
     20        (WebInspector.ScriptFile.prototype.checkMapping):
     21        (WebInspector.ResourceScriptFile):
     22        (WebInspector.ResourceScriptFile.prototype._workingCopyCommitted):
     23        (WebInspector.ResourceScriptFile.prototype._isDiverged):
     24        (WebInspector.ResourceScriptFile.prototype._sourceMatchesScriptSource):
     25        (WebInspector.ResourceScriptFile.prototype._sourceEndsWithSourceURL):
     26        (WebInspector.ResourceScriptFile.prototype.checkMapping.callback):
     27        (WebInspector.ResourceScriptFile.prototype.checkMapping):
     28        * inspector/front-end/ScriptSnippetModel.js:
     29        (WebInspector.SnippetScriptFile.prototype.checkMapping):
     30
    1312013-03-28  Vsevolod Vlasov  <vsevik@chromium.org>
    232
  • trunk/Source/WebCore/inspector/front-end/JavaScriptSourceFrame.js

    r147099 r147102  
    492492            this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.DidMergeToVM, this._didMergeToVM, this);
    493493            this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.DidDivergeFromVM, this._didDivergeFromVM, this);
     494   
     495            if (this.loaded)
     496                this._scriptFile.checkMapping();
    494497        }
    495498    },
     
    509512            this.addMessageToSource(message.lineNumber, message.originalMessage);
    510513        }
     514       
     515        if (this._scriptFile)
     516            this._scriptFile.checkMapping();
    511517    },
    512518
  • trunk/Source/WebCore/inspector/front-end/LiveEditSupport.js

    r147099 r147102  
    135135    },
    136136
     137    checkMapping: function()
     138    {
     139    },
     140
    137141    __proto__: WebInspector.Object.prototype
    138142}
  • trunk/Source/WebCore/inspector/front-end/ResourceScriptMapping.js

    r147099 r147102  
    183183    {
    184184        console.assert(scripts.length);
    185         var scriptFile = new WebInspector.ResourceScriptFile(this, uiSourceCode);
     185        var scriptFile = new WebInspector.ResourceScriptFile(this, uiSourceCode, scripts);
    186186        uiSourceCode.setScriptFile(scriptFile);
    187187        for (var i = 0; i < scripts.length; ++i)
     
    263263     */
    264264    isMergingToVM: function() { return false; },
     265
     266    checkMapping: function() { },
    265267}
    266268
     
    272274 * @param {WebInspector.UISourceCode} uiSourceCode
    273275 */
    274 WebInspector.ResourceScriptFile = function(resourceScriptMapping, uiSourceCode)
     276WebInspector.ResourceScriptFile = function(resourceScriptMapping, uiSourceCode, scripts)
    275277{
     278    console.assert(scripts.length);
     279
    276280    WebInspector.ScriptFile.call(this);
    277281    this._resourceScriptMapping = resourceScriptMapping;
    278282    this._uiSourceCode = uiSourceCode;
     283
     284    if (this._uiSourceCode.contentType() === WebInspector.resourceTypes.Script)
     285        this._script = scripts[0];
    279286
    280287    this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCommitted, this);
     
    292299        {
    293300            if (error) {
    294                 this._lastLiveEditFailed = true;
     301                this._update();
    295302                WebInspector.showErrorMessage(error);
    296303                return;
    297304            }
    298            
    299             delete this._lastLiveEditFailed;
    300             this._mergeToVM();
     305
     306            this._scriptSource = source;
     307            this._update();
    301308        }
    302        
    303         var rawLocation = /** @type {WebInspector.DebuggerModel.Location} */ (this._uiSourceCode.uiLocationToRawLocation(0, 0));
    304         if (!rawLocation)
    305             return;
    306         var script = WebInspector.debuggerModel.scriptForId(rawLocation.scriptId);
    307         WebInspector.debuggerModel.setScriptSource(script.scriptId, this._uiSourceCode.workingCopy(), innerCallback.bind(this));
    308     },
    309 
     309        if (!this._script)
     310            return;
     311        var source = this._uiSourceCode.workingCopy();
     312        if (this._script.hasSourceURL && !this._sourceEndsWithSourceURL(source))
     313            source += "\n //@ sourceURL=" + this._script.sourceURL;
     314        WebInspector.debuggerModel.setScriptSource(this._script.scriptId, source, innerCallback.bind(this));
     315    },
     316
     317    /**
     318     * @return {boolean}
     319     */
    310320    _isDiverged: function()
    311321    {
    312322        if (this._uiSourceCode.isDirty())
    313323            return true;
    314         return this._lastLiveEditFailed;
    315     },
    316 
     324        if (!this._script)
     325            return false;
     326        if (typeof this._scriptSource === "undefined")
     327            return false;
     328        return !this._sourceMatchesScriptSource(this._uiSourceCode.workingCopy(), this._scriptSource);
     329    },
     330
     331    /**
     332     * @param {string} source
     333     * @param {string} scriptSource
     334     * @return {boolean}
     335     */
     336    _sourceMatchesScriptSource: function(source, scriptSource)
     337    {
     338        if (!scriptSource.startsWith(source))
     339            return false;
     340        var scriptSourceTail = scriptSource.substr(source.length).trim();
     341        return !scriptSourceTail || !!scriptSourceTail.match(/^\/\/@\ssourceURL=\s*(\S*?)\s*$/m);
     342    },
     343
     344    /**
     345     * @param {string} source
     346     * @return {boolean}
     347     */
     348    _sourceEndsWithSourceURL: function(source)
     349    {
     350        return !!source.match(/\/\/@\ssourceURL=\s*(\S*?)\s*$/m);
     351    },
     352
     353    /**
     354     * @param {WebInspector.Event} event
     355     */
    317356    _workingCopyChanged: function(event)
    318357    {
     
    370409    },
    371410
     411    checkMapping: function()
     412    {
     413        if (!this._script)
     414            return;
     415        if (typeof this._scriptSource !== "undefined")
     416            return;
     417        this._script.requestContent(callback.bind(this));
     418
     419        /**
     420         * @param {?string} source
     421         * @param {boolean} encoded
     422         * @param {string} contentType
     423         */
     424        function callback(source, encoded, contentType)
     425        {
     426            this._scriptSource = source;
     427            this._update();
     428        }
     429    },
     430
    372431    dispose: function()
    373432    {
  • trunk/Source/WebCore/inspector/front-end/ScriptSnippetModel.js

    r147099 r147102  
    434434    },
    435435
     436    checkMapping: function()
     437    {
     438    },
     439
    436440    /**
    437441     * @return {boolean}
Note: See TracChangeset for help on using the changeset viewer.