You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by "Max Desyatov (JIRA)" <ji...@apache.org> on 2013/02/03 16:32:13 UTC

[jira] [Commented] (COUCHDB-1075) Circular require's in CommonJS modules

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

Max Desyatov commented on COUCHDB-1075:
---------------------------------------

Circular require still doesn't work in 1.2.1, at least in validation functions. Try this one

{
   "_id": "_design/validation",
   "validate_doc_update": "function (newDoc, oldDoc, userCtx, secObj) {\n    if (!(newDoc._deleted != null)) {\n      throw {\n        forbidden: require('lib/test').meow\n      };\n    }\n  }",
   "lib": {
       "test": "exports.blah = 1234; var two = require('./two'); exports.meow = two.meh + 1;",
       "two": "var test = require('./test'); exports.meh = test.blah + 1;"
   }
}

Expected result is 1236.
In CouchDB 1.2.1 it always throws null, though according to CommonJS Modules spec (even 1.0): "If there is a dependency cycle, the foreign module may not have finished executing at the time it is required by one of its transitive dependencies; in this case, the object returned by "require" must contain at least the exports that the foreign module has prepared before the call to require that led to the current module's execution."
                
> Circular require's in CommonJS modules
> --------------------------------------
>
>                 Key: COUCHDB-1075
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1075
>             Project: CouchDB
>          Issue Type: Bug
>          Components: JavaScript View Server
>            Reporter: Caolan McMahon
>              Labels: javascript
>             Fix For: 1.2
>
>         Attachments: module_cache.diff
>
>
> Having a CommonJS module A which requires B, when B also requires A causes the stack to fill up with require calls. A prerequisite for this fix is the caching of modules, even if it is only on a per-request basis.
> Patch incoming.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira