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

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

Issue 2784413003: DevTools: carefully cleanup javascript sourcemaps (Closed)
Patch Set: 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 23 matching lines...) Expand all
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(
45 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._executionContex tDestroyed, this);
46
47 /** @type {!SDK.SourceMapManager<!SDK.Script>} */
48 this._sourceMapManager = new SDK.SourceMapManager(target);
49 /** @type {!Map<string, !SDK.Script>} */
50 this._sourceMapIdToScript = new Map();
44 51
45 /** @type {?SDK.DebuggerPausedDetails} */ 52 /** @type {?SDK.DebuggerPausedDetails} */
46 this._debuggerPausedDetails = null; 53 this._debuggerPausedDetails = null;
47 /** @type {!Object.<string, !SDK.Script>} */ 54 /** @type {!Object.<string, !SDK.Script>} */
48 this._scripts = {}; 55 this._scripts = {};
49 /** @type {!Map.<string, !Array.<!SDK.Script>>} */ 56 /** @type {!Map.<string, !Array.<!SDK.Script>>} */
50 this._scriptsBySourceURL = new Map(); 57 this._scriptsBySourceURL = new Map();
51 /** @type {!Array.<!SDK.Script>} */ 58 /** @type {!Array.<!SDK.Script>} */
52 this._discardableScripts = []; 59 this._discardableScripts = [];
53 60
54 /** @type {!Common.Object} */ 61 /** @type {!Common.Object} */
55 this._breakpointResolvedEventTarget = new Common.Object(); 62 this._breakpointResolvedEventTarget = new Common.Object();
56 63
57 this._isPausing = false; 64 this._isPausing = false;
58 Common.moduleSetting('pauseOnExceptionEnabled').addChangeListener(this._paus eOnExceptionStateChanged, this); 65 Common.moduleSetting('pauseOnExceptionEnabled').addChangeListener(this._paus eOnExceptionStateChanged, this);
59 Common.moduleSetting('pauseOnCaughtException').addChangeListener(this._pause OnExceptionStateChanged, this); 66 Common.moduleSetting('pauseOnCaughtException').addChangeListener(this._pause OnExceptionStateChanged, this);
60 Common.moduleSetting('enableAsyncStackTraces').addChangeListener(this.asyncS tackTracesStateChanged, this); 67 Common.moduleSetting('enableAsyncStackTraces').addChangeListener(this.asyncS tackTracesStateChanged, this);
61 68
62 /** @type {!Map<string, string>} */ 69 /** @type {!Map<string, string>} */
63 this._fileURLToNodeJSPath = new Map(); 70 this._fileURLToNodeJSPath = new Map();
64 this.enableDebugger(); 71 this.enableDebugger();
65 72
66 /** @type {!Map<string, string>} */ 73 /** @type {!Map<string, string>} */
67 this._stringMap = new Map(); 74 this._stringMap = new Map();
75 this._sourceMapManager.setEnabled(Common.moduleSetting('jsSourceMapsEnabled' ).get());
76 Common.moduleSetting('jsSourceMapsEnabled')
77 .addChangeListener(event => this._sourceMapManager.setEnabled(/** @type {boolean} */ (event.data)));
68 } 78 }
69 79
70 /** 80 /**
81 * @param {string} executionContextId
82 * @param {string} sourceURL
83 * @param {?string} sourceMapURL
84 * @return {?string}
85 */
86 static _sourceMapId(executionContextId, sourceURL, sourceMapURL) {
87 if (!sourceMapURL)
88 return null;
89 return executionContextId + ':' + sourceURL + ':' + sourceMapURL;
90 }
91
92 /**
93 * @return {!SDK.SourceMapManager<!SDK.Script>}
94 */
95 sourceMapManager() {
96 return this._sourceMapManager;
97 }
98
99 /**
71 * @return {!SDK.RuntimeModel} 100 * @return {!SDK.RuntimeModel}
72 */ 101 */
73 runtimeModel() { 102 runtimeModel() {
74 return this._runtimeModel; 103 return this._runtimeModel;
75 } 104 }
76 105
77 /** 106 /**
78 * @return {boolean} 107 * @return {boolean}
79 */ 108 */
80 debuggerEnabled() { 109 debuggerEnabled() {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 this._reset(); 340 this._reset();
312 // TODO(dgozman): move clients to ExecutionContextDestroyed/ScriptCollected events. 341 // TODO(dgozman): move clients to ExecutionContextDestroyed/ScriptCollected events.
313 this.dispatchEventToListeners(SDK.DebuggerModel.Events.GlobalObjectCleared, this); 342 this.dispatchEventToListeners(SDK.DebuggerModel.Events.GlobalObjectCleared, this);
314 } 343 }
315 344
316 _reset() { 345 _reset() {
317 this._scripts = {}; 346 this._scripts = {};
318 this._scriptsBySourceURL.clear(); 347 this._scriptsBySourceURL.clear();
319 this._stringMap.clear(); 348 this._stringMap.clear();
320 this._discardableScripts = []; 349 this._discardableScripts = [];
350
351 for (var scriptWithSourceMap of this._sourceMapIdToScript.values())
352 this._sourceMapManager.detachSourceMap(scriptWithSourceMap);
dgozman 2017/03/31 21:57:41 Let's do this before clearing scripts.
lushnikov 2017/03/31 23:53:10 Done.
353 this._sourceMapIdToScript.clear();
321 } 354 }
322 355
323 /** 356 /**
324 * @return {!Object.<string, !SDK.Script>} 357 * @return {!Object.<string, !SDK.Script>}
325 */ 358 */
326 get scripts() { 359 get scripts() {
327 return this._scripts; 360 return this._scripts;
328 } 361 }
329 362
330 /** 363 /**
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 sourceURL = this._internString(sourceURL); 512 sourceURL = this._internString(sourceURL);
480 } 513 }
481 var script = new SDK.Script( 514 var script = new SDK.Script(
482 this, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, e xecutionContextId, 515 this, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, e xecutionContextId,
483 this._internString(hash), isContentScript, isLiveEdit, sourceMapURL, has SourceURL, length); 516 this._internString(hash), isContentScript, isLiveEdit, sourceMapURL, has SourceURL, length);
484 this._registerScript(script); 517 this._registerScript(script);
485 if (!hasSyntaxError) 518 if (!hasSyntaxError)
486 this.dispatchEventToListeners(SDK.DebuggerModel.Events.ParsedScriptSource, script); 519 this.dispatchEventToListeners(SDK.DebuggerModel.Events.ParsedScriptSource, script);
487 else 520 else
488 this.dispatchEventToListeners(SDK.DebuggerModel.Events.FailedToParseScript Source, script); 521 this.dispatchEventToListeners(SDK.DebuggerModel.Events.FailedToParseScript Source, script);
522
523 var sourceMapId = SDK.DebuggerModel._sourceMapId(script.executionContextId, script.sourceURL, script.sourceMapURL);
524 if (sourceMapId && !hasSyntaxError) {
525 var previousSourceMapClient = this._sourceMapIdToScript.get(sourceMapId);
dgozman 2017/03/31 21:57:41 Let's add a comment.
lushnikov 2017/03/31 23:53:10 Done.
526 if (previousSourceMapClient)
dgozman 2017/03/31 21:57:40 previousScript
lushnikov 2017/03/31 23:53:10 Done.
527 this._sourceMapManager.detachSourceMap(previousSourceMapClient);
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)
dgozman 2017/03/31 21:57:41 Figure out null vs undefined vs empty string.
lushnikov 2017/03/31 23:53:10 Not loading sourceMaps for all falsy values of sou
553 return;
554 this._sourceMapIdToScript.set(sourceMapId, script);
555 this._sourceMapManager.attachSourceMap(script, script.sourceURL, script.sour ceMapURL);
556 }
557
558 /**
559 * @param {!Common.Event} event
560 */
561 _executionContextDestroyed(event) {
562 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
563 for (var script of this._sourceMapIdToScript.values()) {
564 if (script.executionContextId === executionContext.id)
565 this._sourceMapManager.detachSourceMap(script);
dgozman 2017/03/31 21:57:41 Remove from this._sourceMapIdToScript as well.
lushnikov 2017/03/31 23:53:10 Done.
566 }
567 }
568
569 /**
570 * @param {!SDK.Script} script
499 */ 571 */
500 _registerScript(script) { 572 _registerScript(script) {
501 this._scripts[script.scriptId] = script; 573 this._scripts[script.scriptId] = script;
502 if (script.isAnonymousScript()) 574 if (script.isAnonymousScript())
503 return; 575 return;
504 576
505 var scripts = this._scriptsBySourceURL.get(script.sourceURL); 577 var scripts = this._scriptsBySourceURL.get(script.sourceURL);
506 if (!scripts) { 578 if (!scripts) {
507 scripts = []; 579 scripts = [];
508 this._scriptsBySourceURL.set(script.sourceURL, scripts); 580 this._scriptsBySourceURL.set(script.sourceURL, scripts);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 if (error) 837 if (error)
766 console.error(error); 838 console.error(error);
767 callback(!error); 839 callback(!error);
768 } 840 }
769 } 841 }
770 842
771 /** 843 /**
772 * @override 844 * @override
773 */ 845 */
774 dispose() { 846 dispose() {
847 this._sourceMapManager.dispose();
848 this._runtimeModel.removeEventListener(
dgozman 2017/03/31 21:57:40 Let's turn this into direct call 'executionContext
lushnikov 2017/03/31 23:53:10 Done.
849 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._executionContex tDestroyed, this);
775 Common.moduleSetting('pauseOnExceptionEnabled').removeChangeListener(this._p auseOnExceptionStateChanged, this); 850 Common.moduleSetting('pauseOnExceptionEnabled').removeChangeListener(this._p auseOnExceptionStateChanged, this);
776 Common.moduleSetting('pauseOnCaughtException').removeChangeListener(this._pa useOnExceptionStateChanged, this); 851 Common.moduleSetting('pauseOnCaughtException').removeChangeListener(this._pa useOnExceptionStateChanged, this);
777 Common.moduleSetting('enableAsyncStackTraces').removeChangeListener(this.asy ncStackTracesStateChanged, this); 852 Common.moduleSetting('enableAsyncStackTraces').removeChangeListener(this.asy ncStackTracesStateChanged, this);
778 } 853 }
779 854
780 /** 855 /**
781 * @override 856 * @override
782 * @return {!Promise} 857 * @return {!Promise}
783 */ 858 */
784 suspendModel() { 859 suspendModel() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 SDK.DebuggerModel.Events = { 915 SDK.DebuggerModel.Events = {
841 DebuggerWasEnabled: Symbol('DebuggerWasEnabled'), 916 DebuggerWasEnabled: Symbol('DebuggerWasEnabled'),
842 DebuggerWasDisabled: Symbol('DebuggerWasDisabled'), 917 DebuggerWasDisabled: Symbol('DebuggerWasDisabled'),
843 DebuggerPaused: Symbol('DebuggerPaused'), 918 DebuggerPaused: Symbol('DebuggerPaused'),
844 DebuggerResumed: Symbol('DebuggerResumed'), 919 DebuggerResumed: Symbol('DebuggerResumed'),
845 ParsedScriptSource: Symbol('ParsedScriptSource'), 920 ParsedScriptSource: Symbol('ParsedScriptSource'),
846 FailedToParseScriptSource: Symbol('FailedToParseScriptSource'), 921 FailedToParseScriptSource: Symbol('FailedToParseScriptSource'),
847 DiscardedAnonymousScriptSource: Symbol('DiscardedAnonymousScriptSource'), 922 DiscardedAnonymousScriptSource: Symbol('DiscardedAnonymousScriptSource'),
848 GlobalObjectCleared: Symbol('GlobalObjectCleared'), 923 GlobalObjectCleared: Symbol('GlobalObjectCleared'),
849 CallFrameSelected: Symbol('CallFrameSelected'), 924 CallFrameSelected: Symbol('CallFrameSelected'),
850 ConsoleCommandEvaluatedInSelectedCallFrame: Symbol('ConsoleCommandEvaluatedInS electedCallFrame'), 925 ConsoleCommandEvaluatedInSelectedCallFrame: Symbol('ConsoleCommandEvaluatedInS electedCallFrame')
851 SourceMapURLAdded: Symbol('SourceMapURLAdded')
852 }; 926 };
853 927
854 /** @enum {string} */ 928 /** @enum {string} */
855 SDK.DebuggerModel.BreakReason = { 929 SDK.DebuggerModel.BreakReason = {
856 DOM: 'DOM', 930 DOM: 'DOM',
857 EventListener: 'EventListener', 931 EventListener: 'EventListener',
858 XHR: 'XHR', 932 XHR: 'XHR',
859 Exception: 'exception', 933 Exception: 'exception',
860 PromiseRejection: 'promiseRejection', 934 PromiseRejection: 'promiseRejection',
861 Assert: 'assert', 935 Assert: 'assert',
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 stack.callFrames.shift(); 1465 stack.callFrames.shift();
1392 if (previous && (!stack.callFrames.length && !stack.promiseCreationFrame)) 1466 if (previous && (!stack.callFrames.length && !stack.promiseCreationFrame))
1393 previous.parent = stack.parent; 1467 previous.parent = stack.parent;
1394 else 1468 else
1395 previous = stack; 1469 previous = stack;
1396 stack = stack.parent; 1470 stack = stack.parent;
1397 } 1471 }
1398 return asyncStackTrace; 1472 return asyncStackTrace;
1399 } 1473 }
1400 }; 1474 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698