couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Candler <>
Subject Re: Use of json2.js in HEAD
Date Tue, 09 Feb 2010 10:42:04 GMT
On Tue, Feb 09, 2010 at 10:43:34AM +0100, Cliff Stanford wrote:
> So it seems that the JSON object has disappeared and toJSON() is
> broken for dates.
> Or am I misunderstanding what should happen?

I think what you're seeing is odd too.

I notice that:

(1) Dates serialize as their useless ASCII string version, not ISO.

$ curl -X POST -d '{"map":"function(doc) { emit([Date(0)],null); }"}'
{"id":"0fc1b193e778a8c0657591618c15e3f2","key":["Tue Feb 09 2010 10:10:12 GMT+0000 (BST)"],"value":null},
{"id":"0fc1b193e778a8c0657591618c15f5aa","key":["Tue Feb 09 2010 10:10:12 GMT+0000 (BST)"],"value":null},
{"id":"foo","key":["Tue Feb 09 2010 10:10:12 GMT+0000 (BST)"],"value":null}

I don't have an older build to compare against, but if you used to get ISO
format dates (and there is clearly code in main.js which could generate
them) then I'd say this is a regression, and needs a test case.

(2) xxx.toJSON() isn't available in map functions

$ curl -X POST -d '{"map":"function(doc) { emit([].toJSON(),null); }"}'

Furthermore, no error is recorded in couch.log if you try to do this.
However, toJSON(xxx) does work.

$ curl -X POST -d '{"map":"function(doc) { emit(toJSON([]),null); }"}'

(3) JSON isn't available in map functions

$ curl -X POST -d '{"map":"function(doc) { emit(JSON.stringify([]),null); }"}'

But in this case an error *is* recorded:

[Tue, 09 Feb 2010 10:13:04 GMT] [info] [<0.457.0>] OS Process #Port<0.1895> Log
:: function raised exception (new ReferenceError("JSON is not defined", "")) with doc._id

It appears to be sandboxed out. With a bit of hacking to main.js I was able
to add JSON to the sandbox.



View raw message