<?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>3537</bug_id>
          
          <creation_ts>2005-06-14 18:33:03 -0700</creation_ts>
          <short_desc>object.constructor returns incorrect object</short_desc>
          <delta_ts>2005-11-02 08:48:01 -0800</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>412</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.4</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="David Wheeler">david</reporter>
          <assigned_to name="Eric Seidel (no email)">eric</assigned_to>
          <cc>paul</cc>
    
    <cc>vicki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>12049</commentid>
    <comment_count>0</comment_count>
    <who name="David Wheeler">david</who>
    <bug_when>2005-06-14 18:33:03 -0700</bug_when>
    <thetext>A growing trend (IMO) in JavaScript is to use objects for namespaces. However, when an object 
constructor is an attribute of an object, the Function.toString() method thinks its an internal function. 
For example, this code:

  var Foo = {};
  Foo.Bar = function () {
    this.bar = 1;
  }; 
  var f = new Foo.Bar();
  document.write(Function.toString.call(f.constructor));

Outputs &quot;(Internal Function)&quot; in Safari and &quot;function () { this.bar = 1; }&quot; in Firefox.  Can Safari be updated 
to output the same string as Firefox?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>12050</commentid>
    <comment_count>1</comment_count>
    <who name="David Wheeler">david</who>
    <bug_when>2005-06-14 18:40:43 -0700</bug_when>
    <thetext>Actually, looking more closly at it, I realize that the problem is not the stringification of the constructor 
of an object created in a class that uses objects for namespaces. The problem is that 
Function.constructor() returns the wrong function object!

  var Foo = {};
  Foo.Bar = function () {
    this.bar = 1;
  };
  var f = new Foo.Bar();
  document.write(Function.toString.call(f.constructor));

Again, this outputs &quot;(Internal Function)&quot; because the return value of f.constructor is not the actual 
constructor function. I have no idea what function it&apos;s returning.

Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>12051</commentid>
    <comment_count>2</comment_count>
    <who name="David Wheeler">david</who>
    <bug_when>2005-06-14 18:41:41 -0700</bug_when>
    <thetext>&gt; Function.constructor() returns the wrong function object!

Uh, make that the constructor attribute of the object has the wrong object.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>12054</commentid>
    <comment_count>3</comment_count>
    <who name="David Wheeler">david</who>
    <bug_when>2005-06-14 18:53:36 -0700</bug_when>
    <thetext>Here&apos;s a simpler test case:

  var Foo = { Bar: function () {}};
  var f = new Foo.Bar();
  document.write(f.constructor == Foo.Bar);

This code outputs true in Firefox, but false in Safari. It should output true.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>12064</commentid>
    <comment_count>4</comment_count>
    <who name="Joost de Valk (AlthA)">joost</who>
    <bug_when>2005-06-14 23:23:06 -0700</bug_when>
    <thetext>I&apos;ll add the testcase in the comment below as a real testcase, please do so next time you post a bug :). And 
i will confirm it, since the behavior IS different from firefox and some will have to look in to it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>12066</commentid>
    <comment_count>5</comment_count>
      <attachid>2347</attachid>
    <who name="Joost de Valk (AlthA)">joost</who>
    <bug_when>2005-06-14 23:24:32 -0700</bug_when>
    <thetext>Created attachment 2347
testcase</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20671</commentid>
    <comment_count>6</comment_count>
      <attachid>4069</attachid>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2005-09-27 11:25:58 -0700</bug_when>
    <thetext>Created attachment 4069
Test case showing broken nameless function support.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20674</commentid>
    <comment_count>7</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2005-09-27 12:41:47 -0700</bug_when>
    <thetext>*** Bug 4042 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20681</commentid>
    <comment_count>8</comment_count>
      <attachid>4071</attachid>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2005-09-27 14:26:08 -0700</bug_when>
    <thetext>Created attachment 4071
