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

eql({}, null) throws WeakMap key error #33

Closed
STRML opened this issue Nov 14, 2016 · 3 comments
Closed

eql({}, null) throws WeakMap key error #33

STRML opened this issue Nov 14, 2016 · 3 comments
Labels

Comments

@STRML
Copy link
Contributor

STRML commented Nov 14, 2016

Simple reproduction:

$ node
> const eql = require('deep-eql')
undefined
> eql({}, null)
TypeError: Invalid value used as weak map key
    at WeakMap.set (native)
    at memoizeSet (/Users/samuelreed/git/forks/ajv/node_modules/deep-eql/index.js:92:17)
    at extensiveDeepEqual (/Users/samuelreed/git/forks/ajv/node_modules/deep-eql/index.js:175:5)
    at deepEqual (/Users/samuelreed/git/forks/ajv/node_modules/deep-eql/index.js:141:10)
    at repl:1:1
    at sigintHandlersWrap (vm.js:22:35)
    at sigintHandlersWrap (vm.js:96:12)
    at ContextifyScript.Script.runInThisContext (vm.js:21:12)
    at REPLServer.defaultEval (repl.js:313:29)
    at bound (domain.js:280:14)
$ node --version
v6.9.1
@STRML
Copy link
Contributor Author

STRML commented Nov 14, 2016

Seems this could be fixed by checking both sides in the entry point:

  // Primitives/null/undefined can be checked for referential equality; returning early
  if (
    typeof leftHandOperand !== 'object' ||
    leftHandOperand === null ||
    leftHandOperand === undefined || // eslint-disable-line no-undefined
    typeof rightHandOperand !== 'object' ||
    rightHandOperand === null ||
    rightHandOperand === undefined // eslint-disable-line no-undefined
  ) {
    return leftHandOperand === rightHandOperand;
  }

Any reason not to?

@keithamus
Copy link
Member

keithamus commented Nov 14, 2016

Thanks for the issue @STRML, also thanks for the proposed solution. Seems completely reasonable to me, if you'd like to write a PR with your proposed solution and some tests, that'd be aaawwwesome! 😝


Edit: nvm, I see you have made one! Thanks, I'll review it 😄

@lucasfcosta
Copy link
Member

Thanks for your work @STRML! Great job 😄

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

No branches or pull requests

3 participants