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 1642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1653 this.mirrors_.push(mirror); | 1653 this.mirrors_.push(mirror); |
1654 } | 1654 } |
1655 | 1655 |
1656 | 1656 |
1657 JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, | 1657 JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, |
1658 details) { | 1658 details) { |
1659 // If serializing a reference to a value just return the reference and add the | 1659 // If serializing a reference to a value just return the reference and add the |
1660 // mirror to the referenced mirrors. | 1660 // mirror to the referenced mirrors. |
1661 if (reference && mirror.isValue()) { | 1661 if (reference && mirror.isValue()) { |
1662 this.add_(mirror); | 1662 this.add_(mirror); |
1663 return '{ref:' + mirror.handle() + '}'; | 1663 return '{"ref":' + mirror.handle() + '}'; |
1664 } | 1664 } |
1665 | 1665 |
1666 // Collect the JSON property/value pairs in an array. | 1666 // Collect the JSON property/value pairs in an array. |
1667 var content = new Array(); | 1667 var content = new Array(); |
1668 | 1668 |
1669 // Add the handle for value mirrors. | 1669 // Add the handle for value mirrors. |
1670 if (mirror.isValue()) { | 1670 if (mirror.isValue()) { |
1671 content.push(MakeJSONPair_('handle', NumberToJSON_(mirror.handle()))); | 1671 content.push(MakeJSONPair_('handle', NumberToJSON_(mirror.handle()))); |
1672 } | 1672 } |
1673 | 1673 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 function ArrayToJSONArray_(content) { | 1915 function ArrayToJSONArray_(content) { |
1916 return '[' + content.join(',') + ']'; | 1916 return '[' + content.join(',') + ']'; |
1917 } | 1917 } |
1918 | 1918 |
1919 | 1919 |
1920 function BooleanToJSON_(value) { | 1920 function BooleanToJSON_(value) { |
1921 return String(value); | 1921 return String(value); |
1922 } | 1922 } |
1923 | 1923 |
1924 | 1924 |
| 1925 /** |
| 1926 * Convert a number to a JSON string value. For all finite numbers the number |
| 1927 * literal representation is used. For non finite numbers NaN, Infinite and |
| 1928 * -Infinite the string representation "NaN", "Infinite" or "-Infinite" |
| 1929 * (including the quotes) is returned. |
| 1930 * |
| 1931 * @param {number} value The number value to convert to a JSON value |
| 1932 * @returns {String} JSON value |
| 1933 */ |
1925 function NumberToJSON_(value) { | 1934 function NumberToJSON_(value) { |
| 1935 if (isNaN(value)) { |
| 1936 return '"NaN"'; |
| 1937 } |
| 1938 if (!isFinite(value)) { |
| 1939 if (value > 0) { |
| 1940 return '"Infinity"'; |
| 1941 } else { |
| 1942 return '"-Infinity"'; |
| 1943 } |
| 1944 } |
1926 return String(value); | 1945 return String(value); |
1927 } | 1946 } |
1928 | 1947 |
1929 | 1948 |
1930 // Mapping of some control characters to avoid the \uXXXX syntax for most | 1949 // Mapping of some control characters to avoid the \uXXXX syntax for most |
1931 // commonly used control cahracters. | 1950 // commonly used control cahracters. |
1932 const ctrlCharMap_ = { | 1951 const ctrlCharMap_ = { |
1933 '\b': '\\b', | 1952 '\b': '\\b', |
1934 '\t': '\\t', | 1953 '\t': '\\t', |
1935 '\n': '\\n', | 1954 '\n': '\\n', |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2006 /** | 2025 /** |
2007 * Convert a Date to ISO 8601 format. To avoid depending on the Date object | 2026 * Convert a Date to ISO 8601 format. To avoid depending on the Date object |
2008 * this method calls the functions in date.js directly and not through the | 2027 * this method calls the functions in date.js directly and not through the |
2009 * value. | 2028 * value. |
2010 * @param {Date} value The Date value to format as JSON | 2029 * @param {Date} value The Date value to format as JSON |
2011 * @return {string} JSON formatted Date value | 2030 * @return {string} JSON formatted Date value |
2012 */ | 2031 */ |
2013 function DateToJSON_(value) { | 2032 function DateToJSON_(value) { |
2014 return '"' + DateToISO8601_(value) + '"'; | 2033 return '"' + DateToISO8601_(value) + '"'; |
2015 } | 2034 } |
OLD | NEW |