Changeset 121673 in webkit


Ignore:
Timestamp:
Jul 2, 2012 5:51:57 AM (12 years ago)
Author:
vsevik@chromium.org
Message:

Web Inspector: Implement snippets evaluation.
https://bugs.webkit.org/show_bug.cgi?id=88707

Reviewed by Pavel Feldman.

Source/WebCore:

Implemented snippet evaluation and adjusted breakpoints behavior when editing snippet.
Snippets are evaluated using separate compile and run.
Breakpoints are updated after compilation (once scriptId is available they can be set in debugger).
If separate compile and run is not supported by port or debugger is paused we fall back to evaluation in console.

  • inspector/front-end/ConsoleView.js:

(WebInspector.ConsoleView.prototype.runScript.runCallback):
(WebInspector.ConsoleView.prototype.runScript):
(WebInspector.ConsoleView.prototype._printResult):

  • inspector/front-end/JavaScriptSource.js:

(WebInspector.JavaScriptSource.prototype.supportsEnabledBreakpointsWhileEditing):

  • inspector/front-end/JavaScriptSourceFrame.js:

(WebInspector.JavaScriptSourceFrame.prototype.afterTextChanged):
(WebInspector.JavaScriptSourceFrame.prototype.beforeTextChanged):
(WebInspector.JavaScriptSourceFrame.prototype._didEditContent):
(WebInspector.JavaScriptSourceFrame.prototype._removeBreakpointsBeforeEditing):
(WebInspector.JavaScriptSourceFrame.prototype._restoreBreakpointsAfterEditing):
(WebInspector.JavaScriptSourceFrame.prototype._addBreakpointDecoration):
(WebInspector.JavaScriptSourceFrame.prototype._onMouseDown):

  • inspector/front-end/ScriptSnippetModel.js:

(WebInspector.ScriptSnippetModel.prototype.deleteScriptSnippet):
(WebInspector.ScriptSnippetModel.prototype._setScriptSnippetContent):
(WebInspector.ScriptSnippetModel.prototype.evaluateScriptSnippet.compileCallback):
(WebInspector.ScriptSnippetModel.prototype.evaluateScriptSnippet):
(WebInspector.ScriptSnippetModel.prototype._rawLocationToUILocation):
(WebInspector.ScriptSnippetModel.prototype._removeBreakpoints):
(WebInspector.ScriptSnippetModel.prototype._restoreBreakpoints):
(WebInspector.ScriptSnippetModel.prototype._evaluationSourceURL):
(WebInspector.SnippetJavaScriptSource.prototype.isDivergedFromVM):
(WebInspector.SnippetJavaScriptSource.prototype.workingCopyCommitted):
(WebInspector.SnippetJavaScriptSource.prototype.workingCopyChanged):
(WebInspector.SnippetJavaScriptSource.prototype.evaluate):
(WebInspector.SnippetJavaScriptSource.prototype.supportsEnabledBreakpointsWhileEditing):
(WebInspector.SnippetJavaScriptSource.prototype.breakpointStorageId):

  • inspector/front-end/ScriptsNavigator.js:

(WebInspector.SnippetsNavigatorView.prototype._handleEvaluateSnippet):

