[webkit-dev] Question about Constructors in WebKit JS Bindings
Adam Barth
abarth at webkit.org
Tue Jul 7 17:25:02 PDT 2009
I think it's quite likely that all the constructors are wrong. If
you're in doubt, you can test Firefox and IE to see how they behave.
On Tue, Jul 7, 2009 at 4:45 PM, Drew Wilson<atwilson at google.com> wrote:
> So it seems like we should never reference lexicalGlobalObject in our
> constructor/prototype creation code at all.
This is likely to be correct. You want these to behave as if they
were native JavaScript constructors defined by the window which they
are originally a member. (This is different than primitives, which
get boxed according to the lexicalGlobalObject.)
> if I invoke "new
> otherWindow.MessageChannel()", I should get a MessageChannel object whose
> prototype chain == otherWindow.MessageChannel.prototype.
Yes. Also, otherWindow.MessageChannel.prototype should eventually
lead to otherWindow.Object.prototype.
> So the constructor
> should look like this instead:
> JSMessageChannelConstructor::JSMessageChannelConstructor(ExecState* exec,
> JSDOMGlobalObject* globalObject)
> :
> DOMObject(JSMessageChannelConstructor::createStructure(globalObject->objectPrototype()))
> , m_globalObject(globalObject)
> {
> putDirect(exec->propertyNames().prototype,
> JSMessageChannelPrototype::self(exec, globalObject), None);
> }
I'd have to look at the code a bit more to know whether this is
correct. Where does |globalObject| come from?
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.
Adam
More information about the webkit-dev
mailing list