You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by "Jason Smith (Commented) (JIRA)" <ji...@apache.org> on 2012/02/02 13:33:53 UTC

[jira] [Commented] (COUCHDB-1397) Function expressions, evals in SpiderMonkey

    [ https://issues.apache.org/jira/browse/COUCHDB-1397?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13198732#comment-13198732 ] 

Jason Smith commented on COUCHDB-1397:
--------------------------------------

## Facts

1. All documentation, all books, all online resources, and almost all code use the "function expression" style to program CouchDB:
    { "views":{"people":{"map":
      "function(doc) { emit(doc.name, 1) }"
    }}}

2. The code in the string is an invalid JavaScript statement, and also an invalid program.

3. (Computer scientists, divert your gaze!) The code is a valid expression, or perhaps an r-value. You can copy and paste it to the right-hand side of an assignment statement, or paste it as a parameter in a function call.

4. CouchDB inadvertently exploited a now-fixed SM bug where you can just eval() the expression, it is treated as a statement, and eval returns the compiled function object.

5. Distinct from Fact 4, CouchDB users inadvertently exploited the bug by writing what are more properly called "programs", with helper functions, and a final (incorrect JavaScript) function expression serving as the entry point for Couch to call into.

6. There may be, if the community wants, a distinction between valid *JavaScript* programming and valid *CouchDB* programming.

## Opinions

Those clever anonymous function expressions are relaxing. They make intuitive sense. Learning how map/reduce works is one of the major emotional payoffs CouchDB provides to a learner.

Asking the wiki maintainers, the book authors, and the CouchDB users to change anything, even one character, is not relaxing, major release or no.

Instead we should ask something else:

1. CouchDB should support the same old same-old. Even on newer SpiderMonkey.
2. People who wrote full-on programs (helper functions, global state, etc.) must adhere to the longstanding documentation and change their code. Perhaps CouchDB or its community might show how.

Finally, unless someone can show otherwise, we should assume that very few people wrote *programs* instead of *expressions* and so CouchDB can justifiably start throwing errors on their code in the 1.2.x branches.
                
> Function expressions, evals in SpiderMonkey
> -------------------------------------------
>
>                 Key: COUCHDB-1397
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1397
>             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: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira