~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/inspector/front-end/DebuggerModel.js

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Google Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are
 
6
 * met:
 
7
 *
 
8
 *     * Redistributions of source code must retain the above copyright
 
9
 * notice, this list of conditions and the following disclaimer.
 
10
 *     * Redistributions in binary form must reproduce the above
 
11
 * copyright notice, this list of conditions and the following disclaimer
 
12
 * in the documentation and/or other materials provided with the
 
13
 * distribution.
 
14
 *     * Neither the name of Google Inc. nor the names of its
 
15
 * contributors may be used to endorse or promote products derived from
 
16
 * this software without specific prior written permission.
 
17
 *
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
19
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
20
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
21
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
22
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
23
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
24
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
25
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
26
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
28
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
 */
 
30
 
 
31
/**
 
32
 * @constructor
 
33
 * @extends {WebInspector.Object}
 
34
 */
 
35
WebInspector.DebuggerModel = function()
 
36
{
 
37
    InspectorBackend.registerDebuggerDispatcher(new WebInspector.DebuggerDispatcher(this));
 
38
 
 
39
    this._debuggerPausedDetails = null;
 
40
    /**
 
41
     * @type {Object.<string, WebInspector.Script>}
 
42
     */
 
43
    this._scripts = {};
 
44
    this._scriptsBySourceURL = {};
 
45
 
 
46
    this._canSetScriptSource = false;
 
47
    this._breakpointsActive = true;
 
48
 
 
49
    WebInspector.settings.pauseOnExceptionStateString = WebInspector.settings.createSetting("pauseOnExceptionStateString", WebInspector.DebuggerModel.PauseOnExceptionsState.DontPauseOnExceptions);
 
50
    WebInspector.settings.pauseOnExceptionStateString.addChangeListener(this._pauseOnExceptionStateChanged, this);
 
51
 
 
52
    if (!Capabilities.debuggerCausesRecompilation || WebInspector.settings.debuggerEnabled.get())
 
53
        this.enableDebugger();
 
54
}
 
55
 
 
56
// Keep these in sync with WebCore::ScriptDebugServer
 
57
WebInspector.DebuggerModel.PauseOnExceptionsState = {
 
58
    DontPauseOnExceptions : "none",
 
59
    PauseOnAllExceptions : "all",
 
60
    PauseOnUncaughtExceptions: "uncaught"
 
61
};
 
62
 
 
63
/**
 
64
 * @constructor
 
65
 * @implements {WebInspector.RawLocation}
 
66
 * @extends {DebuggerAgent.Location}
 
67
 * @param {string} scriptId
 
68
 * @param {number} lineNumber
 
69
 * @param {number} columnNumber
 
70
 */
 
71
WebInspector.DebuggerModel.Location = function(scriptId, lineNumber, columnNumber)
 
72
{
 
73
    this.scriptId = scriptId;
 
74
    this.lineNumber = lineNumber;
 
75
    this.columnNumber = columnNumber;
 
76
}
 
77
 
 
78
WebInspector.DebuggerModel.Events = {
 
79
    DebuggerWasEnabled: "DebuggerWasEnabled",
 
80
    DebuggerWasDisabled: "DebuggerWasDisabled",
 
81
    DebuggerPaused: "DebuggerPaused",
 
82
    DebuggerResumed: "DebuggerResumed",
 
83
    ParsedScriptSource: "ParsedScriptSource",
 
84
    FailedToParseScriptSource: "FailedToParseScriptSource",
 
85
    BreakpointResolved: "BreakpointResolved",
 
86
    GlobalObjectCleared: "GlobalObjectCleared",
 
87
    CallFrameSelected: "CallFrameSelected",
 
88
    ExecutionLineChanged: "ExecutionLineChanged",
 
89
    ConsoleCommandEvaluatedInSelectedCallFrame: "ConsoleCommandEvaluatedInSelectedCallFrame",
 
90
    BreakpointsActiveStateChanged: "BreakpointsActiveStateChanged"
 
91
}
 
92
 
 
93
WebInspector.DebuggerModel.BreakReason = {
 
94
    DOM: "DOM",
 
95
    EventListener: "EventListener",
 
96
    XHR: "XHR",
 
97
    Exception: "exception",
 
98
    Assert: "assert",
 
99
    CSPViolation: "CSPViolation"
 
100
}
 
