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

Side by Side Diff: src/mirror-debugger.js

Issue 184483004: Reduce heavy runtime calls from debug mirrors. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 6 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2012 the V8 project authors. All rights reserved. 1 // Copyright 2006-2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 882
883 /** 883 /**
884 * Returns the script object for the function. 884 * Returns the script object for the function.
885 * @return {ScriptMirror or undefined} Script object for the function or 885 * @return {ScriptMirror or undefined} Script object for the function or
886 * undefined if the function has no script 886 * undefined if the function has no script
887 */ 887 */
888 FunctionMirror.prototype.script = function() { 888 FunctionMirror.prototype.script = function() {
889 // Return script if function is resolved. Otherwise just fall through 889 // Return script if function is resolved. Otherwise just fall through
890 // to return undefined. 890 // to return undefined.
891 if (this.resolved()) { 891 if (this.resolved()) {
892 if (this.script_) {
893 return this.script_;
894 }
892 var script = %FunctionGetScript(this.value_); 895 var script = %FunctionGetScript(this.value_);
893 if (script) { 896 if (script) {
894 return MakeMirror(script); 897 return this.script_ = MakeMirror(script);
895 } 898 }
896 } 899 }
897 }; 900 };
898 901
899 902
900 /** 903 /**
901 * Returns the script source position for the function. Only makes sense 904 * Returns the script source position for the function. Only makes sense
902 * for functions which has a script defined. 905 * for functions which has a script defined.
903 * @return {Number or undefined} in-script position for the function 906 * @return {Number or undefined} in-script position for the function
904 */ 907 */
905 FunctionMirror.prototype.sourcePosition_ = function() { 908 FunctionMirror.prototype.sourcePosition_ = function() {
906 // Return script if function is resolved. Otherwise just fall through 909 // Return script if function is resolved. Otherwise just fall through
907 // to return undefined. 910 // to return undefined.
908 if (this.resolved()) { 911 if (this.resolved()) {
909 return %FunctionGetScriptSourcePosition(this.value_); 912 return %FunctionGetScriptSourcePosition(this.value_);
910 } 913 }
911 }; 914 };
912 915
913 916
914 /** 917 /**
915 * Returns the script source location object for the function. Only makes sense 918 * Returns the script source location object for the function. Only makes sense
916 * for functions which has a script defined. 919 * for functions which has a script defined.
917 * @return {Location or undefined} in-script location for the function begin 920 * @return {Location or undefined} in-script location for the function begin
918 */ 921 */
919 FunctionMirror.prototype.sourceLocation = function() { 922 FunctionMirror.prototype.sourceLocation = function() {
920 if (this.resolved() && this.script()) { 923 if (this.resolved()) {
921 return this.script().locationFromPosition(this.sourcePosition_(), 924 var script = this.script();
922 true); 925 if (script) {
926 return script.locationFromPosition(this.sourcePosition_(), true);
927 }
923 } 928 }
924 }; 929 };
925 930
926 931
927 /** 932 /**
928 * Returns objects constructed by this function. 933 * Returns objects constructed by this function.
929 * @param {number} opt_max_instances Optional parameter specifying the maximum 934 * @param {number} opt_max_instances Optional parameter specifying the maximum
930 * number of instances to return. 935 * number of instances to return.
931 * @return {Array or undefined} The objects constructed by this function. 936 * @return {Array or undefined} The objects constructed by this function.
932 */ 937 */
933 FunctionMirror.prototype.constructedBy = function(opt_max_instances) { 938 FunctionMirror.prototype.constructedBy = function(opt_max_instances) {
934 if (this.resolved()) { 939 if (this.resolved()) {
935 // Find all objects constructed from this function. 940 // Find all objects constructed from this function.
936 var result = %DebugConstructedBy(this.value_, opt_max_instances || 0); 941 var result = %DebugConstructedBy(this.value_, opt_max_instances || 0);
937 942
938 // Make mirrors for all the instances found. 943 // Make mirrors for all the instances found.
939 for (var i = 0; i < result.length; i++) { 944 for (var i = 0; i < result.length; i++) {
940 result[i] = MakeMirror(result[i]); 945 result[i] = MakeMirror(result[i]);
941 } 946 }
942 947
943 return result; 948 return result;
944 } else { 949 } else {
945 return []; 950 return [];
946 } 951 }
947 }; 952 };
948 953
949 954
950 FunctionMirror.prototype.scopeCount = function() { 955 FunctionMirror.prototype.scopeCount = function() {
951 if (this.resolved()) { 956 if (this.resolved()) {
952 return %GetFunctionScopeCount(this.value()); 957 if (IS_UNDEFINED(this.scopeCount_)) {
958 this.scopeCount_ = %GetFunctionScopeCount(this.value());
959 }
960 return this.scopeCount_;
953 } else { 961 } else {
954 return 0; 962 return 0;
955 } 963 }
956 }; 964 };
957 965
958 966
959 FunctionMirror.prototype.scope = function(index) { 967 FunctionMirror.prototype.scope = function(index) {
960 if (this.resolved()) { 968 if (this.resolved()) {
961 return new ScopeMirror(UNDEFINED, this, index); 969 return new ScopeMirror(UNDEFINED, this, index);
962 } 970 }
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 var return_value_offset = 1507 var return_value_offset =
1500 kFrameDetailsFirstDynamicIndex + 1508 kFrameDetailsFirstDynamicIndex +
1501 (this.argumentCount() + this.localCount()) * kFrameDetailsNameValueSize; 1509 (this.argumentCount() + this.localCount()) * kFrameDetailsNameValueSize;
1502 if (this.details_[kFrameDetailsAtReturnIndex]) { 1510 if (this.details_[kFrameDetailsAtReturnIndex]) {
1503 return this.details_[return_value_offset]; 1511 return this.details_[return_value_offset];
1504 } 1512 }
1505 }; 1513 };
1506 1514
1507 1515
1508 FrameDetails.prototype.scopeCount = function() { 1516 FrameDetails.prototype.scopeCount = function() {
1509 return %GetScopeCount(this.break_id_, this.frameId()); 1517 if (IS_UNDEFINED(this.scopeCount_)) {
1518 this.scopeCount_ = %GetScopeCount(this.break_id_, this.frameId());
1519 }
1520 return this.scopeCount_;
1510 }; 1521 };
1511 1522
1512 1523
1513 FrameDetails.prototype.stepInPositionsImpl = function() { 1524 FrameDetails.prototype.stepInPositionsImpl = function() {
1514 return %GetStepInPositions(this.break_id_, this.frameId()); 1525 return %GetStepInPositions(this.break_id_, this.frameId());
1515 }; 1526 };
1516 1527
1517 1528
1518 /** 1529 /**
1519 * Mirror object for stack frames. 1530 * Mirror object for stack frames.
(...skipping 11 matching lines...) Expand all
1531 } 1542 }
1532 inherits(FrameMirror, Mirror); 1543 inherits(FrameMirror, Mirror);
1533 1544
1534 1545
1535 FrameMirror.prototype.index = function() { 1546 FrameMirror.prototype.index = function() {
1536 return this.index_; 1547 return this.index_;
1537 }; 1548 };
1538 1549
1539 1550
1540 FrameMirror.prototype.func = function() { 1551 FrameMirror.prototype.func = function() {
1552 if (this.func_) {
1553 return this.func_;
1554 }
1555
1541 // Get the function for this frame from the VM. 1556 // Get the function for this frame from the VM.
1542 var f = this.details_.func(); 1557 var f = this.details_.func();
1543 1558
1544 // Create a function mirror. NOTE: MakeMirror cannot be used here as the 1559 // Create a function mirror. NOTE: MakeMirror cannot be used here as the
1545 // value returned from the VM might be a string if the function for the 1560 // value returned from the VM might be a string if the function for the
1546 // frame is unresolved. 1561 // frame is unresolved.
1547 if (IS_FUNCTION(f)) { 1562 if (IS_FUNCTION(f)) {
1548 return MakeMirror(f); 1563 return this.func_ = MakeMirror(f);
1549 } else { 1564 } else {
1550 return new UnresolvedFunctionMirror(f); 1565 return new UnresolvedFunctionMirror(f);
1551 } 1566 }
1552 }; 1567 };
1553 1568
1554 1569
1555 FrameMirror.prototype.receiver = function() { 1570 FrameMirror.prototype.receiver = function() {
1556 return MakeMirror(this.details_.receiver()); 1571 return MakeMirror(this.details_.receiver());
1557 }; 1572 };
1558 1573
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 return MakeMirror(this.details_.returnValue()); 1636 return MakeMirror(this.details_.returnValue());
1622 }; 1637 };
1623 1638
1624 1639
1625 FrameMirror.prototype.sourcePosition = function() { 1640 FrameMirror.prototype.sourcePosition = function() {
1626 return this.details_.sourcePosition(); 1641 return this.details_.sourcePosition();
1627 }; 1642 };
1628 1643
1629 1644
1630 FrameMirror.prototype.sourceLocation = function() { 1645 FrameMirror.prototype.sourceLocation = function() {
1631 if (this.func().resolved() && this.func().script()) { 1646 var func = this.func();
1632 return this.func().script().locationFromPosition(this.sourcePosition(), 1647 if (func.resolved()) {
1633 true); 1648 var script = func.script();
1649 if (script) {
1650 return script.locationFromPosition(this.sourcePosition(), true);
1651 }
1634 } 1652 }
1635 }; 1653 };
1636 1654
1637 1655
1638 FrameMirror.prototype.sourceLine = function() { 1656 FrameMirror.prototype.sourceLine = function() {
1639 if (this.func().resolved()) { 1657 var location = this.sourceLocation();
1640 var location = this.sourceLocation(); 1658 if (location) {
1641 if (location) { 1659 return location.line;
1642 return location.line;
1643 }
1644 } 1660 }
1645 }; 1661 };
1646 1662
1647 1663
1648 FrameMirror.prototype.sourceColumn = function() { 1664 FrameMirror.prototype.sourceColumn = function() {
1649 if (this.func().resolved()) { 1665 var location = this.sourceLocation();
1650 var location = this.sourceLocation(); 1666 if (location) {
1651 if (location) { 1667 return location.column;
1652 return location.column;
1653 }
1654 } 1668 }
1655 }; 1669 };
1656 1670
1657 1671
1658 FrameMirror.prototype.sourceLineText = function() { 1672 FrameMirror.prototype.sourceLineText = function() {
1659 if (this.func().resolved()) { 1673 var location = this.sourceLocation();
1660 var location = this.sourceLocation(); 1674 if (location) {
1661 if (location) { 1675 return location.sourceText();
1662 return location.sourceText();
1663 }
1664 } 1676 }
1665 }; 1677 };
1666 1678
1667 1679
1668 FrameMirror.prototype.scopeCount = function() { 1680 FrameMirror.prototype.scopeCount = function() {
1669 return this.details_.scopeCount(); 1681 return this.details_.scopeCount();
1670 }; 1682 };
1671 1683
1672 1684
1673 FrameMirror.prototype.scope = function(index) { 1685 FrameMirror.prototype.scope = function(index) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 1798
1787 return result; 1799 return result;
1788 }; 1800 };
1789 1801
1790 1802
1791 FrameMirror.prototype.sourceAndPositionText = function() { 1803 FrameMirror.prototype.sourceAndPositionText = function() {
1792 // Format source and position. 1804 // Format source and position.
1793 var result = ''; 1805 var result = '';
1794 var func = this.func(); 1806 var func = this.func();
1795 if (func.resolved()) { 1807 if (func.resolved()) {
1796 if (func.script()) { 1808 var script = func.script();
1797 if (func.script().name()) { 1809 if (script) {
1798 result += func.script().name(); 1810 if (script.name()) {
1811 result += script.name();
1799 } else { 1812 } else {
1800 result += '[unnamed]'; 1813 result += '[unnamed]';
1801 } 1814 }
1802 if (!this.isDebuggerFrame()) { 1815 if (!this.isDebuggerFrame()) {
1803 var location = this.sourceLocation(); 1816 var location = this.sourceLocation();
1804 result += ' line '; 1817 result += ' line ';
1805 result += !IS_UNDEFINED(location) ? (location.line + 1) : '?'; 1818 result += !IS_UNDEFINED(location) ? (location.line + 1) : '?';
1806 result += ' column '; 1819 result += ' column ';
1807 result += !IS_UNDEFINED(location) ? (location.column + 1) : '?'; 1820 result += !IS_UNDEFINED(location) ? (location.column + 1) : '?';
1808 if (!IS_UNDEFINED(this.sourcePosition())) { 1821 if (!IS_UNDEFINED(this.sourcePosition())) {
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
2568 } 2581 }
2569 return result; 2582 return result;
2570 }; 2583 };
2571 2584
2572 2585
2573 JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) { 2586 JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) {
2574 content.index = mirror.index(); 2587 content.index = mirror.index();
2575 content.receiver = this.serializeReference(mirror.receiver()); 2588 content.receiver = this.serializeReference(mirror.receiver());
2576 var func = mirror.func(); 2589 var func = mirror.func();
2577 content.func = this.serializeReference(func); 2590 content.func = this.serializeReference(func);
2578 if (func.script()) { 2591 var script = func.script();
2579 content.script = this.serializeReference(func.script()); 2592 if (script) {
2593 content.script = this.serializeReference(script);
2580 } 2594 }
2581 content.constructCall = mirror.isConstructCall(); 2595 content.constructCall = mirror.isConstructCall();
2582 content.atReturn = mirror.isAtReturn(); 2596 content.atReturn = mirror.isAtReturn();
2583 if (mirror.isAtReturn()) { 2597 if (mirror.isAtReturn()) {
2584 content.returnValue = this.serializeReference(mirror.returnValue()); 2598 content.returnValue = this.serializeReference(mirror.returnValue());
2585 } 2599 }
2586 content.debuggerFrame = mirror.isDebuggerFrame(); 2600 content.debuggerFrame = mirror.isDebuggerFrame();
2587 var x = new Array(mirror.argumentCount()); 2601 var x = new Array(mirror.argumentCount());
2588 for (var i = 0; i < mirror.argumentCount(); i++) { 2602 for (var i = 0; i < mirror.argumentCount(); i++) {
2589 var arg = {}; 2603 var arg = {};
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2645 } 2659 }
2646 if (!NUMBER_IS_FINITE(value)) { 2660 if (!NUMBER_IS_FINITE(value)) {
2647 if (value > 0) { 2661 if (value > 0) {
2648 return 'Infinity'; 2662 return 'Infinity';
2649 } else { 2663 } else {
2650 return '-Infinity'; 2664 return '-Infinity';
2651 } 2665 }
2652 } 2666 }
2653 return value; 2667 return value;
2654 } 2668 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698