LayoutTests:

  • inspector/debugger/script-snippet-model-expected.txt:
  • inspector/debugger/script-snippet-model.html:
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r121669 r121673  
     12012-06-22  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: Implement snippets evaluation.
     4        https://bugs.webkit.org/show_bug.cgi?id=88707
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * inspector/debugger/script-snippet-model-expected.txt:
     9        * inspector/debugger/script-snippet-model.html:
     10
    1112012-07-02  Christophe Dumez  <christophe.dumez@intel.com>
    212
  • trunk/LayoutTests/inspector/debugger/script-snippet-model-expected.txt

    r117065 r121673  
    44
    55Running: testEvaluate
    6 Last evaluation source url for snippet: snippets://1_1
    7 Snippet script added, sourceURL = snippets://1_1
    8 Last evaluation source url for snippet: snippets://2_2
    9 Snippet script added, sourceURL = snippets://2_2
    10 Last evaluation source url for snippet: snippets://1_3
    11 Snippet script added, sourceURL = snippets://1_3
     6Last evaluation source url for snippet: snippets:///1_1
     7Snippet script added, sourceURL = snippets:///1_1
     8Snippet execution result: undefined
     9Last evaluation source url for snippet: snippets:///2_2
     10Snippet script added, sourceURL = snippets:///2_2
     11Snippet execution result: function doesNothing()
     12{
     13    var  i = 2+2;
     14}
     15Last evaluation source url for snippet: snippets:///1_3
     16Snippet script added, sourceURL = snippets:///1_3
     17Snippet execution result: undefined
    1218Debugger was disabled.
    1319
  • trunk/LayoutTests/inspector/debugger/script-snippet-model.html

    r117299 r121673  
    2727            content += "// This snippet does nothing.\n";
    2828            content += "var i = 2+2;\n";
    29             WebInspector.scriptSnippetModel.setScriptSnippetContent(snippetJavaScriptSource1, content);
     29            WebInspector.scriptSnippetModel._setScriptSnippetContent(snippetJavaScriptSource1, content);
    3030
    3131            var snippetJavaScriptSource2 = WebInspector.scriptSnippetModel.createScriptSnippet();
    3232            WebInspector.scriptSnippetModel.renameScriptSnippet(snippetJavaScriptSource2, "Snippet2");
    3333            content = "";
    34             content += "// This snippet creates a function that does nothing.\n";
     34            content += "// This snippet creates a function that does nothing and returns it.\n";
    3535            content += "function doesNothing()\n";
    3636            content += "{\n";
    3737            content += "    var  i = 2+2;\n";
    38             content += "}\n";
    39             WebInspector.scriptSnippetModel.setScriptSnippetContent(snippetJavaScriptSource2, content);
     38            content += "};\n";
     39            content += "doesNothing;\n";
     40            WebInspector.scriptSnippetModel._setScriptSnippetContent(snippetJavaScriptSource2, content);
    4041
    4142            function evaluateSnippetAndDumpEvaluationDetails(snippetJavaScriptSource, callback)
    4243            {
    4344                InspectorTest.addSniffer(WebInspector.SnippetScriptMapping.prototype, "addScript", dumpScript);
     45                InspectorTest.addSniffer(WebInspector.ConsoleView.prototype, "_printResult", dumpResult);
    4446                WebInspector.scriptSnippetModel.evaluateScriptSnippet(snippetJavaScriptSource);
    45                 var snippet = WebInspector.scriptSnippetModel._snippetStorage.snippetForId(snippetJavaScriptSource.snippetId);
    46                 InspectorTest.addResult("Last evaluation source url for snippet: " + snippet._lastEvaluationSourceURL);
    47                 InspectorTest.assertEquals(snippet, WebInspector.scriptSnippetModel._snippetForSourceURL(snippet._lastEvaluationSourceURL), "Snippet can not be identified by its evaluation sourceURL.");
     47                var evaluationSourceURL = WebInspector.scriptSnippetModel._evaluationSourceURL(snippetJavaScriptSource);
     48                var snippetId = snippetJavaScriptSource.snippetId;
     49                InspectorTest.addResult("Last evaluation source url for snippet: " + evaluationSourceURL);
     50                InspectorTest.assertEquals(snippetId, WebInspector.scriptSnippetModel._snippetIdForSourceURL(evaluationSourceURL), "Snippet can not be identified by its evaluation sourceURL.");
    4851
    4952                function dumpScript(script)
    5053                {
    5154                    InspectorTest.addResult("Snippet script added, sourceURL = " + script.sourceURL);
     55                }
     56
     57                function dumpResult(result, wasThrown)
     58                {
     59                    InspectorTest.addResult("Snippet execution result: " + result.description);
    5260                    callback();
    5361                }
  • trunk/Source/WebCore/ChangeLog

    r121672 r121673  
     12012-06-22  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: Implement snippets evaluation.
     4        https://bugs.webkit.org/show_bug.cgi?id=88707
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Implemented snippet evaluation and adjusted breakpoints behavior when editing snippet.
     9        Snippets are evaluated using separate compile and run.
     10        Breakpoints are updated after compilation (once scriptId is available they can be set in debugger).
     11        If separate compile and run is not supported by port or debugger is paused we fall back to evaluation in console.
     12
     13        * inspector/front-end/ConsoleView.js:
     14        (WebInspector.ConsoleView.prototype.runScript.runCallback):
     15        (WebInspector.ConsoleView.prototype.runScript):
     16        (WebInspector.ConsoleView.prototype._printResult):
     17        * inspector/front-end/JavaScriptSource.js:
     18        (WebInspector.JavaScriptSource.prototype.supportsEnabledBreakpointsWhileEditing):
     19        * inspector/front-end/JavaScriptSourceFrame.js:
     20        (WebInspector.JavaScriptSourceFrame.prototype.afterTextChanged):
     21        (WebInspector.JavaScriptSourceFrame.prototype.beforeTextChanged):
     22        (WebInspector.JavaScriptSourceFrame.prototype._didEditContent):
     23        (WebInspector.JavaScriptSourceFrame.prototype._removeBreakpointsBeforeEditing):
     24        (WebInspector.JavaScriptSourceFrame.prototype._restoreBreakpointsAfterEditing):
     25        (WebInspector.JavaScriptSourceFrame.prototype._addBreakpointDecoration):
     26        (WebInspector.JavaScriptSourceFrame.prototype._onMouseDown):
     27        * inspector/front-end/ScriptSnippetModel.js:
     28        (WebInspector.ScriptSnippetModel.prototype.deleteScriptSnippet):
     29        (WebInspector.ScriptSnippetModel.prototype._setScriptSnippetContent):
     30        (WebInspector.ScriptSnippetModel.prototype.evaluateScriptSnippet.compileCallback):
     31        (WebInspector.ScriptSnippetModel.prototype.evaluateScriptSnippet):
     32        (WebInspector.ScriptSnippetModel.prototype._rawLocationToUILocation):
     33        (WebInspector.ScriptSnippetModel.prototype._removeBreakpoints):
     34        (WebInspector.ScriptSnippetModel.prototype._restoreBreakpoints):
     35        (WebInspector.ScriptSnippetModel.prototype._evaluationSourceURL):
     36        (WebInspector.SnippetJavaScriptSource.prototype.isDivergedFromVM):
     37        (WebInspector.SnippetJavaScriptSource.prototype.workingCopyCommitted):
     38        (WebInspector.SnippetJavaScriptSource.prototype.workingCopyChanged):
     39        (WebInspector.SnippetJavaScriptSource.prototype.evaluate):
     40        (WebInspector.SnippetJavaScriptSource.prototype.supportsEnabledBreakpointsWhileEditing):
     41        (WebInspector.SnippetJavaScriptSource.prototype.breakpointStorageId):
     42        * inspector/front-end/ScriptsNavigator.js:
     43        (WebInspector.SnippetsNavigatorView.prototype._handleEvaluateSnippet):
     44
    1452012-06-26  Vsevolod Vlasov  <vsevik@chromium.org>
    246
  • trunk/Source/WebCore/bindings/v8/ScriptDebugServer.cpp

    r121538 r121673  
    452452void ScriptDebugServer::runScript(ScriptState* state, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionMessage)
    453453{
     454    if (!m_compiledScripts.contains(scriptId))
     455        return;
    454456    v8::HandleScope handleScope;
    455457    OwnHandle<v8::Script>* scriptOwnHandle = m_compiledScripts.get(scriptId);
  • trunk/Source/WebCore/inspector/front-end/ConsoleView.js

    r120325 r121673  
    713713    },
    714714
     715    runScript: function(scriptId)
     716    {
     717        var contextId = WebInspector.consoleView._currentEvaluationContextId();
     718        DebuggerAgent.runScript(scriptId, contextId, "console", false, runCallback.bind(this));
     719        WebInspector.userMetrics.ConsoleEvaluated.record();
     720
     721        /**
     722         * @param {?string} error
     723         * @param {?RuntimeAgent.RemoteObject} result
     724         * @param {boolean=} wasThrown
     725         */
     726        function runCallback(error, result, wasThrown)
     727        {
     728            if (error) {
     729                console.error(error);
     730                return;
     731            }
     732           
     733            this._printResult(result, wasThrown);
     734        }
     735    },
     736
     737    _printResult: function(result, wasThrown)
     738    {
     739        if (!result)
     740            return;
     741
     742        this._appendConsoleMessage(new WebInspector.ConsoleCommandResult(result, wasThrown, null, this._linkifier));
     743    },
     744
    715745    _appendCommand: function(text, newPromptText, useCommandLineAPI, showResultOnly)
    716746    {
     
    731761                WebInspector.settings.consoleHistory.set(this.prompt.historyData.slice(-30));
    732762            }
    733 
    734             this._appendConsoleMessage(new WebInspector.ConsoleCommandResult(result, wasThrown, commandMessage, this._linkifier));
     763           
     764            this._printResult(result, wasThrown);
    735765        }
    736766        this.evalInInspectedWindow(text, "console", useCommandLineAPI, false, false, printResult.bind(this));
  • trunk/Source/WebCore/inspector/front-end/JavaScriptSource.js

    r120471 r121673  
    161161
    162162    /**
     163     * @return {boolean}
     164     */
     165    supportsEnabledBreakpointsWhileEditing: function()
     166    {
     167        return false;
     168    },
     169
     170    /**
    163171     * @return {string}
    164172     */
     
    189197     */
    190198    workingCopyCommitted: function(callback)
    191     { 
     199    {
    192200        /**
    193201         * @param {?string} error
  • trunk/Source/WebCore/inspector/front-end/JavaScriptSourceFrame.js

    r121535 r121673  
    150150    afterTextChanged: function(oldRange, newRange)
    151151    {
     152        WebInspector.SourceFrame.prototype.afterTextChanged.call(this, oldRange, newRange);
    152153        this._javaScriptSource.setWorkingCopy(this.textModel.text);
    153         if (!this._javaScriptSource.isDirty())
    154             this._didEditContent(null);
     154        this._restoreBreakpointsAfterEditing();
    155155    },
    156156
    157157    beforeTextChanged: function()
    158158    {
    159         if (!this._javaScriptSource.isDirty()) {
     159        WebInspector.SourceFrame.prototype.beforeTextChanged.call(this);
     160        this._removeBreakpointsBeforeEditing();
     161    },
     162
     163    _didEditContent: function(error)
     164    {
     165        delete this._isCommittingEditing;
     166
     167        if (error) {
     168            WebInspector.log(error, WebInspector.ConsoleMessage.MessageLevel.Error, true);
     169            return;
     170        }
     171        if (!this._javaScriptSource.supportsEnabledBreakpointsWhileEditing())
     172            this._restoreBreakpointsAfterEditing();
     173    },
     174
     175    _removeBreakpointsBeforeEditing: function()
     176    {
     177        if (!this._javaScriptSource.isDirty() || this._javaScriptSource.supportsEnabledBreakpointsWhileEditing()) {
    160178            // Disable all breakpoints in the model, store them as muted breakpoints.
    161179            var breakpointLocations = this._breakpointManager.breakpointLocationsForUISourceCode(this._javaScriptSource);
     
    169187            this.clearExecutionLine();
    170188        }
    171 
    172         WebInspector.SourceFrame.prototype.beforeTextChanged.call(this);
    173     },
    174 
    175     _didEditContent: function(error)
    176     {
    177         delete this._isCommittingEditing;
    178 
    179         if (error) {
    180             WebInspector.log(error, WebInspector.ConsoleMessage.MessageLevel.Error, true);
    181             return;
    182         }
    183 
    184         // Restore all muted breakpoints.
    185         for (var lineNumber = 0; lineNumber < this.textModel.linesCount; ++lineNumber) {
    186             var breakpointDecoration = this.textModel.getAttribute(lineNumber, "breakpoint");
    187             if (breakpointDecoration) {
    188                 // Remove fake decoration
    189                 this._removeBreakpointDecoration(lineNumber);
    190                 // Set new breakpoint
    191                 this._setBreakpoint(lineNumber, breakpointDecoration.condition, breakpointDecoration.enabled);
     189    },
     190
     191    _restoreBreakpointsAfterEditing: function()
     192    {
     193        if (!this._javaScriptSource.isDirty() || this._javaScriptSource.supportsEnabledBreakpointsWhileEditing()) {
     194            // Restore all muted breakpoints.
     195            for (var lineNumber = 0; lineNumber < this.textModel.linesCount; ++lineNumber) {
     196                var breakpointDecoration = this.textModel.getAttribute(lineNumber, "breakpoint");
     197                if (breakpointDecoration) {
     198                    // Remove fake decoration
     199                    this._removeBreakpointDecoration(lineNumber);
     200                    // Set new breakpoint
     201                    this._setBreakpoint(lineNumber, breakpointDecoration.condition, breakpointDecoration.enabled);
     202                }
    192203            }
    193204        }
     
    327338        this.textViewer.beginUpdates();
    328339        this.textViewer.addDecoration(lineNumber, "webkit-breakpoint");
    329         if (!enabled || mutedWhileEditing)
     340        if (!enabled || (mutedWhileEditing && !this._javaScriptSource.supportsEnabledBreakpointsWhileEditing()))
    330341            this.textViewer.addDecoration(lineNumber, "webkit-breakpoint-disabled");
    331342        else
     
    350361    _onMouseDown: function(event)
    351362    {
    352         if (this._javaScriptSource.isDirty())
     363        if (this._javaScriptSource.isDirty() && !this._javaScriptSource.supportsEnabledBreakpointsWhileEditing())
    353364            return;
    354365
  • trunk/Source/WebCore/inspector/front-end/ScriptSnippetModel.js

    r119898 r121673  
    4848}
    4949
    50 WebInspector.ScriptSnippetModel.evaluatedSnippetExtraLinesCount = 2;
    51 WebInspector.ScriptSnippetModel.snippetSourceURLPrefix = "snippets://";
     50WebInspector.ScriptSnippetModel.snippetSourceURLPrefix = "snippets:///";
    5251
    5352WebInspector.ScriptSnippetModel.prototype = {
     
    8887        var snippet = this._snippetStorage.snippetForId(snippetJavaScriptSource.snippetId);
    8988        this._snippetStorage.deleteSnippet(snippet);
     89        this._removeBreakpoints(snippetJavaScriptSource);
    9090        this._releaseSnippetScript(snippetJavaScriptSource);
    9191        delete this._snippetJavaScriptSourceForSnippetId[snippet.id];
     
    108108    /**
    109109     * @param {WebInspector.SnippetJavaScriptSource} snippetJavaScriptSource
     110     * @return {boolean}
     111     */
     112    _isDivergedFromVM: function(snippetJavaScriptSource)
     113    {
     114        var script = this._scriptForUISourceCode.get(snippetJavaScriptSource);
     115        return !script;
     116    },
     117
     118    /**
     119     * @param {WebInspector.SnippetJavaScriptSource} snippetJavaScriptSource
    110120     * @param {string} newContent
    111121     */
    112     setScriptSnippetContent: function(snippetJavaScriptSource, newContent)
     122    _setScriptSnippetContent: function(snippetJavaScriptSource, newContent)
    113123    {
    114124        var snippet = this._snippetStorage.snippetForId(snippetJavaScriptSource.snippetId);
     
    120130     * @param {WebInspector.SnippetJavaScriptSource} snippetJavaScriptSource
    121131     */
    122     evaluateScriptSnippet: function(snippetJavaScriptSource)
    123     {
     132    _scriptSnippetEdited: function(snippetJavaScriptSource)
     133    {
     134        var script = this._scriptForUISourceCode.get(snippetJavaScriptSource);
     135        if (!script)
     136            return;
     137       
     138        var breakpointLocations = this._removeBreakpoints(snippetJavaScriptSource);
    124139        this._releaseSnippetScript(snippetJavaScriptSource);
     140        this._restoreBreakpoints(snippetJavaScriptSource, breakpointLocations);
     141    },
     142
     143    /**
     144     * @param {string} snippetId
     145     * @return {number}
     146     */
     147    _nextEvaluationIndex: function(snippetId)
     148    {
    125149        var evaluationIndex = this._lastSnippetEvaluationIndexSetting.get() + 1;
    126150        this._lastSnippetEvaluationIndexSetting.set(evaluationIndex);
    127 
    128         var snippet = this._snippetStorage.snippetForId(snippetJavaScriptSource.snippetId);
    129         var sourceURL = this._sourceURLForSnippet(snippet, evaluationIndex);
    130         snippet._lastEvaluationSourceURL = sourceURL;
    131         var expression = "\n//@ sourceURL=" + sourceURL + "\n" + snippet.content;
    132         WebInspector.evaluateInConsole(expression, true);
     151        return evaluationIndex;
     152    },
     153
     154    /**
     155     * @param {WebInspector.SnippetJavaScriptSource} snippetJavaScriptSource
     156     */
     157    evaluateScriptSnippet: function(snippetJavaScriptSource)
     158    {
     159        var breakpointLocations = this._removeBreakpoints(snippetJavaScriptSource);
     160        this._releaseSnippetScript(snippetJavaScriptSource);
     161        this._restoreBreakpoints(snippetJavaScriptSource, breakpointLocations);
     162        var evaluationIndex = this._nextEvaluationIndex(snippetJavaScriptSource.snippetId);
     163        snippetJavaScriptSource._evaluationIndex = evaluationIndex;
     164        var evaluationUrl = this._evaluationSourceURL(snippetJavaScriptSource);
     165
     166        var expression = snippetJavaScriptSource.workingCopy();
     167       
     168        // In order to stop on the breakpoints during the snippet evaluation we need to compile and run it separately.
     169        // If separate compilation and execution is not supported by the port we fall back to evaluation in console.
     170        // In case we don't need that since debugger is already paused.
     171        // We do the same when we are stopped on the call frame  since debugger is already paused and can not stop on breakpoint anymore.
     172        if (WebInspector.debuggerModel.selectedCallFrame() || !Capabilities.separateScriptCompilationAndExecutionEnabled) {
     173            expression = snippetJavaScriptSource.workingCopy() + "\n//@ sourceURL=" + snippetJavaScriptSource.url + "\n";
     174            WebInspector.evaluateInConsole(expression, true);
     175            return;
     176        }
     177       
     178        WebInspector.showConsole();
     179        DebuggerAgent.compileScript(expression, evaluationUrl, compileCallback.bind(this));
     180
     181        /**
     182         * @param {?string} error
     183         * @param {string=} scriptId
     184         * @param {string=} syntaxErrorMessage
     185         */
     186        function compileCallback(error, scriptId, syntaxErrorMessage)
     187        {
     188            if (!snippetJavaScriptSource || snippetJavaScriptSource._evaluationIndex !== evaluationIndex)
     189                return;
     190
     191            if (error) {
     192                console.error(error);
     193                return;
     194            }
     195
     196            if (!scriptId) {
     197                var consoleMessage = WebInspector.ConsoleMessage.create(
     198                        WebInspector.ConsoleMessage.MessageSource.JS,
     199                        WebInspector.ConsoleMessage.MessageLevel.Error,
     200                        syntaxErrorMessage || "",
     201                        WebInspector.ConsoleMessage.MessageType.Log,
     202                        "", 0, 1, null, null, null);
     203                WebInspector.console.addMessage(consoleMessage);
     204                return;
     205            }
     206
     207            var breakpointLocations = this._removeBreakpoints(snippetJavaScriptSource);
     208            this._restoreBreakpoints(snippetJavaScriptSource, breakpointLocations);
     209
     210            WebInspector.consoleView.runScript(scriptId);
     211        }
    133212    },
    134213
     
    140219    {
    141220        var uiSourceCode = this._uiSourceCodeForScriptId[rawLocation.scriptId];
    142         if (uiSourceCode.isSnippet) {
    143             var uiLineNumber = rawLocation.lineNumber - WebInspector.ScriptSnippetModel.evaluatedSnippetExtraLinesCount;
    144             return new WebInspector.UILocation(uiSourceCode, uiLineNumber, rawLocation.columnNumber || 0);
    145         }
    146 
    147221        return new WebInspector.UILocation(uiSourceCode, rawLocation.lineNumber, rawLocation.columnNumber || 0);
    148222    },
     
    159233        if (!script)
    160234            return null;
    161 
    162         if (uiSourceCode.isSnippet) {
    163             var rawLineNumber = lineNumber + WebInspector.ScriptSnippetModel.evaluatedSnippetExtraLinesCount;
    164             return WebInspector.debuggerModel.createRawLocation(script, rawLineNumber, columnNumber);
    165         }
    166235
    167236        return WebInspector.debuggerModel.createRawLocation(script, lineNumber, columnNumber);
     
    200269        var snippetId = this._snippetIdForSourceURL(script.sourceURL);
    201270        var snippetJavaScriptSource = this._snippetJavaScriptSourceForSnippetId[snippetId];
    202         if (!snippetJavaScriptSource) {
     271       
     272        if (!snippetJavaScriptSource || this._evaluationSourceURL(snippetJavaScriptSource) !== script.sourceURL) {
    203273            this._createUISourceCodeForScript(script);
    204274            return;
     
    226296    /**
    227297     * @param {WebInspector.SnippetJavaScriptSource} snippetJavaScriptSource
     298     * @return {Array.<Object>}
     299     */
     300    _removeBreakpoints: function(snippetJavaScriptSource)
     301    {
     302        var breakpointLocations = WebInspector.breakpointManager.breakpointLocationsForUISourceCode(snippetJavaScriptSource);
     303        for (var i = 0; i < breakpointLocations.length; ++i)
     304            breakpointLocations[i].breakpoint.remove();
     305        return breakpointLocations;
     306    },
     307
     308    /**
     309     * @param {WebInspector.SnippetJavaScriptSource} snippetJavaScriptSource
     310     * @param {Array.<Object>} breakpointLocations
     311     */
     312    _restoreBreakpoints: function(snippetJavaScriptSource, breakpointLocations)
     313    {
     314        for (var i = 0; i < breakpointLocations.length; ++i) {
     315            var uiLocation = breakpointLocations[i].uiLocation;
     316            var breakpoint = breakpointLocations[i].breakpoint;
     317            WebInspector.breakpointManager.setBreakpoint(uiLocation.uiSourceCode, uiLocation.lineNumber, breakpoint.condition(), breakpoint.enabled());
     318        }
     319    },
     320
     321    /**
     322     * @param {WebInspector.SnippetJavaScriptSource} snippetJavaScriptSource
    228323     */
    229324    _releaseSnippetScript: function(snippetJavaScriptSource)
     
    235330        delete this._uiSourceCodeForScriptId[script.scriptId];
    236331        this._scriptForUISourceCode.remove(snippetJavaScriptSource);
    237 
     332        delete snippetJavaScriptSource._evaluationIndex;
    238333        this._createUISourceCodeForScript(script);
    239334    },
    240335
    241336    /**
    242      * @param {WebInspector.Snippet} snippet
    243      * @param {string} evaluationIndex
     337     * @param {WebInspector.SnippetJavaScriptSource} snippetJavaScriptSource
    244338     * @return {string}
    245339     */
    246     _sourceURLForSnippet: function(snippet, evaluationIndex)
     340    _evaluationSourceURL: function(snippetJavaScriptSource)
    247341    {
    248342        var snippetPrefix = WebInspector.ScriptSnippetModel.snippetSourceURLPrefix;
    249         var evaluationSuffix = evaluationIndex ? "_" + evaluationIndex : "";
    250         return snippetPrefix + snippet.id + evaluationSuffix;
     343        var evaluationSuffix = "_" + snippetJavaScriptSource._evaluationIndex;
     344        return snippetPrefix + snippetJavaScriptSource.snippetId + evaluationSuffix;
    251345    },
    252346
     
    263357        var snippetId = splittedURL[0];
    264358        return snippetId;
    265     },
    266 
    267     /**
    268      * @param {string} sourceURL
    269      * @return {WebInspector.Snippet|null}
    270      */
    271     _snippetForSourceURL: function(sourceURL)
    272     {
    273         var snippetId = this._snippetIdForSourceURL(sourceURL);
    274         if (!snippetId)
    275             return null;
    276         var snippet = this._snippetStorage.snippetForId(snippetId);
    277         if (!snippet || snippet._lastEvaluationSourceURL !== sourceURL)
    278             return null;
    279         return snippet;
    280359    },
    281360
     
    318397
    319398    /**
     399     * @return {boolean}
     400     */
     401    isDivergedFromVM: function()
     402    {
     403        return this._scriptSnippetModel._isDivergedFromVM(this);
     404    },
     405
     406    /**
    320407     * @param {function(?string)} callback
    321408     */
    322409    workingCopyCommitted: function(callback)
    323410    { 
    324         this._scriptSnippetModel.setScriptSnippetContent(this, this.workingCopy());
     411        this._scriptSnippetModel._setScriptSnippetContent(this, this.workingCopy());
    325412        callback(null);
     413    },
     414
     415    workingCopyChanged: function()
     416    { 
     417        this._scriptSnippetModel._scriptSnippetEdited(this);
     418    },
     419
     420    evaluate: function()
     421    {
     422        this._scriptSnippetModel.evaluateScriptSnippet(this);
     423    },
     424
     425    /**
     426     * @return {boolean}
     427     */
     428    supportsEnabledBreakpointsWhileEditing: function()
     429    {
     430        return true;
     431    },
     432
     433    /**
     434     * @return {string}
     435     */
     436    breakpointStorageId: function()
     437    {
     438        return WebInspector.ScriptSnippetModel.snippetSourceURLPrefix + this.snippetId;
    326439    },
    327440
  • trunk/Source/WebCore/inspector/front-end/ScriptsNavigator.js

    r117751 r121673  
    233233    _handleEvaluateSnippet: function(uiSourceCode, event)
    234234    {
    235         // FIXME: To be implemented.
     235        if (!uiSourceCode.isSnippet)
     236            return;
     237        var snippetJavaScriptSource = /** @type {WebInspector.SnippetJavaScriptSource} */ uiSourceCode;
     238        snippetJavaScriptSource.evaluate();
    236239    },
    237240
  • trunk/Source/WebCore/inspector/front-end/externs.js

    r120085 r121673  
    148148WebInspector.openResource = function(url, external) {}
    149149
     150WebInspector.showConsole = function() {}
     151
    150152/**
    151153 * @param {string} expression
Note: See TracChangeset for help on using the changeset viewer.