[V8] Move mainWorldContext() from V8Proxy to ScriptController
authorharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Aug 2012 22:42:35 +0000 (22:42 +0000)
committerharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Aug 2012 22:42:35 +0000 (22:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=94453

Reviewed by Adam Barth.

This patch moves mainWorldContext() from V8Proxy to ScriptController.
In addition, this patch removes dependency on V8Proxy from WorldContextHandle.

No tests. No change in behavior.

Source/WebCore:

* bindings/v8/DOMTransaction.cpp:
(WebCore::DOMTransaction::callFunction):
* bindings/v8/NPV8Object.cpp:
(WebCore::toV8Context):
* bindings/v8/ScriptController.cpp:
(WebCore::ScriptController::evaluate):
(WebCore::ScriptController::mainWorldContext):
(WebCore):
(WebCore::ScriptController::bindToWindowObject):
(WebCore::createScriptObject):
(WebCore::ScriptController::createScriptObjectForPluginElement):
* bindings/v8/ScriptController.h:
(ScriptController):
* bindings/v8/ScriptState.cpp:
(WebCore::mainWorldScriptState):
* bindings/v8/V8LazyEventListener.cpp:
(WebCore::V8LazyEventListener::prepareListenerObject):
* bindings/v8/V8Proxy.cpp:
(WebCore::V8Proxy::context):
(WebCore::toV8Context):
* bindings/v8/V8Proxy.h:
(V8Proxy):
* bindings/v8/WorldContextHandle.cpp:
(WebCore::WorldContextHandle::adjustedContext):
* bindings/v8/WorldContextHandle.h:
(WebCore):
(WorldContextHandle):

Source/WebKit/chromium:

* src/WebFrameImpl.cpp:
(WebKit::WebFrameImpl::mainWorldScriptContext):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@126083 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/v8/DOMTransaction.cpp
Source/WebCore/bindings/v8/NPV8Object.cpp
Source/WebCore/bindings/v8/ScriptController.cpp
Source/WebCore/bindings/v8/ScriptController.h
Source/WebCore/bindings/v8/ScriptState.cpp
Source/WebCore/bindings/v8/V8LazyEventListener.cpp
Source/WebCore/bindings/v8/V8Proxy.cpp
Source/WebCore/bindings/v8/V8Proxy.h
Source/WebCore/bindings/v8/WorldContextHandle.cpp
Source/WebCore/bindings/v8/WorldContextHandle.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebFrameImpl.cpp

index 20ea3d3..0e0d971 100644 (file)
@@ -1,3 +1,43 @@
+2012-08-20  Kentaro Hara  <haraken@chromium.org>
+
+        [V8] Move mainWorldContext() from V8Proxy to ScriptController
+        https://bugs.webkit.org/show_bug.cgi?id=94453
+
+        Reviewed by Adam Barth.
+
+        This patch moves mainWorldContext() from V8Proxy to ScriptController.
+        In addition, this patch removes dependency on V8Proxy from WorldContextHandle.
+
+        No tests. No change in behavior.
+
+        * bindings/v8/DOMTransaction.cpp:
+        (WebCore::DOMTransaction::callFunction):
+        * bindings/v8/NPV8Object.cpp:
+        (WebCore::toV8Context):
+        * bindings/v8/ScriptController.cpp:
+        (WebCore::ScriptController::evaluate):
+        (WebCore::ScriptController::mainWorldContext):
+        (WebCore):
+        (WebCore::ScriptController::bindToWindowObject):
+        (WebCore::createScriptObject):
+        (WebCore::ScriptController::createScriptObjectForPluginElement):
+        * bindings/v8/ScriptController.h:
+        (ScriptController):
+        * bindings/v8/ScriptState.cpp:
+        (WebCore::mainWorldScriptState):
+        * bindings/v8/V8LazyEventListener.cpp:
+        (WebCore::V8LazyEventListener::prepareListenerObject):
+        * bindings/v8/V8Proxy.cpp:
+        (WebCore::V8Proxy::context):
+        (WebCore::toV8Context):
+        * bindings/v8/V8Proxy.h:
+        (V8Proxy):
+        * bindings/v8/WorldContextHandle.cpp:
+        (WebCore::WorldContextHandle::adjustedContext):
+        * bindings/v8/WorldContextHandle.h:
+        (WebCore):
+        (WorldContextHandle):
+
 2012-08-20  Adam Klein  <adamk@chromium.org>
 
         Remove redundant TOUCH_LISTENER event type
index 7b88df9..08919c2 100644 (file)
@@ -105,7 +105,7 @@ void DOMTransaction::callFunction(const char* propertyName)
     if (function.IsEmpty())
         return;
 
-    v8::Local<v8::Context> v8Context = m_worldContext.adjustedContext(frame->script()->proxy());
+    v8::Local<v8::Context> v8Context = m_worldContext.adjustedContext(frame->script());
     if (v8Context.IsEmpty())
         return;
 
index b97991c..af7d99e 100644 (file)
@@ -66,7 +66,7 @@ static v8::Local<v8::Context> toV8Context(NPP npp, NPObject* npObject)
     DOMWindow* window = object->rootObject;
     if (!window || !window->isCurrentlyDisplayedInFrame())
         return v8::Local<v8::Context>();
-    return V8Proxy::mainWorldContext(object->rootObject->frame());
+    return ScriptController::mainWorldContext(object->rootObject->frame());
 }
 
 static V8Proxy* toV8Proxy(NPObject* npObject)
