Changeset 243727 in webkit
- Timestamp:
- Apr 1, 2019, 5:20:11 PM (7 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 6 edited
-
ChangeLog (modified) (1 diff)
-
UserInterface/Controllers/DebuggerManager.js (modified) (10 diffs)
-
UserInterface/Models/Breakpoint.js (modified) (6 diffs)
-
UserInterface/Models/BreakpointAction.js (modified) (2 diffs)
-
UserInterface/Views/DebuggerSidebarPanel.js (modified) (1 diff)
-
UserInterface/Views/SourceCodeTextEditor.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r243722 r243727 1 2019-04-01 Devin Rousso <drousso@apple.com> 2 3 Web Inspector: Debugger: modernize serialization of breakpoints and the maps that hold them 4 https://bugs.webkit.org/show_bug.cgi?id=196230 5 <rdar://problem/49236485> 6 7 Reviewed by Joseph Pecoraro. 8 9 * UserInterface/Controllers/DebuggerManager.js: 10 (WI.DebuggerManager): 11 (WI.DebuggerManager.prototype.breakpointsForSourceCode): 12 (WI.DebuggerManager.prototype.addBreakpoint): 13 (WI.DebuggerManager.prototype.removeBreakpoint): 14 (WI.DebuggerManager.prototype._setBreakpoint): 15 (WI.DebuggerManager.prototype._setBreakpoint.didSetBreakpoint): 16 17 * UserInterface/Models/Breakpoint.js: 18 (WI.Breakpoint): 19 (WI.Breakpoint.fromJSON): Added. 20 (WI.Breakpoint.prototype.toJSON): 21 (WI.Breakpoint.prototype.set resolved): 22 (WI.Breakpoint.prototype.recreateAction): 23 (WI.Breakpoint.prototype.saveIdentityToCookie): 24 (WI.Breakpoint.prototype._isSpecial): Added. 25 (WI.Breakpoint.set resolved.isSpecialBreakpoint): Deleted. 26 (WI.Breakpoint.serializeOptions): Deleted. 27 28 * UserInterface/Models/BreakpointAction.js: 29 (WI.BreakpointAction): 30 (WI.BreakpointAction.fromJSON): Added. 31 (WI.BreakpointAction.prototype.toProtocol): Added. 32 33 * UserInterface/Views/DebuggerSidebarPanel.js: 34 (WI.DebuggerSidebarPanel.prototype._addBreakpointsForSourceCode): 35 36 * UserInterface/Views/SourceCodeTextEditor.js: 37 (WI.SourceCodeTextEditor.prototype._prepareEditorForInitialContent): 38 (WI.SourceCodeTextEditor.prototype._breakpointsEnabledDidChange): 39 1 40 2019-04-01 Devin Rousso <drousso@apple.com> 2 41 -
trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js
r243226 r243727 59 59 let specialBreakpointLocation = new WI.SourceCodeLocation(null, Infinity, Infinity); 60 60 61 this._allExceptionsBreakpoint = new WI.Breakpoint(specialBreakpointLocation, !this._allExceptionsBreakpointEnabledSetting.value); 61 this._allExceptionsBreakpoint = new WI.Breakpoint(specialBreakpointLocation, { 62 disabled: !this._allExceptionsBreakpointEnabledSetting.value, 63 }); 62 64 this._allExceptionsBreakpoint.resolved = true; 63 65 64 this._uncaughtExceptionsBreakpoint = new WI.Breakpoint(specialBreakpointLocation, !this._uncaughtExceptionsBreakpointEnabledSetting.value); 65 66 this._assertionFailuresBreakpoint = new WI.Breakpoint(specialBreakpointLocation, !this._assertionFailuresBreakpointEnabledSetting.value); 66 this._uncaughtExceptionsBreakpoint = new WI.Breakpoint(specialBreakpointLocation, { 67 disabled: !this._uncaughtExceptionsBreakpointEnabledSetting.value, 68 }); 69 this._uncaughtExceptionsBreakpoint.resolved = true; 70 71 this._assertionFailuresBreakpoint = new WI.Breakpoint(specialBreakpointLocation, { 72 disabled: !this._assertionFailuresBreakpointEnabledSetting.value, 73 }); 67 74 this._assertionFailuresBreakpoint.resolved = true; 68 75 69 76 this._breakpoints = []; 70 this._breakpointContentIdentifierMap = new M ap;71 this._breakpointScriptIdentifierMap = new M ap;77 this._breakpointContentIdentifierMap = new Multimap; 78 this._breakpointScriptIdentifierMap = new Multimap; 72 79 this._breakpointIdMap = new Map; 73 80 … … 104 111 if (existingSerializedBreakpoints) { 105 112 for (let existingSerializedBreakpoint of existingSerializedBreakpoints) 106 await WI.objectStores.breakpoints.putObject( new WI.Breakpoint(existingSerializedBreakpoint));113 await WI.objectStores.breakpoints.putObject(WI.Breakpoint.fromJSON(existingSerializedBreakpoint)); 107 114 } 108 115 … … 111 118 this._restoringBreakpoints = true; 112 119 for (let serializedBreakpoint of serializedBreakpoints) { 113 let breakpoint = new WI.Breakpoint(serializedBreakpoint);120 let breakpoint = WI.Breakpoint.fromJSON(serializedBreakpoint); 114 121 115 122 const key = null; … … 212 219 console.assert(sourceCode instanceof WI.Resource || sourceCode instanceof WI.Script); 213 220 214 if (sourceCode instanceof WI.SourceMapResource) { 215 let originalSourceCodeBreakpoints = this.breakpointsForSourceCode(sourceCode.sourceMap.originalSourceCode); 216 return originalSourceCodeBreakpoints.filter(function(breakpoint) { 217 return breakpoint.sourceCodeLocation.displaySourceCode === sourceCode; 218 }); 219 } 221 if (sourceCode instanceof WI.SourceMapResource) 222 return Array.from(this.breakpointsForSourceCode(sourceCode.sourceMap.originalSourceCode)).filter((breakpoint) => breakpoint.sourceCodeLocation.displaySourceCode === sourceCode); 220 223 221 224 let contentIdentifierBreakpoints = this._breakpointContentIdentifierMap.get(sourceCode.contentIdentifier); … … 481 484 } 482 485 483 if (breakpoint.contentIdentifier) { 484 let contentIdentifierBreakpoints = this._breakpointContentIdentifierMap.get(breakpoint.contentIdentifier); 485 if (!contentIdentifierBreakpoints) { 486 contentIdentifierBreakpoints = []; 487 this._breakpointContentIdentifierMap.set(breakpoint.contentIdentifier, contentIdentifierBreakpoints); 488 } 489 contentIdentifierBreakpoints.push(breakpoint); 490 } 491 492 if (breakpoint.scriptIdentifier) { 493 let scriptIdentifierBreakpoints = this._breakpointScriptIdentifierMap.get(breakpoint.scriptIdentifier); 494 if (!scriptIdentifierBreakpoints) { 495 scriptIdentifierBreakpoints = []; 496 this._breakpointScriptIdentifierMap.set(breakpoint.scriptIdentifier, scriptIdentifierBreakpoints); 497 } 498 scriptIdentifierBreakpoints.push(breakpoint); 499 } 486 if (breakpoint.contentIdentifier) 487 this._breakpointContentIdentifierMap.add(breakpoint.contentIdentifier, breakpoint); 488 489 if (breakpoint.scriptIdentifier) 490 this._breakpointScriptIdentifierMap.add(breakpoint.scriptIdentifier, breakpoint); 500 491 501 492 this._breakpoints.push(breakpoint); … … 538 529 this._removeBreakpoint(breakpoint); 539 530 540 if (breakpoint.contentIdentifier) { 541 let contentIdentifierBreakpoints = this._breakpointContentIdentifierMap.get(breakpoint.contentIdentifier); 542 if (contentIdentifierBreakpoints) { 543 contentIdentifierBreakpoints.remove(breakpoint); 544 if (!contentIdentifierBreakpoints.length) 545 this._breakpointContentIdentifierMap.delete(breakpoint.contentIdentifier); 546 } 547 } 548 549 if (breakpoint.scriptIdentifier) { 550 let scriptIdentifierBreakpoints = this._breakpointScriptIdentifierMap.get(breakpoint.scriptIdentifier); 551 if (scriptIdentifierBreakpoints) { 552 scriptIdentifierBreakpoints.remove(breakpoint); 553 if (!scriptIdentifierBreakpoints.length) 554 this._breakpointScriptIdentifierMap.delete(breakpoint.scriptIdentifier); 555 } 556 } 531 if (breakpoint.contentIdentifier) 532 this._breakpointContentIdentifierMap.delete(breakpoint.contentIdentifier, breakpoint); 533 534 if (breakpoint.scriptIdentifier) 535 this._breakpointScriptIdentifierMap.delete(breakpoint.scriptIdentifier, breakpoint); 557 536 558 537 // Disable the breakpoint first, so removing actions doesn't re-add the breakpoint. … … 904 883 _debuggerBreakpointOptions(breakpoint) 905 884 { 906 const templatePlaceholderRegex = /\$\{.*?\}/; 907 908 let options = breakpoint.serializeOptions(); 909 options.actions = options.actions.filter((action) => { 885 let actions = breakpoint.actions; 886 actions = actions.map((action) => action.toProtocol()); 887 actions = actions.filter((action) => { 910 888 if (action.type !== WI.BreakpointAction.Type.Log) 911 889 return true; 912 890 913 if (! templatePlaceholderRegex.test(action.data))891 if (!/\$\{.*?\}/.test(action.data)) 914 892 return true; 915 893 … … 931 909 return true; 932 910 }); 933 return options; 911 912 return { 913 condition: breakpoint.condition, 914 ignoreCount: breakpoint.ignoreCount, 915 autoContinue: breakpoint.autoContinue, 916 actions, 917 }; 934 918 } 935 919 … … 947 931 } 948 932 949 function didSetBreakpoint(target, error, breakpointIdentifier, locations) 950 {951 if (error)933 function didSetBreakpoint(target, error, breakpointIdentifier, locations) { 934 if (error) { 935 WI.reportInternalError(error); 952 936 return; 937 } 953 938 954 939 this._breakpointIdMap.set(breakpointIdentifier, breakpoint); … … 996 981 options 997 982 }, didSetBreakpoint.bind(this, target), target.DebuggerAgent); 998 } 983 } else 984 WI.reportInternalError("Unknown source for breakpoint."); 999 985 } 1000 986 -
trunk/Source/WebInspectorUI/UserInterface/Models/Breakpoint.js
r243226 r243727 26 26 WI.Breakpoint = class Breakpoint extends WI.Object 27 27 { 28 constructor(sourceCodeLocationOrInfo, disabled, condition) 29 { 28 constructor(sourceCodeLocation, {contentIdentifier, disabled, condition, ignoreCount, autoContinue} = {}) 29 { 30 console.assert(sourceCodeLocation instanceof WI.SourceCodeLocation); 31 console.assert(!contentIdentifier || typeof contentIdentifier === "string"); 32 console.assert(!disabled || typeof disabled === "boolean"); 33 console.assert(!condition || typeof condition === "string"); 34 console.assert(!ignoreCount || !isNaN(ignoreCount)); 35 console.assert(!autoContinue || typeof autoContinue === "boolean"); 36 30 37 super(); 31 38 32 if (sourceCodeLocationOrInfo instanceof WI.SourceCodeLocation) { 33 var sourceCode = sourceCodeLocationOrInfo.sourceCode; 34 var contentIdentifier = sourceCode ? sourceCode.contentIdentifier : null; 35 var scriptIdentifier = sourceCode instanceof WI.Script ? sourceCode.id : null; 36 var target = sourceCode instanceof WI.Script ? sourceCode.target : null; 37 var location = sourceCodeLocationOrInfo; 38 } else if (sourceCodeLocationOrInfo && typeof sourceCodeLocationOrInfo === "object") { 39 // The 'url' fallback is for transitioning from older frontends and should be removed. 40 var contentIdentifier = sourceCodeLocationOrInfo.contentIdentifier || sourceCodeLocationOrInfo.url; 41 var lineNumber = sourceCodeLocationOrInfo.lineNumber || 0; 42 var columnNumber = sourceCodeLocationOrInfo.columnNumber || 0; 43 var location = new WI.SourceCodeLocation(null, lineNumber, columnNumber); 44 var ignoreCount = sourceCodeLocationOrInfo.ignoreCount || 0; 45 var autoContinue = sourceCodeLocationOrInfo.autoContinue || false; 46 var actions = sourceCodeLocationOrInfo.actions || []; 47 for (var i = 0; i < actions.length; ++i) 48 actions[i] = new WI.BreakpointAction(this, actions[i]); 49 disabled = sourceCodeLocationOrInfo.disabled; 50 condition = sourceCodeLocationOrInfo.condition; 39 this._id = null; 40 this._sourceCodeLocation = sourceCodeLocation; 41 42 let sourceCode = this._sourceCodeLocation.sourceCode; 43 if (sourceCode) { 44 this._contentIdentifier = sourceCode.contentIdentifier; 45 console.assert(!contentIdentifier || contentIdentifier === this._contentIdentifier, "The content identifier from the source code should match the given value."); 51 46 } else 52 console.error("Unexpected type passed to WI.Breakpoint", sourceCodeLocationOrInfo); 53 54 this._id = null; 55 this._contentIdentifier = contentIdentifier || null; 56 this._scriptIdentifier = scriptIdentifier || null; 57 this._target = target || null; 47 this._contentIdentifier = contentIdentifier || null; 48 console.assert(this._contentIdentifier || this._isSpecial(), "There should always be a content identifier for a breakpoint."); 49 50 this._scriptIdentifier = sourceCode instanceof WI.Script ? sourceCode.id : null; 51 this._target = sourceCode instanceof WI.Script ? sourceCode.target : null; 58 52 this._disabled = disabled || false; 59 53 this._condition = condition || ""; 60 54 this._ignoreCount = ignoreCount || 0; 61 55 this._autoContinue = autoContinue || false; 62 this._actions = actions ||[];56 this._actions = []; 63 57 this._resolved = false; 64 58 65 this._sourceCodeLocation = location;66 59 this._sourceCodeLocation.addEventListener(WI.SourceCodeLocation.Event.LocationChanged, this._sourceCodeLocationLocationChanged, this); 67 60 this._sourceCodeLocation.addEventListener(WI.SourceCodeLocation.Event.DisplayLocationChanged, this._sourceCodeLocationDisplayLocationChanged, this); 68 61 } 69 62 63 // Import / Export 64 65 static fromJSON(json) 66 { 67 const sourceCode = null; 68 let breakpoint = new Breakpoint(new WI.SourceCodeLocation(sourceCode, json.lineNumber || 0, json.columnNumber || 0), { 69 // The 'url' fallback is for transitioning from older frontends and should be removed. 70 contentIdentifier: json.contentIdentifier || json.url, 71 disabled: json.disabled, 72 condition: json.condition, 73 ignoreCount: json.ignoreCount, 74 autoContinue: json.autoContinue, 75 }); 76 breakpoint._actions = json.actions.map((actionJSON) => WI.BreakpointAction.fromJSON(actionJSON, breakpoint)); 77 return breakpoint; 78 } 79 80 toJSON(key) 81 { 82 // The id, scriptIdentifier, target, and resolved state are tied to the current session, so don't include them for serialization. 83 let json = { 84 contentIdentifier: this._contentIdentifier, 85 lineNumber: this._sourceCodeLocation.lineNumber, 86 columnNumber: this._sourceCodeLocation.columnNumber, 87 disabled: this._disabled, 88 condition: this._condition, 89 ignoreCount: this._ignoreCount, 90 actions: this._actions.map((action) => action.toJSON()), 91 autoContinue: this._autoContinue, 92 }; 93 if (key === WI.ObjectStore.toJSONSymbol) 94 json[WI.objectStores.breakpoints.keyPath] = this._contentIdentifier + ":" + this._sourceCodeLocation.lineNumber + ":" + this._sourceCodeLocation.columnNumber; 95 return json; 96 } 97 70 98 // Public 71 99 100 get sourceCodeLocation() { return this._sourceCodeLocation; } 101 get contentIdentifier() { return this._contentIdentifier; } 102 get scriptIdentifier() { return this._scriptIdentifier; } 103 get target() { return this._target; } 104 72 105 get identifier() 73 106 { … … 80 113 } 81 114 82 get contentIdentifier()83 {84 return this._contentIdentifier;85 }86 87 get scriptIdentifier()88 {89 return this._scriptIdentifier;90 }91 92 get target()93 {94 return this._target;95 }96 97 get sourceCodeLocation()98 {99 return this._sourceCodeLocation;100 }101 102 115 get resolved() 103 116 { … … 110 123 return; 111 124 112 function isSpecialBreakpoint() 113 { 114 return this._sourceCodeLocation.isEqual(new WI.SourceCodeLocation(null, Infinity, Infinity)); 115 } 116 117 console.assert(!resolved || this._sourceCodeLocation.sourceCode || isSpecialBreakpoint.call(this), "Breakpoints must have a SourceCode to be resolved.", this); 125 console.assert(!resolved || this._sourceCodeLocation.sourceCode || this._isSpecial(), "Breakpoints must have a SourceCode to be resolved.", this); 118 126 119 127 this._resolved = resolved || false; … … 242 250 recreateAction(type, actionToReplace) 243 251 { 244 var newAction = new WI.BreakpointAction(this, type, null); 245 246 var index = this._actions.indexOf(actionToReplace); 252 let index = this._actions.indexOf(actionToReplace); 247 253 console.assert(index !== -1); 248 254 if (index === -1) 249 255 return null; 250 256 251 this._actions[index] = newAction; 252 253 this.dispatchEventToListeners(WI.Breakpoint.Event.ActionsDidChange); 254 255 return newAction; 257 const data = null; 258 let action = new WI.BreakpointAction(this, type, data); 259 this._actions[index] = action; 260 261 this.dispatchEventToListeners(WI.Breakpoint.Event.ActionsDidChange); 262 263 return action; 256 264 } 257 265 … … 283 291 saveIdentityToCookie(cookie) 284 292 { 285 cookie["breakpoint-content-identifier"] = this.contentIdentifier; 286 cookie["breakpoint-line-number"] = this.sourceCodeLocation.lineNumber; 287 cookie["breakpoint-column-number"] = this.sourceCodeLocation.columnNumber; 288 } 289 290 serializeOptions() 291 { 292 return { 293 condition: this._condition, 294 ignoreCount: this._ignoreCount, 295 actions: this._actions.map((action) => action.toJSON()), 296 autoContinue: this._autoContinue, 297 }; 298 } 299 300 toJSON(key) 301 { 302 // The id, scriptIdentifier, target, and resolved state are tied to the current session, so don't include them for serialization. 303 let json = { 304 contentIdentifier: this._contentIdentifier, 305 lineNumber: this._sourceCodeLocation.lineNumber, 306 columnNumber: this._sourceCodeLocation.columnNumber, 307 disabled: this._disabled, 308 ...this.serializeOptions(), 309 }; 310 if (key === WI.ObjectStore.toJSONSymbol) 311 json[WI.objectStores.breakpoints.keyPath] = this._contentIdentifier + ":" + this._sourceCodeLocation.lineNumber + ":" + this._sourceCodeLocation.columnNumber; 312 return json; 293 cookie["breakpoint-content-identifier"] = this._contentIdentifier; 294 cookie["breakpoint-line-number"] = this._sourceCodeLocation.lineNumber; 295 cookie["breakpoint-column-number"] = this._sourceCodeLocation.columnNumber; 313 296 } 314 297 … … 326 309 327 310 // Private 311 312 _isSpecial() 313 { 314 return this._sourceCodeLocation.isEqual(new WI.SourceCodeLocation(null, Infinity, Infinity)); 315 } 328 316 329 317 _sourceCodeLocationLocationChanged(event) -
trunk/Source/WebInspectorUI/UserInterface/Models/BreakpointAction.js
r243226 r243727 26 26 WI.BreakpointAction = class BreakpointAction 27 27 { 28 constructor(breakpoint, type OrInfo, data)28 constructor(breakpoint, type, data) 29 29 { 30 console.assert(breakpoint );31 console.assert( typeOrInfo);30 console.assert(breakpoint instanceof WI.Breakpoint); 31 console.assert(Object.values(WI.BreakpointAction.Type).includes(type)); 32 32 33 33 this._breakpoint = breakpoint; 34 this._type = type; 35 this._data = data || null; 36 this._id = WI.debuggerManager.nextBreakpointActionIdentifier(); 37 } 34 38 35 if (typeof typeOrInfo === "string") { 36 this._type = typeOrInfo; 37 this._data = data || null; 38 } else if (typeof typeOrInfo === "object") { 39 this._type = typeOrInfo.type; 40 this._data = typeOrInfo.data || null; 41 } else 42 console.error("Unexpected type passed to WI.BreakpointAction"); 39 // Import / Export 43 40 44 console.assert(typeof this._type === "string"); 45 this._id = WI.debuggerManager.nextBreakpointActionIdentifier(); 41 static fromJSON(json, breakpoint) 42 { 43 return new BreakpointAction(breakpoint, json.type, json.data); 44 } 45 46 toJSON() 47 { 48 let json = { 49 type: this._type, 50 }; 51 if (this._data) 52 json.data = this._data; 53 return json; 46 54 } 47 55 … … 67 75 } 68 76 69 to JSON()77 toProtocol() 70 78 { 71 let json = { 72 type: this._type, 73 id: this._id, 74 }; 75 if (this._data) 76 json.data = this._data; 79 let json = this.toJSON(); 80 json.id = this._id; 77 81 return json; 78 82 } -
trunk/Source/WebInspectorUI/UserInterface/Views/DebuggerSidebarPanel.js
r243715 r243727 561 561 _addBreakpointsForSourceCode(sourceCode) 562 562 { 563 var breakpoints = WI.debuggerManager.breakpointsForSourceCode(sourceCode); 564 for (var i = 0; i < breakpoints.length; ++i) 565 this._addBreakpoint(breakpoints[i], sourceCode); 563 for (let breakpoint of WI.debuggerManager.breakpointsForSourceCode(sourceCode)) 564 this._addBreakpoint(breakpoint, sourceCode); 566 565 } 567 566 -
trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js
r242049 r243727 500 500 this._breakpointMap = {}; 501 501 502 var breakpoints = WI.debuggerManager.breakpointsForSourceCode(this._sourceCode); 503 for (var i = 0; i < breakpoints.length; ++i) { 504 var breakpoint = breakpoints[i]; 502 for (let breakpoint of WI.debuggerManager.breakpointsForSourceCode(this._sourceCode)) { 505 503 console.assert(this._matchesBreakpoint(breakpoint)); 506 504 var lineInfo = this._editorLineInfoForSourceCodeLocation(breakpoint.sourceCodeLocation); … … 563 561 console.assert(this._supportsDebugging); 564 562 565 var breakpoints = WI.debuggerManager.breakpointsForSourceCode(this._sourceCode); 566 for (var breakpoint of breakpoints) 563 for (let breakpoint of WI.debuggerManager.breakpointsForSourceCode(this._sourceCode)) 567 564 this._updateBreakpointStatus(breakpoint); 568 565 }
Note:
See TracChangeset
for help on using the changeset viewer.