Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/DebuggerModel.js

Issue 2784413003: DevTools: carefully cleanup javascript sourcemaps (Closed)
Patch Set: address comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 24 matching lines...) Expand all
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 44
45 /** @type {!SDK.SourceMapManager<!SDK.Script>} */
46 this._sourceMapManager = new SDK.SourceMapManager(target);
47 /** @type {!Map<string, !SDK.Script>} */
48 this._sourceMapIdToScript = new Map();
49
45 /** @type {?SDK.DebuggerPausedDetails} */ 50 /** @type {?SDK.DebuggerPausedDetails} */
46 this._debuggerPausedDetails = null; 51 this._debuggerPausedDetails = null;
47 /** @type {!Object.<string, !SDK.Script>} */ 52 /** @type {!Object.<string, !SDK.Script>} */
48 this._scripts = {}; 53 this._scripts = {};
49 /** @type {!Map.<string, !Array.<!SDK.Script>>} */ 54 /** @type {!Map.<string, !Array.<!SDK.Script>>} */
50 this._scriptsBySourceURL = new Map(); 55 this._scriptsBySourceURL = new Map();
51 /** @type {!Array.<!SDK.Script>} */ 56 /** @type {!Array.<!SDK.Script>} */
52 this._discardableScripts = []; 57 this._discardableScripts = [];
53 58
54 /** @type {!Common.Object} */ 59 /** @type {!Common.Object} */
55 this._breakpointResolvedEventTarget = new Common.Object(); 60 this._breakpointResolvedEventTarget = new Common.Object();
56 61
57 this._isPausing = false; 62 this._isPausing = false;
58 Common.moduleSetting('pauseOnExceptionEnabled').addChangeListener(this._paus eOnExceptionStateChanged, this); 63 Common.moduleSetting('pauseOnExceptionEnabled').addChangeListener(this._paus eOnExceptionStateChanged, this);
59 Common.moduleSetting('pauseOnCaughtException').addChangeListener(this._pause OnExceptionStateChanged, this); 64 Common.moduleSetting('pauseOnCaughtException').addChangeListener(this._pause OnExceptionStateChanged, this);
60 Common.moduleSetting('enableAsyncStackTraces').addChangeListener(this.asyncS tackTracesStateChanged, this); 65 Common.moduleSetting('enableAsyncStackTraces').addChangeListener(this.asyncS tackTracesStateChanged, this);
61 66
62 /** @type {!Map<string, string>} */ 67 /** @type {!Map<string, string>} */
63 this._fileURLToNodeJSPath = new Map(); 68 this._fileURLToNodeJSPath = new Map();
64 this.enableDebugger(); 69 this.enableDebugger();
65 70
66 /** @type {!Map<string, string>} */ 71 /** @type {!Map<string, string>} */
67 this._stringMap = new Map(); 72 this._stringMap = new Map();
73 this._sourceMapManager.setEnabled(Common.moduleSetting('jsSourceMapsEnabled' ).get());
74 Common.moduleSetting('jsSourceMapsEnabled')
75 .addChangeListener(event => this._sourceMapManager.setEnabled(/** @type {boolean} */ (event.data)));
68 } 76 }
69 77
70 /** 78 /**
79 * @param {string} executionContextId
80 * @param {string} sourceURL
81 * @param {?string} sourceMapURL
82 * @return {?string}
83 */
84 static _sourceMapId(executionContextId, sourceURL, sourceMapURL) {
85 if (!sourceMapURL)
86 return null;
87 return executionContextId + ':' + sourceURL + ':' + sourceMapURL;
88 }
89
90 /**
91 * @return {!SDK.SourceMapManager<!SDK.Script>}
92 */
93 sourceMapManager() {
94 return this._sourceMapManager;
95 }
96
97 /**
71 * @return {!SDK.RuntimeModel} 98 * @return {!SDK.RuntimeModel}
72 */ 99 */
73 runtimeModel() { 100 runtimeModel() {
74 return this._runtimeModel; 101 return this._runtimeModel;
75 } 102 }
76 103
77 /** 104 /**
78 * @return {boolean} 105 * @return {boolean}
79 */ 106 */
80 debuggerEnabled() { 107 debuggerEnabled() {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 334 }
308 335
309 globalObjectCleared() { 336 globalObjectCleared() {
310 this._setDebuggerPausedDetails(null); 337 this._setDebuggerPausedDetails(null);
311 this._reset(); 338 this._reset();
312 // TODO(dgozman): move clients to ExecutionContextDestroyed/ScriptCollected events. 339 // TODO(dgozman): move clients to ExecutionContextDestroyed/ScriptCollected events.
313 this.dispatchEventToListeners(SDK.DebuggerModel.Events.GlobalObjectCleared, this); 340 this.dispatchEventToListeners(SDK.DebuggerModel.Events.GlobalObjectCleared, this);
314 } 341 }
315 342
316 _reset() { 343 _reset() {
344 for (var scriptWithSourceMap of this._sourceMapIdToScript.values())
345 this._sourceMapManager.detachSourceMap(scriptWithSourceMap);
346 this._sourceMapIdToScript.clear();
347
317 this._scripts = {}; 348 this._scripts = {};
318 this._scriptsBySourceURL.clear(); 349 this._scriptsBySourceURL.clear();
319 this._stringMap.clear(); 350 this._stringMap.clear();
320 this._discardableScripts = []; 351 this._discardableScripts = [];
321 } 352 }
322 353
323 /** 354 /**
324 * @return {!Object.<string, !SDK.Script>} 355 * @return {!Object.<string, !SDK.Script>}
325 */ 356 */
326 get scripts() { 357 get scripts() {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 sourceURL = this._internString(sourceURL); 510 sourceURL = this._internString(sourceURL);
480 } 511 }
481 var script = new SDK.Script( 512 var script = new SDK.Script(
482 this, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, e xecutionContextId, 513 this, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, e xecutionContextId,
483 this._internString(hash), isContentScript, isLiveEdit, sourceMapURL, has SourceURL, length); 514 this._internString(hash), isContentScript, isLiveEdit, sourceMapURL, has SourceURL, length);
484 this._registerScript(script); 515 this._registerScript(script);
485 if (!hasSyntaxError) 516 if (!hasSyntaxError)
486 this.dispatchEventToListeners(SDK.DebuggerModel.Events.ParsedScriptSource, script); 517 this.dispatchEventToListeners(SDK.DebuggerModel.Events.ParsedScriptSource, script);
487 else 518 else
488 this.dispatchEventToListeners(SDK.DebuggerModel.Events.FailedToParseScript Source, script); 519 this.dispatchEventToListeners(SDK.DebuggerModel.Events.FailedToParseScript Source, script);
520
521 var sourceMapId = SDK.DebuggerModel._sourceMapId(script.executionContextId, script.sourceURL, script.sourceMapURL);
522 if (sourceMapId && !hasSyntaxError) {
523 // Consecutive script evaluations in the same execution context with the s ame sourceURL
524 // and sourceMappingURL should result in source map reloading.
525 var previousScript = this._sourceMapIdToScript.get(sourceMapId);
526 if (previousScript)
527 this._sourceMapManager.detachSourceMap(previousScript);
528 this._sourceMapIdToScript.set(sourceMapId, script);
529 this._sourceMapManager.attachSourceMap(script, script.sourceURL, script.so urceMapURL);
530 }
531
489 var isDiscardable = hasSyntaxError && script.isAnonymousScript(); 532 var isDiscardable = hasSyntaxError && script.isAnonymousScript();
490 if (isDiscardable) { 533 if (isDiscardable) {
491 this._discardableScripts.push(script); 534 this._discardableScripts.push(script);
492 this._collectDiscardedScripts(); 535 this._collectDiscardedScripts();
493 } 536 }
494 return script; 537 return script;
495 } 538 }
496 539
497 /** 540 /**
498 * @param {!SDK.Script} script 541 * @param {!SDK.Script} script
542 * @param {string} newSourceMapURL
543 */
544 setSourceMapURL(script, newSourceMapURL) {
545 var sourceMapId = SDK.DebuggerModel._sourceMapId(script.executionContextId, script.sourceURL, script.sourceMapURL);
546 if (sourceMapId && this._sourceMapIdToScript.get(sourceMapId) === script)
547 this._sourceMapIdToScript.delete(sourceMapId);
548 this._sourceMapManager.detachSourceMap(script);
549
550 script.sourceMapURL = newSourceMapURL;
551 sourceMapId = SDK.DebuggerModel._sourceMapId(script.executionContextId, scri pt.sourceURL, script.sourceMapURL);
552 if (!sourceMapId)
553 return;
554 this._sourceMapIdToScript.set(sourceMapId, script);
555 this._sourceMapManager.attachSourceMap(script, script.sourceURL, script.sour ceMapURL);
556 }
557
558 /**
559 * @param {!SDK.ExecutionContext} executionContext
560 */
561 executionContextDestroyed(executionContext) {
562 var sourceMapIds = Array.from(this._sourceMapIdToScript.keys());
563 for (var sourceMapId of sourceMapIds) {
564 var script = this._sourceMapIdToScript.get(sourceMapId);
565 if (script.executionContextId === executionContext.id) {
566 this._sourceMapIdToScript.delete(sourceMapId);
567 this._sourceMapManager.detachSourceMap(script);
568 }
569 }
570 }
571
572 /**
573 * @param {!SDK.Script} script
499 */ 574 */
500 _registerScript(script) { 575 _registerScript(script) {
501 this._scripts[script.scriptId] = script; 576 this._scripts[script.scriptId] = script;
502 if (script.isAnonymousScript()) 577 if (script.isAnonymousScript())
503 return; 578 return;
504 579
505 var scripts = this._scriptsBySourceURL.get(script.sourceURL); 580 var scripts = this._scriptsBySourceURL.get(script.sourceURL);
506 if (!scripts) { 581 if (!scripts) {
507 scripts = []; 582 scripts = [];
508 this._scriptsBySourceURL.set(script.sourceURL, scripts); 583 this._scriptsBySourceURL.set(script.sourceURL, scripts);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 if (error) 840 if (error)
766 console.error(error); 841 console.error(error);
767 callback(!error); 842 callback(!error);
768 } 843 }
769 } 844 }
770 845
771 /** 846 /**
772 * @override 847 * @override
773 */ 848 */
774 dispose() { 849 dispose() {
850 this._sourceMapManager.dispose();
775 Common.moduleSetting('pauseOnExceptionEnabled').removeChangeListener(this._p auseOnExceptionStateChanged, this); 851 Common.moduleSetting('pauseOnExceptionEnabled').removeChangeListener(this._p auseOnExceptionStateChanged, this);
776 Common.moduleSetting('pauseOnCaughtException').removeChangeListener(this._pa useOnExceptionStateChanged, this); 852 Common.moduleSetting('pauseOnCaughtException').removeChangeListener(this._pa useOnExceptionStateChanged, this);
777 Common.moduleSetting('enableAsyncStackTraces').removeChangeListener(this.asy ncStackTracesStateChanged, this); 853 Common.moduleSetting('enableAsyncStackTraces').removeChangeListener(this.asy ncStackTracesStateChanged, this);
778 } 854 }
779 855
780 /** 856 /**
781 * @override 857 * @override
782 * @return {!Promise} 858 * @return {!Promise}
783 */ 859 */
784 suspendModel() { 860 suspendModel() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 SDK.DebuggerModel.Events = { 916 SDK.DebuggerModel.Events = {
841 DebuggerWasEnabled: Symbol('DebuggerWasEnabled'), 917 DebuggerWasEnabled: Symbol('DebuggerWasEnabled'),
842 DebuggerWasDisabled: Symbol('DebuggerWasDisabled'), 918 DebuggerWasDisabled: Symbol('DebuggerWasDisabled'),
843 DebuggerPaused: Symbol('DebuggerPaused'), 919 DebuggerPaused: Symbol('DebuggerPaused'),
844 DebuggerResumed: Symbol('DebuggerResumed'), 920 DebuggerResumed: Symbol('DebuggerResumed'),
845 ParsedScriptSource: Symbol('ParsedScriptSource'), 921 ParsedScriptSource: Symbol('ParsedScriptSource'),
846 FailedToParseScriptSource: Symbol('FailedToParseScriptSource'), 922 FailedToParseScriptSource: Symbol('FailedToParseScriptSource'),
847 DiscardedAnonymousScriptSource: Symbol('DiscardedAnonymousScriptSource'), 923 DiscardedAnonymousScriptSource: Symbol('DiscardedAnonymousScriptSource'),
848 GlobalObjectCleared: Symbol('GlobalObjectCleared'), 924 GlobalObjectCleared: Symbol('GlobalObjectCleared'),
849 CallFrameSelected: Symbol('CallFrameSelected'), 925 CallFrameSelected: Symbol('CallFrameSelected'),
850 ConsoleCommandEvaluatedInSelectedCallFrame: Symbol('ConsoleCommandEvaluatedInS electedCallFrame'), 926 ConsoleCommandEvaluatedInSelectedCallFrame: Symbol('ConsoleCommandEvaluatedInS electedCallFrame')
851 SourceMapURLAdded: Symbol('SourceMapURLAdded')
852 }; 927 };
853 928
854 /** @enum {string} */ 929 /** @enum {string} */
855 SDK.DebuggerModel.BreakReason = { 930 SDK.DebuggerModel.BreakReason = {
856 DOM: 'DOM', 931 DOM: 'DOM',
857 EventListener: 'EventListener', 932 EventListener: 'EventListener',
858 XHR: 'XHR', 933 XHR: 'XHR',
859 Exception: 'exception', 934 Exception: 'exception',
860 PromiseRejection: 'promiseRejection', 935 PromiseRejection: 'promiseRejection',
861 Assert: 'assert', 936 Assert: 'assert',
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 stack.callFrames.shift(); 1466 stack.callFrames.shift();
1392 if (previous && (!stack.callFrames.length && !stack.promiseCreationFrame)) 1467 if (previous && (!stack.callFrames.length && !stack.promiseCreationFrame))
1393 previous.parent = stack.parent; 1468 previous.parent = stack.parent;
1394 else 1469 else
1395 previous = stack; 1470 previous = stack;
1396 stack = stack.parent; 1471 stack = stack.parent;
1397 } 1472 }
1398 return asyncStackTrace; 1473 return asyncStackTrace;
1399 } 1474 }
1400 }; 1475 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698