Last Comment Bug 510537 - ES5: Array.isArray
: ES5: Array.isArray
fixed-in-tracemonkey [doc-waiting-lan...
: dev-doc-complete
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: Trunk
: All All
-- enhancement (vote)
: ---
Assigned To: Jeff Walden [:Waldo] (remove +bmo to email)
: Jason Orendorff [:jorendorff]
: 537548 (view as bug list)
Depends on:
Blocks: es5
  Show dependency treegraph
Reported: 2009-08-14 10:19 PDT by Jeff Walden [:Waldo] (remove +bmo to email)
Modified: 2012-02-14 09:27 PST (History)
11 users (show)
sayrer: wanted1.9.2+
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---

Patch (2.40 KB, patch)
2009-08-14 10:19 PDT, Jeff Walden [:Waldo] (remove +bmo to email)
jorendorff: review+
Details | Diff | Splinter Review

Description User image Jeff Walden [:Waldo] (remove +bmo to email) 2009-08-14 10:19:58 PDT
Created attachment 394528 [details] [diff] [review]

Recent array method discussion reminded me of this addition in ES5.  Trivial patch, in-browser users want it, out-of-browser users want it, about as no-risk a feature as they get -- nice driveby pickup for 3.6.  We should skim the spec for other ten-minute features...

Test fodder:

assertEq(Array.isArray.length, 1);
var empty = [];
var fastSmall = [1];
var slow = [];
slow.slow = 0;
var slowSmall = [];
slowSmall[999999] = 0;
slowSmall.length = 0;
var all = [empty, fastSmall, slow, slowSmall];
all.forEach(function(a) { assertEq(Array.isArray(a), true); });
assertEq(Array.isArray(), false);
assertEq(Array.isArray({}), false);
assertEq(Array.isArray(null), false);
assertEq(Array.isArray(undefined), false);
assertEq(Array.isArray(17), false);
assertEq(Array.isArray("Array"), false);
assertEq(Array.isArray(Math.PI), false);
assertEq(Array.isArray(true), false);
assertEq(Array.isArray(false), false);
Comment 1 User image Jason Orendorff [:jorendorff] 2009-08-14 12:40:03 PDT
Comment on attachment 394528 [details] [diff] [review]

Looks good.
Comment 2 User image Jeff Walden [:Waldo] (remove +bmo to email) 2009-08-14 15:15:54 PDT
Comment 3 User image Brendan Eich [:brendan] 2009-08-14 15:30:54 PDT
Any more like this missing from the es5 buglist?

Why not a traceable native?

Comment 4 User image Jeff Walden [:Waldo] (remove +bmo to email) 2009-08-14 16:36:50 PDT
I don't know if anything else is missing -- I've been too busy diving into Object.defineProperties and all those object meta-hooks at the moment to really look lately (and those are much orders of magnitude less trivial than this).  I probably should remedy that, maybe I'll do a spec skim over the weekend at some point.

As for why not a traceable native,

1) It's a driveby patch, didn't want to spend any more time on it than necessary.
2) We can do better than a traceable native; this really cries out for a bug 497173-based solution.
3) I think we get better ROI if I spend time on something like Object.defineProperties than if I spend time wringing out a couple dozen instructions' execution time for one method that nobody uses (yet).

I'm working on a web-tech post on this at the moment, although to be honest I'm less up on the reasons why someone would want to know if a value is an array than I'd like to be.  I'm probably going to lean a little on this URL for rationales and use cases for doing so, maybe ask a few people around Mozilla as well.  No rush, especially since this wants to be on branch before anything would actually be published.
Comment 5 User image Brendan Eich [:brendan] 2009-08-14 18:42:10 PDT
Just askin', no sweat. Indeed bug 497173 approach could do a lot better than a traceable native!

You might ask jresig, bgalbraith, and dalmaer about isArray use cases.

Comment 6 User image Jeff Walden [:Waldo] (remove +bmo to email) 2009-08-17 21:04:42 PDT
Draft post:

(Mother Superior) jumping the gun a bit as this hasn't made 192 yet, but that'll happen eventually enough to make it worth posting this now...
Comment 8 User image Eric Shepherd [:sheppy] 2009-08-31 13:56:11 PDT
Would appreciate it if someone would let me know when this officially lands on 1.9.2.
Comment 9 User image Eric Shepherd [:sheppy] 2009-10-28 11:12:19 PDT
Is this going to land on 1.9.2?
Comment 10 User image Jeff Walden [:Waldo] (remove +bmo to email) 2010-01-02 18:15:24 PST
*** Bug 537548 has been marked as a duplicate of this bug. ***
Comment 11 User image Juriy "kangax" Zaytsev 2010-01-02 18:26:18 PST
I wonder why searching for "Array.isArray" in bugzilla (before I created bug 537548) returned 0 results. Sigh.
Comment 13 User image Jeff Walden [:Waldo] (remove +bmo to email) 2012-02-14 09:27:17 PST
The eventual blog post following on comment 6 was made here:

Note You need to log in before you can comment on or make changes to this bug.