RESOLVED DUPLICATE of bug 14163 16677
declared variable in window.eval statement not preserved after return from calling context
https://bugs.webkit.org/show_bug.cgi?id=16677
Summary declared variable in window.eval statement not preserved after return from ca...
qomo.team
Reported 2007-12-30 06:52:39 PST
Well, the Bug #14163 is NOT fixed ...It is reproducable in nightly builds till now & the shipped Safari 3. There seems to be misunderstanding, take a look at the original test case: By declaring either with or without "var", both of them is available in the context of function f() (thus two alert dialog with "1" and "2" showed). And then, after function f() ends, the test1 exsist, BUT test2 disappeared! This is different from what IE's execScript() and Gecko's eval() with syntax "window.eval(script);" does. (the other ways in Gecko such like "window.eval(script, lang);" "eval(script)" has the bug same as what described here, with even worse effects such as leading a crash. But they seems not going to resolve that, referenced as https://bugzilla.mozilla.org/show_bug.cgi?id=352045). +++ This bug was initially created as a clone of Bug #14163 +++ (This bug is reported as #4458636 to Apple Bug Reporter in Feb. 2006, but exists till now) Webkit doesn't work correctly on the lifetime control of global variables declared explicitly in window.eval() method while calling from a function. Those variables declared explicitly will be destoryed out of the caller function of window.eval(). The attached test.html shows the problem: alert() in f() works fine, both test1 & test2 will popup, but only test1 will popup by alert() in the global context. And if window.eval() is called in the global context, both places of alert() works fine. Workaround: Don't use var while declare global variables in eval() test.html: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Testcase</title> <script> function f() { window.eval('test1=1', 'JavaScript'); window.eval('var test2=2', 'JavaScript'); alert(test1); alert(test2); } f(); alert(test1); alert(test2); </script> </head> <body /> </html>
Attachments
qomo.team
Comment 1 2007-12-30 06:57:58 PST
*** This bug has been marked as a duplicate of 14163 ***
Note You need to log in before you can comment on or make changes to this bug.