index 606cdc3..6e84744 100644 (file)
@@ -256,7 +256,7 @@ ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode)
     m_sourceURL = &sourceURL;
 
     v8::HandleScope handleScope;
-    v8::Handle<v8::Context> v8Context = V8Proxy::mainWorldContext(m_proxy->frame());
+    v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_proxy->frame());
     if (v8Context.IsEmpty())
         return ScriptValue();
 
@@ -287,12 +287,26 @@ void ScriptController::finishedWithEvent(Event* event)
     m_proxy->finishedWithEvent(event);
 }
 
+v8::Local<v8::Context> ScriptController::mainWorldContext()
+{
+    windowShell()->initContextIfNeeded();
+    return v8::Local<v8::Context>::New(windowShell()->context());
+}
+
+v8::Local<v8::Context> ScriptController::mainWorldContext(Frame* frame)
+{
+    if (!frame)
+        return v8::Local<v8::Context>();
+
+    return frame->script()->mainWorldContext();
+}
+
 // Create a V8 object with an interceptor of NPObjectPropertyGetter.
 void ScriptController::bindToWindowObject(Frame* frame, const String& key, NPObject* object)
 {
     v8::HandleScope handleScope;
 
-    v8::Handle<v8::Context> v8Context = V8Proxy::mainWorldContext(frame);
+    v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(frame);
     if (v8Context.IsEmpty())
         return;
 
@@ -449,7 +463,7 @@ static NPObject* createNoScriptObject()
 static NPObject* createScriptObject(Frame* frame)
 {
     v8::HandleScope handleScope;
-    v8::Handle<v8::Context> v8Context = V8Proxy::mainWorldContext(frame);
+    v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(frame);
     if (v8Context.IsEmpty())
         return createNoScriptObject();
 
@@ -489,7 +503,7 @@ NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement
         return createNoScriptObject();
 
     v8::HandleScope handleScope;
-    v8::Handle<v8::Context> v8Context = V8Proxy::mainWorldContext(m_frame);
+    v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_frame);
     if (v8Context.IsEmpty())
         return createNoScriptObject();
     v8::Context::Scope scope(v8Context);
index fe7b763..4d02290 100644 (file)
@@ -158,6 +158,11 @@ public:
     // V8Proxy::retrieveFrameForEnteredContext() for more information.
     static Frame* retrieveFrameForCurrentContext();
 
+    // Returns V8 Context of a frame. If none exists, creates
+    // a new context. It is potentially slow and consumes memory.
+    static v8::Local<v8::Context> mainWorldContext(Frame*);
+    v8::Local<v8::Context> mainWorldContext();
+
     // Pass command-line flags to the JS engine.
     static void setFlags(const char* string, int length);
 
index e21c6ca..a975b14 100644 (file)
@@ -145,8 +145,7 @@ void setEvalEnabled(ScriptState* scriptState, bool enabled)
 ScriptState* mainWorldScriptState(Frame* frame)
 {
     v8::HandleScope handleScope;
-    V8Proxy* proxy = frame->script()->proxy();
-    return ScriptState::forContext(proxy->mainWorldContext());
+    return ScriptState::forContext(frame->script()->mainWorldContext());
 }
 
 ScriptState* scriptStateFromNode(DOMWrapperWorld*, Node* node)
index fdb9cd5..f107146 100644 (file)
@@ -124,7 +124,7 @@ void V8LazyEventListener::prepareListenerObject(ScriptExecutionContext* context)
     if (!frame->script()->canExecuteScripts(NotAboutToExecuteScript))
         return;
     // Use the outer scope to hold context.
-    v8::Local<v8::Context> v8Context = worldContext().adjustedContext(frame->script()->proxy());
+    v8::Local<v8::Context> v8Context = worldContext().adjustedContext(frame->script());
     // Bail out if we cannot get the context.
     if (v8Context.IsEmpty())
         return;
index 38c7bb4..62a653f 100644 (file)
@@ -374,7 +374,7 @@ void V8Proxy::clearForNavigation()
 
 v8::Local<v8::Context> V8Proxy::context(Frame* frame)
 {
-    v8::Local<v8::Context> context = V8Proxy::mainWorldContext(frame);
+    v8::Local<v8::Context> context = ScriptController::mainWorldContext(frame);
     if (context.IsEmpty())
         return v8::Local<v8::Context>();
 
@@ -395,13 +395,7 @@ v8::Local<v8::Context> V8Proxy::context()
             return v8::Local<v8::Context>();
         return v8::Local<v8::Context>::New(context->get());
     }
-    return mainWorldContext();
-}
-
-v8::Local<v8::Context> V8Proxy::mainWorldContext()
-{
-    windowShell()->initContextIfNeeded();
-    return v8::Local<v8::Context>::New(windowShell()->context());
+    return frame()->script()->mainWorldContext();
 }
 
 v8::Local<v8::Context> V8Proxy::isolatedWorldContext(int worldId)
