| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // FIXME: Support live editing of scripts mapped to some file. | 56 // FIXME: Support live editing of scripts mapped to some file. |
| 57 if (uiLocation.uiSourceCode !== uiSourceCode) | 57 if (uiLocation.uiSourceCode !== uiSourceCode) |
| 58 return uiLocation.uiSourceCode; | 58 return uiLocation.uiSourceCode; |
| 59 if (this._uiSourceCodeForScriptId[script.scriptId]) | 59 if (this._uiSourceCodeForScriptId[script.scriptId]) |
| 60 return this._uiSourceCodeForScriptId[script.scriptId]; | 60 return this._uiSourceCodeForScriptId[script.scriptId]; |
| 61 | 61 |
| 62 console.assert(!script.isInlineScript()); | 62 console.assert(!script.isInlineScript()); |
| 63 var path = this._projectDelegate.addScript(script, true); | 63 var path = this._projectDelegate.addScript(script, true); |
| 64 var liveEditUISourceCode = this._workspace.uiSourceCode(this._projectId,
path); | 64 var liveEditUISourceCode = this._workspace.uiSourceCode(this._projectId,
path); |
| 65 | 65 |
| 66 liveEditUISourceCode.setScriptFile(new WebInspector.LiveEditScriptFile(u
iSourceCode, liveEditUISourceCode, script.scriptId)); | 66 liveEditUISourceCode.addEventListener(WebInspector.UISourceCode.Events.W
orkingCopyCommitted, this._workingCopyCommitted, this); |
| 67 this._uiSourceCodeForScriptId[script.scriptId] = liveEditUISourceCode; | 67 this._uiSourceCodeForScriptId[script.scriptId] = liveEditUISourceCode; |
| 68 this._scriptIdForUISourceCode.put(liveEditUISourceCode, script.scriptId)
; | 68 this._scriptIdForUISourceCode.put(liveEditUISourceCode, script.scriptId)
; |
| 69 return liveEditUISourceCode; | 69 return liveEditUISourceCode; |
| 70 }, | 70 }, |
| 71 | 71 |
| 72 _debuggerReset: function() | 72 _debuggerReset: function() |
| 73 { | 73 { |
| 74 /** @type {!Object.<string, !WebInspector.UISourceCode>} */ | 74 /** @type {!Object.<string, !WebInspector.UISourceCode>} */ |
| 75 this._uiSourceCodeForScriptId = {}; | 75 this._uiSourceCodeForScriptId = {}; |
| 76 /** @type {!Map.<!WebInspector.UISourceCode, string>} */ | 76 /** @type {!Map.<!WebInspector.UISourceCode, string>} */ |
| 77 this._scriptIdForUISourceCode = new Map(); | 77 this._scriptIdForUISourceCode = new Map(); |
| 78 this._projectDelegate.reset(); | 78 this._projectDelegate.reset(); |
| 79 }, | 79 }, |
| 80 |
| 81 /** |
| 82 * @param {!WebInspector.Event} event |
| 83 */ |
| 84 _workingCopyCommitted: function(event) |
| 85 { |
| 86 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.targ
et); |
| 87 var scriptId = /** @type {string} */ (this._scriptIdForUISourceCode.get(
uiSourceCode)); |
| 88 WebInspector.debuggerModel.setScriptSource(scriptId, uiSourceCode.workin
gCopy(), innerCallback); |
| 89 |
| 90 /** |
| 91 * @param {?string} error |
| 92 * @param {!DebuggerAgent.SetScriptSourceError=} errorData |
| 93 */ |
| 94 function innerCallback(error, errorData) |
| 95 { |
| 96 if (error) { |
| 97 var script = WebInspector.debuggerModel.scriptForId(scriptId); |
| 98 WebInspector.LiveEditSupport.logDetailedError(error, errorData,
script); |
| 99 return; |
| 100 } |
| 101 WebInspector.LiveEditSupport.logSuccess(); |
| 102 } |
| 103 } |
| 80 } | 104 } |
| 81 | 105 |
| 82 /** | 106 /** |
| 83 * @param {?string} error | 107 * @param {?string} error |
| 84 * @param {!DebuggerAgent.SetScriptSourceError=} errorData | 108 * @param {!DebuggerAgent.SetScriptSourceError=} errorData |
| 85 * @param {!WebInspector.Script=} contextScript | 109 * @param {!WebInspector.Script=} contextScript |
| 86 */ | 110 */ |
| 87 WebInspector.LiveEditSupport.logDetailedError = function(error, errorData, conte
xtScript) | 111 WebInspector.LiveEditSupport.logDetailedError = function(error, errorData, conte
xtScript) |
| 88 { | 112 { |
| 89 var warningLevel = WebInspector.ConsoleMessage.MessageLevel.Warning; | 113 var warningLevel = WebInspector.ConsoleMessage.MessageLevel.Warning; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 100 } else { | 124 } else { |
| 101 WebInspector.console.log(WebInspector.UIString("Unknown LiveEdit error:
%s; %s", JSON.stringify(errorData), error), warningLevel, false); | 125 WebInspector.console.log(WebInspector.UIString("Unknown LiveEdit error:
%s; %s", JSON.stringify(errorData), error), warningLevel, false); |
| 102 } | 126 } |
| 103 } | 127 } |
| 104 | 128 |
| 105 WebInspector.LiveEditSupport.logSuccess = function() | 129 WebInspector.LiveEditSupport.logSuccess = function() |
| 106 { | 130 { |
| 107 WebInspector.console.log(WebInspector.UIString("Recompilation and update suc
ceeded."), WebInspector.ConsoleMessage.MessageLevel.Debug, false); | 131 WebInspector.console.log(WebInspector.UIString("Recompilation and update suc
ceeded."), WebInspector.ConsoleMessage.MessageLevel.Debug, false); |
| 108 } | 132 } |
| 109 | 133 |
| 110 /** | |
| 111 * @constructor | |
| 112 * @implements {WebInspector.ScriptFile} | |
| 113 * @extends {WebInspector.Object} | |
| 114 * @param {!WebInspector.UISourceCode} uiSourceCode | |
| 115 * @param {!WebInspector.UISourceCode} liveEditUISourceCode | |
| 116 * @param {string} scriptId | |
| 117 */ | |
| 118 WebInspector.LiveEditScriptFile = function(uiSourceCode, liveEditUISourceCode, s
criptId) | |
| 119 { | |
| 120 WebInspector.ScriptFile.call(this); | |
| 121 this._uiSourceCode = uiSourceCode; | |
| 122 this._liveEditUISourceCode = liveEditUISourceCode; | |
| 123 this._scriptId = scriptId; | |
| 124 this._liveEditUISourceCode.addEventListener(WebInspector.UISourceCode.Events
.WorkingCopyCommitted, this._workingCopyCommitted, this); | |
| 125 } | |
| 126 | |
| 127 WebInspector.LiveEditScriptFile.prototype = { | |
| 128 _workingCopyCommitted: function(event) | |
| 129 { | |
| 130 /** | |
| 131 * @param {?string} error | |
| 132 * @param {!DebuggerAgent.SetScriptSourceError=} errorData | |
| 133 * @this {WebInspector.LiveEditScriptFile} | |
| 134 */ | |
| 135 function innerCallback(error, errorData) | |
| 136 { | |
| 137 if (error) { | |
| 138 var script = WebInspector.debuggerModel.scriptForId(this._script
Id); | |
| 139 WebInspector.LiveEditSupport.logDetailedError(error, errorData,
script); | |
| 140 return; | |
| 141 } | |
| 142 WebInspector.LiveEditSupport.logSuccess(); | |
| 143 } | |
| 144 | |
| 145 var script = WebInspector.debuggerModel.scriptForId(this._scriptId); | |
| 146 WebInspector.debuggerModel.setScriptSource(script.scriptId, this._liveEd
itUISourceCode.workingCopy(), innerCallback.bind(this)); | |
| 147 }, | |
| 148 | |
| 149 /** | |
| 150 * @return {boolean} | |
| 151 */ | |
| 152 hasDivergedFromVM: function() | |
| 153 { | |
| 154 return true; | |
| 155 }, | |
| 156 | |
| 157 /** | |
| 158 * @return {boolean} | |
| 159 */ | |
| 160 isDivergingFromVM: function() | |
| 161 { | |
| 162 return false; | |
| 163 }, | |
| 164 | |
| 165 /** | |
| 166 * @return {boolean} | |
| 167 */ | |
| 168 isMergingToVM: function() | |
| 169 { | |
| 170 return false; | |
| 171 }, | |
| 172 | |
| 173 checkMapping: function() | |
| 174 { | |
| 175 }, | |
| 176 | |
| 177 __proto__: WebInspector.Object.prototype | |
| 178 } | |
| 179 | |
| 180 /** @type {!WebInspector.LiveEditSupport} */ | 134 /** @type {!WebInspector.LiveEditSupport} */ |
| 181 WebInspector.liveEditSupport; | 135 WebInspector.liveEditSupport; |
| OLD | NEW |