Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-1118

tojson() crashes when .constructor is null

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.5.2
    • Affects Version/s: 1.3.3, 1.4.2
    • Component/s: Shell
    • None
    • Environment:
      OS X, 32 bit

      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.

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            admackin Andy MacKinlay
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: