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

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

Issue 196133017: Experimental parser: merge r19949 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
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 | Annotate | Revision Log
« no previous file with comments | « src/mips/stub-cache-mips.cc ('k') | src/object-observe.js » ('j') | 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.
1520 * @param {number} break_id The break id in the VM for which this frame is 1531 * @param {number} break_id The break id in the VM for which this frame is
1521 valid 1532 valid
1522 * @param {number} index The frame index (top frame is index 0) 1533 * @param {number} index The frame index (top frame is index 0)
1523 * @constructor 1534 * @constructor
1524 * @extends Mirror 1535 * @extends Mirror
1525 */ 1536 */
1526 function FrameMirror(break_id, index) { 1537 function FrameMirror(break_id, index) {
1527 %_CallFunction(this, FRAME_TYPE, Mirror); 1538 %_CallFunction(this, FRAME_TYPE, Mirror);
1528 this.break_id_ = break_id; 1539 this.break_id_ = break_id;
1529 this.index_ = index; 1540 this.index_ = index;
1530 this.details_ = new FrameDetails(break_id, index); 1541 this.details_ = new FrameDetails(break_id, index);
1531 } 1542 }
1532 inherits(FrameMirror, Mirror); 1543 inherits(FrameMirror, Mirror);
1533 1544
1534 1545
1546 FrameMirror.prototype.details = function() {
1547 return this.details_;
1548 };
1549
1550
1535 FrameMirror.prototype.index = function() { 1551 FrameMirror.prototype.index = function() {
1536 return this.index_; 1552 return this.index_;
1537 }; 1553 };
1538 1554
1539 1555
1540 FrameMirror.prototype.func = function() { 1556 FrameMirror.prototype.func = function() {
1557 if (this.func_) {
1558 return this.func_;
1559 }
1560
1541 // Get the function for this frame from the VM. 1561 // Get the function for this frame from the VM.
1542 var f = this.details_.func(); 1562 var f = this.details_.func();
1543 1563
1544 // Create a function mirror. NOTE: MakeMirror cannot be used here as the 1564 // 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 1565 // value returned from the VM might be a string if the function for the
1546 // frame is unresolved. 1566 // frame is unresolved.
1547 if (IS_FUNCTION(f)) { 1567 if (IS_FUNCTION(f)) {
1548 return MakeMirror(f); 1568 return this.func_ = MakeMirror(f);
1549 } else { 1569 } else {
1550 return new UnresolvedFunctionMirror(f); 1570 return new UnresolvedFunctionMirror(f);
1551 } 1571 }
1552 }; 1572 };
1553 1573
1554 1574
1555 FrameMirror.prototype.receiver = function() { 1575 FrameMirror.prototype.receiver = function() {
1556 return MakeMirror(this.details_.receiver()); 1576 return MakeMirror(this.details_.receiver());
1557 }; 1577 };
1558 1578
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 return MakeMirror(this.details_.returnValue()); 1641 return MakeMirror(this.details_.returnValue());
1622 }; 1642 };
1623 1643
1624 1644
1625 FrameMirror.prototype.sourcePosition = function() { 1645 FrameMirror.prototype.sourcePosition = function() {
1626 return this.details_.sourcePosition(); 1646 return this.details_.sourcePosition();
1627 }; 1647 };
1628 1648
1629 1649
1630 FrameMirror.prototype.sourceLocation = function() { 1650 FrameMirror.prototype.sourceLocation = function() {
1631 if (this.func().resolved() && this.func().script()) { 1651 var func = this.func();
1632 return this.func().script().locationFromPosition(this.sourcePosition(), 1652 if (func.resolved()) {
1633 true); 1653 var script = func.script();
1654 if (script) {
1655 return script.locationFromPosition(this.sourcePosition(), true);
1656 }
1634 } 1657 }
1635 }; 1658 };
1636 1659
1637 1660
1638 FrameMirror.prototype.sourceLine = function() { 1661 FrameMirror.prototype.sourceLine = function() {
1639 if (this.func().resolved()) { 1662 var location = this.sourceLocation();
1640 var location = this.sourceLocation(); 1663 if (location) {
1641 if (location) { 1664 return location.line;
1642 return location.line;
1643 }
1644 } 1665 }
1645 }; 1666 };
1646 1667
1647 1668
1648 FrameMirror.prototype.sourceColumn = function() { 1669 FrameMirror.prototype.sourceColumn = function() {
1649 if (this.func().resolved()) { 1670 var location = this.sourceLocation();
1650 var location = this.sourceLocation(); 1671 if (location) {
1651 if (location) { 1672 return location.column;
1652 return location.column;
1653 }
1654 } 1673 }
1655 }; 1674 };
1656 1675
1657 1676
1658 FrameMirror.prototype.sourceLineText = function() { 1677 FrameMirror.prototype.sourceLineText = function() {
1659 if (this.func().resolved()) { 1678 var location = this.sourceLocation();
1660 var location = this.sourceLocation(); 1679 if (location) {
1661 if (location) { 1680 return location.sourceText();
1662 return location.sourceText();
1663 }
1664 } 1681 }
1665 }; 1682 };
1666 1683
1667 1684
1668 FrameMirror.prototype.scopeCount = function() { 1685 FrameMirror.prototype.scopeCount = function() {
1669 return this.details_.scopeCount(); 1686 return this.details_.scopeCount();
1670 }; 1687 };
1671 1688
1672 1689
1673 FrameMirror.prototype.scope = function(index) { 1690 FrameMirror.prototype.scope = function(index) {
1674 return new ScopeMirror(this, UNDEFINED, index); 1691 return new ScopeMirror(this, UNDEFINED, index);
1675 }; 1692 };
1676 1693
1677 1694
1695 FrameMirror.prototype.allScopes = function() {
1696 var scopeDetails = %GetAllScopesDetails(this.break_id_,
1697 this.details_.frameId(),
1698 this.details_.inlinedFrameIndex());
1699 var result = [];
1700 for (var i = 0; i < scopeDetails.length; ++i) {
1701 result.push(new ScopeMirror(this, UNDEFINED, i, scopeDetails[i]));
1702 }
1703 return result;
1704 };
1705
1706
1678 FrameMirror.prototype.stepInPositions = function() { 1707 FrameMirror.prototype.stepInPositions = function() {
1679 var script = this.func().script(); 1708 var script = this.func().script();
1680 var funcOffset = this.func().sourcePosition_(); 1709 var funcOffset = this.func().sourcePosition_();
1681 1710
1682 var stepInRaw = this.details_.stepInPositionsImpl(); 1711 var stepInRaw = this.details_.stepInPositionsImpl();
1683 var result = []; 1712 var result = [];
1684 if (stepInRaw) { 1713 if (stepInRaw) {
1685 for (var i = 0; i < stepInRaw.length; i++) { 1714 for (var i = 0; i < stepInRaw.length; i++) {
1686 var posStruct = {}; 1715 var posStruct = {};
1687 var offset = script.locationFromPosition(funcOffset + stepInRaw[i], 1716 var offset = script.locationFromPosition(funcOffset + stepInRaw[i],
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 1815
1787 return result; 1816 return result;
1788 }; 1817 };
1789 1818
1790 1819
1791 FrameMirror.prototype.sourceAndPositionText = function() { 1820 FrameMirror.prototype.sourceAndPositionText = function() {
1792 // Format source and position. 1821 // Format source and position.
1793 var result = ''; 1822 var result = '';
1794 var func = this.func(); 1823 var func = this.func();
1795 if (func.resolved()) { 1824 if (func.resolved()) {
1796 if (func.script()) { 1825 var script = func.script();
1797 if (func.script().name()) { 1826 if (script) {
1798 result += func.script().name(); 1827 if (script.name()) {
1828 result += script.name();
1799 } else { 1829 } else {
1800 result += '[unnamed]'; 1830 result += '[unnamed]';
1801 } 1831 }
1802 if (!this.isDebuggerFrame()) { 1832 if (!this.isDebuggerFrame()) {
1803 var location = this.sourceLocation(); 1833 var location = this.sourceLocation();
1804 result += ' line '; 1834 result += ' line ';
1805 result += !IS_UNDEFINED(location) ? (location.line + 1) : '?'; 1835 result += !IS_UNDEFINED(location) ? (location.line + 1) : '?';
1806 result += ' column '; 1836 result += ' column ';
1807 result += !IS_UNDEFINED(location) ? (location.column + 1) : '?'; 1837 result += !IS_UNDEFINED(location) ? (location.column + 1) : '?';
1808 if (!IS_UNDEFINED(this.sourcePosition())) { 1838 if (!IS_UNDEFINED(this.sourcePosition())) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 result += '\n'; 1888 result += '\n';
1859 result += this.localsText(); 1889 result += this.localsText();
1860 } 1890 }
1861 return result; 1891 return result;
1862 }; 1892 };
1863 1893
1864 1894
1865 var kScopeDetailsTypeIndex = 0; 1895 var kScopeDetailsTypeIndex = 0;
1866 var kScopeDetailsObjectIndex = 1; 1896 var kScopeDetailsObjectIndex = 1;
1867 1897
1868 function ScopeDetails(frame, fun, index) { 1898 function ScopeDetails(frame, fun, index, opt_details) {
1869 if (frame) { 1899 if (frame) {
1870 this.break_id_ = frame.break_id_; 1900 this.break_id_ = frame.break_id_;
1871 this.details_ = %GetScopeDetails(frame.break_id_, 1901 this.details_ = opt_details ||
1902 %GetScopeDetails(frame.break_id_,
1872 frame.details_.frameId(), 1903 frame.details_.frameId(),
1873 frame.details_.inlinedFrameIndex(), 1904 frame.details_.inlinedFrameIndex(),
1874 index); 1905 index);
1875 this.frame_id_ = frame.details_.frameId(); 1906 this.frame_id_ = frame.details_.frameId();
1876 this.inlined_frame_id_ = frame.details_.inlinedFrameIndex(); 1907 this.inlined_frame_id_ = frame.details_.inlinedFrameIndex();
1877 } else { 1908 } else {
1878 this.details_ = %GetFunctionScopeDetails(fun.value(), index); 1909 this.details_ = opt_details || %GetFunctionScopeDetails(fun.value(), index);
1879 this.fun_value_ = fun.value(); 1910 this.fun_value_ = fun.value();
1880 this.break_id_ = undefined; 1911 this.break_id_ = undefined;
1881 } 1912 }
1882 this.index_ = index; 1913 this.index_ = index;
1883 } 1914 }
1884 1915
1885 1916
1886 ScopeDetails.prototype.type = function() { 1917 ScopeDetails.prototype.type = function() {
1887 if (!IS_UNDEFINED(this.break_id_)) { 1918 if (!IS_UNDEFINED(this.break_id_)) {
1888 %CheckExecutionState(this.break_id_); 1919 %CheckExecutionState(this.break_id_);
(...skipping 25 matching lines...) Expand all
1914 } 1945 }
1915 }; 1946 };
1916 1947
1917 1948
1918 /** 1949 /**
1919 * Mirror object for scope of frame or function. Either frame or function must 1950 * Mirror object for scope of frame or function. Either frame or function must
1920 * be specified. 1951 * be specified.
1921 * @param {FrameMirror} frame The frame this scope is a part of 1952 * @param {FrameMirror} frame The frame this scope is a part of
1922 * @param {FunctionMirror} function The function this scope is a part of 1953 * @param {FunctionMirror} function The function this scope is a part of
1923 * @param {number} index The scope index in the frame 1954 * @param {number} index The scope index in the frame
1955 * @param {Array=} opt_details Raw scope details data
1924 * @constructor 1956 * @constructor
1925 * @extends Mirror 1957 * @extends Mirror
1926 */ 1958 */
1927 function ScopeMirror(frame, function, index) { 1959 function ScopeMirror(frame, function, index, opt_details) {
1928 %_CallFunction(this, SCOPE_TYPE, Mirror); 1960 %_CallFunction(this, SCOPE_TYPE, Mirror);
1929 if (frame) { 1961 if (frame) {
1930 this.frame_index_ = frame.index_; 1962 this.frame_index_ = frame.index_;
1931 } else { 1963 } else {
1932 this.frame_index_ = undefined; 1964 this.frame_index_ = undefined;
1933 } 1965 }
1934 this.scope_index_ = index; 1966 this.scope_index_ = index;
1935 this.details_ = new ScopeDetails(frame, function, index); 1967 this.details_ = new ScopeDetails(frame, function, index, opt_details);
1936 } 1968 }
1937 inherits(ScopeMirror, Mirror); 1969 inherits(ScopeMirror, Mirror);
1938 1970
1939 1971
1972 ScopeMirror.prototype.details = function() {
1973 return this.details_;
1974 };
1975
1976
1940 ScopeMirror.prototype.frameIndex = function() { 1977 ScopeMirror.prototype.frameIndex = function() {
1941 return this.frame_index_; 1978 return this.frame_index_;
1942 }; 1979 };
1943 1980
1944 1981
1945 ScopeMirror.prototype.scopeIndex = function() { 1982 ScopeMirror.prototype.scopeIndex = function() {
1946 return this.scope_index_; 1983 return this.scope_index_;
1947 }; 1984 };
1948 1985
1949 1986
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
2568 } 2605 }
2569 return result; 2606 return result;
2570 }; 2607 };
2571 2608
2572 2609
2573 JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) { 2610 JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) {
2574 content.index = mirror.index(); 2611 content.index = mirror.index();
2575 content.receiver = this.serializeReference(mirror.receiver()); 2612 content.receiver = this.serializeReference(mirror.receiver());
2576 var func = mirror.func(); 2613 var func = mirror.func();
2577 content.func = this.serializeReference(func); 2614 content.func = this.serializeReference(func);
2578 if (func.script()) { 2615 var script = func.script();
2579 content.script = this.serializeReference(func.script()); 2616 if (script) {
2617 content.script = this.serializeReference(script);
2580 } 2618 }
2581 content.constructCall = mirror.isConstructCall(); 2619 content.constructCall = mirror.isConstructCall();
2582 content.atReturn = mirror.isAtReturn(); 2620 content.atReturn = mirror.isAtReturn();
2583 if (mirror.isAtReturn()) { 2621 if (mirror.isAtReturn()) {
2584 content.returnValue = this.serializeReference(mirror.returnValue()); 2622 content.returnValue = this.serializeReference(mirror.returnValue());
2585 } 2623 }
2586 content.debuggerFrame = mirror.isDebuggerFrame(); 2624 content.debuggerFrame = mirror.isDebuggerFrame();
2587 var x = new Array(mirror.argumentCount()); 2625 var x = new Array(mirror.argumentCount());
2588 for (var i = 0; i < mirror.argumentCount(); i++) { 2626 for (var i = 0; i < mirror.argumentCount(); i++) {
2589 var arg = {}; 2627 var arg = {};
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2645 } 2683 }
2646 if (!NUMBER_IS_FINITE(value)) { 2684 if (!NUMBER_IS_FINITE(value)) {
2647 if (value > 0) { 2685 if (value > 0) {
2648 return 'Infinity'; 2686 return 'Infinity';
2649 } else { 2687 } else {
2650 return '-Infinity'; 2688 return '-Infinity';
2651 } 2689 }
2652 } 2690 }
2653 return value; 2691 return value;
2654 } 2692 }
OLDNEW
« no previous file with comments | « src/mips/stub-cache-mips.cc ('k') | src/object-observe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698