[SERVER-8048] Object.create(null) throws Created: 29/Dec/12  Updated: 11/Jul/16  Resolved: 17/Jan/13

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: 2.3.2
Fix Version/s: 2.4.0-rc0

Type: Bug Priority: Major - P3
Reporter: Aaron Heckmann Assignee: Ben Becker
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

osx 10.7.5


Issue Links:
Related
Operating System: ALL
Steps To Reproduce:

see description

Participants:

 Description   

var a = Object.create(null); 
a

throws exception:

Fri Dec 28 16:08:39.103 exec error: src/mongo/shell/utils.js:1051 TypeError: Object object has no method 'toString'
if ( x.toString() == "[object MaxKey]" )



 Comments   
Comment by auto [ 16/Jan/13 ]

Author:

{u'date': u'2013-01-16T23:49:20Z', u'email': u'ben.becker@10gen.com', u'name': u'Ben Becker'}

Message: SERVER-8048: catch exception if toString() doesn't exist on an object.
Branch: master
https://github.com/mongodb/mongo/commit/9a675e0ff77f1a1f7e0bbf056c2c64a17c08f71d

Comment by Ben Becker [ 16/Jan/13 ]

Objects with a null prototypes won't have the 'hasOwnProperty' method, so I think the best work-around here is to simply add a check in utils.js for Object._proto_ === null.

This doesn't fix autocomplete, but I think the exception we throw when trying to auto-complete is slightly more acceptable (given the nature of the problem):

exception during autocomplete: "Cannot convert object to primitive value"

Generated at Thu Feb 08 03:16:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.