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 00:52:53 GMT


Jason Smith commented on COUCHDB-1397:

Paul, tl;dr: I see your point but disagree because I love the old syntax. I also have a fixed
JS server (i.e. the code couchjs runs) working in all (IMO) important cases. Would you care
to at least see the patch?

Next I continue my plea to retain CouchDB's aesthetic decency...

After years of a relaxing API, why would CouchDB force us to stop writing perfectly valid
functions and instead write valid programs? It is redundant. It is confusing. There is no
obvious benefit to the user. It is Kafkaesque.

The current syntax that better matches our mental model is this:

{ "views": {
    "example": {
      "map": "function(doc) { emit(1, 2) }"

That is intuitively relaxing because it feels like Javascript:

doc =
{"views": {
  "example": {
    "map": function(doc) { emit(1, 2) }

Please re-read your own examples. How many new ways does it confuse the user? And for what?
Because we can't' be bothered to do anything except the simplest possible implementation:
just run it through eval(). What about this view object:

"Map": "function map(D) { emit(1,D) } // wrong JSON key"
"map": "function mapo(D) { emit(1, D) } // fat-fingered the function name"

Really, if CouchDB will insist that users begin writing *programs* and not just expressions,
it makes more sense to eradicate the "map" and "reduce" fields and replace the whole object
with a string.

{"views": {
  "people": "
    function map(D) {
      emit(, 1)

    function reduce(K, V, re) {
      return sum(K)

OTOH, given a previously well-formed view definition and newer SpiderMonkey, couchjs should
DTRT, do what it takes to make it work, as the user has already begun relaxing.
> Function expressions, evals in SpiderMonkey
> -------------------------------------------
>                 Key: COUCHDB-1397
>                 URL:
>             Project: CouchDB
>          Issue Type: Bug
>          Components: JavaScript View Server
>    Affects Versions: 1.2
>         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