Bug 94596 - [V8] Move matchesCurrentContext() from V8Proxy to ScriptController
Summary: [V8] Move matchesCurrentContext() from V8Proxy to ScriptController
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kentaro Hara
URL:
Keywords:
Depends on:
Blocks: 85330
  Show dependency treegraph
 
Reported: 2012-08-21 06:49 PDT by Kentaro Hara
Modified: 2012-08-23 04:18 PDT (History)
3 users (show)

See Also:


Attachments
Patch (8.36 KB, patch)
2012-08-21 06:52 PDT, Kentaro Hara
no flags Details | Formatted Diff | Diff
Patch (8.71 KB, patch)
2012-08-21 21:14 PDT, Kentaro Hara
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kentaro Hara 2012-08-21 06:49:43 PDT
To kill V8Proxy:

- We can move matchesCurrentContext() from V8Proxy to ScriptController.
- We can remove V8Proxy::isolatedWorldContext() since it is not used by anybody.
- We can remove V8Proxy::finishedWithEvent() since it is empty.
Comment 1 Kentaro Hara 2012-08-21 06:52:07 PDT
Created attachment 159681 [details]
Patch
Comment 2 Adam Barth 2012-08-21 08:34:36 PDT
Comment on attachment 159681 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=159681&action=review

> Source/WebCore/bindings/v8/ScriptController.cpp:392
> +bool ScriptController::matchesCurrentContext()

How is this different from v8::Context::GetCurrent() == contextForCurrentWorld() or I guess v8::Context::GetCurrent() == m_proxy->context() since the other patch hasn't landed yet?
Comment 3 Adam Barth 2012-08-21 08:35:52 PDT
Sorry to be asking all these questions, but we're getting to the really yucky functions in V8Proxy.  We can move them around without changing them, but this is a good opportunity to understand them and clean them up.
Comment 4 Kentaro Hara 2012-08-21 08:46:17 PDT
Comment on attachment 159681 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=159681&action=review

>> Source/WebCore/bindings/v8/ScriptController.cpp:392
>> +bool ScriptController::matchesCurrentContext()
> 
> How is this different from v8::Context::GetCurrent() == contextForCurrentWorld() or I guess v8::Context::GetCurrent() == m_proxy->context() since the other patch hasn't landed yet?

This is the code I wrote:) I introduced it in https://bugs.webkit.org/show_bug.cgi?id=82201 for perf optimization. Let me take a detailed look tomorrow. Thanks for review!
Comment 5 Adam Barth 2012-08-21 08:51:23 PDT
> This is the code I wrote:)

Sorry, I didn't mean to impune your code!  I just meant that it's using a pattern I introduced sometime around http://trac.webkit.org/changeset/46523 that I'm not proud of.
Comment 6 Kentaro Hara 2012-08-21 21:08:08 PDT
Comment on attachment 159681 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=159681&action=review

>>> Source/WebCore/bindings/v8/ScriptController.cpp:392
>>> +bool ScriptController::matchesCurrentContext()
>> 
>> How is this different from v8::Context::GetCurrent() == contextForCurrentWorld() or I guess v8::Context::GetCurrent() == m_proxy->context() since the other patch hasn't landed yet?
> 
> This is the code I wrote:) I introduced it in https://bugs.webkit.org/show_bug.cgi?id=82201 for perf optimization. Let me take a detailed look tomorrow. Thanks for review!

v8::Context::GetCurrent() == contextForCurrentWorld() works correctly, but it will be slow because contextForCurrentWorld() creates a new local context.

As discussed in bug 82201, this is a hot call path of creating DOM object constructor. So it might make sense to leave the current matchesCurrentContext() as is. I'll add a comment that explains this.
Comment 7 Kentaro Hara 2012-08-21 21:14:32 PDT
Created attachment 159855 [details]
Patch
Comment 8 Adam Barth 2012-08-22 11:59:30 PDT
Comment on attachment 159855 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=159855&action=review

> Source/WebCore/bindings/v8/ScriptController.cpp:397
> +    // This method is equivalent to 'return v8::Context::GetCurrent() == contextForCurrentWorld()',
> +    // but is written without using contextForCurrentWorld().
> +    // Given that this method is used by a hot call path of DOM object constructor,
> +    // we want to avoid the overhead of contextForCurrentWorld() creating Local<Context> every time.

Ok.  One option is to split contextForCurrentWorld() into two pieces: a private piece that returns the underlying persistent handle and a second pieces that returns a new local handle to the object.  This function could then share the first piece with currentWorldContext.  We don't need to do that in this patch if you'd rather get this one landed first.

nit: contextForCurrentWorld -> currentWorldContext

> Source/WebCore/bindings/v8/ScriptController.cpp:407
> +    return context == context->GetCurrent();

Can we change context->GetCurrent() to v8::Context::GetCurrent()?  (It's a static function right?)
Comment 9 Kentaro Hara 2012-08-22 17:30:52 PDT
(In reply to comment #8)
> Ok.  One option is to split contextForCurrentWorld() into two pieces: a private piece that returns the underlying persistent handle and a second pieces that returns a new local handle to the object.  This function could then share the first piece with currentWorldContext.  We don't need to do that in this patch if you'd rather get this one landed first.

OK, let me fix it in a later patch.

> nit: contextForCurrentWorld -> currentWorldContext

Done.

> > Source/WebCore/bindings/v8/ScriptController.cpp:407
> > +    return context == context->GetCurrent();
> 
> Can we change context->GetCurrent() to v8::Context::GetCurrent()?  (It's a static function right?)

Done.
Comment 10 Kentaro Hara 2012-08-22 17:38:08 PDT
Committed r126370: <http://trac.webkit.org/changeset/126370>