Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: Source/WebCore/inspector/InjectedScriptSource.js

Issue 11415185: Merge 134053 - Web Inspector: wrong output for empty object {} (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1312/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 if (generatePreview && (this.type === "object" || injectedScript._isHTMLAllC ollection(object))) 796 if (generatePreview && (this.type === "object" || injectedScript._isHTMLAllC ollection(object)))
797 this._generatePreview(object); 797 this._generatePreview(object);
798 } 798 }
799 799
800 InjectedScript.RemoteObject.prototype = { 800 InjectedScript.RemoteObject.prototype = {
801 /** 801 /**
802 * @param {Object} object 802 * @param {Object} object
803 */ 803 */
804 _generatePreview: function(object) 804 _generatePreview: function(object)
805 { 805 {
806 var preview = {}; 806 this.preview = {};
807 this.preview.lossless = true;
808 this.preview.overflow = false;
809 this.preview.properties = [];
810
807 var isArray = this.subtype === "array"; 811 var isArray = this.subtype === "array";
808 var elementsToDump = isArray ? 100 : 5; 812 var elementsToDump = isArray ? 100 : 5;
809
810 var propertyNames = Object.getOwnPropertyNames(/** @type {!Object} */(ob ject));
811 preview.lossless = true;
812 preview.overflow = false;
813 var properties = preview.properties = [];
814 813
814 for (var o = object; injectedScript._isDefined(o); o = o.__proto__)
815 this._generateProtoPreview(o, elementsToDump);
816 },
817
818 /**
819 * @param {Object} object
820 * @param {number} elementsToDump
821 */
822 _generateProtoPreview: function(object, elementsToDump)
823 {
824 var propertyNames = Object.keys(/** @type {!Object} */(object));
815 try { 825 try {
816 for (var i = 0; i < propertyNames.length; ++i) { 826 for (var i = 0; i < propertyNames.length; ++i) {
817 if (properties.length >= elementsToDump) { 827 if (this.preview.properties.length >= elementsToDump) {
818 preview.overflow = true; 828 this.preview.overflow = true;
819 preview.lossless = false; 829 this.preview.lossless = false;
820 break; 830 break;
821 } 831 }
822 var name = propertyNames[i]; 832 var name = propertyNames[i];
823 if (isArray && name === "length") 833 if (this.subtype === "array" && name === "length")
824 continue; 834 continue;
825 835
826 var descriptor = Object.getOwnPropertyDescriptor(/** @type {!Obj ect} */(object), name); 836 var descriptor = Object.getOwnPropertyDescriptor(/** @type {!Obj ect} */(object), name);
827 if (!("value" in descriptor) || !descriptor.enumerable) { 837 if (!("value" in descriptor) || !descriptor.enumerable) {
828 preview.lossless = false; 838 this.preview.lossless = false;
829 continue; 839 continue;
830 } 840 }
831 841
832 var value = descriptor.value; 842 var value = descriptor.value;
833 if (value === null) { 843 if (value === null) {
834 properties.push({ name: name, type: "object", value: "null" }); 844 this.preview.properties.push({ name: name, type: "object", v alue: "null" });
835 continue; 845 continue;
836 } 846 }
837 847
838 const maxLength = 100; 848 const maxLength = 100;
839 var type = typeof value; 849 var type = typeof value;
840 850
841 if (InjectedScript.primitiveTypes[type]) { 851 if (InjectedScript.primitiveTypes[type]) {
842 if (type === "string") { 852 if (type === "string") {
843 if (value.length > maxLength) { 853 if (value.length > maxLength) {
844 value = this._abbreviateString(value, maxLength, tru e); 854 value = this._abbreviateString(value, maxLength, tru e);
845 preview.lossless = false; 855 this.preview.lossless = false;
846 } 856 }
847 value = "\"" + value.replace(/\n/g, "\u21B5") + "\""; 857 value = "\"" + value.replace(/\n/g, "\u21B5") + "\"";
848 } 858 }
849 properties.push({ name: name, type: type, value: value + "" }); 859 this.preview.properties.push({ name: name, type: type, value : value + "" });
850 continue; 860 continue;
851 } 861 }
852 862
853 preview.lossless = false; 863 this.preview.lossless = false;
854
855 if (type === "function")
856 continue;
857 864
858 var subtype = injectedScript._subtype(value); 865 var subtype = injectedScript._subtype(value);
859 var property = { name: name, type: type, value: this._abbreviate String(/** @type {string} */ (injectedScript._describe(value)), maxLength, subty pe === "regexp") }; 866 var description = "";
867 if (type !== "function")
868 description = this._abbreviateString(/** @type {string} */ ( injectedScript._describe(value)), maxLength, subtype === "regexp");
869
870 var property = { name: name, type: type, value: description };
860 if (subtype) 871 if (subtype)
861 property.subtype = subtype; 872 property.subtype = subtype;
862 properties.push(property); 873 this.preview.properties.push(property);
863 } 874 }
864 if (properties.length)
865 this.preview = preview;
866 } catch (e) { 875 } catch (e) {
867 } 876 }
868 }, 877 },
869 878
870 /** 879 /**
871 * @param {string} string 880 * @param {string} string
872 * @param {number} maxLength 881 * @param {number} maxLength
873 * @param {boolean=} middle 882 * @param {boolean=} middle
874 * @returns 883 * @returns
875 */ 884 */
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 */ 1207 */
1199 _logEvent: function(event) 1208 _logEvent: function(event)
1200 { 1209 {
1201 console.log(event.type, event); 1210 console.log(event.type, event);
1202 } 1211 }
1203 } 1212 }
1204 1213
1205 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); 1214 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl();
1206 return injectedScript; 1215 return injectedScript;
1207 }) 1216 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698