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

Unified Diff: Source/core/inspector/InjectedScriptSource.js

Issue 197073004: DevTools: Fix wrong is-array-like detection when logging in console. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/inspector/console/console-format-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/inspector/InjectedScriptSource.js
diff --git a/Source/core/inspector/InjectedScriptSource.js b/Source/core/inspector/InjectedScriptSource.js
index 6897dcfb408b1149ab35f57eb4d9776580e3a428..e8dcf1457cb4b90d83cfcfee94878922cc23e5cc 100644
--- a/Source/core/inspector/InjectedScriptSource.js
+++ b/Source/core/inspector/InjectedScriptSource.js
@@ -111,6 +111,30 @@ function nullifyObjectProto(obj)
}
/**
+ * FireBug's array detection.
+ * @param {*} obj
+ * @return {boolean}
+ */
+function isArrayLike(obj)
+{
+ try {
+ if (typeof obj !== "object")
+ return false;
+ if (typeof obj.splice === "function")
+ return isFinite(obj.length);
+ var str = Object.prototype.toString.call(obj);
+ if (str === "[object Array]" ||
+ str === "[object Arguments]" ||
+ str === "[object HTMLCollection]" ||
+ str === "[object NodeList]" ||
+ str === "[object DOMTokenList]")
+ return isFinite(obj.length);
+ } catch (e) {
+ }
+ return false;
+}
+
+/**
* @constructor
*/
var InjectedScript = function()
@@ -893,14 +917,8 @@ InjectedScript.prototype = {
if (preciseType)
return preciseType;
- // FireBug's array detection.
- try {
- if (typeof obj.splice === "function" && isFinite(obj.length))
- return "array";
- if (Object.prototype.toString.call(obj) === "[object Arguments]" && isFinite(obj.length)) // arguments.
- return "array";
- } catch (e) {
- }
+ if (isArrayLike(obj))
+ return "array";
// If owning frame has navigated to somewhere else window properties will be undefined.
return null;
« no previous file with comments | « LayoutTests/inspector/console/console-format-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698