couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Max Desyatov (JIRA)" <>
Subject [jira] [Commented] (COUCHDB-1075) Circular require's in CommonJS modules
Date Sun, 03 Feb 2013 15:32:13 GMT


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 +
       "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:
>             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:

View raw message