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

Side by Side Diff: src/debug-delay.js

Issue 27202: Change the D8 JavaScript debugger to fully use the JSON protocol.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 10 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/d8-debug.cc ('k') | 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-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 return this.exec_state_.frame(0).sourceColumn(); 864 return this.exec_state_.frame(0).sourceColumn();
865 }; 865 };
866 866
867 867
868 ExceptionEvent.prototype.sourceLineText = function() { 868 ExceptionEvent.prototype.sourceLineText = function() {
869 return this.exec_state_.frame(0).sourceLineText(); 869 return this.exec_state_.frame(0).sourceLineText();
870 }; 870 };
871 871
872 872
873 ExceptionEvent.prototype.toJSONProtocol = function() { 873 ExceptionEvent.prototype.toJSONProtocol = function() {
874 var o = { seq: next_response_seq++, 874 var o = new ProtocolMessage();
875 type: "event", 875 o.event = "exception";
876 event: "exception", 876 o.body = { uncaught: this.uncaught_,
877 body: { uncaught: this.uncaught_, 877 exception: MakeMirror(this.exception_)
878 exception: MakeMirror(this.exception_), 878 }
879 sourceLine: this.sourceLine(), 879
880 sourceColumn: this.sourceColumn(), 880 // Exceptions might happen whithout any JavaScript frames.
881 sourceLineText: this.sourceLineText(), 881 if (this.exec_state_.frameCount() > 0) {
882 } 882 o.body.sourceLine = this.sourceLine();
883 } 883 o.body.sourceColumn = this.sourceColumn();
884 o.body.sourceLineText = this.sourceLineText();
884 885
885 // Add script information to the event if available. 886 // Add script information to the event if available.
886 var script = this.func().script(); 887 var script = this.func().script();
887 if (script) { 888 if (script) {
888 o.body.script = { name: script.name(), 889 o.body.script = { name: script.name(),
889 lineOffset: script.lineOffset(), 890 lineOffset: script.lineOffset(),
890 columnOffset: script.columnOffset(), 891 columnOffset: script.columnOffset(),
891 lineCount: script.lineCount() 892 lineCount: script.lineCount()
892 }; 893 };
894 }
895 } else {
896 o.body.sourceLine = -1;
893 } 897 }
894 898
895 return SimpleObjectToJSON_(o); 899 return o.toJSONProtocol();
896 }; 900 };
897 901
898 902
899 function MakeCompileEvent(exec_state, script, before) { 903 function MakeCompileEvent(exec_state, script, before) {
900 return new CompileEvent(exec_state, script, before); 904 return new CompileEvent(exec_state, script, before);
901 } 905 }
902 906
903 907
904 function CompileEvent(exec_state, script, before) { 908 function CompileEvent(exec_state, script, before) {
905 this.exec_state_ = exec_state; 909 this.exec_state_ = exec_state;
(...skipping 14 matching lines...) Expand all
920 return Debug.DebugEvent.AfterCompile; 924 return Debug.DebugEvent.AfterCompile;
921 } 925 }
922 }; 926 };
923 927
924 928
925 CompileEvent.prototype.script = function() { 929 CompileEvent.prototype.script = function() {
926 return this.script_; 930 return this.script_;
927 }; 931 };
928 932
929 933
934 CompileEvent.prototype.toJSONProtocol = function() {
935 var o = new ProtocolMessage();
936 if (this.before_) {
937 o.event = "beforeCompile";
938 } else {
939 o.event = "afterCompile";
940 }
941 o.body = {};
942 o.body.script = { name: this.script_.name(),
943 lineOffset: this.script_.lineOffset(),
944 columnOffset: this.script_.columnOffset(),
945 lineCount: this.script_.lineCount(),
946 source: this.script_.source()
947 };
948
949 return o.toJSONProtocol();
950 }
951
952
930 function MakeNewFunctionEvent(func) { 953 function MakeNewFunctionEvent(func) {
931 return new NewFunctionEvent(func); 954 return new NewFunctionEvent(func);
932 } 955 }
933 956
934 957
935 function NewFunctionEvent(func) { 958 function NewFunctionEvent(func) {
936 this.func = func; 959 this.func = func;
937 } 960 }
938 961
939 962
(...skipping 16 matching lines...) Expand all
956 this.exec_state_ = exec_state; 979 this.exec_state_ = exec_state;
957 this.running_ = false; 980 this.running_ = false;
958 }; 981 };
959 982
960 983
961 DebugCommandProcessor.prototype.processDebugRequest = function (request) { 984 DebugCommandProcessor.prototype.processDebugRequest = function (request) {
962 return this.processDebugJSONRequest(request); 985 return this.processDebugJSONRequest(request);
963 } 986 }
964 987
965 988
966 function ResponsePacket(request) { 989 function ProtocolMessage(request) {
967 // Build the initial response from the request. 990 // Update sequence number.
968 this.seq = next_response_seq++; 991 this.seq = next_response_seq++;
969 this.type = 'response'; 992
970 if (request) this.request_seq = request.seq; 993 if (request) {
971 if (request) this.command = request.command; 994 // If message is based on a request this is a response. Fill the initial
995 // response from the request.
996 this.type = 'response';
997 this.request_seq = request.seq;
998 this.command = request.command;
999 } else {
1000 // If message is not based on a request it is a dabugger generated event.
1001 this.type = 'event';
1002 }
972 this.success = true; 1003 this.success = true;
973 this.running = false; 1004 this.running = false;
974 } 1005 }
975 1006
976 1007
977 ResponsePacket.prototype.failed = function(message) { 1008 ProtocolMessage.prototype.failed = function(message) {
978 this.success = false; 1009 this.success = false;
979 this.message = message; 1010 this.message = message;
980 } 1011 }
981 1012
982 1013
983 ResponsePacket.prototype.toJSONProtocol = function() { 1014 ProtocolMessage.prototype.toJSONProtocol = function() {
984 // Encode the protocol header. 1015 // Encode the protocol header.
985 var json = '{'; 1016 var json = '{';
986 json += '"seq":' + this.seq; 1017 json += '"seq":' + this.seq;
987 if (this.request_seq) { 1018 if (this.request_seq) {
988 json += ',"request_seq":' + this.request_seq; 1019 json += ',"request_seq":' + this.request_seq;
989 } 1020 }
990 json += ',"type":"' + this.type + '"'; 1021 json += ',"type":"' + this.type + '"';
1022 if (this.event) {
1023 json += ',"event":' + StringToJSON_(this.event);
1024 }
991 if (this.command) { 1025 if (this.command) {
992 json += ',"command":' + StringToJSON_(this.command); 1026 json += ',"command":' + StringToJSON_(this.command);
993 } 1027 }
994 if (this.success) { 1028 if (this.success) {
995 json += ',"success":' + this.success; 1029 json += ',"success":' + this.success;
996 } else { 1030 } else {
997 json += ',"success":false'; 1031 json += ',"success":false';
998 } 1032 }
999 if (this.body) { 1033 if (this.body) {
1000 json += ',"body":'; 1034 json += ',"body":';
(...skipping 25 matching lines...) Expand all
1026 json += ',"running":true'; 1060 json += ',"running":true';
1027 } else { 1061 } else {
1028 json += ',"running":false'; 1062 json += ',"running":false';
1029 } 1063 }
1030 json += '}'; 1064 json += '}';
1031 return json; 1065 return json;
1032 } 1066 }
1033 1067
1034 1068
1035 DebugCommandProcessor.prototype.createResponse = function(request) { 1069 DebugCommandProcessor.prototype.createResponse = function(request) {
1036 return new ResponsePacket(request); 1070 return new ProtocolMessage(request);
1037 }; 1071 };
1038 1072
1039 1073
1040 DebugCommandProcessor.prototype.processDebugJSONRequest = function(json_request) { 1074 DebugCommandProcessor.prototype.processDebugJSONRequest = function(json_request) {
1041 var request; // Current request. 1075 var request; // Current request.
1042 var response; // Generated response. 1076 var response; // Generated response.
1043 try { 1077 try {
1044 try { 1078 try {
1045 // Convert the JSON string to an object. 1079 // Convert the JSON string to an object.
1046 request = %CompileString('(' + json_request + ')', 0)(); 1080 request = %CompileString('(' + json_request + ')', 0)();
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 var content = []; 1679 var content = [];
1646 for (var key in object) { 1680 for (var key in object) {
1647 // Only consider string keys. 1681 // Only consider string keys.
1648 if (typeof key == 'string') { 1682 if (typeof key == 'string') {
1649 var property_value = object[key]; 1683 var property_value = object[key];
1650 1684
1651 // Format the value based on its type. 1685 // Format the value based on its type.
1652 var property_value_json; 1686 var property_value_json;
1653 switch (typeof property_value) { 1687 switch (typeof property_value) {
1654 case 'object': 1688 case 'object':
1655 if (typeof property_value.toJSONProtocol == 'function') { 1689 if (property_value instanceof Mirror) {
1690 property_value_json = mirror_serializer.serializeValue(property_valu e);
1691 } else if (typeof property_value.toJSONProtocol == 'function') {
1656 property_value_json = property_value.toJSONProtocol(true) 1692 property_value_json = property_value.toJSONProtocol(true)
1657 } else if (IS_ARRAY(property_value)){ 1693 } else if (IS_ARRAY(property_value)){
1658 property_value_json = SimpleArrayToJSON_(property_value, mirror_seri alizer); 1694 property_value_json = SimpleArrayToJSON_(property_value, mirror_seri alizer);
1659 } else { 1695 } else {
1660 property_value_json = SimpleObjectToJSON_(property_value, mirror_ser ializer); 1696 property_value_json = SimpleObjectToJSON_(property_value, mirror_ser ializer);
1661 } 1697 }
1662 break; 1698 break;
1663 1699
1664 case 'boolean': 1700 case 'boolean':
1665 property_value_json = BooleanToJSON_(property_value); 1701 property_value_json = BooleanToJSON_(property_value);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 json += NumberToJSON_(elem); 1750 json += NumberToJSON_(elem);
1715 } else if (IS_STRING(elem)) { 1751 } else if (IS_STRING(elem)) {
1716 json += StringToJSON_(elem); 1752 json += StringToJSON_(elem);
1717 } else { 1753 } else {
1718 json += elem; 1754 json += elem;
1719 } 1755 }
1720 } 1756 }
1721 json += ']'; 1757 json += ']';
1722 return json; 1758 return json;
1723 } 1759 }
OLDNEW
« no previous file with comments | « src/d8-debug.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698