Closed
Bug 510537
Opened 15 years ago
Closed 15 years ago
ES5: Array.isArray
Categories
(Core :: JavaScript Engine, enhancement)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
People
(Reporter: Waldo, Assigned: Waldo)
References
Details
(Keywords: dev-doc-complete, Whiteboard: fixed-in-tracemonkey [doc-waiting-landing])
Attachments
(1 file)
(deleted),
patch
|
jorendorff
:
review+
|
Details | Diff | Splinter 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);
Attachment #394528 -
Flags: review?(jorendorff)
Flags: wanted1.9.2?
Updated•15 years ago
|
Attachment #394528 -
Flags: review?(jorendorff) → review+
Comment 1•15 years ago
|
||
Comment on attachment 394528 [details] [diff] [review]
Patch
Looks good.
Assignee | ||
Comment 2•15 years ago
|
||
Whiteboard: fixed-in-tracemonkey
Updated•15 years ago
|
Flags: wanted1.9.2? → wanted1.9.2+
Comment 3•15 years ago
|
||
Any more like this missing from the es5 buglist?
Why not a traceable native?
/be
Assignee | ||
Comment 4•15 years ago
|
||
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.
http://thinkweb2.com/projects/prototype/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/
Keywords: dev-doc-needed
Comment 5•15 years ago
|
||
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.
/be
Assignee | ||
Comment 6•15 years ago
|
||
Draft post:
http://web.mit.edu/jwalden/www/isArray.html
(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 7•15 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Comment 8•15 years ago
|
||
Would appreciate it if someone would let me know when this officially lands on 1.9.2.
Updated•15 years ago
|
Whiteboard: fixed-in-tracemonkey → fixed-in-tracemonkey [doc-waiting-landing]
Comment 9•15 years ago
|
||
Is this going to land on 1.9.2?
Comment 11•15 years ago
|
||
I wonder why searching for "Array.isArray" in bugzilla (before I created bug 537548) returned 0 results. Sigh.
Comment 12•14 years ago
|
||
Updated•14 years ago
|
Keywords: dev-doc-needed → dev-doc-complete
Assignee | ||
Comment 13•13 years ago
|
||
The eventual blog post following on comment 6 was made here:
https://developer.mozilla.org/web-tech/2010/07/26/determining-with-absolute-accuracy-whether-or-not-a-javascript-object-is-an-array/
You need to log in
before you can comment on or make changes to this bug.
Description
•