[e-lang] Module naming and identification

Kris Kowal cowbertvonmoo at gmail.com
Thu Apr 16 13:53:50 EDT 2009


On Thu, Apr 16, 2009 at 10:37 AM, Lex Spoon <lex at lexspoon.org> wrote:
> I have to ask: your first message mentions cycles specifically, but three
> messages later you still didn't address them.   Do you have a pointer to
> that issue?  It's highly relevant for modules.

I'm only following this thread shallowly, so please forgive me if this
response does not address the actual issue.

Here's a link to the draft specification for modules that the ServerJS
group is converging on:
https://wiki.mozilla.org/ServerJS/Modules/SecurableModules

1.3 under "Module Context" addresses the requirement to behave
gracefully when there are cyclic dependencies among modules.  The
verbiage here only addresses the requirement, but not how to satisfy
it in an implementation.  The trick is to keep a memo of singleton
module exports object.  The modules do not return these exports
objects, or render them as the last evaluated expression.  Instead,
the sandbox creates an empty object and stores it in the memo *before*
applying the corresponding module factory function.  This ensures that
a cyclic dependency will get the partially completed exports object
instead of recurring indefinitely.  This is perhaps not as elegant as
mutual recursion, but it makes it possible to have mutually dependent
modules.

Kris Kowal


More information about the e-lang mailing list