101
 
 
102
WebInspector.DebuggerModel.prototype = {
 
103
    /**
 
104
     * @return {boolean}
 
105
     */
 
106
    debuggerEnabled: function()
 
107
    {
 
108
        return !!this._debuggerEnabled;
 
109
    },
 
110
 
 
111
    enableDebugger: function()
 
112
    {
 
113
        if (this._debuggerEnabled)
 
114
            return;
 
115
 
 
116
        function callback(error, result)
 
117
        {
 
118
            this._canSetScriptSource = result;
 
119
        }
 
120
        DebuggerAgent.canSetScriptSource(callback.bind(this));
 
121
        DebuggerAgent.enable(this._debuggerWasEnabled.bind(this));
 
122
    },
 
123
 
 
124
    disableDebugger: function()
 
125
    {
 
126
        if (!this._debuggerEnabled)
 
127
            return;
 
128
 
 
129
        DebuggerAgent.disable(this._debuggerWasDisabled.bind(this));
 
130
    },
 
131
 
 
132
    /**
 
133
     * @return {boolean}
 
134
     */
 
135
    canSetScriptSource: function()
 
136
    {
 
137
        return this._canSetScriptSource;
 
138
    },
 
139
 
 
140
    _debuggerWasEnabled: function()
 
141
    {
 
142
        this._debuggerEnabled = true;
 
143
        this._pauseOnExceptionStateChanged();
 
144
        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.DebuggerWasEnabled);
 
145
    },
 
146
 
 
147
    _pauseOnExceptionStateChanged: function()
 
148
    {
 
149
        DebuggerAgent.setPauseOnExceptions(WebInspector.settings.pauseOnExceptionStateString.get());
 
150
    },
 
151
 
 
152
    _debuggerWasDisabled: function()
 
153
    {
 
154
        this._debuggerEnabled = false;
 
155
        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.DebuggerWasDisabled);
 
156
    },
 
157
 
 
158
    /**
 
159
     * @param {WebInspector.DebuggerModel.Location} rawLocation
 
160
     */
 
161
    continueToLocation: function(rawLocation)
 
162
    {
 
163
        DebuggerAgent.continueToLocation(rawLocation);
 
164
    },
 
165
 
 
166
    /**
 
167
     * @param {WebInspector.DebuggerModel.Location} rawLocation
 
168
     * @param {string} condition
 
169
     * @param {function(?DebuggerAgent.BreakpointId, Array.<WebInspector.DebuggerModel.Location>):void=} callback
 
170
     */
 
171
    setBreakpointByScriptLocation: function(rawLocation, condition, callback)
 
172
    {
 
173
        var script = this.scriptForId(rawLocation.scriptId);
 
174
        if (script.sourceURL)
 
175
            this.setBreakpointByURL(script.sourceURL, rawLocation.lineNumber, rawLocation.columnNumber, condition, callback);
 
176
        else
 
177
            this.setBreakpointBySourceId(rawLocation, condition, callback);
 
178
    },
 
179
 
 
180
    /**
 
181
     * @param {string} url
 
182
     * @param {number} lineNumber
 
183
     * @param {number=} columnNumber
 
184
     * @param {string=} condition
 
185
     * @param {function(?DebuggerAgent.BreakpointId, Array.<WebInspector.DebuggerModel.Location>)=} callback
 
186
     */
 
187
    setBreakpointByURL: function(url, lineNumber, columnNumber, condition, callback)
 
188
    {
 
189
        // Adjust column if needed.
 
190
        var minColumnNumber = 0;
 
191
        var scripts = this._scriptsBySourceURL[url] || [];
 
192
        for (var i = 0, l = scripts.length; i < l; ++i) {
 
193
            var script = scripts[i];
 
194
            if (lineNumber === script.lineOffset)
 
195
                minColumnNumber = minColumnNumber ? Math.min(minColumnNumber, script.columnOffset) : script.columnOffset;
 
196
        }
 
197
        columnNumber = Math.max(columnNumber, minColumnNumber);
 
198
 
 
199
        /**
 
200
         * @this {WebInspector.DebuggerModel}
 
201
         * @param {?Protocol.Error} error
 
202
         * @param {DebuggerAgent.BreakpointId} breakpointId
 
203
         * @param {Array.<DebuggerAgent.Location>} locations
 
204
         */
 
205
        function didSetBreakpoint(error, breakpointId, locations)
 
206
        {
 
207
            if (callback) {
 
208
                var rawLocations = /** @type {Array.<WebInspector.DebuggerModel.Location>} */ (locations);
 
209
                callback(error ? null : breakpointId, rawLocations);
 
210
            }
 
211
        }
 
212
        DebuggerAgent.setBreakpointByUrl(lineNumber, url, undefined, columnNumber, condition, didSetBreakpoint.bind(this));
 
213
        WebInspector.userMetrics.ScriptsBreakpointSet.record();
 
214
    },
 
