[webkit-dev] Question about Constructors in WebKit JS Bindings

Adam Barth abarth at webkit.org
Mon Jun 22 22:07:57 PDT 2009


On Mon, Jun 22, 2009 at 9:58 PM, Peter Kasting<pkasting at google.com> wrote:
> On Mon, Jun 22, 2009 at 9:53 PM, Adam Barth <abarth at webkit.org> wrote:
>> On Mon, Jun 22, 2009 at 7:04 PM, Maciej Stachowiak<mjs at apple.com> wrote:
>> > Your proposed alternative will have different behavior. It will use the
>> > lexical global object of the calling JavaScript function, instead of the
>> > global object originally associated with the Options constructor.
>>
>> Yes.  Almost everywhere you see this pattern it's incorrect.  We have
>> this bug a lot.
>
> To be clear, are you saying the original pattern, or the "simpler" one Drew
> proposes is typically the incorrect one?  (I assume the latter.)

The latter one.  The V8 binding are better about this because we have
v8::Context::GetCurrent(), which often gives you the context the JSC
bindings have to manually manage.

Here's how the two bindings relate (if you look at both bindings and wonder):

v8::Context::GetEntered() ~~ exec->dynamicGlobalObject()
v8::Context::GetCalling() ~~ exec->lexicalGlobalObject()
v8::Context::GetCurrent() ~~ ????

It might be good to add a similar "GetCurrent" concept to JSC
(although, hopefully with a better name) so we can remove all this
manual, error-prone caching / mark()ing.

Adam


More information about the webkit-dev mailing list