couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <paul.joseph.da...@gmail.com>
Subject Re: upgrading to json2.js
Date Tue, 26 Jan 2010 04:47:21 GMT
On Mon, Jan 25, 2010 at 11:08 PM, Chris Anderson <jchris@apache.org> wrote:
> On Tue, Dec 22, 2009 at 10:26 AM, Chris Anderson <jchris@apache.org> wrote:
>> On Sat, Dec 19, 2009 at 5:07 PM, Chris Anderson <jchris@apache.org> wrote:
>>> It's well known that in order to take advantage of native JSON
>>> libraries in the newest Mozilla JavaScript VMs, we'll need to change
>>> our handling of 'undefined' in the toJSON() routine.
>>>
>>> I propose we make this change now, by replacing our current JSON
>>> handling with json2.js, the current reference implementation.
>>>
>>> I've started the work here:
>>>
>>> http://github.com/jchris/couchdb/tree/json2
>>
>> I've update my json2 branch to reflect my latest commits to trunk.
>>
>
> I've committed this change to CouchDB. It will appear in the 0.11
> release. From the commit message:
>
>  Replace the old JavaScript query server JSON library with json2.js
>
>    This change makes us interoperate better with other JSON
> implementations. It also means we can use the native JSON handlers in
> JavaScript runtimes that support them.
>
>    There are some potential breaking changes for apps that depend on
> Couch blowing up on 'undefined'. json2.js serializes undefined as
> 'null' instead of crashing.

The change is that undefined in an array gets serialized as null. Thus:

 $ JSON.stringify([undefined]) -> "[null]"

plus the XML stuff.

No idea how JSON.stringify(undefined) behaves but we wrap all results
in an array before passing to Erlang so it shouldn't be a huge deal.

HTH,
Paul Davis

>    This change will also effect people using E4X, as you can't just
> return an XML object and have it serialized to a string for you.
> Calling .toXMLString() on these is what you need to do here.
>
>
> Best,
> Chris
>
>
>> Benoit has fixed the E4X issues. There are a few other test failures
>> which I believe have to do with the changed behavior. If anyone wants
>> to take a look at these and consider changing the tests where
>> appropriate, that'd be super helpful.
>>
>> Chris
>>
>>>
>>> Everything works except E4X. When I run the view_xml tests, I see this
>>> error in the logs:
>>>
>>> OS Process :: function raised exception (TypeError:
>>> String.prototype.toJSON called on incompatible XML) with doc._id
>>> 43840f81289e03fec4e9f620b2c03799
>>>
>>> In our old implementation of toJSON, we run value.toXMLString() to
>>> convert XML to strings. json2.js takes a callback parameter to allow
>>> modification of results, but the TypeError is triggered before the
>>> callback, it seems.
>>>
>>> If any of you JavaScript ninjas wanna give this a shot, please help me
>>> finish it.
>>>
>>> Chris
>>>
>>> --
>>> Chris Anderson
>>> http://jchrisa.net
>>> http://couch.io
>>>
>>
>>
>>
>> --
>> Chris Anderson
>> http://jchrisa.net
>> http://couch.io
>>
>
>
>
> --
> Chris Anderson
> http://jchrisa.net
> http://couch.io
>

Mime
View raw message