More fun with scopes and ScriptObjectMirror
Attila Szegedi
attila.szegedi at oracle.com
Wed Dec 11 05:50:41 PST 2013
On Dec 11, 2013, at 2:22 PM, Tim Fox <timvolpe at gmail.com> wrote:
> On 11/12/13 13:19, A. Sundararajan wrote:
>> The way Avatar/js project ( https://java.net/projects/avatar-js ) project implements CommonJS/require is as follows.
>>
>> It creates a anonymous function code wrapping a module (say like http.js). The anonymous function accepts 'exports' as argument. When you eval that code at top level global scope, because of the anon function wrapping around, all top level vars in a module code like http.js become locals of that anon function.
>
> Isn't that the same as what I described in my last post?
>
> If so, the problem with that is that globals that aren't prefixed with var still leak.
I might be mistaken, but isn't that the best technique browser-based (pure JavaScript) require() implementations can do too? Again, not justifying the design (I'm saying this a lot today), just pointing out that a widespread deployment base - namely, all browsers - might also suffer from the problem.
Attila.
More information about the nashorn-dev
mailing list