<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>14163</bug_id>
          
          <creation_ts>2007-06-15 05:22:30 -0700</creation_ts>
          <short_desc>declared variable in window.eval statement not preserved after return from calling context</short_desc>
          <delta_ts>2012-09-06 16:46:32 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>523.x (Safari 3)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WORKSFORME</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>qomo.team</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>barraclough</cc>
    
    <cc>ggaren</cc>
    
    <cc>mrowe</cc>
    
    <cc>oliver</cc>
    
    <cc>qomo.team</cc>
    
    <cc>sam</cc>
    
    <cc>zwarich</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>7452</commentid>
    <comment_count>0</comment_count>
    <who name="">qomo.team</who>
    <bug_when>2007-06-15 05:22:30 -0700</bug_when>
    <thetext>(This bug is reported as #4458636 to Apple Bug Reporter in Feb. 2006, but exists till now)

Webkit doesn&apos;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 &amp; 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&apos;t use var while declare global variables in eval()


test.html:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.1//EN&quot; &quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;title&gt;Testcase&lt;/title&gt;
&lt;script&gt;
function f()
{
window.eval(&apos;test1=1&apos;, &apos;JavaScript&apos;);
window.eval(&apos;var test2=2&apos;, &apos;JavaScript&apos;);
alert(test1)
alert(test2);
}
f();
alert(test1)
alert(test2);
&lt;/script&gt;
&lt;/head&gt;
&lt;body /&gt;
&lt;/html&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>7450</commentid>
    <comment_count>1</comment_count>
    <who name="">qomo.team</who>
    <bug_when>2007-06-15 05:38:35 -0700</bug_when>
    <thetext>well, the bug also exsists in Mozilla&apos;s JSRef, but can be passed by by using eval.call() or eval.apply() instead of window.eval().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>7448</commentid>
    <comment_count>2</comment_count>
    <who name="">qomo.team</who>
    <bug_when>2007-06-15 05:51:07 -0700</bug_when>
    <thetext>also declaration of functions, a simple test case:

window.eval(&apos;function test1() {}&apos;, &apos;JavaScript&apos;);
window.eval(&apos;test2 = new Function() {}&apos;, &apos;JavaScript&apos;);
alert(test1);
alert(test2);
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>7423</commentid>
    <comment_count>3</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2007-06-15 10:14:51 -0700</bug_when>
    <thetext>Thanks for the bug report!  Which version(s) of Safari and/or WebKit have you tested recently?  We&apos;re especially interested in Safari 3.0 beta as well as a Nightly WebKit build (http://nightly.webkit.org/).

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>7412</commentid>
    <comment_count>4</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2007-06-15 10:15:43 -0700</bug_when>
    <thetext>&lt;rdar://problem/4458636&gt;

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>7320</commentid>
    <comment_count>5</comment_count>
    <who name="">qomo.team</who>
    <bug_when>2007-06-15 19:03:38 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; Thanks for the bug report!  Which version(s) of Safari and/or WebKit have you
&gt; tested recently?  We&apos;re especially interested in Safari 3.0 beta as well as a
&gt; Nightly WebKit build (http://nightly.webkit.org/).
&gt; 

Test with Safari 2.0(419.3), Safari 3.0 Beta(502.10.1 for Mac &amp; 502.11 for Win) and WebKit-SVN-r21955, all of them have this bug.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>7115</commentid>
    <comment_count>6</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2007-06-18 16:53:46 -0700</bug_when>
    <thetext>Is this a dupe of bug 11399?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6634</commentid>
    <comment_count>7</comment_count>
    <who name="">qomo.team</who>
    <bug_when>2007-06-23 00:22:30 -0700</bug_when>
    <thetext>(In reply to comment #6)
&gt; Is this a dupe of bug 11399?
&gt; 

It&apos;s about the same thing(window.eval), but not a duplicate bug.

Bug #11399 means &quot;calling context&quot; is wrong, but we found that the variables are like to handled by a wrong way.
read through ECMA-262 sec. 10.2.2, variables declared in eval() context don&apos;t have a {DontDelete} property, but only what declared by &quot;var &quot; are deleted after.

As a ref: Our scripts sometimes need a way that declaring {DontDelete} variables in evaled codes, in Gecko&apos;s javascript engine, we use eval.apply().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58571</commentid>
    <comment_count>8</comment_count>
    <who name="Marcus Better">marcus</who>
    <bug_when>2007-10-15 05:08:44 -0700</bug_when>
    <thetext>(In reply to comment #2)
&gt; also declaration of functions, a simple test case:
&gt; 
&gt; window.eval(&apos;function test1() {}&apos;, &apos;JavaScript&apos;);
&gt; window.eval(&apos;test2 = new Function() {}&apos;, &apos;JavaScript&apos;);

This test case is flawed. The use of the Function constructor is illegal. It should be
  window.eval(&apos;test2 = new Function()&apos;);

In that case the result is that test1 will not be defined outside of f, but test2 will (confirmed with WebKit nightly build r26570).

Is a fix planned before Safari 3.0?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58623</commentid>
    <comment_count>9</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2007-10-15 20:24:33 -0700</bug_when>
    <thetext>(In reply to comment #8)
&gt; (In reply to comment #2)
&gt; &gt; also declaration of functions, a simple test case:
&gt; &gt; 
&gt; &gt; window.eval(&apos;function test1() {}&apos;, &apos;JavaScript&apos;);
&gt; &gt; window.eval(&apos;test2 = new Function() {}&apos;, &apos;JavaScript&apos;);
&gt; 
&gt; This test case is flawed. The use of the Function constructor is illegal. It
&gt; should be
&gt;   window.eval(&apos;test2 = new Function()&apos;);
&gt; 
&gt; In that case the result is that test1 will not be defined outside of f, but
&gt; test2 will (confirmed with WebKit nightly build r26570).

So are you saying this bug is already fixed with WebKit nightly build r26570?  What about r26359?

&gt; Is a fix planned before Safari 3.0?

It depends on whether this bug is already fixed or not in r26359.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>59186</commentid>
    <comment_count>10</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2007-10-22 13:34:06 -0700</bug_when>
    <thetext>It&apos;s hard to tell if this bug has been fixed or not.

If it hasn&apos;t, it blocks bug 14868 because we need to get the semantics of variable declaration correct before we can optimize it. `var&apos; statements inside `eval&apos; statements are a specifically interesting case that we need to get right.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>59197</commentid>
    <comment_count>11</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2007-10-22 15:14:45 -0700</bug_when>
    <thetext>(In reply to comment #10)
&gt; It&apos;s hard to tell if this bug has been fixed or not.
&gt; 
&gt; If it hasn&apos;t, it blocks bug 14868 because we need to get the semantics of
&gt; variable declaration correct before we can optimize it. `var&apos; statements inside
&gt; `eval&apos; statements are a specifically interesting case that we need to get
&gt; right.

I believe this is in fact working now. The Inspector is a nice testcase for this. Just type the following in the Console:

var a = &quot;hi&quot;;&lt;Enter&gt;
a&lt;Enter&gt;

You will see the value &quot;hi&quot; printed. The Inspector uses window.eval for evaluation, so I think this works now.

Geoff, do you think this is correct?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>65740</commentid>
    <comment_count>12</comment_count>
    <who name="">qomo.team</who>
    <bug_when>2007-12-30 06:57:46 -0800</bug_when>
    <thetext>There seems to be some kind of misunderstanding, take a look at the original test case:

function f()
{
window.eval(&apos;test1=1&apos;, &apos;JavaScript&apos;);
window.eval(&apos;var test2=2&apos;, &apos;JavaScript&apos;);
alert(test1);
alert(test2);
}
f();
---------
By declaring either with or without  &quot;var&quot;, both of them is available in the
context of function f() (thus two alert dialog with &quot;1&quot; and &quot;2&quot; showed).
---------
alert(test1);
alert(test2);
---------
And then, after function f() ends, the test1 exsist, BUT test2 disappeared!
This is different from what IE&apos;s execScript() and Gecko&apos;s eval() with syntax &quot;window.eval(script);&quot; does.

(the other ways in Gecko such like &quot;window.eval(script, lang);&quot; &quot;eval(script)&quot; 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).

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>65742</commentid>
    <comment_count>13</comment_count>
    <who name="">qomo.team</who>
    <bug_when>2007-12-30 06:57:58 -0800</bug_when>
    <thetext>*** Bug 16677 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82540</commentid>
    <comment_count>14</comment_count>
    <who name="Cameron Zwarich (cpst)">zwarich</who>
    <bug_when>2008-06-07 02:10:43 -0700</bug_when>
    <thetext>This does not block bug 14868, because the variable lookup optimizations were landed long ago without resolving this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>713851</commentid>
    <comment_count>15</comment_count>
    <who name="Gavin Barraclough">barraclough</who>
    <bug_when>2012-09-06 16:46:32 -0700</bug_when>
    <thetext>Test case appears to work in Safari 6.0 - all vars appear to be preserved.  Please reopen with more specific expected results if this still repros for you.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>