kjs: variables with/without var [PATCH]

David Faure dfaure at klaralvdalens-datakonsult.se
Thu Jan 23 20:53:28 GMT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Saturday 18 January 2003 22:07, Harri Porten wrote:
> On Sat, 18 Jan 2003, David Faure wrote:
> 
> > Ouch, it seems the var was put in the wrong global object....
> > (the one of the calling interpreter, i.e. the frameset, instead of the
> > one of the frame
> 
> My understanding is different. The calling interpreter belongs to the
> frame so I would assume the used global object to be the frame - no the
> frameset.

Ooops yes I mixed the too....
But anyway that's wrong, the global object of the calling interpreter
is surely not the one where we want to put the var...

(I just found out that this problem also affects http://www.joeys.de/joeys/38/index.htm
(the order form on the right side only appears with my fix applied)).

> > .... and since the frameset's globalobject isn't in the
> > scope chain, the alert() can't find the value of 'myvar').
> 
> It should be there (see the scopeChain copy passed to DeclaredFunctionImp
> in FuncDeclNode::procesFuncDecl). 

Oh ??
Hmm you say this happens when the func is declared. So it's the globalobject
of the frameset (where the func is declared) which is in the scope, NOT
the globalobject of the frame (calling this method).

Ah. Now I see how it worked before - that global object in the scope chain
accepted the new var, so it worked like in other browsers.

> Does this patch satisfy the condition that an alert(top.myvar) in
> frame.html works, too (NS 4.7) ? 
> My khtml build is broken so I can't try.
> But variableObject() should be the variable object created for function
> execution which wouldn't be the same as the top object.

Ah, I see. I was assuming that the code, without the 'var', still means that
the variable should be declared as if the 'var' was there, i.e. as a local var
in the function.
But you're right, Mozilla shows that the var is stored in the frameset's
global object.

> One would have to think of other ways of testing whether other browsers
> maybe do switch the global object when executing functions defined in
> another window.

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.

- -- 
David Faure -- faure at kde.org, dfaure at klaralvdalens-datakonsult.se
Klarälvdalens Datakonsult AB, Platform-independent software solutions
Contributing to: http://www.konqueror.org/, http://www.koffice.org/
KOffice-1.2.1 is available - http://download.kde.org/stable/koffice-1.2.1/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+MFZM72KcVAmwbhARAl94AKCU2N46ogn06tANFL1Muy/zbkeWSQCeMdKF
5HIcohqJCR6z5s68qu63DJg=
=yAQK
-----END PGP SIGNATURE-----





More information about the kfm-devel mailing list