breakpoint-actor-map.js (2247B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 loader.lazyRequireGetter( 8 this, 9 "BreakpointActor", 10 "resource://devtools/server/actors/breakpoint.js", 11 true 12 ); 13 14 /** 15 * A BreakpointActorMap is a map from locations to instances of BreakpointActor. 16 */ 17 class BreakpointActorMap { 18 constructor(threadActor) { 19 this._threadActor = threadActor; 20 this._actors = {}; 21 } 22 23 // Get the key in the _actors table for a given breakpoint location. 24 // See also duplicate code in commands.js :( 25 _locationKey(location) { 26 const { sourceUrl, sourceId, line, column } = location; 27 return `${sourceUrl}:${sourceId}:${line}:${column}`; 28 } 29 30 /** 31 * Return all BreakpointActors in this BreakpointActorMap. 32 */ 33 findActors() { 34 return Object.values(this._actors); 35 } 36 37 listKeys() { 38 return Object.keys(this._actors); 39 } 40 41 /** 42 * Return the BreakpointActor at the given location in this 43 * BreakpointActorMap. 44 * 45 * @param BreakpointLocation location 46 * The location for which the BreakpointActor should be returned. 47 * 48 * @returns BreakpointActor actor 49 * The BreakpointActor at the given location. 50 */ 51 getOrCreateBreakpointActor(location) { 52 const key = this._locationKey(location); 53 if (!this._actors[key]) { 54 this._actors[key] = new BreakpointActor(this._threadActor, location); 55 } 56 return this._actors[key]; 57 } 58 59 get(location) { 60 const key = this._locationKey(location); 61 return this._actors[key]; 62 } 63 64 /** 65 * Delete the BreakpointActor from the given location in this 66 * BreakpointActorMap. 67 * 68 * @param BreakpointLocation location 69 * The location from which the BreakpointActor should be deleted. 70 */ 71 deleteActor(location) { 72 const key = this._locationKey(location); 73 delete this._actors[key]; 74 } 75 76 /** 77 * Unregister all currently active breakpoints. 78 */ 79 removeAllBreakpoints() { 80 for (const bpActor of Object.values(this._actors)) { 81 bpActor.removeScripts(); 82 } 83 this._actors = {}; 84 } 85 } 86 87 exports.BreakpointActorMap = BreakpointActorMap;