Summary: | object.constructor returns incorrect object | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | David Wheeler <david> | ||||||||
Component: | JavaScriptCore | Assignee: | Eric Seidel (no email) <eric> | ||||||||
Status: | RESOLVED FIXED | ||||||||||
Severity: | Normal | CC: | paul, vicki | ||||||||
Priority: | P2 | ||||||||||
Version: | 412 | ||||||||||
Hardware: | Mac | ||||||||||
OS: | OS X 10.4 | ||||||||||
Attachments: |
|
Description
David Wheeler
2005-06-14 18:33:03 PDT
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 "(Internal Function)" because the return value of f.constructor is not the actual constructor function. I have no idea what function it's returning. Thanks! > Function.constructor() returns the wrong function object!
Uh, make that the constructor attribute of the object has the wrong object.
Here'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. I'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. Created attachment 2347 [details]
testcase
Created attachment 4069 [details]
Test case showing broken nameless function support.
*** Bug 4042 has been marked as a duplicate of this bug. *** Created attachment 4071 [details]
A small patch to fix this.
I suggested to Eric that he also test the case of the Function constructor. Comment on attachment 4071 [details]
A small patch to fix this.
r=me
Make sure to make the test case also cover the new Function() case.
Shouldn't the first example in the test case also evaluate to true? |