215
 
 
216
    /**
 
217
     * @param {WebInspector.DebuggerModel.Location} rawLocation
 
218
     * @param {string} condition
 
219
     * @param {function(?DebuggerAgent.BreakpointId, Array.<WebInspector.DebuggerModel.Location>)=} callback
 
220
     */
 
221
    setBreakpointBySourceId: function(rawLocation, condition, callback)
 
222
    {
 
223
        /**
 
224
         * @this {WebInspector.DebuggerModel}
 
225
         * @param {?Protocol.Error} error
 
226
         * @param {DebuggerAgent.BreakpointId} breakpointId
 
227
         * @param {DebuggerAgent.Location} actualLocation
 
228
         */
 
229
        function didSetBreakpoint(error, breakpointId, actualLocation)
 
230
        {
 
231
            if (callback) {
 
232
                var rawLocation = /** @type {WebInspector.DebuggerModel.Location} */ (actualLocation);
 
233
                callback(error ? null : breakpointId, [rawLocation]);
 
234
            }
 
235
        }
 
236
        DebuggerAgent.setBreakpoint(rawLocation, condition, didSetBreakpoint.bind(this));
 
237
        WebInspector.userMetrics.ScriptsBreakpointSet.record();
 
238
    },
 
239
 
 
240
    /**
 
241
     * @param {DebuggerAgent.BreakpointId} breakpointId
 
242
     * @param {function(?Protocol.Error)=} callback
 
243
     */
 
244
    removeBreakpoint: function(breakpointId, callback)
 
245
    {
 
246
        DebuggerAgent.removeBreakpoint(breakpointId, callback);
 
247
    },
 
248
 
 
249
    /**
 
250
     * @param {DebuggerAgent.BreakpointId} breakpointId
 
251
     * @param {DebuggerAgent.Location} location
 
252
     */
 
253
    _breakpointResolved: function(breakpointId, location)
 
254
    {
 
255
        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.BreakpointResolved, {breakpointId: breakpointId, location: location});
 
256
    },
 
257
 
 
258
    _globalObjectCleared: function()
 
259
    {
 
260
        this._setDebuggerPausedDetails(null);
 
261
        this._reset();
 
262
        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.GlobalObjectCleared);
 
263
    },
 
264
 
 
265
    _reset: function()
 
266
    {
 
267
        this._scripts = {};
 
268
        this._scriptsBySourceURL = {};
 
269
    },
 
270
 
 
271
    /**
 
272
     * @return {Object.<string, WebInspector.Script>}
 
273
     */
 
274
    get scripts()
 
275
    {
 
276
        return this._scripts;
 
277
    },
 
278
 
 
279
    /**
 
280
     * @param {DebuggerAgent.ScriptId} scriptId
 
281
     * @return {WebInspector.Script}
 
282
     */
 
283
    scriptForId: function(scriptId)
 
284
    {
 
285
        return this._scripts[scriptId] || null;
 
286
    },
 
287
 
 
288
    /**
 
289
     * @param {DebuggerAgent.ScriptId} scriptId
 
290
     * @param {string} newSource
 
291
     * @param {function(?Protocol.Error)} callback
 
292
     */
 
293
    setScriptSource: function(scriptId, newSource, callback)
 
294
    {
 
295
        this._scripts[scriptId].editSource(newSource, this._didEditScriptSource.bind(this, scriptId, newSource, callback));
 
296
    },
 
297
 
 
298
    /**
 
299
     * @param {DebuggerAgent.ScriptId} scriptId
 
300
     * @param {string} newSource
 
301
     * @param {function(?Protocol.Error)} callback
 
302
     * @param {?Protocol.Error} error
 
303
     * @param {Array.<DebuggerAgent.CallFrame>=} callFrames
 
304
     */
 
