| 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 11 matching lines...) Expand all Loading... |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // jsminify this file, js2c: jsmin | 28 // jsminify this file, js2c: jsmin |
| 29 | 29 |
| 30 // Touch the RegExp and Date functions to make sure that date-delay.js and | 30 // Touch the RegExp and Date functions to make sure that date-delay.js and |
| 31 // regexp-delay.js has been loaded. This is required as the mirrors use | 31 // regexp-delay.js has been loaded. This is required as the mirrors use |
| 32 // functions within these files through the builtins object. See the | 32 // functions within these files through the builtins object. |
| 33 // function DateToISO8601_ as an example. | |
| 34 RegExp; | 33 RegExp; |
| 35 Date; | 34 Date; |
| 36 | 35 |
| 37 | 36 |
| 38 var next_handle_ = 0; | 37 var next_handle_ = 0; |
| 39 var mirror_cache_ = []; | 38 var mirror_cache_ = []; |
| 40 | 39 |
| 41 /** | 40 /** |
| 42 * Clear the mirror handle cache. | 41 * Clear the mirror handle cache. |
| 43 */ | 42 */ |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 * @constructor | 927 * @constructor |
| 929 * @extends ObjectMirror | 928 * @extends ObjectMirror |
| 930 */ | 929 */ |
| 931 function DateMirror(value) { | 930 function DateMirror(value) { |
| 932 ObjectMirror.call(this, value); | 931 ObjectMirror.call(this, value); |
| 933 } | 932 } |
| 934 inherits(DateMirror, ObjectMirror); | 933 inherits(DateMirror, ObjectMirror); |
| 935 | 934 |
| 936 | 935 |
| 937 DateMirror.prototype.toText = function() { | 936 DateMirror.prototype.toText = function() { |
| 938 return DateToISO8601_(this.value_); | 937 var s = JSON.stringify(this.value_); |
| 938 return s.substring(1, s.length - 1); // cut quotes |
| 939 } | 939 } |
| 940 | 940 |
| 941 | 941 |
| 942 /** | 942 /** |
| 943 * Mirror object for regular expressions. | 943 * Mirror object for regular expressions. |
| 944 * @param {RegExp} value The RegExp object reflected by this mirror | 944 * @param {RegExp} value The RegExp object reflected by this mirror |
| 945 * @constructor | 945 * @constructor |
| 946 * @extends ObjectMirror | 946 * @extends ObjectMirror |
| 947 */ | 947 */ |
| 948 function RegExpMirror(value) { | 948 function RegExpMirror(value) { |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1721 */ | 1721 */ |
| 1722 JSONProtocolSerializer.prototype.serializeValue = function(mirror) { | 1722 JSONProtocolSerializer.prototype.serializeValue = function(mirror) { |
| 1723 var json = this.serialize_(mirror, false, true); | 1723 var json = this.serialize_(mirror, false, true); |
| 1724 return json; | 1724 return json; |
| 1725 } | 1725 } |
| 1726 | 1726 |
| 1727 | 1727 |
| 1728 /** | 1728 /** |
| 1729 * Returns a serialization of all the objects referenced. | 1729 * Returns a serialization of all the objects referenced. |
| 1730 * | 1730 * |
| 1731 * @param {Mirror} mirror The mirror to serialize | 1731 * @param {Mirror} mirror The mirror to serialize. |
| 1732 * @returns {String} JSON serialization | 1732 * @returns {Array.<Object>} Array of the referenced objects converted to |
| 1733 * protcol objects. |
| 1733 */ | 1734 */ |
| 1734 JSONProtocolSerializer.prototype.serializeReferencedObjects = function() { | 1735 JSONProtocolSerializer.prototype.serializeReferencedObjects = function() { |
| 1735 // Collect the JSON serialization of the referenced objects in an array. | 1736 // Collect the protocol representation of the referenced objects in an array. |
| 1736 var content = new Array(); | 1737 var content = []; |
| 1737 | 1738 |
| 1738 // Get the number of referenced objects. | 1739 // Get the number of referenced objects. |
| 1739 var count = this.mirrors_.length; | 1740 var count = this.mirrors_.length; |
| 1740 | 1741 |
| 1741 for (var i = 0; i < count; i++) { | 1742 for (var i = 0; i < count; i++) { |
| 1742 content.push(this.serialize_(this.mirrors_[i], false, false)); | 1743 content.push(this.serialize_(this.mirrors_[i], false, false)); |
| 1743 } | 1744 } |
| 1744 | 1745 |
| 1745 var json = ArrayToJSONArray_(content); | 1746 return content; |
| 1746 return json; | |
| 1747 } | 1747 } |
| 1748 | 1748 |
| 1749 | 1749 |
| 1750 JSONProtocolSerializer.prototype.includeSource_ = function() { | 1750 JSONProtocolSerializer.prototype.includeSource_ = function() { |
| 1751 return this.options_ && this.options_.includeSource; | 1751 return this.options_ && this.options_.includeSource; |
| 1752 } | 1752 } |
| 1753 | 1753 |
| 1754 | 1754 |
| 1755 JSONProtocolSerializer.prototype.add_ = function(mirror) { | 1755 JSONProtocolSerializer.prototype.add_ = function(mirror) { |
| 1756 // If this mirror is already in the list just return. | 1756 // If this mirror is already in the list just return. |
| 1757 for (var i = 0; i < this.mirrors_.length; i++) { | 1757 for (var i = 0; i < this.mirrors_.length; i++) { |
| 1758 if (this.mirrors_[i] === mirror) { | 1758 if (this.mirrors_[i] === mirror) { |
| 1759 return; | 1759 return; |
| 1760 } | 1760 } |
| 1761 } | 1761 } |
| 1762 | 1762 |
| 1763 // Add the mirror to the list of mirrors to be serialized. | 1763 // Add the mirror to the list of mirrors to be serialized. |
| 1764 this.mirrors_.push(mirror); | 1764 this.mirrors_.push(mirror); |
| 1765 } | 1765 } |
| 1766 | 1766 |
| 1767 | 1767 |
| 1768 JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, | 1768 JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, |
| 1769 details) { | 1769 details) { |
| 1770 // If serializing a reference to a mirror just return the reference and add | 1770 // If serializing a reference to a mirror just return the reference and add |
| 1771 // the mirror to the referenced mirrors. | 1771 // the mirror to the referenced mirrors. |
| 1772 if (reference && | 1772 if (reference && |
| 1773 (mirror.isValue() || mirror.isScript() || mirror.isContext())) { | 1773 (mirror.isValue() || mirror.isScript() || mirror.isContext())) { |
| 1774 this.add_(mirror); | 1774 this.add_(mirror); |
| 1775 return '{"ref":' + mirror.handle() + '}'; | 1775 return {'ref' : mirror.handle()}; |
| 1776 } | 1776 } |
| 1777 | 1777 |
| 1778 // Collect the JSON property/value pairs in an array. | 1778 // Collect the JSON property/value pairs. |
| 1779 var content = new Array(); | 1779 var content = {}; |
| 1780 | 1780 |
| 1781 // Add the mirror handle. | 1781 // Add the mirror handle. |
| 1782 if (mirror.isValue() || mirror.isScript() || mirror.isContext()) { | 1782 if (mirror.isValue() || mirror.isScript() || mirror.isContext()) { |
| 1783 content.push(MakeJSONPair_('handle', NumberToJSON_(mirror.handle()))); | 1783 content.handle = mirror.handle(); |
| 1784 } | 1784 } |
| 1785 | 1785 |
| 1786 // Always add the type. | 1786 // Always add the type. |
| 1787 content.push(MakeJSONPair_('type', StringToJSON_(mirror.type()))); | 1787 content.type = mirror.type(); |
| 1788 | 1788 |
| 1789 switch (mirror.type()) { | 1789 switch (mirror.type()) { |
| 1790 case UNDEFINED_TYPE: | 1790 case UNDEFINED_TYPE: |
| 1791 case NULL_TYPE: | 1791 case NULL_TYPE: |
| 1792 // Undefined and null are represented just by their type. | 1792 // Undefined and null are represented just by their type. |
| 1793 break; | 1793 break; |
| 1794 | 1794 |
| 1795 case BOOLEAN_TYPE: | 1795 case BOOLEAN_TYPE: |
| 1796 // Boolean values are simply represented by their value. | 1796 // Boolean values are simply represented by their value. |
| 1797 content.push(MakeJSONPair_('value', BooleanToJSON_(mirror.value()))); | 1797 content.value = mirror.value(); |
| 1798 break; | 1798 break; |
| 1799 | 1799 |
| 1800 case NUMBER_TYPE: | 1800 case NUMBER_TYPE: |
| 1801 // Number values are simply represented by their value. | 1801 // Number values are simply represented by their value. |
| 1802 content.push(MakeJSONPair_('value', NumberToJSON_(mirror.value()))); | 1802 content.value = NumberToJSON_(mirror.value()); |
| 1803 break; | 1803 break; |
| 1804 | 1804 |
| 1805 case STRING_TYPE: | 1805 case STRING_TYPE: |
| 1806 // String values might have their value cropped to keep down size. | 1806 // String values might have their value cropped to keep down size. |
| 1807 if (mirror.length() > kMaxProtocolStringLength) { | 1807 if (mirror.length() > kMaxProtocolStringLength) { |
| 1808 var str = mirror.value().substring(0, kMaxProtocolStringLength); | 1808 var str = mirror.value().substring(0, kMaxProtocolStringLength); |
| 1809 content.push(MakeJSONPair_('value', StringToJSON_(str))); | 1809 content.value = str; |
| 1810 content.push(MakeJSONPair_('fromIndex', NumberToJSON_(0))); | 1810 content.fromIndex = 0; |
| 1811 content.push(MakeJSONPair_('toIndex', | 1811 content.toIndex = kMaxProtocolStringLength; |
| 1812 NumberToJSON_(kMaxProtocolStringLength))); | |
| 1813 } else { | 1812 } else { |
| 1814 content.push(MakeJSONPair_('value', StringToJSON_(mirror.value()))); | 1813 content.value = mirror.value(); |
| 1815 } | 1814 } |
| 1816 content.push(MakeJSONPair_('length', NumberToJSON_(mirror.length()))); | 1815 content.length = mirror.length(); |
| 1817 break; | 1816 break; |
| 1818 | 1817 |
| 1819 case OBJECT_TYPE: | 1818 case OBJECT_TYPE: |
| 1820 case FUNCTION_TYPE: | 1819 case FUNCTION_TYPE: |
| 1821 case ERROR_TYPE: | 1820 case ERROR_TYPE: |
| 1822 case REGEXP_TYPE: | 1821 case REGEXP_TYPE: |
| 1823 // Add object representation. | 1822 // Add object representation. |
| 1824 this.serializeObject_(mirror, content, details); | 1823 this.serializeObject_(mirror, content, details); |
| 1825 break; | 1824 break; |
| 1826 | 1825 |
| 1827 case PROPERTY_TYPE: | 1826 case PROPERTY_TYPE: |
| 1828 throw new Error('PropertyMirror cannot be serialized independeltly') | 1827 throw new Error('PropertyMirror cannot be serialized independeltly') |
| 1829 break; | 1828 break; |
| 1830 | 1829 |
| 1831 case FRAME_TYPE: | 1830 case FRAME_TYPE: |
| 1832 // Add object representation. | 1831 // Add object representation. |
| 1833 this.serializeFrame_(mirror, content); | 1832 this.serializeFrame_(mirror, content); |
| 1834 break; | 1833 break; |
| 1835 | 1834 |
| 1836 case SCRIPT_TYPE: | 1835 case SCRIPT_TYPE: |
| 1837 // Script is represented by id, name and source attributes. | 1836 // Script is represented by id, name and source attributes. |
| 1838 if (mirror.name()) { | 1837 if (mirror.name()) { |
| 1839 content.push(MakeJSONPair_('name', StringToJSON_(mirror.name()))); | 1838 content.name = mirror.name(); |
| 1840 } | 1839 } |
| 1841 content.push(MakeJSONPair_('id', NumberToJSON_(mirror.id()))); | 1840 content.id = mirror.id(); |
| 1842 content.push(MakeJSONPair_('lineOffset', | 1841 content.lineOffset = mirror.lineOffset(); |
| 1843 NumberToJSON_(mirror.lineOffset()))); | 1842 content.columnOffset = mirror.columnOffset(); |
| 1844 content.push(MakeJSONPair_('columnOffset', | 1843 content.lineCount = mirror.lineCount(); |
| 1845 NumberToJSON_(mirror.columnOffset()))); | |
| 1846 content.push(MakeJSONPair_('lineCount', | |
| 1847 NumberToJSON_(mirror.lineCount()))); | |
| 1848 if (mirror.data()) { | 1844 if (mirror.data()) { |
| 1849 content.push(MakeJSONPair_('data', JSON.stringify(mirror.data()))); | 1845 content.data = mirror.data(); |
| 1850 } | 1846 } |
| 1851 if (this.includeSource_()) { | 1847 if (this.includeSource_()) { |
| 1852 content.push(MakeJSONPair_('source', | 1848 content.source = mirror.source(); |
| 1853 StringToJSON_(mirror.source()))); | |
| 1854 } else { | 1849 } else { |
| 1855 var sourceStart = mirror.source().substring(0, 80); | 1850 var sourceStart = mirror.source().substring(0, 80); |
| 1856 content.push(MakeJSONPair_('sourceStart', | 1851 content.sourceStart = sourceStart; |
| 1857 StringToJSON_(sourceStart))); | |
| 1858 } | 1852 } |
| 1859 content.push(MakeJSONPair_('sourceLength', | 1853 content.sourceLength = mirror.source().length; |
| 1860 NumberToJSON_(mirror.source().length))); | 1854 content.scriptType = mirror.scriptType(); |
| 1861 content.push(MakeJSONPair_('scriptType', | |
| 1862 NumberToJSON_(mirror.scriptType()))); | |
| 1863 if (mirror.context()) { | 1855 if (mirror.context()) { |
| 1864 content.push(MakeJSONPair_('context', | 1856 content.context = this.serializeReference(mirror.context()); |
| 1865 this.serializeReference(mirror.context()))); | |
| 1866 } | 1857 } |
| 1867 break; | 1858 break; |
| 1868 | 1859 |
| 1869 case CONTEXT_TYPE: | 1860 case CONTEXT_TYPE: |
| 1870 content.push(MakeJSONPair_('data', JSON.stringify(mirror.data()))); | 1861 content.data = mirror.data(); |
| 1871 break; | 1862 break; |
| 1872 } | 1863 } |
| 1873 | 1864 |
| 1874 // Always add the text representation. | 1865 // Always add the text representation. |
| 1875 content.push(MakeJSONPair_('text', StringToJSON_(mirror.toText()))); | 1866 content.text = mirror.toText(); |
| 1876 | 1867 |
| 1877 // Create and return the JSON string. | 1868 // Create and return the JSON string. |
| 1878 return ArrayToJSONObject_(content); | 1869 return content; |
| 1879 } | 1870 } |
| 1880 | 1871 |
| 1881 | 1872 |
| 1882 /** | 1873 /** |
| 1883 * Serialize object information to the following JSON format. | 1874 * Serialize object information to the following JSON format. |
| 1884 * | 1875 * |
| 1885 * {"className":"<class name>", | 1876 * {"className":"<class name>", |
| 1886 * "constructorFunction":{"ref":<number>}, | 1877 * "constructorFunction":{"ref":<number>}, |
| 1887 * "protoObject":{"ref":<number>}, | 1878 * "protoObject":{"ref":<number>}, |
| 1888 * "prototypeObject":{"ref":<number>}, | 1879 * "prototypeObject":{"ref":<number>}, |
| 1889 * "namedInterceptor":<boolean>, | 1880 * "namedInterceptor":<boolean>, |
| 1890 * "indexedInterceptor":<boolean>, | 1881 * "indexedInterceptor":<boolean>, |
| 1891 * "properties":[<properties>]} | 1882 * "properties":[<properties>]} |
| 1892 */ | 1883 */ |
| 1893 JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content, | 1884 JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content, |
| 1894 details) { | 1885 details) { |
| 1895 // Add general object properties. | 1886 // Add general object properties. |
| 1896 content.push(MakeJSONPair_('className', | 1887 content.className = mirror.className(); |
| 1897 StringToJSON_(mirror.className()))); | 1888 content.constructorFunction = |
| 1898 content.push(MakeJSONPair_('constructorFunction', | 1889 this.serializeReference(mirror.constructorFunction()); |
| 1899 this.serializeReference(mirror.constructorFunction()))); | 1890 content.protoObject = this.serializeReference(mirror.protoObject()); |
| 1900 content.push(MakeJSONPair_('protoObject', | 1891 content.prototypeObject = this.serializeReference(mirror.prototypeObject()); |
| 1901 this.serializeReference(mirror.protoObject()))); | |
| 1902 content.push(MakeJSONPair_('prototypeObject', | |
| 1903 this.serializeReference(mirror.prototypeObject()))); | |
| 1904 | 1892 |
| 1905 // Add flags to indicate whether there are interceptors. | 1893 // Add flags to indicate whether there are interceptors. |
| 1906 if (mirror.hasNamedInterceptor()) { | 1894 if (mirror.hasNamedInterceptor()) { |
| 1907 content.push(MakeJSONPair_('namedInterceptor', BooleanToJSON_(true))); | 1895 content.namedInterceptor = true; |
| 1908 } | 1896 } |
| 1909 if (mirror.hasIndexedInterceptor()) { | 1897 if (mirror.hasIndexedInterceptor()) { |
| 1910 content.push(MakeJSONPair_('indexedInterceptor', BooleanToJSON_(true))); | 1898 content.indexedInterceptor = true; |
| 1911 } | 1899 } |
| 1912 | 1900 |
| 1913 // Add function specific properties. | 1901 // Add function specific properties. |
| 1914 if (mirror.isFunction()) { | 1902 if (mirror.isFunction()) { |
| 1915 // Add function specific properties. | 1903 // Add function specific properties. |
| 1916 content.push(MakeJSONPair_('name', StringToJSON_(mirror.name()))); | 1904 content.name = mirror.name(); |
| 1917 if (!IS_UNDEFINED(mirror.inferredName())) { | 1905 if (!IS_UNDEFINED(mirror.inferredName())) { |
| 1918 content.push(MakeJSONPair_('inferredName', | 1906 content.inferredName = mirror.inferredName(); |
| 1919 StringToJSON_(mirror.inferredName()))); | |
| 1920 } | 1907 } |
| 1921 content.push(MakeJSONPair_('resolved', BooleanToJSON_(mirror.resolved()))); | 1908 content.resolved = mirror.resolved(); |
| 1922 if (mirror.resolved()) { | 1909 if (mirror.resolved()) { |
| 1923 content.push(MakeJSONPair_('source', StringToJSON_(mirror.source()))); | 1910 content.source = mirror.source(); |
| 1924 } | 1911 } |
| 1925 if (mirror.script()) { | 1912 if (mirror.script()) { |
| 1926 content.push(MakeJSONPair_('script', this.serializeReference(mirror.script
()))); | 1913 content.script = this.serializeReference(mirror.script()); |
| 1927 } | 1914 } |
| 1928 } | 1915 } |
| 1929 | 1916 |
| 1930 // Add date specific properties. | 1917 // Add date specific properties. |
| 1931 if (mirror.isDate()) { | 1918 if (mirror.isDate()) { |
| 1932 // Add date specific properties. | 1919 // Add date specific properties. |
| 1933 content.push(MakeJSONPair_('value', DateToJSON_(mirror.value()))); | 1920 content.value = mirror.value(); |
| 1934 } | 1921 } |
| 1935 | 1922 |
| 1936 // Add actual properties - named properties followed by indexed properties. | 1923 // Add actual properties - named properties followed by indexed properties. |
| 1937 var propertyNames = mirror.propertyNames(PropertyKind.Named); | 1924 var propertyNames = mirror.propertyNames(PropertyKind.Named); |
| 1938 var propertyIndexes = mirror.propertyNames(PropertyKind.Indexed); | 1925 var propertyIndexes = mirror.propertyNames(PropertyKind.Indexed); |
| 1939 var p = new Array(propertyNames.length + propertyIndexes.length); | 1926 var p = new Array(propertyNames.length + propertyIndexes.length); |
| 1940 for (var i = 0; i < propertyNames.length; i++) { | 1927 for (var i = 0; i < propertyNames.length; i++) { |
| 1941 var property_mirror = mirror.property(propertyNames[i]); | 1928 var propertyMirror = mirror.property(propertyNames[i]); |
| 1942 p[i] = this.serializeProperty_(property_mirror); | 1929 p[i] = this.serializeProperty_(propertyMirror); |
| 1943 if (details) { | 1930 if (details) { |
| 1944 this.add_(property_mirror.value()); | 1931 this.add_(propertyMirror.value()); |
| 1945 } | 1932 } |
| 1946 } | 1933 } |
| 1947 for (var i = 0; i < propertyIndexes.length; i++) { | 1934 for (var i = 0; i < propertyIndexes.length; i++) { |
| 1948 var property_mirror = mirror.property(propertyIndexes[i]); | 1935 var propertyMirror = mirror.property(propertyIndexes[i]); |
| 1949 p[propertyNames.length + i] = this.serializeProperty_(property_mirror); | 1936 p[propertyNames.length + i] = this.serializeProperty_(propertyMirror); |
| 1950 if (details) { | 1937 if (details) { |
| 1951 this.add_(property_mirror.value()); | 1938 this.add_(propertyMirror.value()); |
| 1952 } | 1939 } |
| 1953 } | 1940 } |
| 1954 content.push(MakeJSONPair_('properties', ArrayToJSONArray_(p))); | 1941 content.properties = p; |
| 1955 } | 1942 } |
| 1956 | 1943 |
| 1957 | 1944 |
| 1958 /** | 1945 /** |
| 1959 * Serialize property information to the following JSON format for building the | 1946 * Serialize property information to the following JSON format for building the |
| 1960 * array of properties. | 1947 * array of properties. |
| 1961 * | 1948 * |
| 1962 * {"name":"<property name>", | 1949 * {"name":"<property name>", |
| 1963 * "attributes":<number>, | 1950 * "attributes":<number>, |
| 1964 * "propertyType":<number>, | 1951 * "propertyType":<number>, |
| 1965 * "ref":<number>} | 1952 * "ref":<number>} |
| 1966 * | 1953 * |
| 1967 * If the attribute for the property is PropertyAttribute.None it is not added. | 1954 * If the attribute for the property is PropertyAttribute.None it is not added. |
| 1968 * If the propertyType for the property is PropertyType.Normal it is not added. | 1955 * If the propertyType for the property is PropertyType.Normal it is not added. |
| 1969 * Here are a couple of examples. | 1956 * Here are a couple of examples. |
| 1970 * | 1957 * |
| 1971 * {"name":"hello","ref":1} | 1958 * {"name":"hello","ref":1} |
| 1972 * {"name":"length","attributes":7,"propertyType":3,"ref":2} | 1959 * {"name":"length","attributes":7,"propertyType":3,"ref":2} |
| 1973 * | 1960 * |
| 1974 * @param {PropertyMirror} property_mirror The property to serialize | 1961 * @param {PropertyMirror} propertyMirror The property to serialize. |
| 1975 * @returns {String} JSON serialization | 1962 * @returns {Object} Protocol object representing the property. |
| 1976 */ | 1963 */ |
| 1977 JSONProtocolSerializer.prototype.serializeProperty_ = function(property_mirror)
{ | 1964 JSONProtocolSerializer.prototype.serializeProperty_ = function(propertyMirror) { |
| 1978 var builder = new builtins.StringBuilder(); | 1965 var result = {}; |
| 1979 builder.add('{"name":'); | 1966 |
| 1980 builder.add(StringToJSON_(property_mirror.name())); | 1967 result.name = propertyMirror.name(); |
| 1981 if (property_mirror.attributes() != PropertyAttribute.None) { | 1968 if (propertyMirror.attributes() != PropertyAttribute.None) { |
| 1982 builder.add(',"attributes":'); | 1969 result.attributes = propertyMirror.attributes(); |
| 1983 builder.add(NumberToJSON_(property_mirror.attributes())); | |
| 1984 } | 1970 } |
| 1985 if (property_mirror.propertyType() != PropertyType.Normal) { | 1971 if (propertyMirror.propertyType() != PropertyType.Normal) { |
| 1986 builder.add(',"propertyType":'); | 1972 result.propertyType = propertyMirror.propertyType(); |
| 1987 builder.add(NumberToJSON_(property_mirror.propertyType())); | |
| 1988 } | 1973 } |
| 1989 builder.add(',"ref":'); | 1974 result.ref = propertyMirror.value().handle(); |
| 1990 builder.add(NumberToJSON_(property_mirror.value().handle())); | 1975 return result; |
| 1991 builder.add('}'); | |
| 1992 return builder.generate(); | |
| 1993 } | 1976 } |
| 1994 | 1977 |
| 1995 | 1978 |
| 1996 JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) { | 1979 JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) { |
| 1997 content.push(MakeJSONPair_('index', NumberToJSON_(mirror.index()))); | 1980 content.index = mirror.index(); |
| 1998 content.push(MakeJSONPair_('receiver', | 1981 content.receiver = this.serializeReference(mirror.receiver()); |
| 1999 this.serializeReference(mirror.receiver()))); | |
| 2000 var func = mirror.func(); | 1982 var func = mirror.func(); |
| 2001 content.push(MakeJSONPair_('func', this.serializeReference(func))); | 1983 content.func = this.serializeReference(func); |
| 2002 if (func.script()) { | 1984 if (func.script()) { |
| 2003 content.push(MakeJSONPair_('script', | 1985 content.script = this.serializeReference(func.script()); |
| 2004 this.serializeReference(func.script()))); | |
| 2005 } | 1986 } |
| 2006 content.push(MakeJSONPair_('constructCall', | 1987 content.constructCall = mirror.isConstructCall(); |
| 2007 BooleanToJSON_(mirror.isConstructCall()))); | 1988 content.debuggerFrame = mirror.isDebuggerFrame(); |
| 2008 content.push(MakeJSONPair_('debuggerFrame', | |
| 2009 BooleanToJSON_(mirror.isDebuggerFrame()))); | |
| 2010 var x = new Array(mirror.argumentCount()); | 1989 var x = new Array(mirror.argumentCount()); |
| 2011 for (var i = 0; i < mirror.argumentCount(); i++) { | 1990 for (var i = 0; i < mirror.argumentCount(); i++) { |
| 2012 arg = new Array(); | 1991 var arg = {}; |
| 2013 var argument_name = mirror.argumentName(i) | 1992 var argument_name = mirror.argumentName(i) |
| 2014 if (argument_name) { | 1993 if (argument_name) { |
| 2015 arg.push(MakeJSONPair_('name', StringToJSON_(argument_name))); | 1994 arg.name = argument_name; |
| 2016 } | 1995 } |
| 2017 arg.push(MakeJSONPair_('value', | 1996 arg.value = this.serializeReference(mirror.argumentValue(i)); |
| 2018 this.serializeReference(mirror.argumentValue(i)))); | 1997 x[i] = arg; |
| 2019 x[i] = ArrayToJSONObject_(arg); | |
| 2020 } | 1998 } |
| 2021 content.push(MakeJSONPair_('arguments', ArrayToJSONArray_(x))); | 1999 content.arguments = x; |
| 2022 var x = new Array(mirror.localCount()); | 2000 var x = new Array(mirror.localCount()); |
| 2023 for (var i = 0; i < mirror.localCount(); i++) { | 2001 for (var i = 0; i < mirror.localCount(); i++) { |
| 2024 var name = MakeJSONPair_('name', StringToJSON_(mirror.localName(i))); | 2002 var local = {}; |
| 2025 var value = MakeJSONPair_('value', | 2003 local.name = mirror.localName(i); |
| 2026 this.serializeReference(mirror.localValue(i))); | 2004 local.value = this.serializeReference(mirror.localValue(i)); |
| 2027 x[i] = '{' + name + ',' + value + '}'; | 2005 x[i] = local; |
| 2028 } | 2006 } |
| 2029 content.push(MakeJSONPair_('locals', ArrayToJSONArray_(x))); | 2007 content.locals = x; |
| 2030 content.push(MakeJSONPair_('position', | 2008 content.position = mirror.sourcePosition(); |
| 2031 NumberToJSON_(mirror.sourcePosition()))); | |
| 2032 var line = mirror.sourceLine(); | 2009 var line = mirror.sourceLine(); |
| 2033 if (!IS_UNDEFINED(line)) { | 2010 if (!IS_UNDEFINED(line)) { |
| 2034 content.push(MakeJSONPair_('line', NumberToJSON_(line))); | 2011 content.line = line; |
| 2035 } | 2012 } |
| 2036 var column = mirror.sourceColumn(); | 2013 var column = mirror.sourceColumn(); |
| 2037 if (!IS_UNDEFINED(column)) { | 2014 if (!IS_UNDEFINED(column)) { |
| 2038 content.push(MakeJSONPair_('column', NumberToJSON_(column))); | 2015 content.column = column; |
| 2039 } | 2016 } |
| 2040 var source_line_text = mirror.sourceLineText(); | 2017 var source_line_text = mirror.sourceLineText(); |
| 2041 if (!IS_UNDEFINED(source_line_text)) { | 2018 if (!IS_UNDEFINED(source_line_text)) { |
| 2042 content.push(MakeJSONPair_('sourceLineText', | 2019 content.sourceLineText = source_line_text; |
| 2043 StringToJSON_(source_line_text))); | |
| 2044 } | 2020 } |
| 2045 } | 2021 } |
| 2046 | 2022 |
| 2047 | 2023 |
| 2048 function MakeJSONPair_(name, value) { | |
| 2049 return '"' + name + '":' + value; | |
| 2050 } | |
| 2051 | |
| 2052 | |
| 2053 function ArrayToJSONObject_(content) { | |
| 2054 return '{' + content.join(',') + '}'; | |
| 2055 } | |
| 2056 | |
| 2057 | |
| 2058 function ArrayToJSONArray_(content) { | |
| 2059 return '[' + content.join(',') + ']'; | |
| 2060 } | |
| 2061 | |
| 2062 | |
| 2063 function BooleanToJSON_(value) { | |
| 2064 return String(value); | |
| 2065 } | |
| 2066 | |
| 2067 | |
| 2068 /** | 2024 /** |
| 2069 * Convert a number to a JSON string value. For all finite numbers the number | 2025 * Convert a number to a protocol value. For all finite numbers the number |
| 2070 * literal representation is used. For non finite numbers NaN, Infinite and | 2026 * itself is returned. For non finite numbers NaN, Infinite and |
| 2071 * -Infinite the string representation "NaN", "Infinite" or "-Infinite" | 2027 * -Infinite the string representation "NaN", "Infinite" or "-Infinite" |
| 2072 * (including the quotes) is returned. | 2028 * (not including the quotes) is returned. |
| 2073 * | 2029 * |
| 2074 * @param {number} value The number value to convert to a JSON value | 2030 * @param {number} value The number value to convert to a protocol value. |
| 2075 * @returns {String} JSON value | 2031 * @returns {number|string} Protocol value. |
| 2076 */ | 2032 */ |
| 2077 function NumberToJSON_(value) { | 2033 function NumberToJSON_(value) { |
| 2078 if (isNaN(value)) { | 2034 if (isNaN(value)) { |
| 2079 return '"NaN"'; | 2035 return 'NaN'; |
| 2080 } | 2036 } |
| 2081 if (!isFinite(value)) { | 2037 if (!isFinite(value)) { |
| 2082 if (value > 0) { | 2038 if (value > 0) { |
| 2083 return '"Infinity"'; | 2039 return 'Infinity'; |
| 2084 } else { | 2040 } else { |
| 2085 return '"-Infinity"'; | 2041 return '-Infinity'; |
| 2086 } | 2042 } |
| 2087 } | 2043 } |
| 2088 return String(value); | 2044 return value; |
| 2089 } | 2045 } |
| 2090 | |
| 2091 | |
| 2092 // Mapping of some control characters to avoid the \uXXXX syntax for most | |
| 2093 // commonly used control cahracters. | |
| 2094 const ctrlCharMap_ = { | |
| 2095 '\b': '\\b', | |
| 2096 '\t': '\\t', | |
| 2097 '\n': '\\n', | |
| 2098 '\f': '\\f', | |
| 2099 '\r': '\\r', | |
| 2100 '"' : '\\"', | |
| 2101 '\\': '\\\\' | |
| 2102 }; | |
| 2103 | |
| 2104 | |
| 2105 // Regular expression testing for ", \ and control characters (0x00 - 0x1F). | |
| 2106 const ctrlCharTest_ = new RegExp('["\\\\\x00-\x1F]'); | |
| 2107 | |
| 2108 | |
| 2109 // Regular expression matching ", \ and control characters (0x00 - 0x1F) | |
| 2110 // globally. | |
| 2111 const ctrlCharMatch_ = new RegExp('["\\\\\x00-\x1F]', 'g'); | |
| 2112 | |
| 2113 | |
| 2114 /** | |
| 2115 * Convert a String to its JSON representation (see http://www.json.org/). To | |
| 2116 * avoid depending on the String object this method calls the functions in | |
| 2117 * string.js directly and not through the value. | |
| 2118 * @param {String} value The String value to format as JSON | |
| 2119 * @return {string} JSON formatted String value | |
| 2120 */ | |
| 2121 function StringToJSON_(value) { | |
| 2122 // Check for" , \ and control characters (0x00 - 0x1F). No need to call | |
| 2123 // RegExpTest as ctrlchar is constructed using RegExp. | |
| 2124 if (ctrlCharTest_.test(value)) { | |
| 2125 // Replace ", \ and control characters (0x00 - 0x1F). | |
| 2126 return '"' + | |
| 2127 value.replace(ctrlCharMatch_, function (char) { | |
| 2128 // Use charmap if possible. | |
| 2129 var mapped = ctrlCharMap_[char]; | |
| 2130 if (mapped) return mapped; | |
| 2131 mapped = char.charCodeAt(); | |
| 2132 // Convert control character to unicode escape sequence. | |
| 2133 return '\\u00' + | |
| 2134 %NumberToRadixString(Math.floor(mapped / 16), 16) + | |
| 2135 %NumberToRadixString(mapped % 16, 16); | |
| 2136 }) | |
| 2137 + '"'; | |
| 2138 } | |
| 2139 | |
| 2140 // Simple string with no special characters. | |
| 2141 return '"' + value + '"'; | |
| 2142 } | |
| 2143 | |
| 2144 | |
| 2145 /** | |
| 2146 * Convert a Date to ISO 8601 format. To avoid depending on the Date object | |
| 2147 * this method calls the functions in date.js directly and not through the | |
| 2148 * value. | |
| 2149 * @param {Date} value The Date value to format as JSON | |
| 2150 * @return {string} JSON formatted Date value | |
| 2151 */ | |
| 2152 function DateToISO8601_(value) { | |
| 2153 function f(n) { | |
| 2154 return n < 10 ? '0' + n : n; | |
| 2155 } | |
| 2156 function g(n) { | |
| 2157 return n < 10 ? '00' + n : n < 100 ? '0' + n : n; | |
| 2158 } | |
| 2159 return builtins.GetUTCFullYearFrom(value) + '-' + | |
| 2160 f(builtins.GetUTCMonthFrom(value) + 1) + '-' + | |
| 2161 f(builtins.GetUTCDateFrom(value)) + 'T' + | |
| 2162 f(builtins.GetUTCHoursFrom(value)) + ':' + | |
| 2163 f(builtins.GetUTCMinutesFrom(value)) + ':' + | |
| 2164 f(builtins.GetUTCSecondsFrom(value)) + '.' + | |
| 2165 g(builtins.GetUTCMillisecondsFrom(value)) + 'Z'; | |
| 2166 } | |
| 2167 | |
| 2168 /** | |
| 2169 * Convert a Date to ISO 8601 format. To avoid depending on the Date object | |
| 2170 * this method calls the functions in date.js directly and not through the | |
| 2171 * value. | |
| 2172 * @param {Date} value The Date value to format as JSON | |
| 2173 * @return {string} JSON formatted Date value | |
| 2174 */ | |
| 2175 function DateToJSON_(value) { | |
| 2176 return '"' + DateToISO8601_(value) + '"'; | |
| 2177 } | |
| OLD | NEW |