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

Allow convertObjectToArray to handle objects with no prototype #507

Merged
merged 1 commit into from
Aug 12, 2017

Conversation

southpolesteve
Copy link
Contributor

Currently this method expects hasOwnProperty to exist on the passed object. By using the method on Object.prototype instead, objects created with Object.create(null) can also be properly handled.

Ran into this bug trying to pass graphQL input objects (heavily uses Object.create(null)) directly to hmset commands

@luin
Copy link
Collaborator

luin commented Aug 12, 2017

Nice catch! What about using Object.keys to get the keys? See "Object.keys for loop" in https://jsperf.com/object-keys-vs-for-in-with-closure/3

Currently this method expects `hasOwnProperty` to exist on the passed object. By using the method on `Object.prototype` instead, objects created with `Object.create(null)` can also be properly handled.

Ran into this bug trying to pass graphQL input objects (heavily uses `Object.create(null)`) directly to hmset commands

Use call
@southpolesteve
Copy link
Contributor Author

I was curious how reduce would perform but it looks worse: https://jsperf.com/object-keys-reduce-vs-for-loop/1

Updated to use Object.keys + a for loop. Also added a test for an object without a prototype

@luin luin merged commit 8e17920 into redis:master Aug 12, 2017
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

Successfully merging this pull request may close these issues.

2 participants