Which version of JavaScript for views? And what is builtin?

Gentlefolk,

My Google-fu is weak and I cannot find the answer to the below questions.

What version of Javascript is running the map and reduce functions? Because I have some conditional loops building up an object, I only want to emit it as a value when it actually has properties. This snippet:

Object.keys(value).length

will do the job. But keys() is only available in later versions of Javascript.

Hence, which version of Javascript is running in CB v2.1.1 and what subset of browser Javascript does it support?

Andrew

Couchbase server uses libv8 to execute javascript.

 $ cat /opt/couchbase/VERSION.txt 
2.1.0-718-rel
 $ cat /opt/couchbase/lib/libv8.ver 
447decb75060a106131ab4de934bcc374648e7f2

Then you can get information about this version on github page for this commit:

In this particular case couchbase uses libv8 3.9.7. At this moment debian unstable has 3.14.5.8-4. Most recent release 3.21.6 (9 hours ago).

Having the version you can google on which version of javascript does this v8 implements.

The answer regarding built-ins:
All of them described in the docs: http://couchbase.com/docs/couchbase-manual-2.0/couchbase-views-writing-utilityfuncs.html
Also for reduce you can use special macros instead of reduce function body, which will allow to execute native implementation: http://couchbase.com/docs/couchbase-devguide-2.0/using-built-in-reduces.html

avsej,

Thank you for your reply.

I was hoping that you might have a pointer to which built-ins, both CB and JS, are available to view and reduce functions. You answered the CB built-in question. But the other built-ins are as much a part of your platform as the ones CB writes yourselves. Your Javascript is not browser Javascript and has significantly fewer built-in features. Which ones, exactly? With the version of V8, I can track this information down but the Javascript community doesn’t make this easy. (BTW, the node.js people suffer from this problem too.) Hence, if you had a CB preferred reference link to the built-ins supported by your version of V8, then I know what to spend my time mucking with. If you find and “bless” a preferred link, I would hope it would be added to the page describing the CB authored built-ins.

Anon,
Andrew

avsej,

Also, a guide to debugging Javascript problems would be appreciated. I wrote a reduction that caused the database to infinitely loop creating and deleting the view. Apparently, when the reduction does not reduce the data enough, this happens. (Actually, the group reduction was well within the 64KB limit, there are apparently subsequent reductions that force the memory exhaustion.)

Anon,
Andrew