kjs: variables with/without var [PATCH]

David Faure dfaure at klaralvdalens-datakonsult.se
Sat Jan 18 19:38:56 GMT 2003


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

On Saturday 18 January 2003 16:24, Koos Vriezen wrote:
> Hi,
> 
> This example uses a variable decl. without 'var'

Ah. We changed the alert(myundefinedvar) behaviour (which aborts like
in all browsers now), but this seems to have broken the support for
"setting an undefined var" - in some cases...

>   <HTML><HEAD><SCRIPT>
>     function someFunc() {
>       myvar = "test";
>       alert(myvar);
>     }
>   </SCRIPT></HEAD>
>   <BODY onClick="top.someFunc()"></BODY></HTML>
> which works.

processing parameters for someFunc call
Resolve::evaluateReference: didn't find 'myvar'
KJS: setting property myvar: test : String (0x838d2d8)

(evaluateRerefence creates a Reference2 with base=Null(), and
Reference2::putValue creates the var ..... ah ... )

> Now if I use it with frames it works only with 'var'.
> 
>   <HTML><HEAD><SCRIPT>
>     function someFunc() {
>       var myvar = "test";
>       alert(myvar);
>     }
>   </SCRIPT></HEAD>
>   <FRAMESET COLS="200,*">
>     <FRAME SRC="frame.html">
>     <FRAME SRC="frame.html">
>   </FRAMESET></HTML>
> 
> where frame.html is
> 
>   <HTML><BODY onClick="top.someFunc()"></BODY></HTML>
> 
> If I ommit the 'var', someFunc() is never called

processing parameters for someFunc call
Resolve::evaluateReference: didn't find 'myvar'
KJS: setting property myvar: test : String (0x84af470)
Resolve::evaluate: didn't find 'myvar'
WARNING: KJS Reference error: Can't find variable: myvar
KJS: someFunc throws:  : Object (0x82ece68)
KJS: (internal) throws:  : Object (0x82ece68)

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 .... and since the frameset's globalobject isn't in the
scope chain, the alert() can't find the value of 'myvar').

Hmm, I'm afraid I don't see how putValue() could know the right
globalobject to use..... or is that exec->context().imp()->variableObject() ?

Wow, it works!
Harri, what do you think about this fix?

Index: internal.cpp
===================================================================
RCS file: /home/kde/kdelibs/kjs/internal.cpp,v
retrieving revision 1.141
diff -u -p -r1.141 internal.cpp
- --- internal.cpp        16 Jan 2003 23:30:52 -0000      1.141
+++ internal.cpp        18 Jan 2003 19:36:59 -0000
@@ -256,7 +256,7 @@ void Reference2::putValue(ExecState *exe
                   propertyName()).cstring().c_str(), w);
 #endif
   if (bs.type() == NullType)
- -    exec->interpreter()->globalObject().put(exec, propertyName(), w);
+    exec->context().imp()->variableObject().put(exec, propertyName(), w);
   else
     static_cast<ObjectImp*>(bs.imp())->put(exec, propertyName(), w);
 }

- -- 
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+Ka1R72KcVAmwbhARAuHPAJ9RGLKlKcesw++pTbPea6zhi7StrwCgrkMj
aSWNer/ool/0M58FBtUcM1U=
=LeY6
-----END PGP SIGNATURE-----





More information about the kfm-devel mailing list