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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/sdk/DebuggerModel.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/DebuggerModel.js b/third_party/WebKit/Source/devtools/front_end/sdk/DebuggerModel.js
index 72693cadfdd036e221785df59aa9a22d9f65462d..657d96b6bdd6a58aa2b452f7f7bababdbb69889b 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/DebuggerModel.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/DebuggerModel.js
@@ -42,6 +42,11 @@ SDK.DebuggerModel = class extends SDK.SDKModel {
this._agent = target.debuggerAgent();
this._runtimeModel = /** @type {!SDK.RuntimeModel} */ (target.model(SDK.RuntimeModel));
+ /** @type {!SDK.SourceMapManager<!SDK.Script>} */
+ this._sourceMapManager = new SDK.SourceMapManager(target);
+ /** @type {!Map<string, !SDK.Script>} */
+ this._sourceMapIdToScript = new Map();
+
/** @type {?SDK.DebuggerPausedDetails} */
this._debuggerPausedDetails = null;
/** @type {!Object.<string, !SDK.Script>} */
@@ -65,6 +70,28 @@ SDK.DebuggerModel = class extends SDK.SDKModel {
/** @type {!Map<string, string>} */
this._stringMap = new Map();
+ this._sourceMapManager.setEnabled(Common.moduleSetting('jsSourceMapsEnabled').get());
+ Common.moduleSetting('jsSourceMapsEnabled')
+ .addChangeListener(event => this._sourceMapManager.setEnabled(/** @type {boolean} */ (event.data)));
+ }
+
+ /**
+ * @param {string} executionContextId
+ * @param {string} sourceURL
+ * @param {?string} sourceMapURL
+ * @return {?string}
+ */
+ static _sourceMapId(executionContextId, sourceURL, sourceMapURL) {
+ if (!sourceMapURL)
+ return null;
+ return executionContextId + ':' + sourceURL + ':' + sourceMapURL;
+ }
+
+ /**
+ * @return {!SDK.SourceMapManager<!SDK.Script>}
+ */
+ sourceMapManager() {
+ return this._sourceMapManager;
}
/**
@@ -314,6 +341,10 @@ SDK.DebuggerModel = class extends SDK.SDKModel {
}
_reset() {
+ for (var scriptWithSourceMap of this._sourceMapIdToScript.values())
+ this._sourceMapManager.detachSourceMap(scriptWithSourceMap);
+ this._sourceMapIdToScript.clear();
+
this._scripts = {};
this._scriptsBySourceURL.clear();
this._stringMap.clear();
@@ -486,6 +517,18 @@ SDK.DebuggerModel = class extends SDK.SDKModel {
this.dispatchEventToListeners(SDK.DebuggerModel.Events.ParsedScriptSource, script);
else
this.dispatchEventToListeners(SDK.DebuggerModel.Events.FailedToParseScriptSource, script);
+
+ var sourceMapId = SDK.DebuggerModel._sourceMapId(script.executionContextId, script.sourceURL, script.sourceMapURL);
+ if (sourceMapId && !hasSyntaxError) {
+ // Consecutive script evaluations in the same execution context with the same sourceURL
+ // and sourceMappingURL should result in source map reloading.
+ var previousScript = this._sourceMapIdToScript.get(sourceMapId);
+ if (previousScript)
+ this._sourceMapManager.detachSourceMap(previousScript);
+ this._sourceMapIdToScript.set(sourceMapId, script);
+ this._sourceMapManager.attachSourceMap(script, script.sourceURL, script.sourceMapURL);
+ }
+
var isDiscardable = hasSyntaxError && script.isAnonymousScript();
if (isDiscardable) {
this._discardableScripts.push(script);
@@ -496,6 +539,38 @@ SDK.DebuggerModel = class extends SDK.SDKModel {
/**
* @param {!SDK.Script} script
+ * @param {string} newSourceMapURL
+ */
+ setSourceMapURL(script, newSourceMapURL) {
+ var sourceMapId = SDK.DebuggerModel._sourceMapId(script.executionContextId, script.sourceURL, script.sourceMapURL);
+ if (sourceMapId && this._sourceMapIdToScript.get(sourceMapId) === script)
+ this._sourceMapIdToScript.delete(sourceMapId);
+ this._sourceMapManager.detachSourceMap(script);
+
+ script.sourceMapURL = newSourceMapURL;
+ sourceMapId = SDK.DebuggerModel._sourceMapId(script.executionContextId, script.sourceURL, script.sourceMapURL);
+ if (!sourceMapId)
+ return;
+ this._sourceMapIdToScript.set(sourceMapId, script);
+ this._sourceMapManager.attachSourceMap(script, script.sourceURL, script.sourceMapURL);
+ }
+
+ /**
+ * @param {!SDK.ExecutionContext} executionContext
+ */
+ executionContextDestroyed(executionContext) {
+ var sourceMapIds = Array.from(this._sourceMapIdToScript.keys());
+ for (var sourceMapId of sourceMapIds) {
+ var script = this._sourceMapIdToScript.get(sourceMapId);
+ if (script.executionContextId === executionContext.id) {
+ this._sourceMapIdToScript.delete(sourceMapId);
+ this._sourceMapManager.detachSourceMap(script);
+ }
+ }
+ }
+
+ /**
+ * @param {!SDK.Script} script
*/
_registerScript(script) {
this._scripts[script.scriptId] = script;
@@ -772,6 +847,7 @@ SDK.DebuggerModel = class extends SDK.SDKModel {
* @override
*/
dispose() {
+ this._sourceMapManager.dispose();
Common.moduleSetting('pauseOnExceptionEnabled').removeChangeListener(this._pauseOnExceptionStateChanged, this);
Common.moduleSetting('pauseOnCaughtException').removeChangeListener(this._pauseOnExceptionStateChanged, this);
Common.moduleSetting('enableAsyncStackTraces').removeChangeListener(this.asyncStackTracesStateChanged, this);
@@ -847,8 +923,7 @@ SDK.DebuggerModel.Events = {
DiscardedAnonymousScriptSource: Symbol('DiscardedAnonymousScriptSource'),
GlobalObjectCleared: Symbol('GlobalObjectCleared'),
CallFrameSelected: Symbol('CallFrameSelected'),
- ConsoleCommandEvaluatedInSelectedCallFrame: Symbol('ConsoleCommandEvaluatedInSelectedCallFrame'),
- SourceMapURLAdded: Symbol('SourceMapURLAdded')
+ ConsoleCommandEvaluatedInSelectedCallFrame: Symbol('ConsoleCommandEvaluatedInSelectedCallFrame')
};
/** @enum {string} */

Powered by Google App Engine
This is Rietveld 408576698