kjs: variables with/without var [PATCH]

Maciej Stachowiak mjs at apple.com
Thu Jan 23 21:01:45 GMT 2003


On Thursday, January 23, 2003, at 12:53  PM, David Faure wrote:

>
> Let's see ... Oh yes, you're right. At least in mozilla, alert(self) 
> shows that
> the global object is indeed the frameset, in SomeFunc(), even when 
> called
> from the frame. Ouch. Now this brings back some bad memories of the
> static interpreter pointer kjs-1 had :)
> Can you help with this? What would be the best way to do such a 
> switching
> in a safe way - i.e. in a way that restores the initial globalobject 
> correctly?
> (Meanwhile I'll make a testcase that also works in IE - alert(self) 
> shows
> a pointer address only in mozilla) - to make sure.
>

You could switch the global object when entering a function call to the 
last element of the function's scope chain, and switch it back when 
leaving. However, I don't think there is any need to change the global 
object - rather, kjs should use the last element of the current 
context's scope chain in more places and the global object in fewer. Or 
perhaps the execution state method that returns the global object could 
always return the last element of the current scope chain.

  - Maciej





More information about the kfm-devel mailing list