| OLD | NEW |
| 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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 * @param {!FrameMirror} frameMirror | 409 * @param {!FrameMirror} frameMirror |
| 410 * @return {!JavaScriptCallFrame} | 410 * @return {!JavaScriptCallFrame} |
| 411 */ | 411 */ |
| 412 DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror) | 412 DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror) |
| 413 { | 413 { |
| 414 // Stuff that can not be initialized lazily (i.e. valid while paused with a
valid break_id). | 414 // Stuff that can not be initialized lazily (i.e. valid while paused with a
valid break_id). |
| 415 // The frameMirror and scopeMirror can be accessed only while paused on the
debugger. | 415 // The frameMirror and scopeMirror can be accessed only while paused on the
debugger. |
| 416 var frameDetails = frameMirror.details(); | 416 var frameDetails = frameMirror.details(); |
| 417 | 417 |
| 418 var funcObject = frameDetails.func(); | 418 var funcObject = frameDetails.func(); |
| 419 var scriptObject = frameDetails.script(); | |
| 420 var sourcePosition = frameDetails.sourcePosition(); | 419 var sourcePosition = frameDetails.sourcePosition(); |
| 421 var thisObject = frameDetails.receiver(); | 420 var thisObject = frameDetails.receiver(); |
| 422 | 421 |
| 423 var isAtReturn = !!frameDetails.isAtReturn(); | 422 var isAtReturn = !!frameDetails.isAtReturn(); |
| 424 var returnValue = isAtReturn ? frameDetails.returnValue() : undefined; | 423 var returnValue = isAtReturn ? frameDetails.returnValue() : undefined; |
| 425 | 424 |
| 426 var scopeMirrors = frameMirror.allScopes(false); | 425 var scopeMirrors = frameMirror.allScopes(false); |
| 427 /** @type {!Array<number>} */ | 426 /** @type {!Array<number>} */ |
| 428 var scopeTypes = new Array(scopeMirrors.length); | 427 var scopeTypes = new Array(scopeMirrors.length); |
| 429 /** @type {?Array<!Object>} */ | 428 /** @type {?Array<!Object>} */ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 442 scopeObjects[i] = scopeDetails.object(); | 441 scopeObjects[i] = scopeDetails.object(); |
| 443 scopeNames[i] = scopeDetails.name(); | 442 scopeNames[i] = scopeDetails.name(); |
| 444 scopeStartPositions[i] = scopeDetails.startPosition ? scopeDetails.start
Position() : 0; | 443 scopeStartPositions[i] = scopeDetails.startPosition ? scopeDetails.start
Position() : 0; |
| 445 scopeEndPositions[i] = scopeDetails.endPosition ? scopeDetails.endPositi
on() : 0; | 444 scopeEndPositions[i] = scopeDetails.endPosition ? scopeDetails.endPositi
on() : 0; |
| 446 scopeFunctions[i] = scopeDetails.func ? scopeDetails.func() : null; | 445 scopeFunctions[i] = scopeDetails.func ? scopeDetails.func() : null; |
| 447 } | 446 } |
| 448 | 447 |
| 449 // Calculated lazily. | 448 // Calculated lazily. |
| 450 var scopeChain; | 449 var scopeChain; |
| 451 var funcMirror; | 450 var funcMirror; |
| 452 var scriptMirror; | |
| 453 var location; | 451 var location; |
| 454 /** @type {!Array<?RawLocation>} */ | 452 /** @type {!Array<?RawLocation>} */ |
| 455 var scopeStartLocations; | 453 var scopeStartLocations; |
| 456 /** @type {!Array<?RawLocation>} */ | 454 /** @type {!Array<?RawLocation>} */ |
| 457 var scopeEndLocations; | 455 var scopeEndLocations; |
| 458 var details; | 456 var details; |
| 459 | 457 |
| 460 /** | 458 /** |
| 461 * @param {!ScriptMirror|undefined} script | 459 * @param {!ScriptMirror|undefined} script |
| 462 * @param {number} pos | 460 * @param {number} pos |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 return scopeChain; | 509 return scopeChain; |
| 512 } | 510 } |
| 513 | 511 |
| 514 /** | 512 /** |
| 515 * @return {!JavaScriptCallFrameDetails} | 513 * @return {!JavaScriptCallFrameDetails} |
| 516 */ | 514 */ |
| 517 function lazyDetails() | 515 function lazyDetails() |
| 518 { | 516 { |
| 519 if (!details) { | 517 if (!details) { |
| 520 var scopeObjects = ensureScopeChain(); | 518 var scopeObjects = ensureScopeChain(); |
| 521 var script = ensureScriptMirror(); | 519 var script = ensureFuncMirror().script(); |
| 522 /** @type {!Array<Scope>} */ | 520 /** @type {!Array<Scope>} */ |
| 523 var scopes = []; | 521 var scopes = []; |
| 524 for (var i = 0; i < scopeObjects.length; ++i) { | 522 for (var i = 0; i < scopeObjects.length; ++i) { |
| 525 var scope = { | 523 var scope = { |
| 526 "type": /** @type {string} */(DebuggerScript._scopeTypeNames
.get(scopeTypes[i])), | 524 "type": /** @type {string} */(DebuggerScript._scopeTypeNames
.get(scopeTypes[i])), |
| 527 "object": scopeObjects[i], | 525 "object": scopeObjects[i], |
| 528 }; | 526 }; |
| 529 if (scopeNames[i]) | 527 if (scopeNames[i]) |
| 530 scope.name = scopeNames[i]; | 528 scope.name = scopeNames[i]; |
| 531 if (scopeStartLocations[i]) | 529 if (scopeStartLocations[i]) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 { | 563 { |
| 566 if (!funcMirror) { | 564 if (!funcMirror) { |
| 567 funcMirror = MakeMirror(funcObject); | 565 funcMirror = MakeMirror(funcObject); |
| 568 if (!funcMirror.isFunction()) | 566 if (!funcMirror.isFunction()) |
| 569 funcMirror = new UnresolvedFunctionMirror(funcObject); | 567 funcMirror = new UnresolvedFunctionMirror(funcObject); |
| 570 } | 568 } |
| 571 return /** @type {!FunctionMirror} */(funcMirror); | 569 return /** @type {!FunctionMirror} */(funcMirror); |
| 572 } | 570 } |
| 573 | 571 |
| 574 /** | 572 /** |
| 575 * @return {!ScriptMirror} | |
| 576 */ | |
| 577 function ensureScriptMirror() | |
| 578 { | |
| 579 if (!scriptMirror) { | |
| 580 scriptMirror = MakeMirror(scriptObject); | |
| 581 } | |
| 582 return /** @type {!ScriptMirror} */(scriptMirror); | |
| 583 } | |
| 584 | |
| 585 /** | |
| 586 * @return {!{line: number, column: number}} | 573 * @return {!{line: number, column: number}} |
| 587 */ | 574 */ |
| 588 function ensureLocation() | 575 function ensureLocation() |
| 589 { | 576 { |
| 590 if (!location) { | 577 if (!location) { |
| 591 var script = ensureScriptMirror(); | 578 var script = ensureFuncMirror().script(); |
| 592 location = script.locationFromPosition(sourcePosition, true); | 579 if (script) |
| 580 location = script.locationFromPosition(sourcePosition, true); |
| 593 if (!location) | 581 if (!location) |
| 594 location = { line: 0, column: 0 }; | 582 location = { line: 0, column: 0 }; |
| 595 } | 583 } |
| 596 return location; | 584 return location; |
| 597 } | 585 } |
| 598 | 586 |
| 599 /** | 587 /** |
| 600 * @return {number} | 588 * @return {number} |
| 601 */ | 589 */ |
| 602 function line() | 590 function line() |
| (...skipping 18 matching lines...) Expand all Loading... |
| 621 // Old V8 do not have context() function on these objects | 609 // Old V8 do not have context() function on these objects |
| 622 if (!mirror.context) | 610 if (!mirror.context) |
| 623 return DebuggerScript._executionContextId(mirror.script().value().co
ntext_data); | 611 return DebuggerScript._executionContextId(mirror.script().value().co
ntext_data); |
| 624 var context = mirror.context(); | 612 var context = mirror.context(); |
| 625 if (context) | 613 if (context) |
| 626 return DebuggerScript._executionContextId(context.data()); | 614 return DebuggerScript._executionContextId(context.data()); |
| 627 return 0; | 615 return 0; |
| 628 } | 616 } |
| 629 | 617 |
| 630 /** | 618 /** |
| 631 * @return {number} | 619 * @return {number|undefined} |
| 632 */ | 620 */ |
| 633 function sourceID() | 621 function sourceID() |
| 634 { | 622 { |
| 635 var script = ensureScriptMirror(); | 623 var script = ensureFuncMirror().script(); |
| 636 return script.id(); | 624 return script && script.id(); |
| 637 } | 625 } |
| 638 | 626 |
| 639 /** | 627 /** |
| 640 * @param {string} expression | 628 * @param {string} expression |
| 641 * @return {*} | 629 * @return {*} |
| 642 */ | 630 */ |
| 643 function evaluate(expression) | 631 function evaluate(expression) |
| 644 { | 632 { |
| 645 return frameMirror.evaluate(expression, false).value(); | 633 return frameMirror.evaluate(expression, false).value(); |
| 646 } | 634 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 break; | 703 break; |
| 716 } | 704 } |
| 717 return result; | 705 return result; |
| 718 } | 706 } |
| 719 | 707 |
| 720 // We never resolve Mirror by its handle so to avoid memory leaks caused by Mirr
ors in the cache we disable it. | 708 // We never resolve Mirror by its handle so to avoid memory leaks caused by Mirr
ors in the cache we disable it. |
| 721 ToggleMirrorCache(false); | 709 ToggleMirrorCache(false); |
| 722 | 710 |
| 723 return DebuggerScript; | 711 return DebuggerScript; |
| 724 })(); | 712 })(); |
| OLD | NEW |