Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/DebuggerModel.js

Issue 2795193003: DevTools: carefully cleanup script UISourceCodes (Closed)
Patch Set: address comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 this._agent = target.debuggerAgent(); 42 this._agent = target.debuggerAgent();
43 this._runtimeModel = /** @type {!SDK.RuntimeModel} */ (target.model(SDK.Runt imeModel)); 43 this._runtimeModel = /** @type {!SDK.RuntimeModel} */ (target.model(SDK.Runt imeModel));
44 44
45 /** @type {!SDK.SourceMapManager<!SDK.Script>} */ 45 /** @type {!SDK.SourceMapManager<!SDK.Script>} */
46 this._sourceMapManager = new SDK.SourceMapManager(target); 46 this._sourceMapManager = new SDK.SourceMapManager(target);
47 /** @type {!Map<string, !SDK.Script>} */ 47 /** @type {!Map<string, !SDK.Script>} */
48 this._sourceMapIdToScript = new Map(); 48 this._sourceMapIdToScript = new Map();
49 49
50 /** @type {?SDK.DebuggerPausedDetails} */ 50 /** @type {?SDK.DebuggerPausedDetails} */
51 this._debuggerPausedDetails = null; 51 this._debuggerPausedDetails = null;
52 /** @type {!Object.<string, !SDK.Script>} */ 52 /** @type {!Map<string, !SDK.Script>} */
53 this._scripts = {}; 53 this._scripts = new Map();
54 /** @type {!Map.<string, !Array.<!SDK.Script>>} */ 54 /** @type {!Map.<string, !Array.<!SDK.Script>>} */
55 this._scriptsBySourceURL = new Map(); 55 this._scriptsBySourceURL = new Map();
56 /** @type {!Array.<!SDK.Script>} */ 56 /** @type {!Array.<!SDK.Script>} */
57 this._discardableScripts = []; 57 this._discardableScripts = [];
58 58
59 /** @type {!Common.Object} */ 59 /** @type {!Common.Object} */
60 this._breakpointResolvedEventTarget = new Common.Object(); 60 this._breakpointResolvedEventTarget = new Common.Object();
61 61
62 this._isPausing = false; 62 this._isPausing = false;
63 Common.moduleSetting('pauseOnExceptionEnabled').addChangeListener(this._paus eOnExceptionStateChanged, this); 63 Common.moduleSetting('pauseOnExceptionEnabled').addChangeListener(this._paus eOnExceptionStateChanged, this);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 this._reset(); 338 this._reset();
339 // TODO(dgozman): move clients to ExecutionContextDestroyed/ScriptCollected events. 339 // TODO(dgozman): move clients to ExecutionContextDestroyed/ScriptCollected events.
340 this.dispatchEventToListeners(SDK.DebuggerModel.Events.GlobalObjectCleared, this); 340 this.dispatchEventToListeners(SDK.DebuggerModel.Events.GlobalObjectCleared, this);
341 } 341 }
342 342
343 _reset() { 343 _reset() {
344 for (var scriptWithSourceMap of this._sourceMapIdToScript.values()) 344 for (var scriptWithSourceMap of this._sourceMapIdToScript.values())
345 this._sourceMapManager.detachSourceMap(scriptWithSourceMap); 345 this._sourceMapManager.detachSourceMap(scriptWithSourceMap);
346 this._sourceMapIdToScript.clear(); 346 this._sourceMapIdToScript.clear();
347 347
348 this._scripts = {}; 348 this._scripts.clear();
349 this._scriptsBySourceURL.clear(); 349 this._scriptsBySourceURL.clear();
350 this._stringMap.clear(); 350 this._stringMap.clear();
351 this._discardableScripts = []; 351 this._discardableScripts = [];
352 } 352 }
353 353
354 /** 354 /**
355 * @return {!Object.<string, !SDK.Script>} 355 * @return {!Array<!SDK.Script>}
356 */ 356 */
357 get scripts() { 357 scripts() {
358 return this._scripts; 358 return Array.from(this._scripts.values());
359 } 359 }
360 360
361 /** 361 /**
362 * @param {!Protocol.Runtime.ScriptId} scriptId 362 * @param {!Protocol.Runtime.ScriptId} scriptId
363 * @return {?SDK.Script} 363 * @return {?SDK.Script}
364 */ 364 */
365 scriptForId(scriptId) { 365 scriptForId(scriptId) {
366 return this._scripts[scriptId] || null; 366 return this._scripts.get(scriptId) || null;
367 } 367 }
368 368
369 /** 369 /**
370 * @return {!Array.<!SDK.Script>} 370 * @return {!Array.<!SDK.Script>}
371 */ 371 */
372 scriptsForSourceURL(sourceURL) { 372 scriptsForSourceURL(sourceURL) {
373 if (!sourceURL) 373 if (!sourceURL)
374 return []; 374 return [];
375 return this._scriptsBySourceURL.get(sourceURL) || []; 375 return this._scriptsBySourceURL.get(sourceURL) || [];
376 } 376 }
377 377
378 /** 378 /**
379 * @param {!SDK.ExecutionContext} executionContext
380 * @return {!Array<!SDK.Script>}
381 */
382 scriptsForExecutionContext(executionContext) {
383 var result = [];
384 for (var script of this._scripts.values()) {
385 if (script.executionContextId === executionContext.id)
386 result.push(script);
387 }
388 return result;
389 }
390
391 /**
379 * @param {!Protocol.Runtime.ScriptId} scriptId 392 * @param {!Protocol.Runtime.ScriptId} scriptId
380 * @param {string} newSource 393 * @param {string} newSource
381 * @param {function(?Protocol.Error, !Protocol.Runtime.ExceptionDetails=)} cal lback 394 * @param {function(?Protocol.Error, !Protocol.Runtime.ExceptionDetails=)} cal lback
382 */ 395 */
383 setScriptSource(scriptId, newSource, callback) { 396 setScriptSource(scriptId, newSource, callback) {
384 this._scripts[scriptId].editSource(newSource, this._didEditScriptSource.bind (this, scriptId, newSource, callback)); 397 this._scripts.get(scriptId).editSource(
398 newSource, this._didEditScriptSource.bind(this, scriptId, newSource, cal lback));
385 } 399 }
386 400
387 /** 401 /**
388 * @param {!Protocol.Runtime.ScriptId} scriptId 402 * @param {!Protocol.Runtime.ScriptId} scriptId
389 * @param {string} newSource 403 * @param {string} newSource
390 * @param {function(?Protocol.Error, !Protocol.Runtime.ExceptionDetails=)} cal lback 404 * @param {function(?Protocol.Error, !Protocol.Runtime.ExceptionDetails=)} cal lback
391 * @param {?Protocol.Error} error 405 * @param {?Protocol.Error} error
392 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails 406 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails
393 * @param {!Array.<!Protocol.Debugger.CallFrame>=} callFrames 407 * @param {!Array.<!Protocol.Debugger.CallFrame>=} callFrames
394 * @param {!Protocol.Runtime.StackTrace=} asyncStackTrace 408 * @param {!Protocol.Runtime.StackTrace=} asyncStackTrace
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 this._sourceMapIdToScript.delete(sourceMapId); 580 this._sourceMapIdToScript.delete(sourceMapId);
567 this._sourceMapManager.detachSourceMap(script); 581 this._sourceMapManager.detachSourceMap(script);
568 } 582 }
569 } 583 }
570 } 584 }
571 585
572 /** 586 /**
573 * @param {!SDK.Script} script 587 * @param {!SDK.Script} script
574 */ 588 */
575 _registerScript(script) { 589 _registerScript(script) {
576 this._scripts[script.scriptId] = script; 590 this._scripts.set(script.scriptId, script);
577 if (script.isAnonymousScript()) 591 if (script.isAnonymousScript())
578 return; 592 return;
579 593
580 var scripts = this._scriptsBySourceURL.get(script.sourceURL); 594 var scripts = this._scriptsBySourceURL.get(script.sourceURL);
581 if (!scripts) { 595 if (!scripts) {
582 scripts = []; 596 scripts = [];
583 this._scriptsBySourceURL.set(script.sourceURL, scripts); 597 this._scriptsBySourceURL.set(script.sourceURL, scripts);
584 } 598 }
585 scripts.push(script); 599 scripts.push(script);
586 } 600 }
587 601
588 /** 602 /**
589 * @param {!SDK.Script} script 603 * @param {!SDK.Script} script
590 */ 604 */
591 _unregisterScript(script) { 605 _unregisterScript(script) {
592 console.assert(script.isAnonymousScript()); 606 console.assert(script.isAnonymousScript());
593 delete this._scripts[script.scriptId]; 607 this._scripts.delete(script.scriptId);
594 } 608 }
595 609
596 _collectDiscardedScripts() { 610 _collectDiscardedScripts() {
597 if (this._discardableScripts.length < 1000) 611 if (this._discardableScripts.length < 1000)
598 return; 612 return;
599 var scriptsToDiscard = this._discardableScripts.splice(0, 100); 613 var scriptsToDiscard = this._discardableScripts.splice(0, 100);
600 for (var script of scriptsToDiscard) { 614 for (var script of scriptsToDiscard) {
601 this._unregisterScript(script); 615 this._unregisterScript(script);
602 this.dispatchEventToListeners(SDK.DebuggerModel.Events.DiscardedAnonymousS criptSource, script); 616 this.dispatchEventToListeners(SDK.DebuggerModel.Events.DiscardedAnonymousS criptSource, script);
603 } 617 }
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 stack.callFrames.shift(); 1480 stack.callFrames.shift();
1467 if (previous && (!stack.callFrames.length && !stack.promiseCreationFrame)) 1481 if (previous && (!stack.callFrames.length && !stack.promiseCreationFrame))
1468 previous.parent = stack.parent; 1482 previous.parent = stack.parent;
1469 else 1483 else
1470 previous = stack; 1484 previous = stack;
1471 stack = stack.parent; 1485 stack = stack.parent;
1472 } 1486 }
1473 return asyncStackTrace; 1487 return asyncStackTrace;
1474 } 1488 }
1475 }; 1489 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698