Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array#find is implemented wrong #139

Closed
kylehg opened this issue Jan 5, 2016 · 11 comments
Closed

Array#find is implemented wrong #139

kylehg opened this issue Jan 5, 2016 · 11 comments
Assignees
Milestone

Comments

@kylehg
Copy link

kylehg commented Jan 5, 2016

Your implementation of Array.prototype.find() is wrong — it returns the index of the matching element, not the element itself. See the MDN article on .find() — you've implemented .findIndex.

Relatedly, it's very upsetting that this library doesn't bother to check Array.prototype for a native version first before overwriting. This ruins the party for anyone who consumes this library as a node module, even if it's only as a second-order dependency.

@kriskowal
Copy link
Member

These issues are addressed in version 2 and can be installed via npm
install collections@2. The v1 api is published as latest to avoid breaking
legacy apps.

On Mon, Jan 4, 2016 at 6:27 PM Kyle Hardgrave [email protected]
wrote:

Your implementation of Array.prototype.find() is wrong — it returns the
index of the matching element, not the element itself. See the MDN article
on .find()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
— you've implemented .findIndex.

Relatedly, it's very upsetting that this library doesn't bother to check
Array.prototype for a native version first before overwriting. This ruins
the party for anyone who consumes this library as a node module, even if
it's only as a second-order dependency.


Reply to this email directly or view it on GitHub
#139.

@morlay
Copy link

morlay commented Jan 7, 2016

But, why add the wrong find back in collections@3?
https://github.com/montagejs/collections/blob/v3.0.0/shim-array.js#L135

