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

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

Issue 143263003: DevTools: Fix console.log for arrays in some corner cases. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 months 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 * @template T 103 * @template T
104 */ 104 */
105 function nullifyObjectProto(obj) 105 function nullifyObjectProto(obj)
106 { 106 {
107 if (obj && typeof obj === "object") 107 if (obj && typeof obj === "object")
108 obj.__proto__ = null; 108 obj.__proto__ = null;
109 return obj; 109 return obj;
110 } 110 }
111 111
112 /** 112 /**
113 * @param {string} name
114 * @return {boolean}
115 */
116 function isArrayIndexPropertyName(name)
117 {
118 // Array index check according to the ES5-15.4.
119 var index = name >>> 0;
120 return toString(index) === name && index !== 0xffffffff;
121 }
122
123 /**
113 * @constructor 124 * @constructor
114 */ 125 */
115 var InjectedScript = function() 126 var InjectedScript = function()
116 { 127 {
117 /** @type {number} */ 128 /** @type {number} */
118 this._lastBoundObjectId = 1; 129 this._lastBoundObjectId = 1;
119 /** @type {!Object.<number, Object>} */ 130 /** @type {!Object.<number, Object>} */
120 this._idToWrappedObject = { __proto__: null }; 131 this._idToWrappedObject = { __proto__: null };
121 /** @type {!Object.<number, string>} */ 132 /** @type {!Object.<number, string>} */
122 this._idToObjectGroupName = { __proto__: null }; 133 this._idToObjectGroupName = { __proto__: null };
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 var nameToDescriptors = { __proto__: null }; 1016 var nameToDescriptors = { __proto__: null };
1006 for (var i = 0; i < descriptors.length; ++i) { 1017 for (var i = 0; i < descriptors.length; ++i) {
1007 var descriptor = descriptors[i]; 1018 var descriptor = descriptors[i];
1008 nameToDescriptors["#" + descriptor.name] = descriptor; 1019 nameToDescriptors["#" + descriptor.name] = descriptor;
1009 } 1020 }
1010 descriptors = []; 1021 descriptors = [];
1011 for (var i = 0; i < firstLevelKeys.length; ++i) 1022 for (var i = 0; i < firstLevelKeys.length; ++i)
1012 descriptors.push(nameToDescriptors["#" + firstLevelKeys[i]]) ; 1023 descriptors.push(nameToDescriptors["#" + firstLevelKeys[i]]) ;
1013 } 1024 }
1014 1025
1026 var isArray = (this.subtype === "array");
1015 for (var i = 0; i < descriptors.length; ++i) { 1027 for (var i = 0; i < descriptors.length; ++i) {
1016 if (propertiesThreshold.indexes < 0 || propertiesThreshold.prope rties < 0) 1028 if (propertiesThreshold.indexes < 0 && propertiesThreshold.prope rties < 0)
1017 break; 1029 break;
1018 1030
1019 var descriptor = descriptors[i]; 1031 var descriptor = descriptors[i];
1020 if (!descriptor) 1032 if (!descriptor)
1021 continue; 1033 continue;
1022 if (descriptor.wasThrown) { 1034 if (descriptor.wasThrown) {
1023 preview.lossless = false; 1035 preview.lossless = false;
1024 continue; 1036 continue;
1025 } 1037 }
1026 if (!descriptor.enumerable && !descriptor.isOwn)
1027 continue;
1028 1038
1029 var name = descriptor.name; 1039 var name = descriptor.name;
1030 if (name === "__proto__") 1040 if (name === "__proto__")
1031 continue; 1041 continue;
1032 if (this.subtype === "array" && name === "length") 1042 if (isArray && name === "length")
1043 continue;
1044
1045 var isArrayIndex = isArray && isArrayIndexPropertyName(name);
1046 if (!descriptor.enumerable && !descriptor.isOwn && !isArrayIndex )
1033 continue; 1047 continue;
1034 1048
1035 if (!("value" in descriptor)) { 1049 if (!("value" in descriptor)) {
1036 preview.lossless = false; 1050 preview.lossless = false;
1037 this._appendPropertyPreview(preview, { name: name, type: "ac cessor", __proto__: null }, propertiesThreshold); 1051 this._appendPropertyPreview(preview, { name: name, type: "ac cessor", __proto__: null }, propertiesThreshold);
1038 continue; 1052 continue;
1039 } 1053 }
1040 1054
1041 var value = descriptor.value; 1055 var value = descriptor.value;
1042 if (value === null) { 1056 if (value === null) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 return preview; 1104 return preview;
1091 }, 1105 },
1092 1106
1093 /** 1107 /**
1094 * @param {!RuntimeAgent.ObjectPreview} preview 1108 * @param {!RuntimeAgent.ObjectPreview} preview
1095 * @param {!Object} property 1109 * @param {!Object} property
1096 * @param {!Object} propertiesThreshold 1110 * @param {!Object} propertiesThreshold
1097 */ 1111 */
1098 _appendPropertyPreview: function(preview, property, propertiesThreshold) 1112 _appendPropertyPreview: function(preview, property, propertiesThreshold)
1099 { 1113 {
1100 if (toString(property.name >>> 0) === property.name) 1114 var threshold;
1101 propertiesThreshold.indexes--; 1115 if (isArrayIndexPropertyName(property.name))
1116 threshold = --propertiesThreshold.indexes;
1102 else 1117 else
1103 propertiesThreshold.properties--; 1118 threshold = --propertiesThreshold.properties;
1104 if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0) { 1119 if (threshold < 0) {
1105 preview.overflow = true; 1120 preview.overflow = true;
1106 preview.lossless = false; 1121 preview.lossless = false;
1107 } else { 1122 } else {
1108 preview.properties.push(property); 1123 preview.properties.push(property);
1109 } 1124 }
1110 }, 1125 },
1111 1126
1112 /** 1127 /**
1113 * @param {string} string 1128 * @param {string} string
1114 * @param {number} maxLength 1129 * @param {number} maxLength
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 */ 1534 */
1520 _logEvent: function(event) 1535 _logEvent: function(event)
1521 { 1536 {
1522 inspectedWindow.console.log(event.type, event); 1537 inspectedWindow.console.log(event.type, event);
1523 } 1538 }
1524 } 1539 }
1525 1540
1526 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); 1541 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl();
1527 return injectedScript; 1542 return injectedScript;
1528 }) 1543 })
OLDNEW
« no previous file with comments | « LayoutTests/inspector/console/console-object-preview-expected.txt ('k') | Source/devtools/front_end/ConsoleMessage.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698