Subj : Re: syntax check To : netscape.public.mozilla.jseng From : =?ISO-8859-1?Q?Georg_Maa=DF?= Date : Sat Jan 22 2005 04:56 pm 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? ;-) > > SpiderMonkey output for same script: > > 0 > 1 > > Why not use the activation as the scope chain head? > > /be js> var a = 1; js> js> function f() { var a = 2; var s = Script("a = 0"); s(); print(a); } js> js> f(); 2 js> print(a); 0 js> This is what my SM1.5rc5 outputs, which is identcal to what Igor said about Rhino. Did the implementation change in SM1.5rc6, or is the implementation configurable, or what might be the reason. var a = 1;function b(){var a=2; var s = Script("a = 0"); s(); alert(a);};b(); alert(a); Mozilla also outputs 2 and zero. -- Georg Maaß - bioshop.de D-76227 Karlsruhe, Westmarkstraße 82 HTML, XML / JavaScript, C++, Java, PHP, VB / CGI, JSP, ASP, ASP.net - The ultimate DHTML engine: http://gml-modul.sourceforge.net - http://sourceforge.net/projects/gml-modul .