| OLD | NEW |
| 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 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 json += ',"command":' + StringToJSON_(this.command); | 987 json += ',"command":' + StringToJSON_(this.command); |
| 988 } | 988 } |
| 989 if (this.success) { | 989 if (this.success) { |
| 990 json += ',"success":' + this.success; | 990 json += ',"success":' + this.success; |
| 991 } else { | 991 } else { |
| 992 json += ',"success":false'; | 992 json += ',"success":false'; |
| 993 } | 993 } |
| 994 if (this.body) { | 994 if (this.body) { |
| 995 json += ',"body":'; | 995 json += ',"body":'; |
| 996 // Encode the body part. | 996 // Encode the body part. |
| 997 if (this.body.toJSONProtocol) { | 997 var serializer = MakeMirrorSerializer(true); |
| 998 json += this.body.toJSONProtocol(true); | 998 if (this.body instanceof Mirror) { |
| 999 json += serializer.serializeValue(this.body); |
| 999 } else if (this.body instanceof Array) { | 1000 } else if (this.body instanceof Array) { |
| 1000 json += '['; | 1001 json += '['; |
| 1001 for (var i = 0; i < this.body.length; i++) { | 1002 for (var i = 0; i < this.body.length; i++) { |
| 1002 if (i != 0) json += ','; | 1003 if (i != 0) json += ','; |
| 1003 if (this.body[i].toJSONProtocol) { | 1004 if (this.body[i] instanceof Mirror) { |
| 1004 json += this.body[i].toJSONProtocol(true) | 1005 json += serializer.serializeValue(this.body[i]); |
| 1005 } else { | 1006 } else { |
| 1006 json += SimpleObjectToJSON_(this.body[i]); | 1007 json += SimpleObjectToJSON_(this.body[i], serializer); |
| 1007 } | 1008 } |
| 1008 } | 1009 } |
| 1009 json += ']'; | 1010 json += ']'; |
| 1010 } else { | 1011 } else { |
| 1011 json += SimpleObjectToJSON_(this.body); | 1012 json += SimpleObjectToJSON_(this.body, serializer); |
| 1012 } | 1013 } |
| 1014 json += ',"refs":'; |
| 1015 json += serializer.serializeReferencedObjects(); |
| 1013 } | 1016 } |
| 1014 if (this.message) { | 1017 if (this.message) { |
| 1015 json += ',"message":' + StringToJSON_(this.message) ; | 1018 json += ',"message":' + StringToJSON_(this.message) ; |
| 1016 } | 1019 } |
| 1017 if (this.running) { | 1020 if (this.running) { |
| 1018 json += ',"running":true'; | 1021 json += ',"running":true'; |
| 1019 } else { | 1022 } else { |
| 1020 json += ',"running":false'; | 1023 json += ',"running":false'; |
| 1021 } | 1024 } |
| 1022 json += '}'; | 1025 json += '}'; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 } else if (request.command == 'changebreakpoint') { | 1064 } else if (request.command == 'changebreakpoint') { |
| 1062 this.changeBreakPointRequest_(request, response); | 1065 this.changeBreakPointRequest_(request, response); |
| 1063 } else if (request.command == 'clearbreakpoint') { | 1066 } else if (request.command == 'clearbreakpoint') { |
| 1064 this.clearBreakPointRequest_(request, response); | 1067 this.clearBreakPointRequest_(request, response); |
| 1065 } else if (request.command == 'backtrace') { | 1068 } else if (request.command == 'backtrace') { |
| 1066 this.backtraceRequest_(request, response); | 1069 this.backtraceRequest_(request, response); |
| 1067 } else if (request.command == 'frame') { | 1070 } else if (request.command == 'frame') { |
| 1068 this.frameRequest_(request, response); | 1071 this.frameRequest_(request, response); |
| 1069 } else if (request.command == 'evaluate') { | 1072 } else if (request.command == 'evaluate') { |
| 1070 this.evaluateRequest_(request, response); | 1073 this.evaluateRequest_(request, response); |
| 1074 } else if (request.command == 'lookup') { |
| 1075 this.lookupRequest_(request, response); |
| 1071 } else if (request.command == 'source') { | 1076 } else if (request.command == 'source') { |
| 1072 this.sourceRequest_(request, response); | 1077 this.sourceRequest_(request, response); |
| 1073 } else if (request.command == 'scripts') { | 1078 } else if (request.command == 'scripts') { |
| 1074 this.scriptsRequest_(request, response); | 1079 this.scriptsRequest_(request, response); |
| 1075 } else { | 1080 } else { |
| 1076 throw new Error('Unknown command "' + request.command + '" in request'); | 1081 throw new Error('Unknown command "' + request.command + '" in request'); |
| 1077 } | 1082 } |
| 1078 } catch (e) { | 1083 } catch (e) { |
| 1079 // If there is no response object created one (without command). | 1084 // If there is no response object created one (without command). |
| 1080 if (!response) { | 1085 if (!response) { |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1356 }; | 1361 }; |
| 1357 | 1362 |
| 1358 | 1363 |
| 1359 DebugCommandProcessor.prototype.frameRequest_ = function(request, response) { | 1364 DebugCommandProcessor.prototype.frameRequest_ = function(request, response) { |
| 1360 // No frames no source. | 1365 // No frames no source. |
| 1361 if (this.exec_state_.frameCount() == 0) { | 1366 if (this.exec_state_.frameCount() == 0) { |
| 1362 return response.failed('No frames'); | 1367 return response.failed('No frames'); |
| 1363 } | 1368 } |
| 1364 | 1369 |
| 1365 // With no arguments just keep the selected frame. | 1370 // With no arguments just keep the selected frame. |
| 1366 if (request.arguments && request.arguments.number >= 0) { | 1371 if (request.arguments) { |
| 1372 index = request.arguments.number; |
| 1373 if (index < 0 || this.exec_state_.frameCount() <= index) { |
| 1374 return response.failed('Invalid frame number'); |
| 1375 } |
| 1376 |
| 1367 this.exec_state_.setSelectedFrame(request.arguments.number); | 1377 this.exec_state_.setSelectedFrame(request.arguments.number); |
| 1368 } | 1378 } |
| 1369 response.body = this.exec_state_.frame(); | 1379 response.body = this.exec_state_.frame(); |
| 1370 }; | 1380 }; |
| 1371 | 1381 |
| 1372 | 1382 |
| 1373 DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) { | 1383 DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) { |
| 1374 if (!request.arguments) { | 1384 if (!request.arguments) { |
| 1375 return response.failed('Missing arguments'); | 1385 return response.failed('Missing arguments'); |
| 1376 } | 1386 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 return; | 1429 return; |
| 1420 } else { | 1430 } else { |
| 1421 // Evaluate in the selected frame. | 1431 // Evaluate in the selected frame. |
| 1422 response.body = this.exec_state_.frame().evaluate( | 1432 response.body = this.exec_state_.frame().evaluate( |
| 1423 expression, Boolean(disable_break)); | 1433 expression, Boolean(disable_break)); |
| 1424 return; | 1434 return; |
| 1425 } | 1435 } |
| 1426 }; | 1436 }; |
| 1427 | 1437 |
| 1428 | 1438 |
| 1439 DebugCommandProcessor.prototype.lookupRequest_ = function(request, response) { |
| 1440 if (!request.arguments) { |
| 1441 return response.failed('Missing arguments'); |
| 1442 } |
| 1443 |
| 1444 // Pull out arguments. |
| 1445 var handle = request.arguments.handle; |
| 1446 |
| 1447 // Check for legal arguments. |
| 1448 if (IS_UNDEFINED(handle)) { |
| 1449 return response.failed('Argument "handle" missing'); |
| 1450 } |
| 1451 |
| 1452 // Lookup handle. |
| 1453 var mirror = LookupMirror(handle); |
| 1454 if (mirror) { |
| 1455 response.body = mirror; |
| 1456 } else { |
| 1457 return response.failed('Object #' + handle + '# not found'); |
| 1458 } |
| 1459 }; |
| 1460 |
| 1461 |
| 1429 DebugCommandProcessor.prototype.sourceRequest_ = function(request, response) { | 1462 DebugCommandProcessor.prototype.sourceRequest_ = function(request, response) { |
| 1430 // No frames no source. | 1463 // No frames no source. |
| 1431 if (this.exec_state_.frameCount() == 0) { | 1464 if (this.exec_state_.frameCount() == 0) { |
| 1432 return response.failed('No source'); | 1465 return response.failed('No source'); |
| 1433 } | 1466 } |
| 1434 | 1467 |
| 1435 var from_line; | 1468 var from_line; |
| 1436 var to_line; | 1469 var to_line; |
| 1437 var frame = this.exec_state_.frame(); | 1470 var frame = this.exec_state_.frame(); |
| 1438 if (request.arguments) { | 1471 if (request.arguments) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1561 | 1594 |
| 1562 /** | 1595 /** |
| 1563 * Convert an Object to its JSON representation (see http://www.json.org/). | 1596 * Convert an Object to its JSON representation (see http://www.json.org/). |
| 1564 * This implementation simply runs through all string property names and adds | 1597 * This implementation simply runs through all string property names and adds |
| 1565 * each property to the JSON representation for some predefined types. For type | 1598 * each property to the JSON representation for some predefined types. For type |
| 1566 * "object" the function calls itself recursively unless the object has the | 1599 * "object" the function calls itself recursively unless the object has the |
| 1567 * function property "toJSONProtocol" in which case that is used. This is not | 1600 * function property "toJSONProtocol" in which case that is used. This is not |
| 1568 * a general implementation but sufficient for the debugger. Note that circular | 1601 * a general implementation but sufficient for the debugger. Note that circular |
| 1569 * structures will cause infinite recursion. | 1602 * structures will cause infinite recursion. |
| 1570 * @param {Object} object The object to format as JSON | 1603 * @param {Object} object The object to format as JSON |
| 1604 * @param {MirrorSerializer} mirror_serializer The serializer to use if any |
| 1605 * mirror objects are encountered. |
| 1571 * @return {string} JSON formatted object value | 1606 * @return {string} JSON formatted object value |
| 1572 */ | 1607 */ |
| 1573 function SimpleObjectToJSON_(object) { | 1608 function SimpleObjectToJSON_(object, mirror_serializer) { |
| 1574 var content = []; | 1609 var content = []; |
| 1575 for (var key in object) { | 1610 for (var key in object) { |
| 1576 // Only consider string keys. | 1611 // Only consider string keys. |
| 1577 if (typeof key == 'string') { | 1612 if (typeof key == 'string') { |
| 1578 var property_value = object[key]; | 1613 var property_value = object[key]; |
| 1579 | 1614 |
| 1580 // Format the value based on its type. | 1615 // Format the value based on its type. |
| 1581 var property_value_json; | 1616 var property_value_json; |
| 1582 switch (typeof property_value) { | 1617 switch (typeof property_value) { |
| 1583 case 'object': | 1618 case 'object': |
| 1584 if (typeof property_value.toJSONProtocol == 'function') { | 1619 if (typeof property_value.toJSONProtocol == 'function') { |
| 1585 property_value_json = property_value.toJSONProtocol(true) | 1620 property_value_json = property_value.toJSONProtocol(true) |
| 1586 } else if (IS_ARRAY(property_value)){ | 1621 } else if (IS_ARRAY(property_value)){ |
| 1587 property_value_json = SimpleArrayToJSON_(property_value); | 1622 property_value_json = SimpleArrayToJSON_(property_value, mirror_seri
alizer); |
| 1588 } else { | 1623 } else { |
| 1589 property_value_json = SimpleObjectToJSON_(property_value); | 1624 property_value_json = SimpleObjectToJSON_(property_value, mirror_ser
ializer); |
| 1590 } | 1625 } |
| 1591 break; | 1626 break; |
| 1592 | 1627 |
| 1593 case 'boolean': | 1628 case 'boolean': |
| 1594 property_value_json = BooleanToJSON_(property_value); | 1629 property_value_json = BooleanToJSON_(property_value); |
| 1595 break; | 1630 break; |
| 1596 | 1631 |
| 1597 case 'number': | 1632 case 'number': |
| 1598 property_value_json = NumberToJSON_(property_value); | 1633 property_value_json = NumberToJSON_(property_value); |
| 1599 break; | 1634 break; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1613 } | 1648 } |
| 1614 } | 1649 } |
| 1615 | 1650 |
| 1616 // Make JSON object representation. | 1651 // Make JSON object representation. |
| 1617 return '{' + content.join(',') + '}'; | 1652 return '{' + content.join(',') + '}'; |
| 1618 } | 1653 } |
| 1619 | 1654 |
| 1620 /** | 1655 /** |
| 1621 * Convert an array to its JSON representation. This is a VERY simple | 1656 * Convert an array to its JSON representation. This is a VERY simple |
| 1622 * implementation just to support what is needed for the debugger. | 1657 * implementation just to support what is needed for the debugger. |
| 1623 * @param {Array} arrya The array to format as JSON | 1658 * @param {Array} array The array to format as JSON |
| 1659 * @param {MirrorSerializer} mirror_serializer The serializer to use if any |
| 1660 * mirror objects are encountered. |
| 1624 * @return {string} JSON formatted array value | 1661 * @return {string} JSON formatted array value |
| 1625 */ | 1662 */ |
| 1626 function SimpleArrayToJSON_(array) { | 1663 function SimpleArrayToJSON_(array, mirror_serializer) { |
| 1627 // Make JSON array representation. | 1664 // Make JSON array representation. |
| 1628 var json = '['; | 1665 var json = '['; |
| 1629 for (var i = 0; i < array.length; i++) { | 1666 for (var i = 0; i < array.length; i++) { |
| 1630 if (i != 0) { | 1667 if (i != 0) { |
| 1631 json += ','; | 1668 json += ','; |
| 1632 } | 1669 } |
| 1633 var elem = array[i]; | 1670 var elem = array[i]; |
| 1634 if (elem.toJSONProtocol) { | 1671 if (elem instanceof Mirror) { |
| 1635 json += elem.toJSONProtocol(true) | 1672 json += mirror_serializer.serializeValue(elem); |
| 1636 } else if (IS_OBJECT(elem)) { | 1673 } else if (IS_OBJECT(elem)) { |
| 1637 json += SimpleObjectToJSON_(elem); | 1674 json += SimpleObjectToJSON_(elem); |
| 1638 } else if (IS_BOOLEAN(elem)) { | 1675 } else if (IS_BOOLEAN(elem)) { |
| 1639 json += BooleanToJSON_(elem); | 1676 json += BooleanToJSON_(elem); |
| 1640 } else if (IS_NUMBER(elem)) { | 1677 } else if (IS_NUMBER(elem)) { |
| 1641 json += NumberToJSON_(elem); | 1678 json += NumberToJSON_(elem); |
| 1642 } else if (IS_STRING(elem)) { | 1679 } else if (IS_STRING(elem)) { |
| 1643 json += StringToJSON_(elem); | 1680 json += StringToJSON_(elem); |
| 1644 } else { | 1681 } else { |
| 1645 json += elem; | 1682 json += elem; |
| 1646 } | 1683 } |
| 1647 } | 1684 } |
| 1648 json += ']'; | 1685 json += ']'; |
| 1649 return json; | 1686 return json; |
| 1650 } | 1687 } |
| OLD | NEW |