Subj : Re: syntax check To : netscape.public.mozilla.jseng From : Igor Bukanov Date : Mon Jan 17 2005 11:06 am Brendan Eich wrote: > Igor Bukanov wrote: > >> Georg Maaß wrote: >> >>> ... Is Script also >>> implemented in Rhino? >> >> >> >> Yes, it is implemented in Rhino. >> >>> ... >>> Which context does this script generated by the Script function use? >> >> >> >> I assume you mean scope, not context, right? In Rhino instances of >> Script use the top scope of the scope at then moment of script call so >> script code can assume it has access to top or global variables. For >> example, if you execute the following in Rhino shell: >> >> var a = 1; >> >> function f() >> { >> var a = 2; >> var s = Script("a = 0"); >> s(); >> print(a); >> } >> >> f(); >> print(a); >> >> you should get >> 2 >> 0 >> since code executed via s() does not have access to function scope. > > > Who made up that rule? ;-) AFAICS it was always present in publicly released Rhino. > > SpiderMonkey output for same script: > > 0 > 1 > > Why not use the activation as the scope chain head? Activation is very expensive in Rhino so Rhino does not create one unless it is unavoidable in cases like eval calls, arguments access or presence of nested functions. Since it is not possible to detect calls to Script instances at compile time, Rhino does not do that and simply passes top scope for consistency. It also means that Rhino does nor support indirect evals but that is allowed by ECMAScript. I also assume given https://bugzilla.mozilla.org/show_bug.cgi?id=121414#c70 there is a chance that SM would face the same choice. Regards, Igor .