[webkit-dev] Question about Constructors in WebKit JS Bindings
atwilson at google.com
Tue Jul 7 18:29:31 PDT 2009
Interesting - I ran some tests on both current WebKit and Firefox.
Firefox has a couple of interesting properties. For example this code:
Worker.prototype.foo = 3;
log("Worker.prototype.foo = " + Worker.prototype.foo);
var worker = new Worker("foobar.js");
log("worker.foo = " + worker.foo);
Worker.prototype.foo = 3
worker.foo = undefined
in Firefox, while in Safari it yields worker.foo = 3 as expected.
Along those same lines:
new Worker().__proto__ == Worker.prototype
yields true on Safari, but false on Firefox, which seems broken to me.
This is all within the same page (no frames). I've also verified that new
parent.window.Worker().__proto__ yields a different object than invoking new
window.Worker().__proto__ from the parent page context. So they don't seem
to be doing the right thing wrt prototype chains either.
As expected, WebKit is clearly broken with frames, as parent.window.Worker
does not even yield the same host object that invoking "window.Worker"
yields from the parent page context (not surprising, since we're looking at
lexicalGlobalObject() when we shouldn't be).
On Tue, Jul 7, 2009 at 5:33 PM, Drew Wilson <atwilson at google.com> wrote:
> On Tue, Jul 7, 2009 at 5:25 PM, Adam Barth <abarth at webkit.org> wrote:
>> I'd have to look at the code a bit more to know whether this is
>> correct. Where does |globalObject| come from?
> It comes from the JSDOMWindow object where that constructor is exposed.
> Case in point:
> #if ENABLE(CHANNEL_MESSAGING)
> JSValue JSDOMWindow::messageChannel(ExecState* exec) const
> return getDOMConstructor<JSMessageChannelConstructor>(exec, *this*);
> So, when you first access someWindow.MessageChannel it should create a
> JSMessageChannelConstructor whose prototype property is derived from
> someWindow, then cache it in someWindow.
> I'll run some tests as you suggest.
>> For an added bonus, you should test what happens if you transplant the
>> constructor from one window to another. The constructor should keep
>> its original prototype chain.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the webkit-dev