305
    _didEditScriptSource: function(scriptId, newSource, callback, error, callFrames)
 
306
    {
 
307
        callback(error);
 
308
        if (!error && callFrames && callFrames.length)
 
309
            this._pausedScript(callFrames, this._debuggerPausedDetails.reason, this._debuggerPausedDetails.auxData);
 
310
    },
 
311
 
 
312
    /**
 
313
     * @return {Array.<DebuggerAgent.CallFrame>}
 
314
     */
 
315
    get callFrames()
 
316
    {
 
317
        return this._debuggerPausedDetails ? this._debuggerPausedDetails.callFrames : null;
 
318
    },
 
319
 
 
320
    /**
 
321
     * @return {?WebInspector.DebuggerPausedDetails}
 
322
     */
 
323
    debuggerPausedDetails: function()
 
324
    {
 
325
        return this._debuggerPausedDetails;
 
326
    },
 
327
 
 
328
    /**
 
329
     * @param {?WebInspector.DebuggerPausedDetails} debuggerPausedDetails
 
330
     */
 
331
    _setDebuggerPausedDetails: function(debuggerPausedDetails)
 
332
    {
 
333
        if (this._debuggerPausedDetails)
 
334
            this._debuggerPausedDetails.dispose();
 
335
        this._debuggerPausedDetails = debuggerPausedDetails;
 
336
        if (this._debuggerPausedDetails)
 
337
            this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.DebuggerPaused, this._debuggerPausedDetails);
 
338
        if (debuggerPausedDetails) {
 
339
            this.setSelectedCallFrame(debuggerPausedDetails.callFrames[0]);
 
340
            DebuggerAgent.setOverlayMessage(WebInspector.UIString("Paused in debugger"));
 
341
        } else {
 
342
            this.setSelectedCallFrame(null);
 
343
            DebuggerAgent.setOverlayMessage();
 
344
        }
 
345
    },
 
346
 
 
347
    /**
 
348
     * @param {Array.<DebuggerAgent.CallFrame>} callFrames
 
349
     * @param {string} reason
 
350
     * @param {*} auxData
 
351
     */
 
352
    _pausedScript: function(callFrames, reason, auxData)
 
353
    {
 
354
        this._setDebuggerPausedDetails(new WebInspector.DebuggerPausedDetails(this, callFrames, reason, auxData));
 
355
    },
 
356
 
 
357
    _resumedScript: function()
 
358
    {
 
359
        this._setDebuggerPausedDetails(null);
 
360
        if (this._executionLineLiveLocation)
 
361
            this._executionLineLiveLocation.dispose();
 
362
        this._executionLineLiveLocation = null;
 
363
        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.DebuggerResumed);
 
364
    },
 
365
 
 
366
    /**
 
367
     * @param {DebuggerAgent.ScriptId} scriptId
 
368
     * @param {string} sourceURL
 
369
     * @param {number} startLine
 
370
     * @param {number} startColumn
 
371
     * @param {number} endLine
 
372
     * @param {number} endColumn
 
373
     * @param {boolean} isContentScript
 
374
     * @param {string=} sourceMapURL
 
375
     * @param {boolean=} hasSourceURL
 
376
     */
 
377
    _parsedScriptSource: function(scriptId, sourceURL, startLine, startColumn, endLine, endColumn, isContentScript, sourceMapURL, hasSourceURL)
 
378
    {
 
379
        var script = new WebInspector.Script(scriptId, sourceURL, startLine, startColumn, endLine, endColumn, isContentScript, sourceMapURL, hasSourceURL);
 
380
        this._registerScript(script);
 
381
        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.ParsedScriptSource, script);
 
382
    },
 
383
 
 
384
    /**
 
385
     * @param {WebInspector.Script} script
 
386
     */
 
387
    _registerScript: function(script)
 
388
    {
 
389
        this._scripts[script.scriptId] = script;
 
390
        if (script.sourceURL) {
 
391
            var scripts = this._scriptsBySourceURL[script.sourceURL];
 
392
            if (!scripts) {
 
393
                scripts = [];
 
394
                this._scriptsBySourceURL[script.sourceURL] = scripts;
 
395
            }
 
396
            scripts.push(script);
 
397
        }
 
398
    },
 
