Right now CouchDB uses outdated Spidermonkey 1.8.5. To upgrade it we need
to fix one small issue: Spidermonkey 31 can not eval anonymous functions in
global scope.

It means we can not take string representation of ddoc function and convert
it into executable code using eval('function(args){/*code*/}') in
Spidermonkey 31.

Way to fix it is quite straightforward and does not require touching of
existing C code of couch_js (as I see).

We just need to convert anonymous functions into named before sending them
to couch_js.

To achieve it we must replace /^function[\s\r\n\t]*\(/ to `function
someName(`, that is enough.

To generate function name and make it unreacheable for other functions of
the ddoc by name, we can take some quick hash from
(ddocName+fnBranchName+PID).

There exist another possible obstacle – old SMs support extended syntax of
try/catch – but it seems very unlikely someone uses it in real, so it can
be forgotten, since it‘s totally out of JS standards.

ermouth

Reply via email to