[V8] Move instrumentedCallFunction() from V8Proxy to ScriptController
authorharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Aug 2012 00:52:47 +0000 (00:52 +0000)
committerharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Aug 2012 00:52:47 +0000 (00:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=94456

Reviewed by Adam Barth.

To kill V8Proxy, this patch moves instrumentedCallFunction() from V8Proxy
to ScriptController. Also this patch renames instrumentedCallFunction()
to callFunctionWithInstrumentation(), for consistency with callFunction().

No tests. No change in behavior.

Source/WebCore:

* bindings/v8/ScriptController.cpp:
(WebCore::ScriptController::callFunction):
(WebCore):
(WebCore::handleMaxRecursionDepthExceeded):
(WebCore::resourceInfo):
(WebCore::resourceString):
(WebCore::ScriptController::callFunctionWithInstrumentation):
* bindings/v8/ScriptController.h:
(ScriptController):
* bindings/v8/ScriptFunctionCall.cpp:
(WebCore::ScriptCallback::call):
* bindings/v8/V8Callback.cpp:
(WebCore::invokeCallback):
* bindings/v8/V8NodeFilterCondition.cpp:
(WebCore::V8NodeFilterCondition::acceptNode):
* bindings/v8/V8Proxy.cpp:
(WebCore):
* bindings/v8/V8Proxy.h:
(V8Proxy):
* bindings/v8/V8WindowErrorHandler.cpp:
(WebCore::V8WindowErrorHandler::callListenerFunction):
* bindings/v8/custom/V8CustomXPathNSResolver.cpp:
(WebCore::V8CustomXPathNSResolver::lookupNamespaceURI):

Source/WebKit/chromium:

* src/WebDevToolsFrontendImpl.cpp:
(WebKit::WebDevToolsFrontendImpl::dispatchOnInspectorFrontend):

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

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/v8/ScriptController.cpp
Source/WebCore/bindings/v8/ScriptController.h
Source/WebCore/bindings/v8/ScriptFunctionCall.cpp
Source/WebCore/bindings/v8/V8Callback.cpp
Source/WebCore/bindings/v8/V8NodeFilterCondition.cpp
Source/WebCore/bindings/v8/V8Proxy.cpp
Source/WebCore/bindings/v8/V8Proxy.h
Source/WebCore/bindings/v8/V8WindowErrorHandler.cpp
Source/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebDevToolsFrontendImpl.cpp

index a7718e4..7aa28bc 100644 (file)
@@ -1,3 +1,40 @@
+2012-08-20  Kentaro Hara  <haraken@chromium.org>
+
+        [V8] Move instrumentedCallFunction() from V8Proxy to ScriptController
+        https://bugs.webkit.org/show_bug.cgi?id=94456
+
+        Reviewed by Adam Barth.
+
+        To kill V8Proxy, this patch moves instrumentedCallFunction() from V8Proxy
+        to ScriptController. Also this patch renames instrumentedCallFunction()
+        to callFunctionWithInstrumentation(), for consistency with callFunction().
+
+        No tests. No change in behavior.
+
+        * bindings/v8/ScriptController.cpp:
+        (WebCore::ScriptController::callFunction):
+        (WebCore):
+        (WebCore::handleMaxRecursionDepthExceeded):
+        (WebCore::resourceInfo):
+        (WebCore::resourceString):
+        (WebCore::ScriptController::callFunctionWithInstrumentation):
+        * bindings/v8/ScriptController.h:
+        (ScriptController):
+        * bindings/v8/ScriptFunctionCall.cpp:
+        (WebCore::ScriptCallback::call):
+        * bindings/v8/V8Callback.cpp:
+        (WebCore::invokeCallback):
+        * bindings/v8/V8NodeFilterCondition.cpp:
+        (WebCore::V8NodeFilterCondition::acceptNode):
+        * bindings/v8/V8Proxy.cpp:
+        (WebCore):
+        * bindings/v8/V8Proxy.h:
+        (V8Proxy):
+        * bindings/v8/V8WindowErrorHandler.cpp:
+        (WebCore::V8WindowErrorHandler::callListenerFunction):
+        * bindings/v8/custom/V8CustomXPathNSResolver.cpp:
+        (WebCore::V8CustomXPathNSResolver::lookupNamespaceURI):
+
 2012-08-20  Elliott Sprehn  <esprehn@chromium.org>
 
         Never notify of insertedIntoTree during document destruction.
index 1c8fcb6..1a4f9f6 100644 (file)
 #include "ScriptController.h"
 
 #include "BindingState.h"
-#include "Document.h"
-#include "ScriptCallStack.h"
-#include "ScriptCallStackFactory.h"
-#include "ScriptableDocumentParser.h"
 #include "DOMWindow.h"
+#include "Document.h"
 #include "Event.h"
 #include "EventListener.h"
 #include "EventNames.h"
 #include "Frame.h"
 #include "FrameLoaderClient.h"
+#include "InspectorInstrumentation.h"
+#include "NPObjectWrapper.h"
+#include "NPV8Object.h"
 #include "Node.h"
 #include "NotImplemented.h"
-#include "NPObjectWrapper.h"
 #include "npruntime_impl.h"
 #include "npruntime_priv.h"
-#include "NPV8Object.h"
 #include "PlatformSupport.h"
+#include "ScriptCallStack.h"
+#include "ScriptCallStackFactory.h"
 #include "ScriptSourceCode.h"
+#include "ScriptableDocumentParser.h"
 #include "SecurityOrigin.h"
 #include "Settings.h"
 #include "UserGestureIndicator.h"
 #include <wtf/StdLibExtras.h>
 #include <wtf/StringExtras.h>
 #include <wtf/text/CString.h>
+#include <wtf/text/StringBuilder.h>
+
+#if PLATFORM(CHROMIUM)
+#include "TraceEvent.h"
+#endif
 
 namespace WebCore {
 
@@ -189,7 +195,65 @@ v8::Local<v8::Value> ScriptController::callFunction(v8::Handle<v8::Function> fun
 {
     // Keep Frame (and therefore ScriptController and V8Proxy) alive.
     RefPtr<Frame> protect(m_frame);
-    return V8Proxy::instrumentedCallFunction(m_frame, function, receiver, argc, args);
+    return ScriptController::callFunctionWithInstrumentation(m_frame ? m_frame->document() : 0, function, receiver, argc, args);
+}
+
+static v8::Local<v8::Value> handleMaxRecursionDepthExceeded()
+{
+    throwError(RangeError, "Maximum call stack size exceeded.");
+    return v8::Local<v8::Value>();
+}
+
+static inline void resourceInfo(const v8::Handle<v8::Function> function, String& resourceName, int& lineNumber)
+{
+    v8::ScriptOrigin origin = function->GetScriptOrigin();
+    if (origin.ResourceName().IsEmpty()) {
+        resourceName = "undefined";
+        lineNumber = 1;
+    } else {
+        resourceName = toWebCoreString(origin.ResourceName());
+        lineNumber = function->GetScriptLineNumber() + 1;
+    }
+}
+
+static inline String resourceString(const v8::Handle<v8::Function> function)
+{
+    String resourceName;
+    int lineNumber;
+    resourceInfo(function, resourceName, lineNumber);
+
+    StringBuilder builder;
+    builder.append(resourceName);
+    builder.append(':');
+    builder.append(String::number(lineNumber));
+    return builder.toString();
+}
+
+v8::Local<v8::Value> ScriptController::callFunctionWithInstrumentation(ScriptExecutionContext* context, v8::Handle<v8::Function> function, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[])
+{
+    V8GCController::checkMemoryUsage();
+
+    if (V8RecursionScope::recursionLevel() >= kMaxRecursionDepth)
+        return handleMaxRecursionDepthExceeded();
+
+    InspectorInstrumentationCookie cookie;
+    if (InspectorInstrumentation::hasFrontends() && context) {
+        String resourceName;
+        int lineNumber;
+        resourceInfo(function, resourceName, lineNumber);
+        cookie = InspectorInstrumentation::willCallFunction(context, resourceName, lineNumber);
+    }
+
+    v8::Local<v8::Value> result;
+    {
+        TRACE_EVENT1("v8", "v8.callFunction", "callsite", resourceString(function).utf8());
+        V8RecursionScope recursionScope(context);
+        result = function->Call(receiver, argc, args);
+    }
+
+    InspectorInstrumentation::didCallFunction(cookie);
+    crashIfV8IsDead();
+    return result;
 }
 
 ScriptValue ScriptController::callFunctionEvenIfScriptDisabled(v8::Handle<v8::Function> function, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> argv[])
index 4e7f223..da6ef92 100644 (file)
@@ -77,6 +77,9 @@ public:
     // Call the function with the given receiver and arguments.
     v8::Local<v8::Value> callFunction(v8::Handle<v8::Function>, v8::Handle<v8::Object>, int argc, v8::Handle<v8::Value> argv[]);
 
+    // Call the function with the given receiver and arguments and report times to DevTools.
+    static v8::Local<v8::Value> callFunctionWithInstrumentation(ScriptExecutionContext*, v8::Handle<v8::Function>, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[]);
+
     ScriptValue callFunctionEvenIfScriptDisabled(v8::Handle<v8::Function>, v8::Handle<v8::Object>, int argc, v8::Handle<v8::Value> argv[]);
 
     // Returns true if argument is a JavaScript URL.
index e2db61e..d9b200d 100644 (file)
 #include "config.h"
 #include "ScriptFunctionCall.h"
 
+#include "ScriptController.h"
 #include "ScriptScope.h"
 #include "ScriptState.h"
 #include "ScriptValue.h"
 #include "V8Binding.h"
 #include "V8ObjectConstructor.h"
-#include "V8Proxy.h"
 #include "V8RecursionScope.h"
 #include "V8Utilities.h"
 
@@ -202,7 +202,7 @@ ScriptValue ScriptCallback::call(bool& hadException)
     for (size_t i = 0; i < m_arguments.size(); ++i)
         args[i] = m_arguments[i].v8Value();
 
-    v8::Handle<v8::Value> result = V8Proxy::instrumentedCallFunction(0 /* frame */, function, object, m_arguments.size(), args.get());
+    v8::Handle<v8::Value> result = ScriptController::callFunctionWithInstrumentation(0, function, object, m_arguments.size(), args.get());
 
     if (exceptionCatcher.HasCaught()) {
         hadException = true;
index cfc7eae..54f572a 100644 (file)
@@ -32,7 +32,7 @@
 #include "V8Callback.h"
 
 #include "Document.h"
-#include "V8Proxy.h"
+#include "ScriptController.h"
 
 namespace WebCore {
 
@@ -59,8 +59,7 @@ bool invokeCallback(v8::Persistent<v8::Object> callback, v8::Handle<v8::Object>
     if (callbackFunction.IsEmpty())
         return false;
 
-    Frame* frame = scriptExecutionContext && scriptExecutionContext->isDocument() ? static_cast<Document*>(scriptExecutionContext)->frame() : 0;
-    v8::Handle<v8::Value> result = V8Proxy::instrumentedCallFunction(frame, callbackFunction, thisObject, argc, argv);
+    v8::Handle<v8::Value> result = ScriptController::callFunctionWithInstrumentation(scriptExecutionContext, callbackFunction, thisObject, argc, argv);
 
     callbackReturnValue = !result.IsEmpty() && result->BooleanValue();
     return exceptionCatcher.HasCaught();
index 9c07731..bc52a38 100644 (file)
@@ -33,9 +33,9 @@
 
 #include "Node.h"
 #include "NodeFilter.h"
+#include "ScriptController.h"
 #include "ScriptState.h"
 #include "V8Node.h"
-#include "V8Proxy.h"
 
 #include <wtf/OwnArrayPtr.h>
 
@@ -83,7 +83,7 @@ short V8NodeFilterCondition::acceptNode(ScriptState* state, Node* node) const
     OwnArrayPtr<v8::Handle<v8::Value> > args = adoptArrayPtr(new v8::Handle<v8::Value>[1]);
     args[0] = toV8(node);
 
-    v8::Handle<v8::Value> result = V8Proxy::instrumentedCallFunction(0 /* frame */, callback, object, 1, args.get());
+    v8::Handle<v8::Value> result = ScriptController::callFunctionWithInstrumentation(0, callback, object, 1, args.get());
 
     if (exceptionCatcher.HasCaught()) {
         state->setException(exceptionCatcher.Exception());
index 270180b..eabe02a 100644 (file)
@@ -69,7 +69,6 @@
 #include <wtf/StdLibExtras.h>
 #include <wtf/StringExtras.h>
 #include <wtf/UnusedParam.h>
-#include <wtf/text/StringBuilder.h>
 #include <wtf/text/WTFString.h>
 
 #if PLATFORM(CHROMIUM)
@@ -105,6 +104,7 @@ void V8Proxy::reportUnsafeAccessTo(Document* targetDocument)
     sourceDocument->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, str, stackTrace.release());
 }
 
+// FIXME: This will be soon removed when we move runScript() to ScriptController.
 static v8::Local<v8::Value> handleMaxRecursionDepthExceeded()
 {
     throwError(RangeError, "Maximum call stack size exceeded.");
@@ -258,62 +258,6 @@ v8::Local<v8::Value> V8Proxy::runScript(v8::Handle<v8::Script> script)
     return result;
 }
 
-static inline void resourceInfo(const v8::Handle<v8::Function> function, String& resourceName, int& lineNumber)
-{
-    v8::ScriptOrigin origin = function->GetScriptOrigin();
-    if (origin.ResourceName().IsEmpty()) {
-        resourceName = "undefined";
-        lineNumber = 1;
-    } else {
-        resourceName = toWebCoreString(origin.ResourceName());
-        lineNumber = function->GetScriptLineNumber() + 1;
-    }
-}
-
-static inline String resourceString(const v8::Handle<v8::Function> function)
-{
-    String resourceName;
-    int lineNumber;
-    resourceInfo(function, resourceName, lineNumber);
-
-    StringBuilder builder;
-    builder.append(resourceName);
-    builder.append(':');
-    builder.append(String::number(lineNumber));
-    return builder.toString();
-}
-
-v8::Local<v8::Value> V8Proxy::instrumentedCallFunction(Frame* frame, v8::Handle<v8::Function> function, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[])
-{
-    V8GCController::checkMemoryUsage();
-
-    if (V8RecursionScope::recursionLevel() >= kMaxRecursionDepth)
-        return handleMaxRecursionDepthExceeded();
-
-    ScriptExecutionContext* context = frame ? frame->document() : 0;
-
-    InspectorInstrumentationCookie cookie;
-    if (InspectorInstrumentation::hasFrontends() && context) {
-        String resourceName;
-        int lineNumber;
-        resourceInfo(function, resourceName, lineNumber);
-        cookie = InspectorInstrumentation::willCallFunction(context, resourceName, lineNumber);
-    }
-
-    v8::Local<v8::Value> result;
-    {
-#if PLATFORM(CHROMIUM)
-        TRACE_EVENT1("v8", "v8.callFunction", "callsite", resourceString(function).utf8());
-#endif
-        V8RecursionScope recursionScope(context);
-        result = function->Call(receiver, argc, args);
-    }
-
-    InspectorInstrumentation::didCallFunction(cookie);
-    crashIfV8IsDead();
-    return result;
-}
-
 V8DOMWindowShell* V8Proxy::windowShell() const
 {
     return frame()->script()->windowShell();
index 5acef2c..afb0403 100644 (file)
@@ -97,9 +97,6 @@ namespace WebCore {
         // Run an already compiled script.
         v8::Local<v8::Value> runScript(v8::Handle<v8::Script>);
 
-        // call the function with the given receiver and arguments and report times to DevTools.
-        static v8::Local<v8::Value> instrumentedCallFunction(Frame*, v8::Handle<v8::Function>, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[]);
-
         // Call the function as constructor with the given arguments.
         v8::Local<v8::Value> newInstance(v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]);
 
index aef7d12..f118c35 100644 (file)
@@ -34,8 +34,8 @@
 
 #include "EventNames.h"
 #include "ErrorEvent.h"
+#include "ScriptController.h"
 #include "V8Binding.h"
-#include "V8Proxy.h"
 
 namespace WebCore {
 
@@ -58,7 +58,7 @@ v8::Local<v8::Value> V8WindowErrorHandler::callListenerFunction(ScriptExecutionC
         v8::Handle<v8::Value> parameters[3] = { v8String(errorEvent->message()), v8String(errorEvent->filename()), v8Integer(errorEvent->lineno()) };
         v8::TryCatch tryCatch;
         tryCatch.SetVerbose(true);
-        returnValue = V8Proxy::instrumentedCallFunction(0 /* frame */, callFunction, thisValue, 3, parameters);
+        returnValue = ScriptController::callFunctionWithInstrumentation(0, callFunction, thisValue, 3, parameters);
     }
     return returnValue;
 }
index 0b5db98..8eddc6b 100644 (file)
@@ -31,9 +31,9 @@
 #include "V8CustomXPathNSResolver.h"
 
 #include "ScriptCallStack.h"
+#include "ScriptController.h"
 #include "ScriptExecutionContext.h"
 #include "V8Binding.h"
-#include "V8Proxy.h"
 #include "V8Utilities.h"
 #include <wtf/text/WTFString.h>
 
@@ -79,7 +79,7 @@ String V8CustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
     v8::Handle<v8::Value> argv[argc] = { v8String(prefix) };
     v8::Handle<v8::Function> function = lookupNamespaceURIFunc.IsEmpty() ? v8::Handle<v8::Function>::Cast(m_resolver) : lookupNamespaceURIFunc;
 
-    v8::Handle<v8::Value> retval = V8Proxy::instrumentedCallFunction(0 /* frame */, function, m_resolver, argc, argv);
+    v8::Handle<v8::Value> retval = ScriptController::callFunctionWithInstrumentation(0, function, m_resolver, argc, argv);
 
     // Eat exceptions from namespace resolver and return an empty string. This will most likely cause NAMESPACE_ERR.
     if (try_catch.HasCaught())
index 7aca19a..d90b9f3 100644 (file)
@@ -1,5 +1,21 @@
 2012-08-20  Kentaro Hara  <haraken@chromium.org>
 
+        [V8] Move instrumentedCallFunction() from V8Proxy to ScriptController
+        https://bugs.webkit.org/show_bug.cgi?id=94456
+
+        Reviewed by Adam Barth.
+
+        To kill V8Proxy, this patch moves instrumentedCallFunction() from V8Proxy
+        to ScriptController. Also this patch renames instrumentedCallFunction()
+        to callFunctionWithInstrumentation(), for consistency with callFunction().
+
+        No tests. No change in behavior.
+
+        * src/WebDevToolsFrontendImpl.cpp:
+        (WebKit::WebDevToolsFrontendImpl::dispatchOnInspectorFrontend):
+
+2012-08-20  Kentaro Hara  <haraken@chromium.org>
+
         [V8] Move retrieve{Window,Frame,PerContextData}() from V8Proxy to V8Binding
         https://bugs.webkit.org/show_bug.cgi?id=94460
 
index 054e5b2..9418c0d 100644 (file)
@@ -122,7 +122,7 @@ void WebDevToolsFrontendImpl::dispatchOnInspectorFrontend(const WebString& messa
     args.append(ToV8String(message));
     v8::TryCatch tryCatch;
     tryCatch.SetVerbose(true);
-    V8Proxy::instrumentedCallFunction(frame->frame(), function, inspectorBackend, args.size(), args.data());
+    ScriptController::callFunctionWithInstrumentation(frame->frame() ? frame->frame()->document() : 0, function, inspectorBackend, args.size(), args.data());
 }
 
 } // namespace WebKit