399
 
 
400
    /**
 
401
     * @param {WebInspector.Script} script
 
402
     * @param {number} lineNumber
 
403
     * @param {number} columnNumber
 
404
     * @return {WebInspector.DebuggerModel.Location}
 
405
     */
 
406
    createRawLocation: function(script, lineNumber, columnNumber)
 
407
    {
 
408
        if (script.sourceURL)
 
409
            return this.createRawLocationByURL(script.sourceURL, lineNumber, columnNumber)
 
410
        return new WebInspector.DebuggerModel.Location(script.scriptId, lineNumber, columnNumber);
 
411
    },
 
412
 
 
413
    /**
 
414
     * @param {string} sourceURL
 
415
     * @param {number} lineNumber
 
416
     * @param {number} columnNumber
 
417
     * @return {WebInspector.DebuggerModel.Location}
 
418
     */
 
419
    createRawLocationByURL: function(sourceURL, lineNumber, columnNumber)
 
420
    {
 
421
        var closestScript = null;
 
422
        var scripts = this._scriptsBySourceURL[sourceURL] || [];
 
423
        for (var i = 0, l = scripts.length; i < l; ++i) {
 
424
            var script = scripts[i];
 
425
            if (!closestScript)
 
426
                closestScript = script;
 
427
            if (script.lineOffset > lineNumber || (script.lineOffset === lineNumber && script.columnOffset > columnNumber))
 
428
                continue;
 
429
            if (script.endLine < lineNumber || (script.endLine === lineNumber && script.endColumn <= columnNumber))
 
430
                continue;
 
431
            closestScript = script;
 
432
            break;
 
433
        }
 
434
        return closestScript ? new WebInspector.DebuggerModel.Location(closestScript.scriptId, lineNumber, columnNumber) : null;
 
435
    },
 
436
 
 
437
    /**
 
438
     * @return {boolean}
 
439
     */
 
440
    isPaused: function()
 
441
    {
 
442
        return !!this.debuggerPausedDetails();
 
443
    },
 
444
 
 
445
    /**
 
446
     * @param {?WebInspector.DebuggerModel.CallFrame} callFrame
 
447
     */
 
448
    setSelectedCallFrame: function(callFrame)
 
449
    {
 
450
        if (this._executionLineLiveLocation)
 
451
            this._executionLineLiveLocation.dispose();
 
452
        delete this._executionLineLiveLocation;
 
453
 
 
454
        this._selectedCallFrame = callFrame;
 
455
        if (!this._selectedCallFrame)
 
456
            return;
 
457
 
 
458
        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.CallFrameSelected, callFrame);
 
459
 
 
460
        function updateExecutionLine(uiLocation)
 
461
        {
 
462
            this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.ExecutionLineChanged, uiLocation);
 
463
        }
 
464
        this._executionLineLiveLocation = callFrame.script.createLiveLocation(callFrame.location, updateExecutionLine.bind(this));
 
465
    },
 
466
 
 
467
    /**
 
468
     * @return {?WebInspector.DebuggerModel.CallFrame}
 
469
     */
 
470
    selectedCallFrame: function()
 
471
    {
 
472
        return this._selectedCallFrame;
 
473
    },
 
474
 
 
475
    /**
 
476
     * @param {string} code
 
477
     * @param {string} objectGroup
 
478
     * @param {boolean} includeCommandLineAPI
 
479
     * @param {boolean} doNotPauseOnExceptionsAndMuteConsole
 
480
     * @param {boolean} returnByValue
 
481
     * @param {boolean} generatePreview
 
482
     * @param {function(?WebInspector.RemoteObject, boolean, RuntimeAgent.RemoteObject=)} callback
 
483
     */
 
484
    evaluateOnSelectedCallFrame: function(code, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, callback)
 
485
    {
 
486
        /**
 
487
         * @param {?RuntimeAgent.RemoteObject} result
 
488
         * @param {boolean=} wasThrown
 
489
         */
 
490
        function didEvaluate(result, wasThrown)
 
491
        {
 
492
            if (returnByValue)
 
493
                callback(null, !!wasThrown, wasThrown ? null : result);
 
494
            else
 
495
                callback(WebInspector.RemoteObject.fromPayload(result), !!wasThrown);
 
496
 
 
497
            if (objectGroup === "console")
 
498
                this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.ConsoleCommandEvaluatedInSelectedCallFrame);
 
499
        }
 
