Proposal: Explicitly specify how natives work in Modules

5 views
Skip to first unread message

Thomas Aylott

unread,
Jan 4, 2010, 8:51:01 PM1/4/10
to comm...@googlegroups.com
Ok, here's an official proposal: http://wiki.commonjs.org/wiki/Modules/ProposalForNativeExtension

I'm trying to follow the http://wiki.commonjs.org/wiki/ProposalProcess but I'm an admitted CommonJS n00b, so please forgive me if I am doing something wrong.

This proposal is meant to recognize how some implementations already work and give a name to the two separate existing standards. That way everyone should know what the differences are and the implications.

— Thomas Aylott
   SubtleGradient
   MooTools

On Mon, Jan 4, 2010 at 6:36 PM, Thomas Aylott <obli...@subtlegradient.com> wrote:

Perhaps I should make that an "official" proposal.

Kevin Dangoor

unread,
Jan 5, 2010, 9:35:36 AM1/5/10
to comm...@googlegroups.com
On Mon, Jan 4, 2010 at 8:51 PM, Thomas Aylott <obli...@subtlegradient.com> wrote:
Ok, here's an official proposal: http://wiki.commonjs.org/wiki/Modules/ProposalForNativeExtension

I would rather leave this unspecified, though we can be explicit about the fact that it's unspecified and what exactly that means. This quote from your proposal gets to the heart of it:

An environment may claim CommonJS compliance if it implements at least one of these Modules specifications.

i.e. NodeJS could implement MGN and not MSB and still be a CommonJS compatible environment.


In other words, it's implementation specific. By leaving it unspecified, we're basically saying "you can't count on being able to change the globals from within a CommonJS module". You can do so, but it might not work on all platforms.

A module that is running in a secure environment will never be able to extend the global objects (or, at least, they won't be able to have a global effect in doing so). Therefore, again, you have to know something about the implementation you're running on. It is not for the CommonJS module itself to decide whether or not it has access to change the globals, that's up to the environment (so "requireSafe" wouldn't work).

I'm not running a secure JS environment myself, so perhaps someone who is may have more comments. I have actually modified globals in a CommonJS module (largely to add things like Function.bind), but I do so with the knowledge that those modules may not work in all CommonJS implementations...

Kevin

--
Kevin Dangoor

work: http://labs.mozilla.com/
email: k...@blazingthings.com
blog: http://www.BlueSkyOnMars.com
Reply all
Reply to author
Forward
0 new messages