Diff
Modified: trunk/Source/WebCore/ChangeLog (126376 => 126377)
--- trunk/Source/WebCore/ChangeLog 2012-08-23 01:23:12 UTC (rev 126376)
+++ trunk/Source/WebCore/ChangeLog 2012-08-23 01:27:28 UTC (rev 126377)
@@ -1,3 +1,39 @@
+2012-08-22 Kentaro Hara <[email protected]>
+
+ [V8] Move runScript() from V8Proxy to ScriptRunner
+ https://bugs.webkit.org/show_bug.cgi?id=94706
+
+ Reviewed by Adam Barth.
+
+ To kill V8Proxy, we can move runScript() from V8Proxy to ScriptRunner.
+
+ - ScriptRunner::runScript() should be a static method.
+ It should receive ScriptExecutionContext on which the script is evaluated.
+
+ - After this patch is landed, I'll remove WorkerContextExecutionContext::runScript()
+ and ScriptDebugServer::runScript().
+
+ No tests. No change in behavior.
+
+ * UseV8.cmake:
+ * WebCore.gypi:
+ * bindings/v8/ScriptController.cpp:
+ * bindings/v8/ScriptRunner.cpp: Added.
+ (WebCore):
+ (WebCore::ScriptRunner::runScript):
+ * bindings/v8/ScriptRunner.h: Added.
+ (WebCore):
+ (ScriptRunner):
+ * bindings/v8/V8Binding.cpp:
+ (WebCore::handleMaxRecursionDepthExceeded):
+ (WebCore):
+ * bindings/v8/V8Binding.h:
+ (WebCore):
+ * bindings/v8/V8Proxy.cpp:
+ (WebCore::V8Proxy::evaluate):
+ * bindings/v8/V8Proxy.h:
+ (V8Proxy):
+
2012-08-22 Adam Barth <[email protected]>
[V8] OwnHandle doesn't need to support weak handles
Modified: trunk/Source/WebCore/UseV8.cmake (126376 => 126377)
--- trunk/Source/WebCore/UseV8.cmake 2012-08-23 01:23:12 UTC (rev 126376)
+++ trunk/Source/WebCore/UseV8.cmake 2012-08-23 01:27:28 UTC (rev 126377)
@@ -39,6 +39,7 @@
bindings/v8/ScriptGCEvent.cpp
bindings/v8/ScriptInstance.cpp
bindings/v8/ScriptObject.cpp
+ bindings/v8/ScriptRunner.cpp
bindings/v8/ScriptScope.cpp
bindings/v8/ScriptSourceCode.cpp
bindings/v8/ScriptState.cpp
Modified: trunk/Source/WebCore/WebCore.gypi (126376 => 126377)
--- trunk/Source/WebCore/WebCore.gypi 2012-08-23 01:23:12 UTC (rev 126376)
+++ trunk/Source/WebCore/WebCore.gypi 2012-08-23 01:27:28 UTC (rev 126377)
@@ -2240,6 +2240,8 @@
'bindings/v8/ScriptProfileNode.h',
'bindings/v8/ScriptProfiler.cpp',
'bindings/v8/ScriptProfiler.h',
+ 'bindings/v8/ScriptRunner.cpp',
+ 'bindings/v8/ScriptRunner.h',
'bindings/v8/ScriptScope.cpp',
'bindings/v8/ScriptScope.h',
'bindings/v8/ScriptSourceCode.cpp',
Modified: trunk/Source/WebCore/bindings/v8/ScriptController.cpp (126376 => 126377)
--- trunk/Source/WebCore/bindings/v8/ScriptController.cpp 2012-08-23 01:23:12 UTC (rev 126376)
+++ trunk/Source/WebCore/bindings/v8/ScriptController.cpp 2012-08-23 01:27:28 UTC (rev 126377)
@@ -198,12 +198,6 @@
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();
Added: trunk/Source/WebCore/bindings/v8/ScriptRunner.cpp (0 => 126377)
--- trunk/Source/WebCore/bindings/v8/ScriptRunner.cpp (rev 0)
+++ trunk/Source/WebCore/bindings/v8/ScriptRunner.cpp 2012-08-23 01:27:28 UTC (rev 126377)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ScriptRunner.h"
+
+#include "ScriptExecutionContext.h"
+#include "V8Binding.h"
+#include "V8RecursionScope.h"
+
+namespace WebCore {
+
+v8::Local<v8::Value> ScriptRunner::runCompiledScript(v8::Handle<v8::Script> script, ScriptExecutionContext* context)
+{
+ if (script.IsEmpty())
+ return v8::Local<v8::Value>();
+
+ V8GCController::checkMemoryUsage();
+ if (V8RecursionScope::recursionLevel() >= kMaxRecursionDepth)
+ return handleMaxRecursionDepthExceeded();
+
+ if (handleOutOfMemory())
+ ASSERT(script.IsEmpty());
+
+ // Run the script and keep track of the current recursion depth.
+ v8::Local<v8::Value> result;
+ v8::TryCatch tryCatch;
+ tryCatch.SetVerbose(true);
+ {
+ V8RecursionScope recursionScope(context);
+ result = script->Run();
+ }
+
+ if (handleOutOfMemory())
+ ASSERT(result.IsEmpty());
+
+ // Handle V8 internal error situation.
+ if (tryCatch.HasCaught()) {
+ ASSERT(result.IsEmpty());
+ return v8::Local<v8::Value>();
+ }
+
+ if (result.IsEmpty())
+ return v8::Local<v8::Value>();
+
+ crashIfV8IsDead();
+ return result;
+}
+
+} // namespace WebCore
Added: trunk/Source/WebCore/bindings/v8/ScriptRunner.h (0 => 126377)
--- trunk/Source/WebCore/bindings/v8/ScriptRunner.h (rev 0)
+++ trunk/Source/WebCore/bindings/v8/ScriptRunner.h 2012-08-23 01:27:28 UTC (rev 126377)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ScriptRunner_h
+#define ScriptRunner_h
+
+#include <v8.h>
+
+namespace WebCore {
+
+class ScriptExecutionContext;
+
+class ScriptRunner {
+public:
+ static v8::Local<v8::Value> runCompiledScript(v8::Handle<v8::Script>, ScriptExecutionContext*);
+};
+
+} // namespace WebCore
+
+#endif // ScriptRunner_h
Modified: trunk/Source/WebCore/bindings/v8/V8Binding.cpp (126376 => 126377)
--- trunk/Source/WebCore/bindings/v8/V8Binding.cpp 2012-08-23 01:23:12 UTC (rev 126376)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.cpp 2012-08-23 01:27:28 UTC (rev 126377)
@@ -319,6 +319,12 @@
return true;
}
+v8::Local<v8::Value> handleMaxRecursionDepthExceeded()
+{
+ throwError(RangeError, "Maximum call stack size exceeded.");
+ return v8::Local<v8::Value>();
+}
+
void crashIfV8IsDead()
{
if (v8::V8::IsDead()) {
Modified: trunk/Source/WebCore/bindings/v8/V8Binding.h (126376 => 126377)
--- trunk/Source/WebCore/bindings/v8/V8Binding.h 2012-08-23 01:23:12 UTC (rev 126376)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.h 2012-08-23 01:27:28 UTC (rev 126377)
@@ -372,6 +372,7 @@
// If the current context causes out of memory, _javascript_ setting
// is disabled and it returns true.
bool handleOutOfMemory();
+ v8::Local<v8::Value> handleMaxRecursionDepthExceeded();
void crashIfV8IsDead();
Modified: trunk/Source/WebCore/bindings/v8/V8Proxy.cpp (126376 => 126377)
--- trunk/Source/WebCore/bindings/v8/V8Proxy.cpp 2012-08-23 01:23:12 UTC (rev 126376)
+++ trunk/Source/WebCore/bindings/v8/V8Proxy.cpp 2012-08-23 01:27:28 UTC (rev 126377)
@@ -45,6 +45,7 @@
#include "PlatformSupport.h"
#include "ScriptCallStack.h"
#include "ScriptCallStackFactory.h"
+#include "ScriptRunner.h"
#include "ScriptSourceCode.h"
#include "SecurityOrigin.h"
#include "Settings.h"
@@ -77,13 +78,6 @@
namespace WebCore {
-// 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.");
- return v8::Local<v8::Value>();
-}
-
V8Proxy::V8Proxy(Frame* frame)
: m_frame(frame)
{
@@ -125,7 +119,10 @@
TRACE_EVENT_END0("v8", "v8.compile");
TRACE_EVENT0("v8", "v8.run");
#endif
- result = runScript(script);
+
+ // Keep Frame (and therefore ScriptController) alive.
+ RefPtr<Frame> protect(frame());
+ result = ScriptRunner::runCompiledScript(script, frame()->document());
}
InspectorInstrumentation::didEvaluateScript(cookie);
@@ -133,46 +130,6 @@
return result;
}
-v8::Local<v8::Value> V8Proxy::runScript(v8::Handle<v8::Script> script)
-{
- if (script.IsEmpty())
- return v8::Local<v8::Value>();
-
- V8GCController::checkMemoryUsage();
- if (V8RecursionScope::recursionLevel() >= kMaxRecursionDepth)
- return handleMaxRecursionDepthExceeded();
-
- if (handleOutOfMemory())
- ASSERT(script.IsEmpty());
-
- // Keep Frame (and therefore ScriptController and V8Proxy) alive.
- RefPtr<Frame> protect(frame());
-
- // Run the script and keep track of the current recursion depth.
- v8::Local<v8::Value> result;
- v8::TryCatch tryCatch;
- tryCatch.SetVerbose(true);
- {
- V8RecursionScope recursionScope(frame()->document());
- result = script->Run();
- }
-
- if (handleOutOfMemory())
- ASSERT(result.IsEmpty());
-
- // Handle V8 internal error situation (Out-of-memory).
- if (tryCatch.HasCaught()) {
- ASSERT(result.IsEmpty());
- return v8::Local<v8::Value>();
- }
-
- if (result.IsEmpty())
- return v8::Local<v8::Value>();
-
- crashIfV8IsDead();
- return result;
-}
-
V8DOMWindowShell* V8Proxy::windowShell() const
{
return frame()->script()->windowShell();
Modified: trunk/Source/WebCore/bindings/v8/V8Proxy.h (126376 => 126377)
--- trunk/Source/WebCore/bindings/v8/V8Proxy.h 2012-08-23 01:23:12 UTC (rev 126376)
+++ trunk/Source/WebCore/bindings/v8/V8Proxy.h 2012-08-23 01:27:28 UTC (rev 126377)
@@ -92,9 +92,6 @@
// If cannot evalute the script, it returns an error.
v8::Local<v8::Value> evaluate(const ScriptSourceCode&, Node*);
- // Run an already compiled script.
- v8::Local<v8::Value> runScript(v8::Handle<v8::Script>);
-
// FIXME: This should eventually take DOMWrapperWorld argument!
// FIXME: This method will be soon removed, as all methods that access windowShell()
// will be moved to ScriptController.