A small patch to fix this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20682</commentid>
    <comment_count>9</comment_count>
    <who name="Maciej Stachowiak">mjs</who>
    <bug_when>2005-09-27 15:46:08 -0700</bug_when>
    <thetext>I suggested to Eric that he also test the case of the Function constructor.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20683</commentid>
    <comment_count>10</comment_count>
      <attachid>4071</attachid>
    <who name="Maciej Stachowiak">mjs</who>
    <bug_when>2005-09-27 15:57:44 -0700</bug_when>
    <thetext>Comment on attachment 4071
A small patch to fix this.

r=me

Make sure to make the test case also cover the new Function() case.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>23529</commentid>
    <comment_count>11</comment_count>
    <who name="David Wheeler">david</who>
    <bug_when>2005-11-02 08:48:01 -0800</bug_when>
    <thetext>Shouldn&apos;t the first example in the test case also evaluate to true?</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="0"
              isprivate="0"
          >
            <attachid>2347</attachid>
            <date>2005-06-14 23:24:32 -0700</date>
            <delta_ts>2005-09-27 11:25:58 -0700</delta_ts>
            <desc>testcase</desc>
            <filename>testcase-javascript-constructors.html</filename>
            <type>text/html</type>
            <size>231</size>
            <attacher name="Joost de Valk (AlthA)">joost</attacher>
            
              <data encoding="base64">PGh0bWw+CjxoZWFkPgoJPHRpdGxlPlRlc3RjYXNlIGZvciBiZyAzNTM3PC90aXRsZT4KPC9oZWFk
PgoKPGJvZHk+CjxzY3JpcHQgdHlwZT0idGV4dC9qYXZhc2NyaXB0Ij4KCXZhciBGb28gPSB7IEJh
cjogZnVuY3Rpb24gKCkge319OwogIAkJdmFyIGYgPSBuZXcgRm9vLkJhcigpOwoJCWRvY3VtZW50
LndyaXRlKGYuY29uc3RydWN0b3IgPT0gRm9vLkJhcik7Cjwvc2NyaXB0Pgo8L2JvZHk+CjwvaHRt
bD4K
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>4069</attachid>
            <date>2005-09-27 11:25:58 -0700</date>
            <delta_ts>2005-09-27 11:25:58 -0700</delta_ts>
            <desc>Test case showing broken nameless function support.</desc>
            <filename>testcase-javascript-constructors.html</filename>
            <type>text/html</type>
            <size>716</size>
            <attacher name="Eric Seidel (no email)">eric</attacher>
            
              <data encoding="base64">PGh0bWw+CjxoZWFkPgoJPHRpdGxlPlRlc3RjYXNlIGZvciBidWcgMzUzNzwvdGl0bGU+CjwvaGVh
