[SERVER-1118] tojson() crashes when .constructor is null Created: 14/May/10  Updated: 12/Jul/16  Resolved: 14/May/10

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 1.3.3, 1.4.2
Fix Version/s: 1.5.2

Type: Bug Priority: Minor - P4
Reporter: Andy MacKinlay Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS X, 32 bit


Participants:

 Description   

If you pass in an object with .constructor set to null as argument to tojson(), the tojson call fails:
v1.3.3 with spidermonkey:
> var a = new Object()
> a.constructor = null
null
> tojson(a)
Fri May 14 14:46:28 JS Error: TypeError: x.constructor has no properties (anon):393

error emssage on 1.4.2 with v8:
> tojson(a)
Fri May 14 14:51:14 exec error: shell setup:397 TypeError: Cannot read property 'tojson' of null
if ( typeof( x.constructor.tojson ) == "function" && x.constructor.tojson != t
^
I'm not sure whether have a null value for constructor has sane uses, but there are at least some situations where mongoDB produces it (as 'this' of the map funciton in the mapreduce when using v8, but I"ll open another bug for that). If it doesn't make sense to have a null value there, then please close this bug.



 Comments   
Comment by auto [ 14/May/10 ]

Author:

{'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: don't require constructor to be set SERVER-1118
http://github.com/mongodb/mongo/commit/2dbdcf9e4cc4e095af4ee96607e951a5ad144b33

Generated at Thu Feb 08 02:56:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.