OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 if (subtype === "regexp") | 705 if (subtype === "regexp") |
706 return this._toString(obj); | 706 return this._toString(obj); |
707 | 707 |
708 if (subtype === "date") | 708 if (subtype === "date") |
709 return this._toString(obj); | 709 return this._toString(obj); |
710 | 710 |
711 if (subtype === "node") { | 711 if (subtype === "node") { |
712 var description = obj.nodeName.toLowerCase(); | 712 var description = obj.nodeName.toLowerCase(); |
713 switch (obj.nodeType) { | 713 switch (obj.nodeType) { |
714 case 1 /* Node.ELEMENT_NODE */: | 714 case 1 /* Node.ELEMENT_NODE */: |
715 description = "<" + description + ">"; | 715 description += obj.id ? "#" + obj.id : ""; |
| 716 var className = obj.className; |
| 717 description += className ? "." + className : ""; |
716 break; | 718 break; |
717 case 10 /*Node.DOCUMENT_TYPE_NODE */: | 719 case 10 /*Node.DOCUMENT_TYPE_NODE */: |
718 description = "<!DOCTYPE " + description + ">"; | 720 description = "<!DOCTYPE " + description + ">"; |
719 break; | 721 break; |
720 } | 722 } |
721 return description; | 723 return description; |
722 } | 724 } |
723 | 725 |
724 var className = InjectedScriptHost.internalConstructorName(obj); | 726 var className = InjectedScriptHost.internalConstructorName(obj); |
725 if (subtype === "array") { | 727 if (subtype === "array") { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 * @param {Object} object | 804 * @param {Object} object |
803 */ | 805 */ |
804 _generatePreview: function(object) | 806 _generatePreview: function(object) |
805 { | 807 { |
806 this.preview = {}; | 808 this.preview = {}; |
807 this.preview.lossless = true; | 809 this.preview.lossless = true; |
808 this.preview.overflow = false; | 810 this.preview.overflow = false; |
809 this.preview.properties = []; | 811 this.preview.properties = []; |
810 | 812 |
811 var isArray = this.subtype === "array"; | 813 var isArray = this.subtype === "array"; |
812 var elementsToDump = isArray ? 100 : 5; | 814 var propertiesThreshold = { |
| 815 properties: 5, |
| 816 indexes: 100 |
| 817 }; |
813 | 818 |
814 for (var o = object; injectedScript._isDefined(o); o = o.__proto__) | 819 for (var o = object; injectedScript._isDefined(o); o = o.__proto__) |
815 this._generateProtoPreview(o, elementsToDump); | 820 this._generateProtoPreview(o, propertiesThreshold); |
816 }, | 821 }, |
817 | 822 |
818 /** | 823 /** |
819 * @param {Object} object | 824 * @param {Object} object |
820 * @param {number} elementsToDump | 825 * @param {Object} propertiesThreshold |
821 */ | 826 */ |
822 _generateProtoPreview: function(object, elementsToDump) | 827 _generateProtoPreview: function(object, propertiesThreshold) |
823 { | 828 { |
824 var propertyNames = Object.keys(/** @type {!Object} */(object)); | 829 var propertyNames = Object.keys(/** @type {!Object} */(object)); |
825 try { | 830 try { |
826 for (var i = 0; i < propertyNames.length; ++i) { | 831 for (var i = 0; i < propertyNames.length; ++i) { |
827 if (this.preview.properties.length >= elementsToDump) { | 832 if (!propertiesThreshold.properties || !propertiesThreshold.inde
xes) { |
828 this.preview.overflow = true; | 833 this.preview.overflow = true; |
829 this.preview.lossless = false; | 834 this.preview.lossless = false; |
830 break; | 835 break; |
831 } | 836 } |
832 var name = propertyNames[i]; | 837 var name = propertyNames[i]; |
833 if (this.subtype === "array" && name === "length") | 838 if (this.subtype === "array" && name === "length") |
834 continue; | 839 continue; |
835 | 840 |
836 var descriptor = Object.getOwnPropertyDescriptor(/** @type {!Obj
ect} */(object), name); | 841 var descriptor = Object.getOwnPropertyDescriptor(/** @type {!Obj
ect} */(object), name); |
837 if (!("value" in descriptor) || !descriptor.enumerable) { | 842 if (!("value" in descriptor) || !descriptor.enumerable) { |
838 this.preview.lossless = false; | 843 this.preview.lossless = false; |
839 continue; | 844 continue; |
840 } | 845 } |
841 | 846 |
842 var value = descriptor.value; | 847 var value = descriptor.value; |
843 if (value === null) { | 848 if (value === null) { |
844 this.preview.properties.push({ name: name, type: "object", v
alue: "null" }); | 849 this._appendPropertyPreview({ name: name, type: "object", va
lue: "null" }, propertiesThreshold); |
845 continue; | 850 continue; |
846 } | 851 } |
847 | 852 |
848 const maxLength = 100; | 853 const maxLength = 100; |
849 var type = typeof value; | 854 var type = typeof value; |
850 | 855 |
851 if (InjectedScript.primitiveTypes[type]) { | 856 if (InjectedScript.primitiveTypes[type]) { |
852 if (type === "string") { | 857 if (type === "string") { |
853 if (value.length > maxLength) { | 858 if (value.length > maxLength) { |
854 value = this._abbreviateString(value, maxLength, tru
e); | 859 value = this._abbreviateString(value, maxLength, tru
e); |
855 this.preview.lossless = false; | 860 this.preview.lossless = false; |
856 } | 861 } |
857 value = "\"" + value.replace(/\n/g, "\u21B5") + "\""; | 862 value = "\"" + value.replace(/\n/g, "\u21B5") + "\""; |
858 } | 863 } |
859 this.preview.properties.push({ name: name, type: type, value
: value + "" }); | 864 this._appendPropertyPreview({ name: name, type: type, value:
value + "" }, propertiesThreshold); |
860 continue; | 865 continue; |
861 } | 866 } |
862 | 867 |
863 this.preview.lossless = false; | 868 this.preview.lossless = false; |
864 | 869 |
865 var subtype = injectedScript._subtype(value); | 870 var subtype = injectedScript._subtype(value); |
866 var description = ""; | 871 var description = ""; |
867 if (type !== "function") | 872 if (type !== "function") |
868 description = this._abbreviateString(/** @type {string} */ (
injectedScript._describe(value)), maxLength, subtype === "regexp"); | 873 description = this._abbreviateString(/** @type {string} */ (
injectedScript._describe(value)), maxLength, subtype === "regexp"); |
869 | 874 |
870 var property = { name: name, type: type, value: description }; | 875 var property = { name: name, type: type, value: description }; |
871 if (subtype) | 876 if (subtype) |
872 property.subtype = subtype; | 877 property.subtype = subtype; |
873 this.preview.properties.push(property); | 878 this._appendPropertyPreview(property, propertiesThreshold); |
874 } | 879 } |
875 } catch (e) { | 880 } catch (e) { |
876 } | 881 } |
877 }, | 882 }, |
878 | 883 |
879 /** | 884 /** |
| 885 * @param {Object} property |
| 886 * @param {Object} propertiesThreshold |
| 887 */ |
| 888 _appendPropertyPreview: function(property, propertiesThreshold) |
| 889 { |
| 890 if (isNaN(property.name)) |
| 891 propertiesThreshold.properties--; |
| 892 else |
| 893 propertiesThreshold.indexes--; |
| 894 this.preview.properties.push(property); |
| 895 }, |
| 896 |
| 897 /** |
880 * @param {string} string | 898 * @param {string} string |
881 * @param {number} maxLength | 899 * @param {number} maxLength |
882 * @param {boolean=} middle | 900 * @param {boolean=} middle |
883 * @returns | 901 * @returns |
884 */ | 902 */ |
885 _abbreviateString: function(string, maxLength, middle) | 903 _abbreviateString: function(string, maxLength, middle) |
886 { | 904 { |
887 if (string.length <= maxLength) | 905 if (string.length <= maxLength) |
888 return string; | 906 return string; |
889 if (middle) { | 907 if (middle) { |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 */ | 1225 */ |
1208 _logEvent: function(event) | 1226 _logEvent: function(event) |
1209 { | 1227 { |
1210 console.log(event.type, event); | 1228 console.log(event.type, event); |
1211 } | 1229 } |
1212 } | 1230 } |
1213 | 1231 |
1214 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1232 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
1215 return injectedScript; | 1233 return injectedScript; |
1216 }) | 1234 }) |
OLD | NEW |