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

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 () { this.name = 'bee'; }}}
[Function]
> one = a();
{ b: [Function] }
> two = a();
{ b: [Function] }
> obj1 = new one.b()
{ name: 'bee' }
> obj2 = new two.b()
{ name: 'bee' }
> obj1 instanceof one.b
true
> obj1 instanceof two.b
false

> 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
>         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: http://www.atlassian.com/software/jira

Reply via email to