500
 
 
501
        this.selectedCallFrame().evaluate(code, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, didEvaluate.bind(this));
 
502
    },
 
503
 
 
504
    /**
 
505
     * @param {function(Object)} callback
 
506
     */
 
507
    getSelectedCallFrameVariables: function(callback)
 
508
    {
 
509
        var result = { this: true };
 
510
 
 
511
        var selectedCallFrame = this._selectedCallFrame;
 
512
        if (!selectedCallFrame)
 
513
            callback(result);
 
514
 
 
515
        var pendingRequests = 0;
 
516
 
 
517
        function propertiesCollected(properties)
 
518
        {
 
519
            for (var i = 0; properties && i < properties.length; ++i)
 
520
                result[properties[i].name] = true;
 
521
            if (--pendingRequests == 0)
 
522
                callback(result);
 
523
        }
 
524
 
 
525
        for (var i = 0; i < selectedCallFrame.scopeChain.length; ++i) {
 
526
            var scope = selectedCallFrame.scopeChain[i];
 
527
            var object = WebInspector.RemoteObject.fromPayload(scope.object);
 
528
            pendingRequests++;
 
529
            object.getAllProperties(propertiesCollected);
 
530
        }
 
531
    },
 
532
 
 
533
    /**
 
534
     * @param {boolean} active
 
535
     */
 
536
    setBreakpointsActive: function(active)
 
537
    {
 
538
        if (this._breakpointsActive === active)
 
539
            return;
 
540
        this._breakpointsActive = active;
 
541
        DebuggerAgent.setBreakpointsActive(active);
 
542
        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.BreakpointsActiveStateChanged, active);
 
543
    },
 
544
 
 
545
    /**
 
546
     * @return {boolean}
 
547
     */
 
548
    breakpointsActive: function()
 
549
    {
 
550
        return this._breakpointsActive;
 
551
    },
 
552
 
 
553
    /**
 
554
     * @param {WebInspector.DebuggerModel.Location} rawLocation
 
555
     * @param {function(WebInspector.UILocation):(boolean|undefined)} updateDelegate
 
556
     * @return {WebInspector.Script.Location}
 
557
     */
 
558
    createLiveLocation: function(rawLocation, updateDelegate)
 
559
    {
 
560
        var script = this._scripts[rawLocation.scriptId];
 
561
        return script.createLiveLocation(rawLocation, updateDelegate);
 
562
    },
 
563
 
 
564
    /**
 
565
     * @param {WebInspector.DebuggerModel.Location} rawLocation
 
566
     * @return {?WebInspector.UILocation}
 
567
     */
 
568
    rawLocationToUILocation: function(rawLocation)
 
569
    {
 
570
        var script = this._scripts[rawLocation.scriptId];
 
571
        if (!script)
 
572
            return null;
 
573
        return script.rawLocationToUILocation(rawLocation.lineNumber, rawLocation.columnNumber);
 
574
    },
 
575
 
 
576
    /**
 
577
     * Handles notification from JavaScript VM about updated stack (liveedit or frame restart action).
 
578
     * @this {WebInspector.DebuggerModel}
 
579
     * @param {Array.<DebuggerAgent.CallFrame>=} newCallFrames
 
580
     * @param {Object=} details
 
581
     */
 
582
    callStackModified: function(newCallFrames, details)
 
583
    {
 
584
        // FIXME: declare this property in protocol and in JavaScript.
 
585
        if (details && details["stack_update_needs_step_in"])
 
586
            DebuggerAgent.stepInto();
 
587
        else {
 
588
            if (newCallFrames && newCallFrames.length)
 
589
                this._pausedScript(newCallFrames, this._debuggerPausedDetails.reason, this._debuggerPausedDetails.auxData);
 
590
 
 
591
        }
 
592
    },
 
593
 
 
594
    __proto__: WebInspector.Object.prototype
 
595
}
 
596
 
 
597
WebInspector.DebuggerEventTypes = {
 
598
    JavaScriptPause: 0,
 
599
    JavaScriptBreakpoint: 1,
 
600
    NativeBreakpoint: 2
 
601
};
 
602
 
 
603
/**
 
604
 * @constructor
 
605
 * @implements {DebuggerAgent.Dispatcher}
 
606
 * @param {WebInspector.DebuggerModel} debuggerModel
 
607
 */
 