ZD4KCjxib2R5PgpUaGlzIHRlc3QgY2FzZSBzaG93cyBob3cgaHR0cDovL2J1Z3ppbGxhLm9wZW5k
YXJ3aW4ub3JnL3Nob3dfYnVnLmNnaT9pZD0zNTM3IGZhaWxzIHRvIGR1ZSBicm9rZW4gbmFtZWxl
c3MgZnVuY3Rpb24gc3VwcG9ydC4KPGJyPjxicj4KPHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3Jp
cHQiPgoJdmFyIEZvbyA9IHsgQmFyOiBmdW5jdGlvbiAoKSB7fX07Cgl2YXIgZiA9IG5ldyBGb28u
QmFyKCk7Cglkb2N1bWVudC53cml0ZSgiZi5jb25zdHJ1Y3RvciA9PSBGb28uQmFyIDogIiArIChm
LmNvbnN0cnVjdG9yID09IEZvby5CYXIpICsgIjxicj4iKTsKCWRvY3VtZW50LndyaXRlKCJmLmNv
bnN0cnVjdG9yOiAiICsgZi5jb25zdHJ1Y3RvciArICI8YnI+Iik7CgkKCWRvY3VtZW50LndyaXRl
KCI8YnI+Iik7CgkKCWZ1bmN0aW9uIEYoKSB7fTsKCXZhciBGb28yID0geyBCYXI6IEZ9OwogIAl2
YXIgZjIgPSBuZXcgRm9vMi5CYXIoKTsKCWRvY3VtZW50LndyaXRlKCJmMi5jb25zdHJ1Y3RvciA9
PSBGb28yLkJhciA6ICIgKyAoZjIuY29uc3RydWN0b3IgPT0gRm9vMi5CYXIpICsgIjxicj4iKTsK
CWRvY3VtZW50LndyaXRlKCJmMi5jb25zdHJ1Y3RvcjogIiArIGYyLmNvbnN0cnVjdG9yICsgIjxi
cj4iKTsKPC9zY3JpcHQ+CjwvYm9keT4KPC9odG1sPgo=
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>4071</attachid>
            <date>2005-09-27 14:26:08 -0700</date>
            <delta_ts>2005-09-27 15:57:44 -0700</delta_ts>
            <desc>A small patch to fix this.</desc>
            <filename>fix.patch</filename>
            <type>text/plain</type>
            <size>845</size>
            <attacher name="Eric Seidel (no email)">eric</attacher>
            
              <data encoding="base64">SW5kZXg6IGtqcy9ub2Rlcy5jcHAKPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpSQ1MgZmlsZTogL2N2cy9yb290L0phdmFT
Y3JpcHRDb3JlL2tqcy9ub2Rlcy5jcHAsdgpyZXRyaWV2aW5nIHJldmlzaW9uIDEuODIKZGlmZiAt
cCAtdSAtcjEuODIga2pzL25vZGVzLmNwcAotLS0ga2pzL25vZGVzLmNwcAkyNCBTZXAgMjAwNSAy
MjozNDoxMyAtMDAwMAkxLjgyCisrKyBranMvbm9kZXMuY3BwCTI3IFNlcCAyMDA1IDIxOjI1OjU5
IC0wMDAwCkBAIC0yMzQ1LDcgKzIzNDUsOCBAQCBWYWx1ZUltcCAqRnVuY0V4cHJOb2RlOjpldmFs
dWF0ZShFeGVjU3RhCiAKICAgRnVuY3Rpb25JbXAgKmZpbXAgPSBuZXcgRGVjbGFyZWRGdW5jdGlv
bkltcChleGVjLCBpZGVudCwgYm9keS5nZXQoKSwgY29udGV4dC0+c2NvcGVDaGFpbigpKTsKICAg
VmFsdWVJbXAgKnJldChmaW1wKTsKLSAgVmFsdWVJbXAgKnByb3RvID0gZXhlYy0+bGV4aWNhbElu
dGVycHJldGVyKCktPmJ1aWx0aW5PYmplY3QoKS0+Y29uc3RydWN0KGV4ZWMsIExpc3Q6OmVtcHR5
KCkpOworICBPYmplY3RJbXAgKnByb3RvID0gZXhlYy0+bGV4aWNhbEludGVycHJldGVyKCktPmJ1
aWx0aW5PYmplY3QoKS0+Y29uc3RydWN0KGV4ZWMsIExpc3Q6OmVtcHR5KCkpOworICBwcm90by0+
cHV0KGV4ZWMsIGNvbnN0cnVjdG9yUHJvcGVydHlOYW1lLCByZXQsIFJlYWRPbmx5fERvbnREZWxl
dGV8RG9udEVudW0pOwogICBmaW1wLT5wdXQoZXhlYywgcHJvdG90eXBlUHJvcGVydHlOYW1lLCBw
cm90bywgSW50ZXJuYWx8RG9udERlbGV0ZSk7CiAKICAgaW50IHBsZW4gPSAwOwo=
</data>
<flag name="review"
          id="630"
          type_id="1"
          status="+"
          setter="mjs"
    />
          </attachment>
      

    </bug>

</bugzilla>