diff --git a/front_end/bindings/BlackboxManager.js b/front_end/bindings/BlackboxManager.js index 71c203d6e3..6a985aa589 100644 --- a/front_end/bindings/BlackboxManager.js +++ b/front_end/bindings/BlackboxManager.js @@ -132,7 +132,7 @@ Bindings.BlackboxManager = class { /** * @param {!SDK.Script} script - * @param {?SDK.TextSourceMap} sourceMap + * @param {?SDK.SourceMap} sourceMap * @return {!Promise} */ sourceMapLoaded(script, sourceMap) { diff --git a/front_end/bindings/CompilerScriptMapping.js b/front_end/bindings/CompilerScriptMapping.js index 56daf344f3..dead58720c 100644 --- a/front_end/bindings/CompilerScriptMapping.js +++ b/front_end/bindings/CompilerScriptMapping.js @@ -40,38 +40,59 @@ Bindings.CompilerScriptMapping = class { */ constructor(debuggerModel, workspace, networkProject, debuggerWorkspaceBinding) { this._debuggerModel = debuggerModel; + this._sourceMapManager = this._debuggerModel.sourceMapManager(); this._workspace = workspace; this._networkProject = networkProject; this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; - /** @type {!Map>} */ - this._sourceMapLoadingPromises = new Map(); - /** @type {!Map} */ - this._sourceMapForScriptId = new Map(); - /** @type {!Map.} */ - this._scriptForSourceMap = new Map(); - /** @type {!Map.} */ - this._sourceMapForURL = new Map(); - /** @type {!Map.} */ + /** @type {!Multimap} */ + this._scriptSources = new Multimap(); + /** @type {!Map} */ this._stubUISourceCodes = new Map(); var projectId = Bindings.CompilerScriptMapping.projectIdForTarget(this._debuggerModel.target()); this._stubProject = new Bindings.ContentProviderBasedProject( workspace, projectId, Workspace.projectTypes.Service, '', true /* isServiceProject */); this._eventListeners = [ - workspace.addEventListener( - Workspace.Workspace.Events.UISourceCodeAdded, this._uiSourceCodeAddedToWorkspace, this), - debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this), - debuggerModel.addEventListener(SDK.DebuggerModel.Events.SourceMapURLAdded, this._sourceMapURLAdded.bind(this)) + this._sourceMapManager.addEventListener( + SDK.SourceMapManager.Events.SourceMapWillAttach, this._sourceMapWillAttach, this), + this._sourceMapManager.addEventListener( + SDK.SourceMapManager.Events.SourceMapFailedToAttach, this._sourceMapFailedToAttach, this), + this._sourceMapManager.addEventListener( + SDK.SourceMapManager.Events.SourceMapAttached, this._sourceMapAttached, this), + this._sourceMapManager.addEventListener( + SDK.SourceMapManager.Events.SourceMapDetached, this._sourceMapDetached, this), ]; } + /** + * @param {!SDK.Script} script + */ + _addStubUISourceCode(script) { + var stubUISourceCode = this._stubProject.addContentProvider( + script.sourceURL + ':sourcemap', + Common.StaticContentProvider.fromString( + script.sourceURL, Common.resourceTypes.Script, + '\n\n\n\n\n// Please wait a bit.\n// Compiled script is not shown while source map is being loaded!')); + this._stubUISourceCodes.set(script, stubUISourceCode); + } + + /** + * @param {!SDK.Script} script + */ + _removeStubUISourceCode(script) { + var uiSourceCode = this._stubUISourceCodes.get(script); + this._stubUISourceCodes.delete(script); + this._stubProject.removeFile(uiSourceCode.url()); + } + /** * @param {!Workspace.UISourceCode} uiSourceCode * @return {?string} */ static uiSourceCodeOrigin(uiSourceCode) { - return uiSourceCode[Bindings.CompilerScriptMapping._originSymbol] || null; + var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol]; + return script ? script.sourceURL : null; } /** @@ -87,10 +108,10 @@ Bindings.CompilerScriptMapping = class { * @return {boolean} */ mapsToSourceCode(rawLocation) { - var sourceMap = this._sourceMapForScriptId.get(rawLocation.scriptId); + var script = rawLocation.script(); + var sourceMap = script ? this._sourceMapManager.sourceMapForClient(script) : null; if (!sourceMap) return true; - return !!sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNumber); } @@ -100,23 +121,22 @@ Bindings.CompilerScriptMapping = class { * @return {?Workspace.UILocation} */ rawLocationToUILocation(rawLocation) { - var debuggerModelLocation = /** @type {!SDK.DebuggerModel.Location} */ (rawLocation); + var script = rawLocation.script(); + if (!script) + return null; - var stubUISourceCode = this._stubUISourceCodes.get(debuggerModelLocation.scriptId); + var lineNumber = rawLocation.lineNumber; + var columnNumber = rawLocation.columnNumber || 0; + var stubUISourceCode = this._stubUISourceCodes.get(script); if (stubUISourceCode) - return new Workspace.UILocation(stubUISourceCode, rawLocation.lineNumber, rawLocation.columnNumber); + return new Workspace.UILocation(stubUISourceCode, lineNumber, columnNumber); - var sourceMap = this._sourceMapForScriptId.get(debuggerModelLocation.scriptId); + var sourceMap = this._sourceMapManager.sourceMapForClient(script); if (!sourceMap) return null; - var lineNumber = debuggerModelLocation.lineNumber; - var columnNumber = debuggerModelLocation.columnNumber || 0; var entry = sourceMap.findEntry(lineNumber, columnNumber); if (!entry || !entry.sourceURL) return null; - var script = rawLocation.script(); - if (!script) - return null; var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForScriptURL( this._workspace, /** @type {string} */ (entry.sourceURL), script); if (!uiSourceCode) @@ -133,13 +153,12 @@ Bindings.CompilerScriptMapping = class { * @return {?SDK.DebuggerModel.Location} */ uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { - if (uiSourceCode.project().type() === Workspace.projectTypes.Service) + var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol]; + if (!script) return null; - var sourceMap = this._sourceMapForURL.get(uiSourceCode.url()); + var sourceMap = this._sourceMapManager.sourceMapForClient(script); if (!sourceMap) return null; - var script = /** @type {!SDK.Script} */ (this._scriptForSourceMap.get(sourceMap)); - console.assert(script); var entry = sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber); if (!entry) return null; @@ -147,128 +166,97 @@ Bindings.CompilerScriptMapping = class { } /** - * @param {!SDK.Script} script + * @param {!Common.Event} event */ - addScript(script) { - if (script.sourceMapURL) - this._processScript(script); + _sourceMapWillAttach(event) { + var script = /** @type {!SDK.Script} */ (event.data); + // Create stub UISourceCode for the time source mapping is being loaded. + this._addStubUISourceCode(script); + this._debuggerWorkspaceBinding.pushSourceMapping(script, this); } /** - * @param {!SDK.Script} script - * @return {?SDK.TextSourceMap} + * @param {!Common.Event} event */ - sourceMapForScript(script) { - return this._sourceMapForScriptId.get(script.scriptId) || null; + _sourceMapFailedToAttach(event) { + var script = /** @type {!SDK.Script} */ (event.data); + this._removeStubUISourceCode(script); } /** - * @param {!SDK.Script} script + * @param {!Common.Event} event */ - maybeLoadSourceMap(script) { - if (!script.sourceMapURL) - return; - if (this._sourceMapLoadingPromises.has(script.sourceMapURL)) - return; - if (this._sourceMapForScriptId.has(script.scriptId)) + _sourceMapAttached(event) { + var script = /** @type {!SDK.Script} */ (event.data.client); + var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap); + this._removeStubUISourceCode(script); + + if (Bindings.blackboxManager.isBlackboxedURL(script.sourceURL, script.isContentScript())) return; - this._processScript(script); + Bindings.blackboxManager.sourceMapLoaded(script, sourceMap); + + this._populateSourceMapSources(script, sourceMap); + this._sourceMapAttachedForTest(sourceMap); } /** * @param {!Common.Event} event */ - _sourceMapURLAdded(event) { - var script = /** @type {!SDK.Script} */ (event.data); - if (!script.sourceMapURL) + _sourceMapDetached(event) { + var script = /** @type {!SDK.Script} */ (event.data.client); + var sources = this._scriptSources.get(script); + if (!sources.size) return; - this._processScript(script); + var frameId = script[Bindings.CompilerScriptMapping._frameIdSymbol]; + for (var uiSourceCode of sources) { + this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSourceCode, null); + this._networkProject.removeSourceMapFile(uiSourceCode.url(), frameId, script.isContentScript()); + } + this._debuggerWorkspaceBinding.updateLocations(script); } /** * @param {!SDK.Script} script + * @return {?SDK.SourceMap} */ - _processScript(script) { - if (Bindings.blackboxManager.isBlackboxedURL(script.sourceURL, script.isContentScript())) - return; - // Create stub UISourceCode for the time source mapping is being loaded. - var stubUISourceCode = this._stubProject.addContentProvider( - script.sourceURL + ':sourcemap', - Common.StaticContentProvider.fromString( - script.sourceURL, Common.resourceTypes.Script, - '\n\n\n\n\n// Please wait a bit.\n// Compiled script is not shown while source map is being loaded!')); - this._stubUISourceCodes.set(script.scriptId, stubUISourceCode); + sourceMapForScript(script) { + return this._sourceMapManager.sourceMapForClient(script); + } - this._debuggerWorkspaceBinding.pushSourceMapping(script, this); - this._loadSourceMapForScript(script).then(sourceMap => { - this._sourceMapLoaded(script, stubUISourceCode.url(), sourceMap); - this._sourceMapAttachedForTest(sourceMap); - }); + /** + * @param {!SDK.Script} script + */ + maybeLoadSourceMap(script) { + var sourceMap = this._sourceMapManager.sourceMapForClient(script); + if (!sourceMap || this._scriptSources.has(script)) + return; + this._populateSourceMapSources(script, sourceMap); } /** - * @param {?SDK.TextSourceMap} sourceMap + * @param {?SDK.SourceMap} sourceMap */ _sourceMapAttachedForTest(sourceMap) { } /** * @param {!SDK.Script} script - * @param {string} uiSourceCodePath - * @param {?SDK.TextSourceMap} sourceMap + * @param {!SDK.SourceMap} sourceMap */ - _sourceMapLoaded(script, uiSourceCodePath, sourceMap) { - Bindings.blackboxManager.sourceMapLoaded(script, sourceMap); - - this._stubUISourceCodes.delete(script.scriptId); - this._stubProject.removeFile(uiSourceCodePath); - - if (!sourceMap) { - this._debuggerWorkspaceBinding.updateLocations(script); - return; - } - - if (this._scriptForSourceMap.get(sourceMap)) { - this._sourceMapForScriptId.set(script.scriptId, sourceMap); - this._debuggerWorkspaceBinding.updateLocations(script); - return; - } - - this._sourceMapForScriptId.set(script.scriptId, sourceMap); - this._scriptForSourceMap.set(sourceMap, script); - - // Report sources. - var missingSources = []; + _populateSourceMapSources(script, sourceMap) { var executionContext = script.executionContext(); var frameId = executionContext ? executionContext.frameId || '' : ''; + script[Bindings.CompilerScriptMapping._frameIdSymbol] = frameId; for (var sourceURL of sourceMap.sourceURLs()) { - if (this._sourceMapForURL.get(sourceURL)) - continue; - this._sourceMapForURL.set(sourceURL, sourceMap); - var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForScriptURL(this._workspace, sourceURL, script); - if (!uiSourceCode) { - var contentProvider = sourceMap.sourceContentProvider(sourceURL, Common.resourceTypes.SourceMapScript); - var embeddedContent = sourceMap.embeddedContentByURL(sourceURL); - var embeddedContentLength = typeof embeddedContent === 'string' ? embeddedContent.length : null; - uiSourceCode = this._networkProject.addSourceMapFile( - contentProvider, frameId, script.isContentScript(), embeddedContentLength); - uiSourceCode[Bindings.CompilerScriptMapping._originSymbol] = script.sourceURL; - } - if (uiSourceCode) { - this._bindUISourceCode(uiSourceCode); - } else { - if (missingSources.length < 3) - missingSources.push(sourceURL); - else if (missingSources.peekLast() !== '\u2026') - missingSources.push('\u2026'); - } + var contentProvider = sourceMap.sourceContentProvider(sourceURL, Common.resourceTypes.SourceMapScript); + var embeddedContent = sourceMap.embeddedContentByURL(sourceURL); + var embeddedContentLength = typeof embeddedContent === 'string' ? embeddedContent.length : null; + var uiSourceCode = this._networkProject.addSourceMapFile( + contentProvider, frameId, script.isContentScript(), embeddedContentLength); + uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol] = script; + this._scriptSources.set(script, uiSourceCode); + this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSourceCode, this); } - if (missingSources.length) { - Common.console.warn(Common.UIString( - 'Source map %s points to the files missing from the workspace: [%s]', sourceMap.url(), - missingSources.join(', '))); - } - this._debuggerWorkspaceBinding.updateLocations(script); } @@ -287,105 +275,18 @@ Bindings.CompilerScriptMapping = class { * @return {boolean} */ uiLineHasMapping(uiSourceCode, lineNumber) { - var sourceMap = this._sourceMapForURL.get(uiSourceCode.url()); + var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol]; + var sourceMap = script ? this._sourceMapManager.sourceMapForClient(script) : null; if (!sourceMap) return true; return !!sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber); } - /** - * @param {!Workspace.UISourceCode} uiSourceCode - */ - _bindUISourceCode(uiSourceCode) { - this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSourceCode, this); - } - - /** - * @param {!Workspace.UISourceCode} uiSourceCode - */ - _unbindUISourceCode(uiSourceCode) { - this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSourceCode, null); - } - - /** - * @param {!Common.Event} event - */ - _uiSourceCodeAddedToWorkspace(event) { - var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); - if (!this._sourceMapForURL.get(uiSourceCode.url())) - return; - this._bindUISourceCode(uiSourceCode); - } - - /** - * @param {!SDK.Script} script - * @return {!Promise} - */ - _loadSourceMapForScript(script) { - // script.sourceURL can be a random string, but is generally an absolute path -> complete it to inspected page url for - // relative links. - var scriptURL = Common.ParsedURL.completeURL(this._debuggerModel.target().inspectedURL(), script.sourceURL); - if (!scriptURL) - return Promise.resolve(/** @type {?SDK.TextSourceMap} */ (null)); - - console.assert(script.sourceMapURL); - var scriptSourceMapURL = /** @type {string} */ (script.sourceMapURL); - - var sourceMapURL = Common.ParsedURL.completeURL(scriptURL, scriptSourceMapURL); - if (!sourceMapURL) - return Promise.resolve(/** @type {?SDK.TextSourceMap} */ (null)); - - var loadingPromise = this._sourceMapLoadingPromises.get(sourceMapURL); - if (!loadingPromise) { - loadingPromise = SDK.TextSourceMap.load(sourceMapURL, scriptURL).then(sourceMapLoaded.bind(this, sourceMapURL)); - this._sourceMapLoadingPromises.set(sourceMapURL, loadingPromise); - } - return loadingPromise; - - /** - * @param {string} url - * @param {?SDK.TextSourceMap} sourceMap - * @this {Bindings.CompilerScriptMapping} - */ - function sourceMapLoaded(url, sourceMap) { - if (!sourceMap) { - this._sourceMapLoadingPromises.delete(url); - return null; - } - - return sourceMap; - } - } - - _debuggerReset() { - /** - * @param {!SDK.TextSourceMap} sourceMap - * @this {Bindings.CompilerScriptMapping} - */ - function unbindSourceMapSources(sourceMap) { - var script = this._scriptForSourceMap.get(sourceMap); - if (!script) - return; - for (var sourceURL of sourceMap.sourceURLs()) { - var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForScriptURL(this._workspace, sourceURL, script); - if (uiSourceCode) - this._unbindUISourceCode(uiSourceCode); - } - } - - Array.from(new Set(this._sourceMapForURL.values())).forEach(unbindSourceMapSources.bind(this)); - - this._sourceMapLoadingPromises.clear(); - this._sourceMapForScriptId.clear(); - this._scriptForSourceMap.clear(); - this._sourceMapForURL.clear(); - } - dispose() { Common.EventTarget.removeEventListeners(this._eventListeners); - this._debuggerReset(); this._stubProject.dispose(); } }; -Bindings.CompilerScriptMapping._originSymbol = Symbol('origin'); +Bindings.CompilerScriptMapping._scriptSymbol = Symbol('Bindings.CompilerScriptMapping._scriptSymbol'); +Bindings.CompilerScriptMapping._frameIdSymbol = Symbol('Bindings.CompilerScriptMapping._frameIdSymbol'); \ No newline at end of file diff --git a/front_end/bindings/DebuggerWorkspaceBinding.js b/front_end/bindings/DebuggerWorkspaceBinding.js index 7f5ac4bd1d..d956076032 100644 --- a/front_end/bindings/DebuggerWorkspaceBinding.js +++ b/front_end/bindings/DebuggerWorkspaceBinding.js @@ -233,7 +233,7 @@ Bindings.DebuggerWorkspaceBinding = class extends Common.Object { /** * @param {!SDK.Script} script - * @return {?SDK.TextSourceMap} + * @return {?SDK.SourceMap} */ sourceMapForScript(script) { var modelData = this._debuggerModelToData.get(script.debuggerModel); @@ -370,9 +370,6 @@ Bindings.DebuggerWorkspaceBinding.ModelData = class { var script = /** @type {!SDK.Script} */ (event.data); this._defaultMapping.addScript(script); this._resourceMapping.addScript(script); - - if (Common.moduleSetting('jsSourceMapsEnabled').get()) - this._compilerMapping.addScript(script); } /** diff --git a/front_end/bindings/ResourceScriptMapping.js b/front_end/bindings/ResourceScriptMapping.js index 7c506733e9..1c9adacc6d 100644 --- a/front_end/bindings/ResourceScriptMapping.js +++ b/front_end/bindings/ResourceScriptMapping.js @@ -425,7 +425,7 @@ Bindings.ResourceScriptFile = class extends Common.Object { addSourceMapURL(sourceMapURL) { if (!this._script) return; - this._script.addSourceMapURL(sourceMapURL); + this._script.debuggerModel.setSourceMapURL(this._script, sourceMapURL); } /** diff --git a/front_end/platform/utilities.js b/front_end/platform/utilities.js index cd66061bbc..cea60fb5c5 100644 --- a/front_end/platform/utilities.js +++ b/front_end/platform/utilities.js @@ -1213,12 +1213,14 @@ Multimap.prototype = { /** * @param {K} key * @param {V} value + * @return {boolean} */ remove: function(key, value) { var values = this.get(key); - values.delete(value); + var result = values.delete(value); if (!values.size) this._map.delete(key); + return result; }, /** diff --git a/front_end/sdk/DebuggerModel.js b/front_end/sdk/DebuggerModel.js index 72693cadfd..657d96b6bd 100644 --- a/front_end/sdk/DebuggerModel.js +++ b/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} */ + this._sourceMapManager = new SDK.SourceMapManager(target); + /** @type {!Map} */ + this._sourceMapIdToScript = new Map(); + /** @type {?SDK.DebuggerPausedDetails} */ this._debuggerPausedDetails = null; /** @type {!Object.} */ @@ -65,6 +70,28 @@ SDK.DebuggerModel = class extends SDK.SDKModel { /** @type {!Map} */ 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} + */ + 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); @@ -494,6 +537,38 @@ SDK.DebuggerModel = class extends SDK.SDKModel { return script; } + /** + * @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 */ @@ -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} */ diff --git a/front_end/sdk/RuntimeModel.js b/front_end/sdk/RuntimeModel.js index 5dddab0bdf..a6da9eb7ee 100644 --- a/front_end/sdk/RuntimeModel.js +++ b/front_end/sdk/RuntimeModel.js @@ -123,6 +123,7 @@ SDK.RuntimeModel = class extends SDK.SDKModel { var executionContext = this._executionContextById.get(executionContextId); if (!executionContext) return; + this.debuggerModel().executionContextDestroyed(executionContext); this._executionContextById.delete(executionContextId); this.dispatchEventToListeners(SDK.RuntimeModel.Events.ExecutionContextDestroyed, executionContext); } diff --git a/front_end/sdk/Script.js b/front_end/sdk/Script.js index 2e47e99037..1a019d4efd 100644 --- a/front_end/sdk/Script.js +++ b/front_end/sdk/Script.js @@ -55,7 +55,7 @@ SDK.Script = class { this.endLine = endLine; this.endColumn = endColumn; - this._executionContextId = executionContextId; + this.executionContextId = executionContextId; this.hash = hash; this._isContentScript = isContentScript; this._isLiveEdit = isLiveEdit; @@ -97,7 +97,7 @@ SDK.Script = class { * @return {?SDK.ExecutionContext} */ executionContext() { - return this.debuggerModel.runtimeModel().executionContext(this._executionContextId); + return this.debuggerModel.runtimeModel().executionContext(this.executionContextId); } /** @@ -259,16 +259,6 @@ SDK.Script = class { return !!this.sourceURL && !startsAtZero; } - /** - * @param {string} sourceMapURL - */ - addSourceMapURL(sourceMapURL) { - if (this.sourceMapURL) - return; - this.sourceMapURL = sourceMapURL; - this.debuggerModel.dispatchEventToListeners(SDK.DebuggerModel.Events.SourceMapURLAdded, this); - } - /** * @return {boolean} */ diff --git a/front_end/sdk/SourceMapManager.js b/front_end/sdk/SourceMapManager.js index 54c978fac3..5a29b7e15b 100644 --- a/front_end/sdk/SourceMapManager.js +++ b/front_end/sdk/SourceMapManager.js @@ -131,6 +131,8 @@ SDK.SourceMapManager = class extends SDK.SDKObject { if (!this._isEnabled) return; + this.dispatchEventToListeners(SDK.SourceMapManager.Events.SourceMapWillAttach, client); + if (this._sourceMapByURL.has(sourceMapURL)) { attach.call(this, sourceMapURL, client); return; @@ -169,8 +171,13 @@ SDK.SourceMapManager = class extends SDK.SDKObject { this._sourceMapLoadedForTest(); var clients = this._sourceMapURLToLoadingClients.get(sourceMapURL); this._sourceMapURLToLoadingClients.removeAll(sourceMapURL); - if (!sourceMap || !clients.size) + if (!clients.size) + return; + if (!sourceMap) { + for (var client of clients) + this.dispatchEventToListeners(SDK.SourceMapManager.Events.SourceMapFailedToAttach, client); return; + } this._sourceMapByURL.set(sourceMapURL, sourceMap); for (var client of clients) attach.call(this, sourceMapURL, client); @@ -217,7 +224,8 @@ SDK.SourceMapManager = class extends SDK.SDKObject { if (!sourceMapURL) return; if (!this._sourceMapURLToClients.hasValue(sourceMapURL, client)) { - this._sourceMapURLToLoadingClients.remove(sourceMapURL, client); + if (this._sourceMapURLToLoadingClients.remove(sourceMapURL, client)) + this.dispatchEventToListeners(SDK.SourceMapManager.Events.SourceMapFailedToAttach, client); return; } this._sourceMapURLToClients.remove(sourceMapURL, client); @@ -238,6 +246,8 @@ SDK.SourceMapManager = class extends SDK.SDKObject { }; SDK.SourceMapManager.Events = { + SourceMapWillAttach: Symbol('SourceMapWillAttach'), + SourceMapFailedToAttach: Symbol('SourceMapFailedToAttach'), SourceMapAttached: Symbol('SourceMapAttached'), SourceMapDetached: Symbol('SourceMapDetached'), SourceMapChanged: Symbol('SourceMapChanged')