Drew,

quick answer:  When you use V8 you have to enter a context before
giving V8 some code to execute.  GetEntered() returns the last context
that you entered using the API.  When you call JavaScript functions,
the JavaScript engine enters the context in which that function was
defined.  When calling functions across frames, this context will be
different from the context that you entered through the API.
GetCurrent will always give you the context of the currently executing
function (the context in which the currently executing function was
declared).  GetCalling will get you the context of the function that
called the function you are currently executing.

Cheers,     -- Mads

On Thu, Jul 9, 2009 at 1:04 PM, Drew Wilson<[email protected]> wrote:
> Hi all,
> I've been poking around quite a bit recently in the WebKit JS
> bindings/constructor code, trying to make some sense of their widespread use
> of the lexicalGlobalObject() - basically, it seems like looking at the
> lexicalGlobalObject() is seldom what they actually want, because it means
> that if you call between frames you unexpectedly start pulling things from a
> different context.
> As a very simple example (bear with me, I'll get to the chrome-specific
> question in a second) - imagine that you have a page containing a child
> frame. In the parent page, you define this:
> function getImage() {
>   return new Image();
> }
> ...now down in your child frame, you have code that does this:
> var image1 = new Image();
> var image2 = parent.window.getImage();
> assert(image1.__proto__ == image2.__proto__);  // Fails in WebKit currently,
> because the Image constructor lookup uses the lexicalGlobalObject.
>
> JSC defines dynamicGlobalObject() and lexicalGlobalObject() - I suspect that
> they generally want to be using dynamicGlobalObject instead of
> lexicalGlobalObject when trying to access something from global scope. Or am
> I missing some subtlety here?
> That brings me to my Chromium/V8 question - there are 3 context-grabbing
> functions in V8: GetEntered(), GetCalling(), GetCurrent(). When is it
> appropriate to use one over the others (what are the effective differences)?
> The descriptions are kind of terse, and I'm afraid I'm missing some of the
> subtleties between "the context of the calling JavaScript code" vs "The
> context on the top of the stack" vs "The last entered context" (for example,
> I would have naively thought that the calling JavaScript code's context
> would *inherently* be the last entered one, and hence would be on the top of
> the stack, but clearly that's not true :)
> -atw
> >
>

--~--~---------~--~----~------------~-------~--~----~
Chromium Developers mailing list: [email protected] 
View archives, change email options, or unsubscribe: 
    http://groups.google.com/group/chromium-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to