couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Smith (Commented) (JIRA)" <>
Subject [jira] [Commented] (COUCHDB-1397) Function expressions, evals in SpiderMonkey
Date Fri, 03 Feb 2012 13:25:53 GMT


Jason Smith commented on COUCHDB-1397:


We really need to define "invalid JavaScript" and distinguish it from "invalid CouchDB programming"
which is why I wrote Fact #6.

For example, Benoit suggested that we could provide only the function *bodies*. They are implicitly
wrapped in a function(doc) { ... }. That's neat! In a world where CouchDB had always worked
that way, we would all call "emit(doc._id, null)" *valid CouchDB* but we know it is invalid
JavaScript (doc is unbound).

I take you to mean that "valid CouchDB" implies "valid JavaScript."

But valid CouchDB is more relaxing with anonymous functions ("invalid JavaScript"). Business
as usual is beautiful.

How could it be implemented on all SM versions? What if we catch the eval()? If the error
is "anonymous function at a top level scope" then we try again with "("+code+")". Yes, it
is a tiny source transformation, and that is bad; however it is a common idiom in Javascript
when building code from data.

(If you ask me, it is the helper function people who should see their code broken; not we
who have followed the customs and conventions all along. Thus I prefer your original patch
the most: wrap it in parens.)
> Function expressions, evals in SpiderMonkey
> -------------------------------------------
>                 Key: COUCHDB-1397
>                 URL:
>             Project: CouchDB
>          Issue Type: Bug
>          Components: JavaScript View Server
>    Affects Versions: 1.2.1
>         Environment: All
>            Reporter: Jason Smith
> New SpiderMonkey releases do not eval() a sole anonymous function expression. That is
not a valid JavaScript statement, and so it is not a valid JavaScript script.
> COUCHDB-1302 addressed this for 1.1 and the 1.1.x branch. This ticket is for 1.2. (Sorry
to spam COUCHDB-1302. I saw "Unassigned" and read "Unresolved.")

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message