Skip to content

Correctly handle hashing of objects that return non-objects from valueOf() #1654

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

Closed
wants to merge 1 commit into from

Conversation

adamshone
Copy link

@adamshone adamshone commented Nov 27, 2018

Fixes #1643.

JSFiddle showing the issue: https://jsfiddle.net/ey7opm1w

The problem is described well by @joakim-hagglund in this comment: #1643 (comment)

The return value from valueOf was being passed to hashJSObj, and subsequently failing because non-objects cannot be used as keys in a WeakMap.

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@adamshone adamshone changed the title Fixes #1643 Correctly handle hashing of objects that return non-objects from valueOf() Nov 27, 2018
@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

randytarampi added a commit to randytarampi/me that referenced this pull request Dec 22, 2018
randytarampi added a commit to randytarampi/me that referenced this pull request Jan 14, 2019
…shcode.

I don't think the fix from immutable-js/immutable-js#1654 is quite complete – either that or `Post.fromJSON` is doing something non-deterministic.
@timvracer
Copy link

Is this ever going to be incorporated? Or is the position of immutable that they will not support this use case (in particular, using moment() )

@adamshone
Copy link
Author

I don't know :/

For me it wasn't moment, it was a Decimal, but it breaks for anything that implements valueOf. So it definitely needs fixing.

@asazernik do you have any insight about what I can do to get this merged?

@jelder
Copy link

jelder commented Mar 23, 2019

The problem is easy to reproduce with Date. It looks like any value greater than Date(8) will crash Immutable. This is true even if the Date instance is part of a Map or Record, which is in turn a member of a Set.

This makes Immutable completely break for our application, and we've had to refactor away all uses of Immutable Set. Hopefully this PR can get merged and a new rc released soon.

const { Set } = require("immutable")

const bad = []
let set = Set()
let i = 0

while (true) {
  i++
  try {
    set = set.add(new Date(i))
    console.log(i, "is ok")
  } catch (err) {
    console.log(i, err.message)
    bad.push(i)
  }
  if (bad.length > 100) {
    console.log(bad)
    break
  }
}

@TikiTDO
Copy link

TikiTDO commented Mar 29, 2019

@leebyron You were the last one to complete a merge into this repo, so is there any chance to get this fix merged in? Or is there anyone else we can tag to get this resolved?

Copy link

@robincafolla robincafolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing this locally worked for me. LGTM

@aaronwhite
Copy link

Lack of activity and commit history suggest this repo died on Valentine’s Day 2019 :/ RIP, even true, immutable-love isn’t forever 💔

@asazernik
Copy link

@aaronwhite it kind of goes into hibernation, and then gets a burst of pulls every month or three.

@cypherfunc
Copy link

cypherfunc commented Jul 10, 2019

Can someone please merge this? The regression is 9 months old, and this fix was requested 8 months ago.

Is @leebyron still the maintainer, or is there someone else who can commit this?

@TikiTDO
Copy link

TikiTDO commented Jul 10, 2019

@EricTheRed-VT It honestly looks like this project is proper dead. It's been 5 months since a commit, and I haven't seen a single person with merge authority so much as comment. My recommendation is to move off of this library entirely sooner rather than later.

@cypherfunc
Copy link

cypherfunc commented Jul 10, 2019

@TikiTDO We're pretty happy with it in general, aside from the rare bug like this. Dropping Immutable would be too costly for my team, not to mention that there isn't a good replacement library (that I'm aware of). If this really never gets fixed, we might have to fork it and maintain a private version. 😞

It's just hard to believe that a widely popular library like this would be completely abandoned.

subash-a pushed a commit to subash-a/immutable-js that referenced this pull request Sep 24, 2019
subash-a pushed a commit to subash-a/immutable-js that referenced this pull request Sep 24, 2019
subash-a pushed a commit to subash-a/immutable-js that referenced this pull request Sep 24, 2019
@jdeniau
Copy link
Member

jdeniau commented Jun 29, 2021

Thanks your for your contribution ! The immutable-js oss fork will soon be merged and this fix has been included in #1833 (possibly by you !). Once this PR is merged, this issue will be resolved in the main branch. We will then do our best to to release the 4.0.0 version.

Commit reference : 45196e3

@jdeniau jdeniau closed this Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hashing breaks for custom objects with "Invalid value used as weak map key"