Closed
Bug 726298
Opened 12 years ago
Closed 12 years ago
Expose Map and Set size
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
FIXED
mozilla13
People
(Reporter: jorendorff, Assigned: jorendorff)
References
(Blocks 1 open bug)
Details
(Keywords: dev-doc-complete)
Attachments
(1 file)
9.00 KB,
patch
|
luke
:
review+
|
Details | Diff | Splinter Review |
There is currently no way to ask how many entries are in a Map or Set. TC39 apparently did not reach a consensus at the last meeting as to what this method or accessor should be called. I don't have an opinion. I'm going with size().
Assignee | ||
Comment 1•12 years ago
|
||
Assignee: general → jorendorff
Attachment #596323 -
Flags: review?(luke)
![]() |
||
Comment 2•12 years ago
|
||
Comment on attachment 596323 [details] [diff] [review] v1 Review of attachment 596323 [details] [diff] [review]: ----------------------------------------------------------------- Sorry for the delay. ::: js/src/builtin/MapObject.cpp @@ +246,5 @@ > JSBool > +MapObject::size(JSContext *cx, uintN argc, Value *vp) > +{ > + THIS_MAP(get, cx, argc, vp, args, map); > + args.rval().setNumber(double(map.count())); How about a JS_STATIC_ASSERT(sizeof map.count() <= sizeof uint32_t); here and in SetObject::size?
Attachment #596323 -
Flags: review?(luke) → review+
Assignee | ||
Comment 3•12 years ago
|
||
Hmm. Currently we have: uint32_t js::detail::HashTable<>::count() const; size_t js::HashMap<>::count() const { return impl.count(); } size_t js::HashSet<>::count() const { return impl.count(); } So, do you mean I should change the latter two to return uint32_t? If so, then I can add the static assertions you mention and remove the 'double()' part.
![]() |
||
Comment 4•12 years ago
|
||
Oops, didn't even realize that; that's a bug; HashTable::count returns a uint32_t. Yes, changing them sounds good.
Comment 5•12 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/3f51e7052b7d
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla13
Comment 6•12 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/2d534a06e561
Updated•12 years ago
|
Keywords: dev-doc-needed
Comment 7•12 years ago
|
||
Added the method description and added it to the example code. https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Map an Set
Keywords: dev-doc-needed → dev-doc-complete
You need to log in
before you can comment on or make changes to this bug.
Description
•