OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 275 |
276 case 'print': | 276 case 'print': |
277 case 'p': | 277 case 'p': |
278 this.request_ = this.printCommandToJSONRequest_(args); | 278 this.request_ = this.printCommandToJSONRequest_(args); |
279 break; | 279 break; |
280 | 280 |
281 case 'dir': | 281 case 'dir': |
282 this.request_ = this.dirCommandToJSONRequest_(args); | 282 this.request_ = this.dirCommandToJSONRequest_(args); |
283 break; | 283 break; |
284 | 284 |
| 285 case 'references': |
| 286 this.request_ = this.referencesCommandToJSONRequest_(args); |
| 287 break; |
| 288 |
| 289 case 'instances': |
| 290 this.request_ = this.instancesCommandToJSONRequest_(args); |
| 291 break; |
| 292 |
285 case 'source': | 293 case 'source': |
286 this.request_ = this.sourceCommandToJSONRequest_(args); | 294 this.request_ = this.sourceCommandToJSONRequest_(args); |
287 break; | 295 break; |
288 | 296 |
289 case 'scripts': | 297 case 'scripts': |
290 this.request_ = this.scriptsCommandToJSONRequest_(args); | 298 this.request_ = this.scriptsCommandToJSONRequest_(args); |
291 break; | 299 break; |
292 | 300 |
293 case 'break': | 301 case 'break': |
294 case 'b': | 302 case 'b': |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 DebugRequest.prototype.createRequest = function(command) { | 364 DebugRequest.prototype.createRequest = function(command) { |
357 return new RequestPacket(command); | 365 return new RequestPacket(command); |
358 }; | 366 }; |
359 | 367 |
360 | 368 |
361 // Create a JSON request for the evaluation command. | 369 // Create a JSON request for the evaluation command. |
362 DebugRequest.prototype.makeEvaluateJSONRequest_ = function(expression) { | 370 DebugRequest.prototype.makeEvaluateJSONRequest_ = function(expression) { |
363 // Check if the expression is a handle id in the form #<handle>#. | 371 // Check if the expression is a handle id in the form #<handle>#. |
364 var handle_match = expression.match(/^#([0-9]*)#$/); | 372 var handle_match = expression.match(/^#([0-9]*)#$/); |
365 if (handle_match) { | 373 if (handle_match) { |
366 // Build an evaluate request. | 374 // Build a lookup request. |
367 var request = this.createRequest('lookup'); | 375 var request = this.createRequest('lookup'); |
368 request.arguments = {}; | 376 request.arguments = {}; |
369 request.arguments.handle = parseInt(handle_match[1]); | 377 request.arguments.handle = parseInt(handle_match[1]); |
370 return request.toJSONProtocol(); | 378 return request.toJSONProtocol(); |
371 } else { | 379 } else { |
372 // Build an evaluate request. | 380 // Build an evaluate request. |
373 var request = this.createRequest('evaluate'); | 381 var request = this.createRequest('evaluate'); |
374 request.arguments = {}; | 382 request.arguments = {}; |
375 request.arguments.expression = expression; | 383 request.arguments.expression = expression; |
376 return request.toJSONProtocol(); | 384 return request.toJSONProtocol(); |
377 } | 385 } |
378 }; | 386 }; |
379 | 387 |
380 | 388 |
| 389 // Create a JSON request for the references/instances command. |
| 390 DebugRequest.prototype.makeReferencesJSONRequest_ = function(handle, type) { |
| 391 // Build a references request. |
| 392 var handle_match = handle.match(/^#([0-9]*)#$/); |
| 393 if (handle_match) { |
| 394 var request = this.createRequest('references'); |
| 395 request.arguments = {}; |
| 396 request.arguments.type = type; |
| 397 request.arguments.handle = parseInt(handle_match[1]); |
| 398 return request.toJSONProtocol(); |
| 399 } else { |
| 400 throw new Error('Invalid object id.'); |
| 401 } |
| 402 }; |
| 403 |
381 | 404 |
382 // Create a JSON request for the continue command. | 405 // Create a JSON request for the continue command. |
383 DebugRequest.prototype.continueCommandToJSONRequest_ = function(args) { | 406 DebugRequest.prototype.continueCommandToJSONRequest_ = function(args) { |
384 var request = this.createRequest('continue'); | 407 var request = this.createRequest('continue'); |
385 return request.toJSONProtocol(); | 408 return request.toJSONProtocol(); |
386 }; | 409 }; |
387 | 410 |
388 | 411 |
389 // Create a JSON request for the step command. | 412 // Create a JSON request for the step command. |
390 DebugRequest.prototype.stepCommandToJSONRequest_ = function(args) { | 413 DebugRequest.prototype.stepCommandToJSONRequest_ = function(args) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 // Create a JSON request for the dir command. | 521 // Create a JSON request for the dir command. |
499 DebugRequest.prototype.dirCommandToJSONRequest_ = function(args) { | 522 DebugRequest.prototype.dirCommandToJSONRequest_ = function(args) { |
500 // Build an evaluate request from the text command. | 523 // Build an evaluate request from the text command. |
501 if (args.length == 0) { | 524 if (args.length == 0) { |
502 throw new Error('Missing expression.'); | 525 throw new Error('Missing expression.'); |
503 } | 526 } |
504 return this.makeEvaluateJSONRequest_(args); | 527 return this.makeEvaluateJSONRequest_(args); |
505 }; | 528 }; |
506 | 529 |
507 | 530 |
| 531 // Create a JSON request for the references command. |
| 532 DebugRequest.prototype.referencesCommandToJSONRequest_ = function(args) { |
| 533 // Build an evaluate request from the text command. |
| 534 if (args.length == 0) { |
| 535 throw new Error('Missing object id.'); |
| 536 } |
| 537 |
| 538 return this.makeReferencesJSONRequest_(args, 'referencedBy'); |
| 539 }; |
| 540 |
| 541 |
| 542 // Create a JSON request for the instances command. |
| 543 DebugRequest.prototype.instancesCommandToJSONRequest_ = function(args) { |
| 544 // Build an evaluate request from the text command. |
| 545 if (args.length == 0) { |
| 546 throw new Error('Missing object id.'); |
| 547 } |
| 548 |
| 549 // Build a references request. |
| 550 return this.makeReferencesJSONRequest_(args, 'constructedBy'); |
| 551 }; |
| 552 |
| 553 |
508 // Create a JSON request for the source command. | 554 // Create a JSON request for the source command. |
509 DebugRequest.prototype.sourceCommandToJSONRequest_ = function(args) { | 555 DebugRequest.prototype.sourceCommandToJSONRequest_ = function(args) { |
510 // Build a evaluate request from the text command. | 556 // Build a evaluate request from the text command. |
511 var request = this.createRequest('source'); | 557 var request = this.createRequest('source'); |
512 | 558 |
513 // Default is ten lines starting five lines before the current location. | 559 // Default is ten lines starting five lines before the current location. |
514 var from = Debug.State.currentSourceLine - 5; | 560 var from = Debug.State.currentSourceLine - 5; |
515 var lines = 10; | 561 var lines = 10; |
516 | 562 |
517 // Parse the arguments. | 563 // Parse the arguments. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 print('trace compile'); | 699 print('trace compile'); |
654 print('help'); | 700 print('help'); |
655 } | 701 } |
656 | 702 |
657 | 703 |
658 function formatHandleReference_(value) { | 704 function formatHandleReference_(value) { |
659 return '#' + value.handle() + '#'; | 705 return '#' + value.handle() + '#'; |
660 } | 706 } |
661 | 707 |
662 | 708 |
| 709 function formatObject_(value, include_properties) { |
| 710 var result = ''; |
| 711 result += formatHandleReference_(value); |
| 712 result += ', type: object' |
| 713 result += ', constructor '; |
| 714 var ctor = value.constructorFunctionValue(); |
| 715 result += formatHandleReference_(ctor); |
| 716 result += ', __proto__ '; |
| 717 var proto = value.protoObjectValue(); |
| 718 result += formatHandleReference_(proto); |
| 719 result += ', '; |
| 720 result += value.propertyCount(); |
| 721 result += ' properties.'; |
| 722 if (include_properties) { |
| 723 result += '\n'; |
| 724 for (var i = 0; i < value.propertyCount(); i++) { |
| 725 result += ' '; |
| 726 result += value.propertyName(i); |
| 727 result += ': '; |
| 728 var property_value = value.propertyValue(i); |
| 729 if (property_value && property_value.type()) { |
| 730 result += property_value.type(); |
| 731 } else { |
| 732 result += '<no type>'; |
| 733 } |
| 734 result += ' '; |
| 735 result += formatHandleReference_(property_value); |
| 736 result += '\n'; |
| 737 } |
| 738 } |
| 739 return result; |
| 740 } |
| 741 |
| 742 |
663 // Convert a JSON response to text for display in a text based debugger. | 743 // Convert a JSON response to text for display in a text based debugger. |
664 function DebugResponseDetails(json_response) { | 744 function DebugResponseDetails(json_response) { |
665 details = {text:'', running:false} | 745 details = {text:'', running:false} |
666 | 746 |
667 try { | 747 try { |
668 // Convert the JSON string to an object. | 748 // Convert the JSON string to an object. |
669 var response = new ProtocolPackage(json_response); | 749 var response = new ProtocolPackage(json_response); |
670 | 750 |
671 if (!response.success()) { | 751 if (!response.success()) { |
672 details.text = response.message(); | 752 details.text = response.message(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 Debug.State.currentFrame = body.index; | 792 Debug.State.currentFrame = body.index; |
713 break; | 793 break; |
714 | 794 |
715 case 'evaluate': | 795 case 'evaluate': |
716 case 'lookup': | 796 case 'lookup': |
717 if (last_cmd == 'p' || last_cmd == 'print') { | 797 if (last_cmd == 'p' || last_cmd == 'print') { |
718 details.text = body.text; | 798 details.text = body.text; |
719 } else { | 799 } else { |
720 var value = response.bodyValue(); | 800 var value = response.bodyValue(); |
721 if (value.isObject()) { | 801 if (value.isObject()) { |
722 result += formatHandleReference_(value); | 802 result += formatObject_(value, true); |
723 result += ', type: object' | |
724 result += ', constructor '; | |
725 var ctor = value.constructorFunctionValue(); | |
726 result += formatHandleReference_(ctor); | |
727 result += ', __proto__ '; | |
728 var proto = value.protoObjectValue(); | |
729 result += formatHandleReference_(proto); | |
730 result += ', '; | |
731 result += value.propertyCount(); | |
732 result += ' properties.\n'; | |
733 for (var i = 0; i < value.propertyCount(); i++) { | |
734 result += ' '; | |
735 result += value.propertyName(i); | |
736 result += ': '; | |
737 var property_value = value.propertyValue(i); | |
738 if (property_value && property_value.type()) { | |
739 result += property_value.type(); | |
740 } else { | |
741 result += '<no type>'; | |
742 } | |
743 result += ' '; | |
744 result += formatHandleReference_(property_value); | |
745 result += '\n'; | |
746 } | |
747 } else { | 803 } else { |
748 result += 'type: '; | 804 result += 'type: '; |
749 result += value.type(); | 805 result += value.type(); |
750 if (!value.isUndefined() && !value.isNull()) { | 806 if (!value.isUndefined() && !value.isNull()) { |
751 result += ', '; | 807 result += ', '; |
752 if (value.isString()) { | 808 if (value.isString()) { |
753 result += '"'; | 809 result += '"'; |
754 } | 810 } |
755 result += value.value(); | 811 result += value.value(); |
756 if (value.isString()) { | 812 if (value.isString()) { |
757 result += '"'; | 813 result += '"'; |
758 } | 814 } |
759 } | 815 } |
760 result += '\n'; | 816 result += '\n'; |
761 } | 817 } |
762 } | 818 } |
763 details.text = result; | 819 details.text = result; |
764 break; | 820 break; |
| 821 |
| 822 case 'references': |
| 823 var count = body.length; |
| 824 result += 'found ' + count + ' objects'; |
| 825 result += '\n'; |
| 826 for (var i = 0; i < count; i++) { |
| 827 var value = response.bodyValue(i); |
| 828 result += formatObject_(value, false); |
| 829 result += '\n'; |
| 830 } |
| 831 details.text = result; |
| 832 break; |
765 | 833 |
766 case 'source': | 834 case 'source': |
767 // Get the source from the response. | 835 // Get the source from the response. |
768 var source = body.source; | 836 var source = body.source; |
769 var from_line = body.fromLine + 1; | 837 var from_line = body.fromLine + 1; |
770 var lines = source.split('\n'); | 838 var lines = source.split('\n'); |
771 var maxdigits = 1 + Math.floor(log10(from_line + lines.length)); | 839 var maxdigits = 1 + Math.floor(log10(from_line + lines.length)); |
772 if (maxdigits < 3) { | 840 if (maxdigits < 3) { |
773 maxdigits = 3; | 841 maxdigits = 3; |
774 } | 842 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 ProtocolPackage.prototype.command = function() { | 976 ProtocolPackage.prototype.command = function() { |
909 return this.packet_.command; | 977 return this.packet_.command; |
910 } | 978 } |
911 | 979 |
912 | 980 |
913 ProtocolPackage.prototype.body = function() { | 981 ProtocolPackage.prototype.body = function() { |
914 return this.packet_.body; | 982 return this.packet_.body; |
915 } | 983 } |
916 | 984 |
917 | 985 |
918 ProtocolPackage.prototype.bodyValue = function() { | 986 ProtocolPackage.prototype.bodyValue = function(index) { |
919 return new ProtocolValue(this.packet_.body, this); | 987 if (IS_UNDEFINED(index)) { |
| 988 return new ProtocolValue(this.packet_.body, this); |
| 989 } else { |
| 990 return new ProtocolValue(this.packet_.body[index], this); |
| 991 } |
920 } | 992 } |
921 | 993 |
922 | 994 |
923 ProtocolPackage.prototype.body = function() { | 995 ProtocolPackage.prototype.body = function() { |
924 return this.packet_.body; | 996 return this.packet_.body; |
925 } | 997 } |
926 | 998 |
927 | 999 |
928 ProtocolPackage.prototype.lookup = function(handle) { | 1000 ProtocolPackage.prototype.lookup = function(handle) { |
929 var value = this.refs_[handle]; | 1001 var value = this.refs_[handle]; |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 json += NumberToJSON_(elem); | 1376 json += NumberToJSON_(elem); |
1305 } else if (typeof(elem) === 'string') { | 1377 } else if (typeof(elem) === 'string') { |
1306 json += StringToJSON_(elem); | 1378 json += StringToJSON_(elem); |
1307 } else { | 1379 } else { |
1308 json += elem; | 1380 json += elem; |
1309 } | 1381 } |
1310 } | 1382 } |
1311 json += ']'; | 1383 json += ']'; |
1312 return json; | 1384 return json; |
1313 } | 1385 } |
OLD | NEW |