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

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

@Marcello, yes I am okay with the idea of JavaScript programs (I've realized 
the word "invalid" is not helpful in this discussion).

However once again, CommonJS is the clear, obvious goal. It clarifies and 
unifies CouchDB, and CouchApps would immediately become Node.js apps (at least, 
you could require() their parts for unit testing which I have started to do as 
well.)

I agree that emit(), log(), etc. should be global; but I disagree that they can 
be injected. There is a third way, the way CommonJS works. The code is 
implicitly wrapped in a larger function where `emit`, `log`, etc. had been 
passed as parameters.

In CommonJS, your code is inside a function--not even conceptually, really. See 
share/server/util.js, around line 90.

    var s = "function (module, exports, require) { " + newModule.current + " }";

This is the sort of source code transforms I hope Paul would agree is fine. If 
newModule.current was wrong before (suppose it defined an anonymous function), 
then it is still wrong. And this pattern is well-known and well-exercised in 
several JavaScript environments. Perhaps one day there will be:

    var map_runner = "function (emit, log, sum) { " + map_value + "}"
                
> 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.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: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to