Chromium Code Reviews| 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..055d5a1a36c41825173a561824c7066bb866d166 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/sdk/DebuggerModel.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/sdk/DebuggerModel.js |
| @@ -41,6 +41,13 @@ SDK.DebuggerModel = class extends SDK.SDKModel { |
| target.registerDebuggerDispatcher(new SDK.DebuggerDispatcher(this)); |
| this._agent = target.debuggerAgent(); |
| this._runtimeModel = /** @type {!SDK.RuntimeModel} */ (target.model(SDK.RuntimeModel)); |
| + this._runtimeModel.addEventListener( |
| + SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._executionContextDestroyed, this); |
| + |
| + /** @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; |
| @@ -65,6 +72,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; |
| } |
| /** |
| @@ -318,6 +347,10 @@ SDK.DebuggerModel = class extends SDK.SDKModel { |
| this._scriptsBySourceURL.clear(); |
| this._stringMap.clear(); |
| this._discardableScripts = []; |
| + |
| + for (var scriptWithSourceMap of this._sourceMapIdToScript.values()) |
| + 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.
|
| + this._sourceMapIdToScript.clear(); |
| } |
| /** |
| @@ -486,6 +519,16 @@ 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) { |
| + 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.
|
| + if (previousSourceMapClient) |
|
dgozman
2017/03/31 21:57:40
previousScript
lushnikov
2017/03/31 23:53:10
Done.
|
| + this._sourceMapManager.detachSourceMap(previousSourceMapClient); |
| + 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,35 @@ 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) |
|
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
|
| + return; |
| + this._sourceMapIdToScript.set(sourceMapId, script); |
| + this._sourceMapManager.attachSourceMap(script, script.sourceURL, script.sourceMapURL); |
| + } |
| + |
| + /** |
| + * @param {!Common.Event} event |
| + */ |
| + _executionContextDestroyed(event) { |
| + var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); |
| + for (var script of this._sourceMapIdToScript.values()) { |
| + if (script.executionContextId === executionContext.id) |
| + 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.
|
| + } |
| + } |
| + |
| + /** |
| + * @param {!SDK.Script} script |
| */ |
| _registerScript(script) { |
| this._scripts[script.scriptId] = script; |
| @@ -772,6 +844,9 @@ SDK.DebuggerModel = class extends SDK.SDKModel { |
| * @override |
| */ |
| dispose() { |
| + this._sourceMapManager.dispose(); |
| + 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.
|
| + SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._executionContextDestroyed, this); |
| Common.moduleSetting('pauseOnExceptionEnabled').removeChangeListener(this._pauseOnExceptionStateChanged, this); |
| Common.moduleSetting('pauseOnCaughtException').removeChangeListener(this._pauseOnExceptionStateChanged, this); |
| Common.moduleSetting('enableAsyncStackTraces').removeChangeListener(this.asyncStackTracesStateChanged, this); |
| @@ -847,8 +922,7 @@ SDK.DebuggerModel.Events = { |
| DiscardedAnonymousScriptSource: Symbol('DiscardedAnonymousScriptSource'), |
| GlobalObjectCleared: Symbol('GlobalObjectCleared'), |
| CallFrameSelected: Symbol('CallFrameSelected'), |
| - ConsoleCommandEvaluatedInSelectedCallFrame: Symbol('ConsoleCommandEvaluatedInSelectedCallFrame'), |
| - SourceMapURLAdded: Symbol('SourceMapURLAdded') |
| + ConsoleCommandEvaluatedInSelectedCallFrame: Symbol('ConsoleCommandEvaluatedInSelectedCallFrame') |
| }; |
| /** @enum {string} */ |