@@ -426,19 +420,11 @@ bool V8Proxy::matchesCurrentContext()
     return context == context->GetCurrent();
 }
 
-v8::Local<v8::Context> V8Proxy::mainWorldContext(Frame* frame)
-{
-    if (!frame)
-        return v8::Local<v8::Context>();
-
-    return frame->script()->proxy()->mainWorldContext();
-}
-
 v8::Local<v8::Context> toV8Context(ScriptExecutionContext* context, const WorldContextHandle& worldContext)
 {
     if (context->isDocument()) {
         if (Frame* frame = static_cast<Document*>(context)->frame())
-            return worldContext.adjustedContext(frame->script()->proxy());
+            return worldContext.adjustedContext(frame->script());
 #if ENABLE(WORKERS)
     } else if (context->isWorkerContext()) {
         if (WorkerContextExecutionProxy* proxy = static_cast<WorkerContext*>(context)->script()->proxy())
index 425888e..fefdd6c 100644 (file)
@@ -118,7 +118,6 @@ namespace WebCore {
         // Returns V8 Context of a frame. If none exists, creates
         // a new context. It is potentially slow and consumes memory.
         static v8::Local<v8::Context> context(Frame*);
-        static v8::Local<v8::Context> mainWorldContext(Frame*);
 
         // If the current context causes out of memory, JavaScript setting
         // is disabled and it returns true.
@@ -127,7 +126,6 @@ namespace WebCore {
         static v8::Handle<v8::Script> compileScript(v8::Handle<v8::String> code, const String& fileName, const TextPosition& scriptStartPosition, v8::ScriptData* = 0);
 
         v8::Local<v8::Context> context();
-        v8::Local<v8::Context> mainWorldContext();
         v8::Local<v8::Context> isolatedWorldContext(int worldId);
         bool matchesCurrentContext();
 
index 8456a3e..488f3b5 100644 (file)
@@ -31,8 +31,8 @@
 #include "config.h"
 #include "WorldContextHandle.h"
 
+#include "ScriptController.h"
 #include "V8IsolatedContext.h"
-#include "V8Proxy.h"
 
 namespace WebCore {
 
@@ -46,10 +46,10 @@ WorldContextHandle::WorldContextHandle(WorldToUse worldToUse)
         m_context = context->sharedContext();
 }
 
-v8::Local<v8::Context> WorldContextHandle::adjustedContext(V8Proxy* proxy) const
+v8::Local<v8::Context> WorldContextHandle::adjustedContext(ScriptController* script) const
 {
     if (m_worldToUse == UseMainWorld || !m_context || m_context->get().IsEmpty())
-        return proxy->mainWorldContext();
+        return script->mainWorldContext();
 
     return v8::Local<v8::Context>::New(m_context->get());
 }
index ad0983e..5574742 100644 (file)
 
 namespace WebCore {
 
-class V8Proxy;
+class ScriptController;
 
 enum WorldToUse { UseMainWorld, UseCurrentWorld };
 
 class WorldContextHandle {
 public:
     WorldContextHandle(WorldToUse);
-    v8::Local<v8::Context> adjustedContext(V8Proxy*) const;
+    v8::Local<v8::Context> adjustedContext(ScriptController*) const;
 
 private:
     WorldToUse m_worldToUse;
index 9a6478b..ac91b37 100644 (file)
@@ -1,3 +1,18 @@
+2012-08-20  Kentaro Hara  <haraken@chromium.org>
+
+        [V8] Move mainWorldContext() from V8Proxy to ScriptController
+        https://bugs.webkit.org/show_bug.cgi?id=94453
+
+        Reviewed by Adam Barth.
+
+        This patch moves mainWorldContext() from V8Proxy to ScriptController.
+        In addition, this patch removes dependency on V8Proxy from WorldContextHandle.
+
+        No tests. No change in behavior.
+
+        * src/WebFrameImpl.cpp:
+        (WebKit::WebFrameImpl::mainWorldScriptContext):
+
 2012-08-20  Adam Klein  <adamk@chromium.org>
 
         Remove redundant TOUCH_LISTENER event type
index c6c2811..d3923e6 100644 (file)
@@ -960,7 +960,7 @@ v8::Local<v8::Context> WebFrameImpl::mainWorldScriptContext() const
     if (!m_frame)
         return v8::Local<v8::Context>();
 
-    return V8Proxy::mainWorldContext(m_frame);
+    return ScriptController::mainWorldContext(m_frame);
 }
 
 v8::Handle<v8::Value> WebFrameImpl::createFileSystem(WebFileSystem::Type type,