| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 22 matching lines...) Expand all Loading... |
| 33 */ | 33 */ |
| 34 Bindings.DefaultScriptMapping = class { | 34 Bindings.DefaultScriptMapping = class { |
| 35 /** | 35 /** |
| 36 * @param {!SDK.DebuggerModel} debuggerModel | 36 * @param {!SDK.DebuggerModel} debuggerModel |
| 37 * @param {!Workspace.Workspace} workspace | 37 * @param {!Workspace.Workspace} workspace |
| 38 * @param {!Bindings.DebuggerWorkspaceBinding} debuggerWorkspaceBinding | 38 * @param {!Bindings.DebuggerWorkspaceBinding} debuggerWorkspaceBinding |
| 39 */ | 39 */ |
| 40 constructor(debuggerModel, workspace, debuggerWorkspaceBinding) { | 40 constructor(debuggerModel, workspace, debuggerWorkspaceBinding) { |
| 41 this._debuggerModel = debuggerModel; | 41 this._debuggerModel = debuggerModel; |
| 42 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; | 42 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; |
| 43 var projectId = Bindings.DefaultScriptMapping.projectIdForTarget(debuggerMod
el.target()); | |
| 44 this._project = new Bindings.ContentProviderBasedProject( | 43 this._project = new Bindings.ContentProviderBasedProject( |
| 45 workspace, projectId, Workspace.projectTypes.Debugger, '', true /* isSer
viceProject */); | 44 workspace, 'debugger:' + debuggerModel.target().id(), Workspace.projectT
ypes.Debugger, '', |
| 46 this._eventListeners = | 45 true /* isServiceProject */); |
| 47 [debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCle
ared, this._debuggerReset, this)]; | 46 this._eventListeners = [ |
| 47 debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleare
d, this._debuggerReset, this), |
| 48 debuggerModel.addEventListener(SDK.DebuggerModel.Events.ParsedScriptSource
, this._parsedScriptSource, this), |
| 49 debuggerModel.addEventListener( |
| 50 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedScript
Source, this), |
| 51 debuggerModel.addEventListener( |
| 52 SDK.DebuggerModel.Events.DiscardedAnonymousScriptSource, this._discard
edScriptSource, this) |
| 53 ]; |
| 48 } | 54 } |
| 49 | 55 |
| 50 /** | 56 /** |
| 51 * @param {!Workspace.UISourceCode} uiSourceCode | 57 * @param {!Workspace.UISourceCode} uiSourceCode |
| 52 * @return {?SDK.Script} | 58 * @return {?SDK.Script} |
| 53 */ | 59 */ |
| 54 static scriptForUISourceCode(uiSourceCode) { | 60 static scriptForUISourceCode(uiSourceCode) { |
| 55 return uiSourceCode[Bindings.DefaultScriptMapping._scriptSymbol] || null; | 61 return uiSourceCode[Bindings.DefaultScriptMapping._scriptSymbol] || null; |
| 56 } | 62 } |
| 57 | 63 |
| 58 /** | 64 /** |
| 59 * @param {!SDK.Target} target | |
| 60 * @return {string} | |
| 61 */ | |
| 62 static projectIdForTarget(target) { | |
| 63 return 'debugger:' + target.id(); | |
| 64 } | |
| 65 | |
| 66 /** | |
| 67 * @override | 65 * @override |
| 68 * @param {!SDK.DebuggerModel.Location} rawLocation | 66 * @param {!SDK.DebuggerModel.Location} rawLocation |
| 69 * @return {?Workspace.UILocation} | 67 * @return {?Workspace.UILocation} |
| 70 */ | 68 */ |
| 71 rawLocationToUILocation(rawLocation) { | 69 rawLocationToUILocation(rawLocation) { |
| 72 var script = rawLocation.script(); | 70 var script = rawLocation.script(); |
| 73 if (!script) | 71 if (!script) |
| 74 return null; | 72 return null; |
| 75 var uiSourceCode = script[Bindings.DefaultScriptMapping._uiSourceCodeSymbol]
; | 73 var uiSourceCode = script[Bindings.DefaultScriptMapping._uiSourceCodeSymbol]
; |
| 76 var lineNumber = rawLocation.lineNumber - (script.isInlineScriptWithSourceUR
L() ? script.lineOffset : 0); | 74 var lineNumber = rawLocation.lineNumber - (script.isInlineScriptWithSourceUR
L() ? script.lineOffset : 0); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 92 if (!script) | 90 if (!script) |
| 93 return null; | 91 return null; |
| 94 if (script.isInlineScriptWithSourceURL()) { | 92 if (script.isInlineScriptWithSourceURL()) { |
| 95 return this._debuggerModel.createRawLocation( | 93 return this._debuggerModel.createRawLocation( |
| 96 script, lineNumber + script.lineOffset, lineNumber ? columnNumber : co
lumnNumber + script.columnOffset); | 94 script, lineNumber + script.lineOffset, lineNumber ? columnNumber : co
lumnNumber + script.columnOffset); |
| 97 } | 95 } |
| 98 return this._debuggerModel.createRawLocation(script, lineNumber, columnNumbe
r); | 96 return this._debuggerModel.createRawLocation(script, lineNumber, columnNumbe
r); |
| 99 } | 97 } |
| 100 | 98 |
| 101 /** | 99 /** |
| 102 * @param {!SDK.Script} script | 100 * @param {!Common.Event} event |
| 103 */ | 101 */ |
| 104 addScript(script) { | 102 _parsedScriptSource(event) { |
| 103 var script = /** @type {!SDK.Script} */ (event.data); |
| 105 var name = Common.ParsedURL.extractName(script.sourceURL); | 104 var name = Common.ParsedURL.extractName(script.sourceURL); |
| 106 var url = 'debugger:///VM' + script.scriptId + (name ? ' ' + name : ''); | 105 var url = 'debugger:///VM' + script.scriptId + (name ? ' ' + name : ''); |
| 107 | 106 |
| 108 var uiSourceCode = this._project.createUISourceCode(url, Common.resourceType
s.Script); | 107 var uiSourceCode = this._project.createUISourceCode(url, Common.resourceType
s.Script); |
| 109 uiSourceCode[Bindings.DefaultScriptMapping._scriptSymbol] = script; | 108 uiSourceCode[Bindings.DefaultScriptMapping._scriptSymbol] = script; |
| 110 script[Bindings.DefaultScriptMapping._uiSourceCodeSymbol] = uiSourceCode; | 109 script[Bindings.DefaultScriptMapping._uiSourceCodeSymbol] = uiSourceCode; |
| 111 this._project.addUISourceCodeWithProvider(uiSourceCode, script, null, 'text/
javascript'); | 110 this._project.addUISourceCodeWithProvider(uiSourceCode, script, null, 'text/
javascript'); |
| 112 this._debuggerWorkspaceBinding.updateLocations(script); | 111 this._debuggerWorkspaceBinding.updateLocations(script); |
| 113 } | 112 } |
| 114 | 113 |
| 115 /** | 114 /** |
| 116 * @param {!SDK.Script} script | 115 * @param {!Common.Event} event |
| 117 */ | 116 */ |
| 118 removeScript(script) { | 117 _discardedScriptSource(event) { |
| 118 var script = /** @type {!SDK.Script} */ (event.data); |
| 119 var uiSourceCode = script[Bindings.DefaultScriptMapping._uiSourceCodeSymbol]
; | 119 var uiSourceCode = script[Bindings.DefaultScriptMapping._uiSourceCodeSymbol]
; |
| 120 if (!uiSourceCode) | 120 if (!uiSourceCode) |
| 121 return; | 121 return; |
| 122 delete script[Bindings.DefaultScriptMapping._uiSourceCodeSymbol]; | 122 delete script[Bindings.DefaultScriptMapping._uiSourceCodeSymbol]; |
| 123 delete uiSourceCode[Bindings.DefaultScriptMapping._scriptSymbol]; | 123 delete uiSourceCode[Bindings.DefaultScriptMapping._scriptSymbol]; |
| 124 this._project.removeUISourceCode(uiSourceCode.url()); | 124 this._project.removeUISourceCode(uiSourceCode.url()); |
| 125 } | 125 } |
| 126 | 126 |
| 127 _debuggerReset() { | 127 _debuggerReset() { |
| 128 this._project.reset(); | 128 this._project.reset(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 dispose() { | 131 dispose() { |
| 132 Common.EventTarget.removeEventListeners(this._eventListeners); | 132 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 133 this._debuggerReset(); | 133 this._debuggerReset(); |
| 134 this._project.dispose(); | 134 this._project.dispose(); |
| 135 } | 135 } |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 Bindings.DefaultScriptMapping._scriptSymbol = Symbol('symbol'); | 138 Bindings.DefaultScriptMapping._scriptSymbol = Symbol('symbol'); |
| 139 Bindings.DefaultScriptMapping._uiSourceCodeSymbol = Symbol('uiSourceCodeSymbol')
; | 139 Bindings.DefaultScriptMapping._uiSourceCodeSymbol = Symbol('uiSourceCodeSymbol')
; |
| OLD | NEW |