Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 this._agent = target.debuggerAgent(); | 42 this._agent = target.debuggerAgent(); |
| 43 this._runtimeModel = /** @type {!SDK.RuntimeModel} */ (target.model(SDK.Runt imeModel)); | 43 this._runtimeModel = /** @type {!SDK.RuntimeModel} */ (target.model(SDK.Runt imeModel)); |
| 44 | 44 |
| 45 /** @type {!SDK.SourceMapManager<!SDK.Script>} */ | 45 /** @type {!SDK.SourceMapManager<!SDK.Script>} */ |
| 46 this._sourceMapManager = new SDK.SourceMapManager(target); | 46 this._sourceMapManager = new SDK.SourceMapManager(target); |
| 47 /** @type {!Map<string, !SDK.Script>} */ | 47 /** @type {!Map<string, !SDK.Script>} */ |
| 48 this._sourceMapIdToScript = new Map(); | 48 this._sourceMapIdToScript = new Map(); |
| 49 | 49 |
| 50 /** @type {?SDK.DebuggerPausedDetails} */ | 50 /** @type {?SDK.DebuggerPausedDetails} */ |
| 51 this._debuggerPausedDetails = null; | 51 this._debuggerPausedDetails = null; |
| 52 /** @type {!Object.<string, !SDK.Script>} */ | 52 /** @type {!Map<string, !SDK.Script>} */ |
| 53 this._scripts = {}; | 53 this._scripts = new Map(); |
|
dgozman
2017/04/05 18:22:55
Is it as performant? We have a lot of scripts!
lushnikov
2017/04/06 03:32:35
According to
https://docs.google.com/spreadsheets
| |
| 54 /** @type {!Map.<string, !Array.<!SDK.Script>>} */ | 54 /** @type {!Map.<string, !Array.<!SDK.Script>>} */ |
| 55 this._scriptsBySourceURL = new Map(); | 55 this._scriptsBySourceURL = new Map(); |
| 56 /** @type {!Array.<!SDK.Script>} */ | 56 /** @type {!Array.<!SDK.Script>} */ |
| 57 this._discardableScripts = []; | 57 this._discardableScripts = []; |
| 58 | 58 |
| 59 /** @type {!Common.Object} */ | 59 /** @type {!Common.Object} */ |
| 60 this._breakpointResolvedEventTarget = new Common.Object(); | 60 this._breakpointResolvedEventTarget = new Common.Object(); |
| 61 | 61 |
| 62 this._isPausing = false; | 62 this._isPausing = false; |
| 63 Common.moduleSetting('pauseOnExceptionEnabled').addChangeListener(this._paus eOnExceptionStateChanged, this); | 63 Common.moduleSetting('pauseOnExceptionEnabled').addChangeListener(this._paus eOnExceptionStateChanged, this); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 this._reset(); | 338 this._reset(); |
| 339 // TODO(dgozman): move clients to ExecutionContextDestroyed/ScriptCollected events. | 339 // TODO(dgozman): move clients to ExecutionContextDestroyed/ScriptCollected events. |
| 340 this.dispatchEventToListeners(SDK.DebuggerModel.Events.GlobalObjectCleared, this); | 340 this.dispatchEventToListeners(SDK.DebuggerModel.Events.GlobalObjectCleared, this); |
| 341 } | 341 } |
| 342 | 342 |
| 343 _reset() { | 343 _reset() { |
| 344 for (var scriptWithSourceMap of this._sourceMapIdToScript.values()) | 344 for (var scriptWithSourceMap of this._sourceMapIdToScript.values()) |
| 345 this._sourceMapManager.detachSourceMap(scriptWithSourceMap); | 345 this._sourceMapManager.detachSourceMap(scriptWithSourceMap); |
| 346 this._sourceMapIdToScript.clear(); | 346 this._sourceMapIdToScript.clear(); |
| 347 | 347 |
| 348 this._scripts = {}; | 348 this._scripts.clear(); |
| 349 this._scriptsBySourceURL.clear(); | 349 this._scriptsBySourceURL.clear(); |
| 350 this._stringMap.clear(); | 350 this._stringMap.clear(); |
| 351 this._discardableScripts = []; | 351 this._discardableScripts = []; |
| 352 } | 352 } |
| 353 | 353 |
| 354 /** | 354 /** |
| 355 * @return {!Object.<string, !SDK.Script>} | 355 * @return {!Array<!SDK.Script>} |
| 356 */ | 356 */ |
| 357 get scripts() { | 357 scripts() { |
| 358 return this._scripts; | 358 return Array.from(this._scripts.values()); |
|
dgozman
2017/04/05 18:22:55
Is this method performance-critical? Does it make
lushnikov
2017/04/06 03:32:35
No, it's used by blackbox model only
| |
| 359 } | 359 } |
| 360 | 360 |
| 361 /** | 361 /** |
| 362 * @param {!Protocol.Runtime.ScriptId} scriptId | 362 * @param {!Protocol.Runtime.ScriptId} scriptId |
| 363 * @return {?SDK.Script} | 363 * @return {?SDK.Script} |
| 364 */ | 364 */ |
| 365 scriptForId(scriptId) { | 365 scriptForId(scriptId) { |
| 366 return this._scripts[scriptId] || null; | 366 return this._scripts.get(scriptId) || null; |
| 367 } | 367 } |
| 368 | 368 |
| 369 /** | 369 /** |
| 370 * @return {!Array.<!SDK.Script>} | 370 * @return {!Array.<!SDK.Script>} |
| 371 */ | 371 */ |
| 372 scriptsForSourceURL(sourceURL) { | 372 scriptsForSourceURL(sourceURL) { |
| 373 if (!sourceURL) | 373 if (!sourceURL) |
| 374 return []; | 374 return []; |
| 375 return this._scriptsBySourceURL.get(sourceURL) || []; | 375 return this._scriptsBySourceURL.get(sourceURL) || []; |
| 376 } | 376 } |
| 377 | 377 |
| 378 /** | 378 /** |
| 379 * @param {!Protocol.Runtime.ScriptId} scriptId | 379 * @param {!Protocol.Runtime.ScriptId} scriptId |
| 380 * @param {string} newSource | 380 * @param {string} newSource |
| 381 * @param {function(?Protocol.Error, !Protocol.Runtime.ExceptionDetails=)} cal lback | 381 * @param {function(?Protocol.Error, !Protocol.Runtime.ExceptionDetails=)} cal lback |
| 382 */ | 382 */ |
| 383 setScriptSource(scriptId, newSource, callback) { | 383 setScriptSource(scriptId, newSource, callback) { |
| 384 this._scripts[scriptId].editSource(newSource, this._didEditScriptSource.bind (this, scriptId, newSource, callback)); | 384 this._scripts.get(scriptId).editSource( |
| 385 newSource, this._didEditScriptSource.bind(this, scriptId, newSource, cal lback)); | |
| 385 } | 386 } |
| 386 | 387 |
| 387 /** | 388 /** |
| 388 * @param {!Protocol.Runtime.ScriptId} scriptId | 389 * @param {!Protocol.Runtime.ScriptId} scriptId |
| 389 * @param {string} newSource | 390 * @param {string} newSource |
| 390 * @param {function(?Protocol.Error, !Protocol.Runtime.ExceptionDetails=)} cal lback | 391 * @param {function(?Protocol.Error, !Protocol.Runtime.ExceptionDetails=)} cal lback |
| 391 * @param {?Protocol.Error} error | 392 * @param {?Protocol.Error} error |
| 392 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails | 393 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails |
| 393 * @param {!Array.<!Protocol.Debugger.CallFrame>=} callFrames | 394 * @param {!Array.<!Protocol.Debugger.CallFrame>=} callFrames |
| 394 * @param {!Protocol.Runtime.StackTrace=} asyncStackTrace | 395 * @param {!Protocol.Runtime.StackTrace=} asyncStackTrace |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 */ | 561 */ |
| 561 executionContextDestroyed(executionContext) { | 562 executionContextDestroyed(executionContext) { |
| 562 var sourceMapIds = Array.from(this._sourceMapIdToScript.keys()); | 563 var sourceMapIds = Array.from(this._sourceMapIdToScript.keys()); |
| 563 for (var sourceMapId of sourceMapIds) { | 564 for (var sourceMapId of sourceMapIds) { |
| 564 var script = this._sourceMapIdToScript.get(sourceMapId); | 565 var script = this._sourceMapIdToScript.get(sourceMapId); |
| 565 if (script.executionContextId === executionContext.id) { | 566 if (script.executionContextId === executionContext.id) { |
| 566 this._sourceMapIdToScript.delete(sourceMapId); | 567 this._sourceMapIdToScript.delete(sourceMapId); |
| 567 this._sourceMapManager.detachSourceMap(script); | 568 this._sourceMapManager.detachSourceMap(script); |
| 568 } | 569 } |
| 569 } | 570 } |
| 571 var affectedScripts = []; | |
| 572 for (var script of this._scripts.values()) { | |
| 573 if (script.executionContextId === executionContext.id) | |
| 574 affectedScripts.push(script); | |
| 575 } | |
| 576 this.dispatchEventToListeners(SDK.DebuggerModel.Events.ExecutionContextDestr oyed, affectedScripts); | |
| 570 } | 577 } |
| 571 | 578 |
| 572 /** | 579 /** |
| 573 * @param {!SDK.Script} script | 580 * @param {!SDK.Script} script |
| 574 */ | 581 */ |
| 575 _registerScript(script) { | 582 _registerScript(script) { |
| 576 this._scripts[script.scriptId] = script; | 583 this._scripts.set(script.scriptId, script); |
| 577 if (script.isAnonymousScript()) | 584 if (script.isAnonymousScript()) |
| 578 return; | 585 return; |
| 579 | 586 |
| 580 var scripts = this._scriptsBySourceURL.get(script.sourceURL); | 587 var scripts = this._scriptsBySourceURL.get(script.sourceURL); |
| 581 if (!scripts) { | 588 if (!scripts) { |
| 582 scripts = []; | 589 scripts = []; |
| 583 this._scriptsBySourceURL.set(script.sourceURL, scripts); | 590 this._scriptsBySourceURL.set(script.sourceURL, scripts); |
| 584 } | 591 } |
| 585 scripts.push(script); | 592 scripts.push(script); |
| 586 } | 593 } |
| 587 | 594 |
| 588 /** | 595 /** |
| 589 * @param {!SDK.Script} script | 596 * @param {!SDK.Script} script |
| 590 */ | 597 */ |
| 591 _unregisterScript(script) { | 598 _unregisterScript(script) { |
| 592 console.assert(script.isAnonymousScript()); | 599 console.assert(script.isAnonymousScript()); |
| 593 delete this._scripts[script.scriptId]; | 600 this._scripts.delete(script.scriptId); |
| 594 } | 601 } |
| 595 | 602 |
| 596 _collectDiscardedScripts() { | 603 _collectDiscardedScripts() { |
| 597 if (this._discardableScripts.length < 1000) | 604 if (this._discardableScripts.length < 1000) |
| 598 return; | 605 return; |
| 599 var scriptsToDiscard = this._discardableScripts.splice(0, 100); | 606 var scriptsToDiscard = this._discardableScripts.splice(0, 100); |
| 600 for (var script of scriptsToDiscard) { | 607 for (var script of scriptsToDiscard) { |
| 601 this._unregisterScript(script); | 608 this._unregisterScript(script); |
| 602 this.dispatchEventToListeners(SDK.DebuggerModel.Events.DiscardedAnonymousS criptSource, script); | 609 this.dispatchEventToListeners(SDK.DebuggerModel.Events.DiscardedAnonymousS criptSource, script); |
| 603 } | 610 } |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 911 PauseOnAllExceptions: 'all', | 918 PauseOnAllExceptions: 'all', |
| 912 PauseOnUncaughtExceptions: 'uncaught' | 919 PauseOnUncaughtExceptions: 'uncaught' |
| 913 }; | 920 }; |
| 914 | 921 |
| 915 /** @enum {symbol} */ | 922 /** @enum {symbol} */ |
| 916 SDK.DebuggerModel.Events = { | 923 SDK.DebuggerModel.Events = { |
| 917 DebuggerWasEnabled: Symbol('DebuggerWasEnabled'), | 924 DebuggerWasEnabled: Symbol('DebuggerWasEnabled'), |
| 918 DebuggerWasDisabled: Symbol('DebuggerWasDisabled'), | 925 DebuggerWasDisabled: Symbol('DebuggerWasDisabled'), |
| 919 DebuggerPaused: Symbol('DebuggerPaused'), | 926 DebuggerPaused: Symbol('DebuggerPaused'), |
| 920 DebuggerResumed: Symbol('DebuggerResumed'), | 927 DebuggerResumed: Symbol('DebuggerResumed'), |
| 928 ExecutionContextDestroyed: Symbol('ExecutionContextDestroyed'), | |
|
dgozman
2017/04/05 18:22:55
DiscardedScriptSources, and merge with DiscardedAn
lushnikov
2017/04/06 03:32:35
As discussed offline, i'm started to listen to Run
| |
| 921 ParsedScriptSource: Symbol('ParsedScriptSource'), | 929 ParsedScriptSource: Symbol('ParsedScriptSource'), |
| 922 FailedToParseScriptSource: Symbol('FailedToParseScriptSource'), | 930 FailedToParseScriptSource: Symbol('FailedToParseScriptSource'), |
| 923 DiscardedAnonymousScriptSource: Symbol('DiscardedAnonymousScriptSource'), | 931 DiscardedAnonymousScriptSource: Symbol('DiscardedAnonymousScriptSource'), |
| 924 GlobalObjectCleared: Symbol('GlobalObjectCleared'), | 932 GlobalObjectCleared: Symbol('GlobalObjectCleared'), |
| 925 CallFrameSelected: Symbol('CallFrameSelected'), | 933 CallFrameSelected: Symbol('CallFrameSelected'), |
| 926 ConsoleCommandEvaluatedInSelectedCallFrame: Symbol('ConsoleCommandEvaluatedInS electedCallFrame') | 934 ConsoleCommandEvaluatedInSelectedCallFrame: Symbol('ConsoleCommandEvaluatedInS electedCallFrame') |
| 927 }; | 935 }; |
| 928 | 936 |
| 929 /** @enum {string} */ | 937 /** @enum {string} */ |
| 930 SDK.DebuggerModel.BreakReason = { | 938 SDK.DebuggerModel.BreakReason = { |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1466 stack.callFrames.shift(); | 1474 stack.callFrames.shift(); |
| 1467 if (previous && (!stack.callFrames.length && !stack.promiseCreationFrame)) | 1475 if (previous && (!stack.callFrames.length && !stack.promiseCreationFrame)) |
| 1468 previous.parent = stack.parent; | 1476 previous.parent = stack.parent; |
| 1469 else | 1477 else |
| 1470 previous = stack; | 1478 previous = stack; |
| 1471 stack = stack.parent; | 1479 stack = stack.parent; |
| 1472 } | 1480 } |
| 1473 return asyncStackTrace; | 1481 return asyncStackTrace; |
| 1474 } | 1482 } |
| 1475 }; | 1483 }; |
| OLD | NEW |