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



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:


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?



Couchbase server uses libv8 to execute javascript.

 $ cat /opt/couchbase/VERSION.txt 
 $ cat /opt/couchbase/lib/libv8.ver 

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 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



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.




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.)