Diff
Modified: trunk/Source/WebCore/ChangeLog (127105 => 127106)
--- trunk/Source/WebCore/ChangeLog 2012-08-30 06:21:03 UTC (rev 127105)
+++ trunk/Source/WebCore/ChangeLog 2012-08-30 06:24:37 UTC (rev 127106)
@@ -1,3 +1,31 @@
+2012-08-29 Adam Barth <[email protected]>
+
+ [V8] ScriptController::matchesCurrentContext duplicates code from ScriptController::currentWorldContext
+ https://bugs.webkit.org/show_bug.cgi?id=95156
+
+ Reviewed by Eric Seidel.
+
+ matchesCurrentContext duplicated code from currentWorldContext in order
+ to avoid creating a new v8::Local handle in the (common) case that
+ we're already in the right context. This patch just exposes an accessor
+ for the underlying handle so that the bindings code can do this work
+ itself.
+
+ * bindings/scripts/CodeGeneratorV8.pm:
+ (GenerateToV8Converters):
+ * bindings/scripts/test/V8/V8TestActiveDOMObject.cpp:
+ (WebCore::V8TestActiveDOMObject::wrapSlow):
+ * bindings/scripts/test/V8/V8TestNode.cpp:
+ (WebCore::V8TestNode::wrapSlow):
+ * bindings/v8/ScriptController.cpp:
+ (WebCore::ScriptController::unsafeHandleToCurrentWorldContext):
+ (WebCore):
+ (WebCore::ScriptController::currentWorldContext):
+ * bindings/v8/ScriptController.h:
+ (ScriptController):
+ * bindings/v8/V8DOMWindowShell.h:
+ (WebCore::V8DOMWindowShell::context):
+
2012-08-29 Nat Duca <[email protected]>
[chromium] setNeedsAnimate should not cause commitRequested to become true
Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm (127105 => 127106)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm 2012-08-30 06:21:03 UTC (rev 127105)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm 2012-08-30 06:24:37 UTC (rev 127106)
@@ -3399,12 +3399,15 @@
// Enter the node's context and create the wrapper in that context.
v8::Handle<v8::Context> context;
- if (frame && !frame->script()->matchesCurrentContext()) {
- // For performance, we enter the context only if the currently running context
- // is different from the context that we are about to enter.
- context = frame->script()->currentWorldContext();
- if (!context.IsEmpty())
- context->Enter();
+ if (frame) {
+ v8::Handle<v8::Context> underlyingHandle = frame->script()->unsafeHandleToCurrentWorldContext();
+ if (v8::Context::GetCurrent() != underlyingHandle) {
+ // For performance, we enter the context only if the currently running context
+ // is different from the context that we are about to enter.
+ context = v8::Local<v8::Context>::New(underlyingHandle);
+ if (!context.IsEmpty())
+ context->Enter();
+ }
}
END
}
Modified: trunk/Source/WebCore/bindings/scripts/test/V8/V8TestActiveDOMObject.cpp (127105 => 127106)
--- trunk/Source/WebCore/bindings/scripts/test/V8/V8TestActiveDOMObject.cpp 2012-08-30 06:21:03 UTC (rev 127105)
+++ trunk/Source/WebCore/bindings/scripts/test/V8/V8TestActiveDOMObject.cpp 2012-08-30 06:24:37 UTC (rev 127106)
@@ -187,12 +187,15 @@
// Enter the node's context and create the wrapper in that context.
v8::Handle<v8::Context> context;
- if (frame && !frame->script()->matchesCurrentContext()) {
- // For performance, we enter the context only if the currently running context
- // is different from the context that we are about to enter.
- context = frame->script()->currentWorldContext();
- if (!context.IsEmpty())
- context->Enter();
+ if (frame) {
+ v8::Handle<v8::Context> underlyingHandle = frame->script()->unsafeHandleToCurrentWorldContext();
+ if (v8::Context::GetCurrent() != underlyingHandle) {
+ // For performance, we enter the context only if the currently running context
+ // is different from the context that we are about to enter.
+ context = v8::Local<v8::Context>::New(underlyingHandle);
+ if (!context.IsEmpty())
+ context->Enter();
+ }
}
wrapper = V8DOMWrapper::instantiateV8Object(frame, &info, impl.get());
// Exit the node's context if it was entered.
Modified: trunk/Source/WebCore/bindings/scripts/test/V8/V8TestNode.cpp (127105 => 127106)
--- trunk/Source/WebCore/bindings/scripts/test/V8/V8TestNode.cpp 2012-08-30 06:21:03 UTC (rev 127105)
+++ trunk/Source/WebCore/bindings/scripts/test/V8/V8TestNode.cpp 2012-08-30 06:24:37 UTC (rev 127106)
@@ -117,12 +117,15 @@
// Enter the node's context and create the wrapper in that context.
v8::Handle<v8::Context> context;
- if (frame && !frame->script()->matchesCurrentContext()) {
- // For performance, we enter the context only if the currently running context
- // is different from the context that we are about to enter.
- context = frame->script()->currentWorldContext();
- if (!context.IsEmpty())
- context->Enter();
+ if (frame) {
+ v8::Handle<v8::Context> underlyingHandle = frame->script()->unsafeHandleToCurrentWorldContext();
+ if (v8::Context::GetCurrent() != underlyingHandle) {
+ // For performance, we enter the context only if the currently running context
+ // is different from the context that we are about to enter.
+ context = v8::Local<v8::Context>::New(underlyingHandle);
+ if (!context.IsEmpty())
+ context->Enter();
+ }
}
wrapper = V8DOMWrapper::instantiateV8Object(frame, &info, impl.get());
// Exit the node's context if it was entered.
Modified: trunk/Source/WebCore/bindings/v8/ScriptController.cpp (127105 => 127106)
--- trunk/Source/WebCore/bindings/v8/ScriptController.cpp 2012-08-30 06:21:03 UTC (rev 127105)
+++ trunk/Source/WebCore/bindings/v8/ScriptController.cpp 2012-08-30 06:24:37 UTC (rev 127106)
@@ -411,17 +411,23 @@
{
}
-v8::Local<v8::Context> ScriptController::currentWorldContext()
+v8::Persistent<v8::Context> ScriptController::unsafeHandleToCurrentWorldContext()
{
if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered()) {
RefPtr<SharedPersistent<v8::Context> > context = isolatedContext->sharedContext();
if (m_frame != toFrameIfNotDetached(context->get()))
- return v8::Local<v8::Context>();
- return v8::Local<v8::Context>::New(context->get());
+ return v8::Persistent<v8::Context>();
+ return context->get();
}
- return mainWorldContext();
+ windowShell()->initializeIfNeeded();
+ return windowShell()->context();
}
+v8::Local<v8::Context> ScriptController::currentWorldContext()
+{
+ return v8::Local<v8::Context>::New(unsafeHandleToCurrentWorldContext());
+}
+
v8::Local<v8::Context> ScriptController::mainWorldContext()
{
windowShell()->initializeIfNeeded();
@@ -436,24 +442,6 @@
return frame->script()->mainWorldContext();
}
-bool ScriptController::matchesCurrentContext()
-{
- // 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.
- v8::Handle<v8::Context> context;
- if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered()) {
- context = isolatedContext->sharedContext()->get();
- if (m_frame != toFrameIfNotDetached(context))
- return false;
- } else {
- windowShell()->initializeIfNeeded();
- context = windowShell()->context();
- }
- return context == v8::Context::GetCurrent();
-}
-
// Create a V8 object with an interceptor of NPObjectPropertyGetter.
void ScriptController::bindToWindowObject(Frame* frame, const String& key, NPObject* object)
{
Modified: trunk/Source/WebCore/bindings/v8/ScriptController.h (127105 => 127106)
--- trunk/Source/WebCore/bindings/v8/ScriptController.h 2012-08-30 06:21:03 UTC (rev 127105)
+++ trunk/Source/WebCore/bindings/v8/ScriptController.h 2012-08-30 06:24:37 UTC (rev 127106)
@@ -172,7 +172,8 @@
v8::Local<v8::Context> mainWorldContext();
v8::Local<v8::Context> currentWorldContext();
- bool matchesCurrentContext();
+ // WARNING! The handle returned by this function might be Disposed() when _javascript_ is executed.
+ v8::Persistent<v8::Context> unsafeHandleToCurrentWorldContext();
// Pass command-line flags to the JS engine.
static void setFlags(const char* string, int length);
Modified: trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h (127105 => 127106)
--- trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h 2012-08-30 06:21:03 UTC (rev 127105)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h 2012-08-30 06:24:37 UTC (rev 127106)
@@ -53,7 +53,7 @@
public:
static PassRefPtr<V8DOMWindowShell> create(Frame*);
- v8::Handle<v8::Context> context() const { return m_context.get(); }
+ v8::Persistent<v8::Context> context() const { return m_context.get(); }
// Update document object of the frame.
void updateDocument();