608
WebInspector.DebuggerDispatcher = function(debuggerModel)
 
609
{
 
610
    this._debuggerModel = debuggerModel;
 
611
}
 
612
 
 
613
WebInspector.DebuggerDispatcher.prototype = {
 
614
    /**
 
615
     * @param {Array.<DebuggerAgent.CallFrame>} callFrames
 
616
     * @param {string} reason
 
617
     * @param {Object=} auxData
 
618
     */
 
619
    paused: function(callFrames, reason, auxData)
 
620
    {
 
621
        this._debuggerModel._pausedScript(callFrames, reason, auxData);
 
622
    },
 
623
 
 
624
    resumed: function()
 
625
    {
 
626
        this._debuggerModel._resumedScript();
 
627
    },
 
628
 
 
629
    globalObjectCleared: function()
 
630
    {
 
631
        this._debuggerModel._globalObjectCleared();
 
632
    },
 
633
 
 
634
    /**
 
635
     * @param {DebuggerAgent.ScriptId} scriptId
 
636
     * @param {string} sourceURL
 
637
     * @param {number} startLine
 
638
     * @param {number} startColumn
 
639
     * @param {number} endLine
 
640
     * @param {number} endColumn
 
641
     * @param {boolean=} isContentScript
 
642
     * @param {string=} sourceMapURL
 
643
     * @param {boolean=} hasSourceURL
 
644
     */
 
645
    scriptParsed: function(scriptId, sourceURL, startLine, startColumn, endLine, endColumn, isContentScript, sourceMapURL, hasSourceURL)
 
646
    {
 
647
        this._debuggerModel._parsedScriptSource(scriptId, sourceURL, startLine, startColumn, endLine, endColumn, !!isContentScript, sourceMapURL, hasSourceURL);
 
648
    },
 
649
 
 
650
    /**
 
651
     * @param {string} sourceURL
 
652
     * @param {string} source
 
653
     * @param {number} startingLine
 
654
     * @param {number} errorLine
 
655
     * @param {string} errorMessage
 
656
     */
 
657
    scriptFailedToParse: function(sourceURL, source, startingLine, errorLine, errorMessage)
 
658
    {
 
659
    },
 
660
 
 
661
    /**
 
662
    * @param {DebuggerAgent.BreakpointId} breakpointId
 
663
    * @param {DebuggerAgent.Location} location
 
664
     */
 
665
    breakpointResolved: function(breakpointId, location)
 
666
    {
 
667
        this._debuggerModel._breakpointResolved(breakpointId, location);
 
668
    }
 
669
}
 
670
 
 
671
/**
 
672
 * @constructor
 
673
 * @param {WebInspector.Script} script
 
674
 * @param {DebuggerAgent.CallFrame} payload
 
675
 */
 
676
WebInspector.DebuggerModel.CallFrame = function(script, payload)
 
677
{
 
678
    this._script = script;
 
679
    this._payload = payload;
 
680
    this._locations = [];
 
681
}
 
