couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Caolan McMahon (JIRA)" <>
Subject [jira] [Commented] (COUCHDB-1075) Circular require's in CommonJS modules
Date Fri, 06 May 2011 16:38:03 GMT


Caolan McMahon commented on COUCHDB-1075:

I don't see the point in storing a function on the design doc if the results of the function
will never change. We may as well store the results of the function. The only issue is detecting
that a require path has found a module and not an object. Using a function allows us to detect
this because a design doc is JSON and won't contain them, but the results of a module can
be anything, so we wouldn't know if the require path had worked or if we'd found a pre-compiled
module. Having a separate store for compiled modules avoids this issue without having to constantly
call a function which will always give the same result.

Also, by caching the result and not the function you can be sure that instanceof checks will
work correctly. Consider the following, where 'a' is the cached function for a module (instead
of a module result):

> a = function () {return {b: function () { = 'bee'; }}}
> one = a();
{ b: [Function] }
> two = a();
{ b: [Function] }
> obj1 = new one.b()
{ name: 'bee' }
> obj2 = new two.b()
{ name: 'bee' }
> obj1 instanceof one.b
> obj1 instanceof two.b

> Circular require's in CommonJS modules
> --------------------------------------
>                 Key: COUCHDB-1075
>                 URL:
>             Project: CouchDB
>          Issue Type: Bug
>          Components: JavaScript View Server
>            Reporter: Caolan McMahon
>              Labels: javascript
>         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.
For more information on JIRA, see:

View raw message