Closed
Bug 305002
Opened 20 years ago
Closed 20 years ago
Array.every should return |true| on empty arrays
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
People
(Reporter: engel, Assigned: engel)
References
Details
(Keywords: fixed1.8, js1.5)
Attachments
(1 file, 1 obsolete file)
1.29 KB,
patch
|
brendan
:
review+
brendan
:
superreview+
brendan
:
approval1.8b4+
|
Details | Diff | Splinter Review |
The behavior of |every| is described in
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:every#Description
|every| executes the provided function (callback) once for each element
present in the array until it finds one where callback returns a false value.
If such an element is found, the test aborts and |false| is returned,
otherwise (callback returned a true value for each of the elements) |every|
will return |true|.
Thus, for an empty array |a = []|, |a.every(f)| must always return |true|
(because no element is found where the callback returns |false|, in fact the
callback is never called at all).
This definition for |every| makes much sense, since for an array |a| and a
constant callback |f|, |every| and |some| are related via
a.every(f) == !a.some(not_f),
which always evaluates to true with
function not_f(x) { return !f(x); }
This relation holds for an empty array if |every| returns |true| and |some|
returns |false|.
Assignee | ||
Comment 1•20 years ago
|
||
Historical note: The current behavior of returning |false| on empty arrays was
introduced in Bug 290592, Comment 22.
Assignee | ||
Comment 2•20 years ago
|
||
Assignee | ||
Updated•20 years ago
|
Attachment #192977 -
Flags: review?(shaver)
Comment 3•20 years ago
|
||
Comment on attachment 192977 [details] [diff] [review]
[ ].every(f) now returns true
r=shaver, thanks.
Attachment #192977 -
Flags: review?(shaver) → review+
Comment 4•20 years ago
|
||
With this fix, could you remove the |else if (mode == EVERY)| clause just before
the out label?
Assignee | ||
Comment 5•20 years ago
|
||
Thank you for the hint. Indeed, now the assigments to |*rval| after the loop
over the array can be removed (both for |some| and for |every|).
Attachment #192977 -
Attachment is obsolete: true
Attachment #193100 -
Flags: superreview?(brendan)
Attachment #193100 -
Flags: review?(shaver)
Comment 6•20 years ago
|
||
Comment on attachment 193100 [details] [diff] [review]
[ ].every(f) now returns true; also removing extra assignments at end of loop
sr+a=me -- mrbkap, can you do the honors for trunk and 1.8 branch? Thanks,
/be
Attachment #193100 -
Flags: superreview?(brendan)
Attachment #193100 -
Flags: superreview+
Attachment #193100 -
Flags: review?(shaver)
Attachment #193100 -
Flags: review+
Attachment #193100 -
Flags: approval1.8b4+
Comment 7•20 years ago
|
||
Checked in. Thanks for the patch, Hans-Andreas!
/be
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Comment 8•20 years ago
|
||
Checking in regress-305002.js;
/cvsroot/mozilla/js/tests/js1_6/Array/regress-305002.js,v <-- regress-305002.js
initial revision: 1.1
done
Flags: testcase+
You need to log in
before you can comment on or make changes to this bug.
Description
•