682
 
 
683
WebInspector.DebuggerModel.CallFrame.prototype = {
 
684
    /**
 
685
     * @return {WebInspector.Script}
 
686
     */
 
687
    get script()
 
688
    {
 
689
        return this._script;
 
690
    },
 
691
 
 
692
    /**
 
693
     * @return {string}
 
694
     */
 
695
    get type()
 
696
    {
 
697
        return this._payload.type;
 
698
    },
 
699
 
 
700
    /**
 
701
     * @return {Array.<DebuggerAgent.Scope>}
 
702
     */
 
703
    get scopeChain()
 
704
    {
 
705
        return this._payload.scopeChain;
 
706
    },
 
707
 
 
708
    /**
 
709
     * @return {RuntimeAgent.RemoteObject}
 
710
     */
 
711
    get this()
 
712
    {
 
713
        return this._payload.this;
 
714
    },
 
715
 
 
716
    /**
 
717
     * @return {string}
 
718
     */
 
719
    get functionName()
 
720
    {
 
721
        return this._payload.functionName;
 
722
    },
 
723
 
 
724
    /**
 
725
     * @return {WebInspector.DebuggerModel.Location}
 
726
     */
 
727
    get location()
 
728
    {
 
729
        var rawLocation = /** @type {WebInspector.DebuggerModel.Location} */ (this._payload.location);
 
730
        return rawLocation;
 
731
    },
 
732
 
 
733
    /**
 
734
     * @param {string} code
 
735
     * @param {string} objectGroup
 
736
     * @param {boolean} includeCommandLineAPI
 
737
     * @param {boolean} doNotPauseOnExceptionsAndMuteConsole
 
738
     * @param {boolean} returnByValue
 
739
     * @param {boolean} generatePreview
 
740
     * @param {function(?RuntimeAgent.RemoteObject, boolean=)=} callback
 
741
     */
 
742
    evaluate: function(code, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, callback)
 
743
    {
 
744
        /**
 
745
         * @this {WebInspector.DebuggerModel.CallFrame}
 
746
         * @param {?Protocol.Error} error
 
747
         * @param {RuntimeAgent.RemoteObject} result
 
748
         * @param {boolean=} wasThrown
 
749
         */
 
750
        function didEvaluateOnCallFrame(error, result, wasThrown)
 
751
        {
 
752
            if (error) {
 
753
                console.error(error);
 
754
                callback(null, false);
 
755
                return;
 
756
            }
 
757
            callback(result, wasThrown);
 
758
        }
 
759
        DebuggerAgent.evaluateOnCallFrame(this._payload.callFrameId, code, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, didEvaluateOnCallFrame.bind(this));
 
760
    },
 
761
 
 
762
    /**
 
763
     * @param {function(?Protocol.Error=)=} callback
 
764
     */
 
765
    restart: function(callback)
 
766
    {
 
767
        /**
 
768
         * @this {WebInspector.DebuggerModel.CallFrame}
 
769
         * @param {?Protocol.Error} error
 
770
         * @param {Array.<DebuggerAgent.CallFrame>=} callFrames
 
771
         * @param {Object=} details
 
772
         */
 
773
        function protocolCallback(error, callFrames, details)
 
774
        {
 
775
            if (!error)
 
776
                WebInspector.debuggerModel.callStackModified(callFrames, details);
 
777
            if (callback)
 
778
                callback(error);
 
779
        }
 
780
        DebuggerAgent.restartFrame(this._payload.callFrameId, protocolCallback);
 
781
    },
 
782
 
 
783
    /**
 
784
     * @param {function(WebInspector.UILocation):(boolean|undefined)} updateDelegate
 
785
     */
 
786
    createLiveLocation: function(updateDelegate)
 
787
    {
 
788
        var location = this._script.createLiveLocation(this.location, updateDelegate);
 
789
        this._locations.push(location);
 
790
        return location;
 
791
    },
 
792
 
 
793
    dispose: function(updateDelegate)
 
794
    {
 
795
        for (var i = 0; i < this._locations.length; ++i)
 
796
            this._locations[i].dispose();
 
797
        this._locations = [];
 
798
    }
 
799
}
 
800
 
 
801
/**
 
802
 * @constructor
 
803
 * @param {WebInspector.DebuggerModel} model
 
804
 * @param {Array.<DebuggerAgent.CallFrame>} callFrames
 
805
 * @param {string} reason
 
806
 * @param {*} auxData
 
807
 */
 
808
WebInspector.DebuggerPausedDetails = function(model, callFrames, reason, auxData)
 
809
{
 
810
    this.callFrames = [];
 
811
    for (var i = 0; i < callFrames.length; ++i) {
 
812
        var callFrame = callFrames[i];
 
813
        var script = model.scriptForId(callFrame.location.scriptId);
 
814
        if (script)
 
815
            this.callFrames.push(new WebInspector.DebuggerModel.CallFrame(script, callFrame));
 
816
    }
 
817
    this.reason = reason;
 
818
    this.auxData = auxData;
 
819
}
 
820
 
 
821
WebInspector.DebuggerPausedDetails.prototype = {
 
822
    dispose: function()
 
823
    {
 
824
        for (var i = 0; i < this.callFrames.length; ++i) {
 
825
            var callFrame = this.callFrames[i];
 
826
            callFrame.dispose();
 
827
        }
 
828
    }
 
829
}
 
830
 
 
831
/**
 
832
 * @type {?WebInspector.DebuggerModel}
 
833
 */
 
834
WebInspector.debuggerModel = null;