couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marcello Nuccio (Commented) (JIRA)" <>
Subject [jira] [Commented] (COUCHDB-1397) Function expressions, evals in SpiderMonkey
Date Sat, 04 Feb 2012 15:59:53 GMT


Marcello Nuccio commented on COUCHDB-1397:


CommonJS is fine, but it doesn't help for unit testing. CommonJS is a linker (runs on load
time), dependency injection is done at run-time. One assembles code, the other object graph.
Not the same thing.

To ease unit testing, you need dependency injection. You can't easily test:

    function (doc) {
      var util = require('views/lib/util');
      if (util.isSomething(doc)) {
        emit(doc._id, 1);

It's doable (I'm doing it), but not easy. Testing the following is trivial:

    function (doc, view, require) {
      var util = require('views/lib/util');
      if (util.isSomething(doc)) {
        view.emit(doc._id, 1);

Globals, make the code harder to:

 - read (where do these values come from?);
 - test (how do I mock globals at run-time?);
 - write (you need to tell to your code-checker what globals you use.)
> 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