rlgomes pushed a commit to rlgomes/node-grok that referenced this issue Jan 21, 2016
there was a bug with Array.find that was giving us trouble (bug:
montagejs/collections#139) and this bug is no
longer present in 2.0 version of collections.
mstemm pushed a commit to juttle/outrigger that referenced this issue Jan 21, 2016
This fixes this problem:

[2016-01-20 17:58:43.560] [ERROR] demo-job-manager - child-process-error Unhandled rejection TypeError: serializer.serialize is not a function
    at PluggableJSON._serialize (/Users/mstemm/work/src/outrigger/node_modules/juttle-jsdp/node_modules/pluggable-json/lib/index.js:64:35)
    at PluggableJSON.serialize (/Users/mstemm/work/src/outrigger/node_modules/juttle-jsdp/node_modules/pluggable-json/lib/index.js:53:41)
    at Object.serialize (/Users/mstemm/work/src/outrigger/node_modules/juttle-jsdp/lib/protocol/index.js:21:30)
    at send (/Users/mstemm/work/src/outrigger/lib/juttle-subprocess.js:61:23)
    at /Users/mstemm/work/src/outrigger/lib/juttle-subprocess.js:177:13

And was related to this:

montagejs/collections#139
mstemm pushed a commit to juttle/outrigger that referenced this issue Jan 21, 2016
This fixes this problem:

[2016-01-20 17:58:43.560] [ERROR] demo-job-manager - child-process-error Unhandled rejection TypeError: serializer.serialize is not a function
    at PluggableJSON._serialize (/Users/mstemm/work/src/outrigger/node_modules/juttle-jsdp/node_modules/pluggable-json/lib/index.js:64:35)
    at PluggableJSON.serialize (/Users/mstemm/work/src/outrigger/node_modules/juttle-jsdp/node_modules/pluggable-json/lib/index.js:53:41)
    at Object.serialize (/Users/mstemm/work/src/outrigger/node_modules/juttle-jsdp/lib/protocol/index.js:21:30)
    at send (/Users/mstemm/work/src/outrigger/lib/juttle-subprocess.js:61:23)
    at /Users/mstemm/work/src/outrigger/lib/juttle-subprocess.js:177:13

And was related to this:

montagejs/collections#139
@icfantv
Copy link

icfantv commented Feb 26, 2016

@kriskowal, do you have an answer to @morlay's question? Thanks.

@kriskowal
Copy link
Member

Collections are managed by Montage Studio. They needed to cut a major version that fixed other things, but retained this old behavior for compatibility with deployed versions in production. So version 2 is still ahead of version 3 in this regard. Montage was not able to use version 2 because I made radical changes to the observer subsystem, factoring it into a library and changing the interface. Montage will not be able to reunite with the changes I made for version 2 until someone upgrades FRB to use version 2 change observers. This is not on my roadmap.

@kriskowal
Copy link
Member

However, Version 4 could cherry-pick the fixes in version 2 for this feature with minimal impact to Montage applications and without breaking FRB.

@icfantv
Copy link

icfantv commented Feb 26, 2016

ok, thanks. v2 it is.

@kriskowal
Copy link
Member

For issues and pulls against v2, I maintain v2 as the master branch on my fork https://github.com/kriskowal/collections. Thanks.

@xjamundx
Copy link

Is there any way we can add a deprecated warning or something on this. It caused a production bug for us as well.

@kriskowal
Copy link
Member

I think a deprecation warning would be reasonable, a log to console like “Warning: collections v1 monkey-patches the find method in a way inconsistent with the ECMAScript 6 specification.” What the warning suggests you do is the hard part. v2 is not eligible for folks using Montage. v3 does not solve this problem. v2 in fact, no longer monkey-patches Array at all, and instead favors polymorphic functions like swap(collection, start, minusLength, plus) from pop-swap.

I’ll defer to @marchant to sort out the deprecation and migration story.

nknapp added a commit to bootprint/customize that referenced this issue Jul 22, 2016
This method is injected in the `collections`-package as array-shim, which is
a dependency of q-io. Version 1.x of `collections` implements the method with
the semantics of `Array.prototype.findIndex` instead. This leads to problems
with other packages that rely on the implementation as defined in the ES6-Standard

See also: montagejs/collections#139
nknapp added a commit to nknapp/thoughtful-release that referenced this issue Jul 22, 2016
This method is injected in the `collections`-package as array-shim, which is a dependency of q-io.
Version 1.x of `collections` implements the method with the semantics of `Array.prototype.findIndex`
instead. This leads to problems with other packages that rely on the implementation as defined in the ES6-Standard  See also: https://github.com/montagejs/collections/issues/139Use q-io@2 to exclude wrongly implemented "Array.prototype.find"-method  This method is injected in the `collections`-package as array-shim, which is a dependency of q-io. Version 1.x of `collections` implements the method with the semantics of `Array.prototype.findIndex` instead. This leads to problems with other packages that rely on the implementation as defined in the ES6-Standard  See also: montagejs/collections#139
nknapp added a commit to nknapp/thoughtful-release that referenced this issue Jul 22, 2016
…otype.find"

This method is injected in the `collections`-package as array-shim, which is a dependency of q-io.
Version 1.x of `collections` implements the method with the semantics of `Array.prototype.findIndex`
instead. This leads to problems with other packages that rely on the implementation as defined in the ES6-Standard
See also: https://github.com/montagejs/collections/issues/139Use q-io@2 to exclude wrongly implemented
"Array.prototype.find"-method This method is injected in the `collections`-package as array-shim, which is a dependency
of q-io. Version 1.x of `collections` implements the method with the semantics of `Array.prototype.findIndex` instead.
This leads to problems with other packages that rely on the implementation as defined in the ES6-Standard See also:
montagejs/collections#139

Zeilen,
@hthetiot
Copy link
Contributor

hthetiot commented Dec 7, 2017

Duplicate #185

@hthetiot hthetiot closed this as completed Dec 7, 2017
@hthetiot hthetiot added this to the 5.0.x milestone Dec 7, 2017
@codebling
Copy link

See also issues #36 #70 #94 #95 #116 #139 #145 #162 #165 #169 #178 #182 #185 #197 #215 #220 and PRs #94 #95 #116 #173 #189 #212. Branch v2 fixes these issues by avoiding global object modification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants