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 23 matching lines...) Expand all Loading... |
34 SDK.DebuggerModel = class extends SDK.SDKModel { | 34 SDK.DebuggerModel = class extends SDK.SDKModel { |
35 /** | 35 /** |
36 * @param {!SDK.Target} target | 36 * @param {!SDK.Target} target |
37 */ | 37 */ |
38 constructor(target) { | 38 constructor(target) { |
39 super(target); | 39 super(target); |
40 | 40 |
41 target.registerDebuggerDispatcher(new SDK.DebuggerDispatcher(this)); | 41 target.registerDebuggerDispatcher(new SDK.DebuggerDispatcher(this)); |
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 this._runtimeModel.addEventListener(SDK.RuntimeModel.Events.ExecutionContext
Destroyed, this._executionContextDestroyed, this); |
| 45 |
| 46 /** @type {!SDK.SourceMapManager<!SDK.Script>} */ |
| 47 this._sourceMapManager = new SDK.SourceMapManager(target); |
| 48 /** @type {!Map<string, !SDK.Script>} */ |
| 49 this._sourceMapIdToScript = new Map(); |
44 | 50 |
45 /** @type {?SDK.DebuggerPausedDetails} */ | 51 /** @type {?SDK.DebuggerPausedDetails} */ |
46 this._debuggerPausedDetails = null; | 52 this._debuggerPausedDetails = null; |
47 /** @type {!Object.<string, !SDK.Script>} */ | 53 /** @type {!Object.<string, !SDK.Script>} */ |
48 this._scripts = {}; | 54 this._scripts = {}; |
49 /** @type {!Map.<string, !Array.<!SDK.Script>>} */ | 55 /** @type {!Map.<string, !Array.<!SDK.Script>>} */ |
50 this._scriptsBySourceURL = new Map(); | 56 this._scriptsBySourceURL = new Map(); |
51 /** @type {!Array.<!SDK.Script>} */ | 57 /** @type {!Array.<!SDK.Script>} */ |
52 this._discardableScripts = []; | 58 this._discardableScripts = []; |
53 | 59 |
54 /** @type {!Common.Object} */ | 60 /** @type {!Common.Object} */ |
55 this._breakpointResolvedEventTarget = new Common.Object(); | 61 this._breakpointResolvedEventTarget = new Common.Object(); |
56 | 62 |
57 this._isPausing = false; | 63 this._isPausing = false; |
58 Common.moduleSetting('pauseOnExceptionEnabled').addChangeListener(this._paus
eOnExceptionStateChanged, this); | 64 Common.moduleSetting('pauseOnExceptionEnabled').addChangeListener(this._paus
eOnExceptionStateChanged, this); |
59 Common.moduleSetting('pauseOnCaughtException').addChangeListener(this._pause
OnExceptionStateChanged, this); | 65 Common.moduleSetting('pauseOnCaughtException').addChangeListener(this._pause
OnExceptionStateChanged, this); |
60 Common.moduleSetting('enableAsyncStackTraces').addChangeListener(this.asyncS
tackTracesStateChanged, this); | 66 Common.moduleSetting('enableAsyncStackTraces').addChangeListener(this.asyncS
tackTracesStateChanged, this); |
61 | 67 |
62 /** @type {!Map<string, string>} */ | 68 /** @type {!Map<string, string>} */ |
63 this._fileURLToNodeJSPath = new Map(); | 69 this._fileURLToNodeJSPath = new Map(); |
64 this.enableDebugger(); | 70 this.enableDebugger(); |
65 | 71 |
66 /** @type {!Map<string, string>} */ | 72 /** @type {!Map<string, string>} */ |
67 this._stringMap = new Map(); | 73 this._stringMap = new Map(); |
| 74 this._sourceMapManager.setEnabled(Common.moduleSetting('jsSourceMapsEnabled'
).get()); |
| 75 Common.moduleSetting('jsSourceMapsEnabled') |
| 76 .addChangeListener(event => this._sourceMapManager.setEnabled(/** @type
{boolean} */ (event.data))); |
68 } | 77 } |
69 | 78 |
70 /** | 79 /** |
| 80 * @param {string} executionContextId |
| 81 * @param {string} sourceURL |
| 82 * @param {?string} sourceMapURL |
| 83 * @return {?string} |
| 84 */ |
| 85 static _sourceMapId(executionContextId, sourceURL, sourceMapURL) { |
| 86 if (!sourceMapURL) |
| 87 return null; |
| 88 return executionContextId + ':' + sourceURL + ':' + sourceMapURL; |
| 89 } |
| 90 |
| 91 /** |
| 92 * @return {!SDK.SourceMapManager<!SDK.Script>} |
| 93 */ |
| 94 sourceMapManager() { |
| 95 return this._sourceMapManager; |
| 96 } |
| 97 |
| 98 /** |
71 * @return {!SDK.RuntimeModel} | 99 * @return {!SDK.RuntimeModel} |
72 */ | 100 */ |
73 runtimeModel() { | 101 runtimeModel() { |
74 return this._runtimeModel; | 102 return this._runtimeModel; |
75 } | 103 } |
76 | 104 |
77 /** | 105 /** |
78 * @return {boolean} | 106 * @return {boolean} |
79 */ | 107 */ |
80 debuggerEnabled() { | 108 debuggerEnabled() { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 this._reset(); | 339 this._reset(); |
312 // TODO(dgozman): move clients to ExecutionContextDestroyed/ScriptCollected
events. | 340 // TODO(dgozman): move clients to ExecutionContextDestroyed/ScriptCollected
events. |
313 this.dispatchEventToListeners(SDK.DebuggerModel.Events.GlobalObjectCleared,
this); | 341 this.dispatchEventToListeners(SDK.DebuggerModel.Events.GlobalObjectCleared,
this); |
314 } | 342 } |
315 | 343 |
316 _reset() { | 344 _reset() { |
317 this._scripts = {}; | 345 this._scripts = {}; |
318 this._scriptsBySourceURL.clear(); | 346 this._scriptsBySourceURL.clear(); |
319 this._stringMap.clear(); | 347 this._stringMap.clear(); |
320 this._discardableScripts = []; | 348 this._discardableScripts = []; |
| 349 |
| 350 for (var scriptWithSourceMap of this._sourceMapIdToScript.values()) |
| 351 this._sourceMapManager.detachSourceMap(scriptWithSourceMap); |
| 352 this._sourceMapIdToScript.clear(); |
321 } | 353 } |
322 | 354 |
323 /** | 355 /** |
324 * @return {!Object.<string, !SDK.Script>} | 356 * @return {!Object.<string, !SDK.Script>} |
325 */ | 357 */ |
326 get scripts() { | 358 get scripts() { |
327 return this._scripts; | 359 return this._scripts; |
328 } | 360 } |
329 | 361 |
330 /** | 362 /** |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 sourceURL = this._internString(sourceURL); | 511 sourceURL = this._internString(sourceURL); |
480 } | 512 } |
481 var script = new SDK.Script( | 513 var script = new SDK.Script( |
482 this, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, e
xecutionContextId, | 514 this, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, e
xecutionContextId, |
483 this._internString(hash), isContentScript, isLiveEdit, sourceMapURL, has
SourceURL, length); | 515 this._internString(hash), isContentScript, isLiveEdit, sourceMapURL, has
SourceURL, length); |
484 this._registerScript(script); | 516 this._registerScript(script); |
485 if (!hasSyntaxError) | 517 if (!hasSyntaxError) |
486 this.dispatchEventToListeners(SDK.DebuggerModel.Events.ParsedScriptSource,
script); | 518 this.dispatchEventToListeners(SDK.DebuggerModel.Events.ParsedScriptSource,
script); |
487 else | 519 else |
488 this.dispatchEventToListeners(SDK.DebuggerModel.Events.FailedToParseScript
Source, script); | 520 this.dispatchEventToListeners(SDK.DebuggerModel.Events.FailedToParseScript
Source, script); |
| 521 |
| 522 var sourceMapId = SDK.DebuggerModel._sourceMapId(script.executionContextId,
script.sourceURL, script.sourceMapURL); |
| 523 if (sourceMapId && !hasSyntaxError) { |
| 524 var previousSourceMapClient = this._sourceMapIdToScript.get(sourceMapId); |
| 525 if (previousSourceMapClient) |
| 526 this._sourceMapManager.detachSourceMap(previousSourceMapClient); |
| 527 this._sourceMapIdToScript.set(sourceMapId, script); |
| 528 this._sourceMapManager.attachSourceMap(script, script.sourceURL, script.so
urceMapURL); |
| 529 } |
| 530 |
489 var isDiscardable = hasSyntaxError && script.isAnonymousScript(); | 531 var isDiscardable = hasSyntaxError && script.isAnonymousScript(); |
490 if (isDiscardable) { | 532 if (isDiscardable) { |
491 this._discardableScripts.push(script); | 533 this._discardableScripts.push(script); |
492 this._collectDiscardedScripts(); | 534 this._collectDiscardedScripts(); |
493 } | 535 } |
494 return script; | 536 return script; |
495 } | 537 } |
496 | 538 |
497 /** | 539 /** |
498 * @param {!SDK.Script} script | 540 * @param {!SDK.Script} script |
| 541 * @param {string} newSourceMapURL |
| 542 */ |
| 543 setSourceMapURL(script, newSourceMapURL) { |
| 544 var sourceMapId = SDK.DebuggerModel._sourceMapId(script.executionContextId,
script.sourceURL, script.sourceMapURL); |
| 545 if (sourceMapId && this._sourceMapIdToScript.get(sourceMapId) === script) |
| 546 this._sourceMapIdToScript.delete(sourceMapId); |
| 547 this._sourceMapManager.detachSourceMap(script); |
| 548 |
| 549 script.sourceMapURL = newSourceMapURL; |
| 550 sourceMapId = SDK.DebuggerModel._sourceMapId(script.executionContextId, scri
pt.sourceURL, script.sourceMapURL); |
| 551 this._sourceMapIdToScript.set(sourceMapId, script); |
| 552 this._sourceMapManager.attachSourceMap(script, script.sourceURL, script.sour
ceMapURL); |
| 553 } |
| 554 |
| 555 /** |
| 556 * @param {!Common.Event} event |
| 557 */ |
| 558 _executionContextDestroyed(event) { |
| 559 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); |
| 560 for (var script of this._sourceMapIdToScript.values()) { |
| 561 if (script.executionContextId === executionContext.id) |
| 562 this._sourceMapManager.detachSourceMap(script); |
| 563 } |
| 564 } |
| 565 |
| 566 /** |
| 567 * @param {!SDK.Script} script |
499 */ | 568 */ |
500 _registerScript(script) { | 569 _registerScript(script) { |
501 this._scripts[script.scriptId] = script; | 570 this._scripts[script.scriptId] = script; |
502 if (script.isAnonymousScript()) | 571 if (script.isAnonymousScript()) |
503 return; | 572 return; |
504 | 573 |
505 var scripts = this._scriptsBySourceURL.get(script.sourceURL); | 574 var scripts = this._scriptsBySourceURL.get(script.sourceURL); |
506 if (!scripts) { | 575 if (!scripts) { |
507 scripts = []; | 576 scripts = []; |
508 this._scriptsBySourceURL.set(script.sourceURL, scripts); | 577 this._scriptsBySourceURL.set(script.sourceURL, scripts); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 if (error) | 834 if (error) |
766 console.error(error); | 835 console.error(error); |
767 callback(!error); | 836 callback(!error); |
768 } | 837 } |
769 } | 838 } |
770 | 839 |
771 /** | 840 /** |
772 * @override | 841 * @override |
773 */ | 842 */ |
774 dispose() { | 843 dispose() { |
| 844 this._runtimeModel.removeEventListener(SDK.RuntimeModel.Events.ExecutionCont
extDestroyed, this._executionContextDestroyed, this); |
775 Common.moduleSetting('pauseOnExceptionEnabled').removeChangeListener(this._p
auseOnExceptionStateChanged, this); | 845 Common.moduleSetting('pauseOnExceptionEnabled').removeChangeListener(this._p
auseOnExceptionStateChanged, this); |
776 Common.moduleSetting('pauseOnCaughtException').removeChangeListener(this._pa
useOnExceptionStateChanged, this); | 846 Common.moduleSetting('pauseOnCaughtException').removeChangeListener(this._pa
useOnExceptionStateChanged, this); |
777 Common.moduleSetting('enableAsyncStackTraces').removeChangeListener(this.asy
ncStackTracesStateChanged, this); | 847 Common.moduleSetting('enableAsyncStackTraces').removeChangeListener(this.asy
ncStackTracesStateChanged, this); |
778 } | 848 } |
779 | 849 |
780 /** | 850 /** |
781 * @override | 851 * @override |
782 * @return {!Promise} | 852 * @return {!Promise} |
783 */ | 853 */ |
784 suspendModel() { | 854 suspendModel() { |
(...skipping 26 matching lines...) Expand all Loading... |
811 | 881 |
812 /** | 882 /** |
813 * @param {string} string | 883 * @param {string} string |
814 * @return {string} string | 884 * @return {string} string |
815 */ | 885 */ |
816 _internString(string) { | 886 _internString(string) { |
817 if (!this._stringMap.has(string)) | 887 if (!this._stringMap.has(string)) |
818 this._stringMap.set(string, string); | 888 this._stringMap.set(string, string); |
819 return this._stringMap.get(string); | 889 return this._stringMap.get(string); |
820 } | 890 } |
| 891 |
| 892 /** |
| 893 * @override |
| 894 */ |
| 895 dispose() { |
| 896 super.dispose(); |
| 897 this._sourceMapManager.dispose(); |
| 898 } |
821 }; | 899 }; |
822 | 900 |
823 SDK.SDKModel.register(SDK.DebuggerModel, SDK.Target.Capability.JS, true); | 901 SDK.SDKModel.register(SDK.DebuggerModel, SDK.Target.Capability.JS, true); |
824 | 902 |
825 /** @typedef {{location: ?SDK.DebuggerModel.Location, functionName: string}} */ | 903 /** @typedef {{location: ?SDK.DebuggerModel.Location, functionName: string}} */ |
826 SDK.DebuggerModel.FunctionDetails; | 904 SDK.DebuggerModel.FunctionDetails; |
827 | 905 |
828 /** | 906 /** |
829 * Keep these in sync with WebCore::V8Debugger | 907 * Keep these in sync with WebCore::V8Debugger |
830 * | 908 * |
831 * @enum {string} | 909 * @enum {string} |
832 */ | 910 */ |
833 SDK.DebuggerModel.PauseOnExceptionsState = { | 911 SDK.DebuggerModel.PauseOnExceptionsState = { |
834 DontPauseOnExceptions: 'none', | 912 DontPauseOnExceptions: 'none', |
835 PauseOnAllExceptions: 'all', | 913 PauseOnAllExceptions: 'all', |
836 PauseOnUncaughtExceptions: 'uncaught' | 914 PauseOnUncaughtExceptions: 'uncaught' |
837 }; | 915 }; |
838 | 916 |
839 /** @enum {symbol} */ | 917 /** @enum {symbol} */ |
840 SDK.DebuggerModel.Events = { | 918 SDK.DebuggerModel.Events = { |
841 DebuggerWasEnabled: Symbol('DebuggerWasEnabled'), | 919 DebuggerWasEnabled: Symbol('DebuggerWasEnabled'), |
842 DebuggerWasDisabled: Symbol('DebuggerWasDisabled'), | 920 DebuggerWasDisabled: Symbol('DebuggerWasDisabled'), |
843 DebuggerPaused: Symbol('DebuggerPaused'), | 921 DebuggerPaused: Symbol('DebuggerPaused'), |
844 DebuggerResumed: Symbol('DebuggerResumed'), | 922 DebuggerResumed: Symbol('DebuggerResumed'), |
845 ParsedScriptSource: Symbol('ParsedScriptSource'), | 923 ParsedScriptSource: Symbol('ParsedScriptSource'), |
846 FailedToParseScriptSource: Symbol('FailedToParseScriptSource'), | 924 FailedToParseScriptSource: Symbol('FailedToParseScriptSource'), |
847 DiscardedAnonymousScriptSource: Symbol('DiscardedAnonymousScriptSource'), | 925 DiscardedAnonymousScriptSource: Symbol('DiscardedAnonymousScriptSource'), |
848 GlobalObjectCleared: Symbol('GlobalObjectCleared'), | 926 GlobalObjectCleared: Symbol('GlobalObjectCleared'), |
849 CallFrameSelected: Symbol('CallFrameSelected'), | 927 CallFrameSelected: Symbol('CallFrameSelected'), |
850 ConsoleCommandEvaluatedInSelectedCallFrame: Symbol('ConsoleCommandEvaluatedInS
electedCallFrame'), | 928 ConsoleCommandEvaluatedInSelectedCallFrame: Symbol('ConsoleCommandEvaluatedInS
electedCallFrame') |
851 SourceMapURLAdded: Symbol('SourceMapURLAdded') | |
852 }; | 929 }; |
853 | 930 |
854 /** @enum {string} */ | 931 /** @enum {string} */ |
855 SDK.DebuggerModel.BreakReason = { | 932 SDK.DebuggerModel.BreakReason = { |
856 DOM: 'DOM', | 933 DOM: 'DOM', |
857 EventListener: 'EventListener', | 934 EventListener: 'EventListener', |
858 XHR: 'XHR', | 935 XHR: 'XHR', |
859 Exception: 'exception', | 936 Exception: 'exception', |
860 PromiseRejection: 'promiseRejection', | 937 PromiseRejection: 'promiseRejection', |
861 Assert: 'assert', | 938 Assert: 'assert', |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 stack.callFrames.shift(); | 1468 stack.callFrames.shift(); |
1392 if (previous && (!stack.callFrames.length && !stack.promiseCreationFrame)) | 1469 if (previous && (!stack.callFrames.length && !stack.promiseCreationFrame)) |
1393 previous.parent = stack.parent; | 1470 previous.parent = stack.parent; |
1394 else | 1471 else |
1395 previous = stack; | 1472 previous = stack; |
1396 stack = stack.parent; | 1473 stack = stack.parent; |
1397 } | 1474 } |
1398 return asyncStackTrace; | 1475 return asyncStackTrace; |
1399 } | 1476 } |
1400 }; | 1477 }; |
OLD | NEW |