Title: [100347] trunk/Source/WebCore
Revision
100347
Author
ad...@chromium.org
Date
2011-11-15 15:34:04 -0800 (Tue, 15 Nov 2011)

Log Message

Factor out V8Proxy's max recursion depth handling code
https://bugs.webkit.org/show_bug.cgi?id=72422

Reviewed by Nate Chapin.

Previously, V8Proxy used slightly different code to handle stack limit
violations depending on whether they occured in runScript or
callFunction. As described in http://webkit.org/b/72063, I intend to
expand the usage of m_recursion when calling into script. This patch
is intended to unify the existing handling code, making it easier to
move elsewhere without causing unintended side-effects.

No tests changed, as the only change in behavior is the string passed
to RangeError in the runScript case, and it's not mentioned anywhere
in the LayoutTests.

* bindings/v8/V8Proxy.cpp:
(WebCore::handleMaxRecursionDepthExceeded):
(WebCore::V8Proxy::runScript): Use callFunction's factored-out code.
(WebCore::V8Proxy::callFunction): Simplify and factor out code into handleMaxRecursionDepthExceeded.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (100346 => 100347)


--- trunk/Source/WebCore/ChangeLog	2011-11-15 23:29:19 UTC (rev 100346)
+++ trunk/Source/WebCore/ChangeLog	2011-11-15 23:34:04 UTC (rev 100347)
@@ -1,3 +1,26 @@
+2011-11-15  Adam Klein  <ad...@chromium.org>
+
+        Factor out V8Proxy's max recursion depth handling code
+        https://bugs.webkit.org/show_bug.cgi?id=72422
+
+        Reviewed by Nate Chapin.
+
+        Previously, V8Proxy used slightly different code to handle stack limit
+        violations depending on whether they occured in runScript or
+        callFunction. As described in http://webkit.org/b/72063, I intend to
+        expand the usage of m_recursion when calling into script. This patch
+        is intended to unify the existing handling code, making it easier to
+        move elsewhere without causing unintended side-effects.
+
+        No tests changed, as the only change in behavior is the string passed
+        to RangeError in the runScript case, and it's not mentioned anywhere
+        in the LayoutTests.
+
+        * bindings/v8/V8Proxy.cpp:
+        (WebCore::handleMaxRecursionDepthExceeded):
+        (WebCore::V8Proxy::runScript): Use callFunction's factored-out code.
+        (WebCore::V8Proxy::callFunction): Simplify and factor out code into handleMaxRecursionDepthExceeded.
+
 2011-11-15  Jessie Berlin  <jber...@apple.com>
 
         NSURLRequest leak beneath ResourceRequest::setStorageSession seen on Leaks bot.

Modified: trunk/Source/WebCore/bindings/v8/V8Proxy.cpp (100346 => 100347)


--- trunk/Source/WebCore/bindings/v8/V8Proxy.cpp	2011-11-15 23:29:19 UTC (rev 100346)
+++ trunk/Source/WebCore/bindings/v8/V8Proxy.cpp	2011-11-15 23:34:04 UTC (rev 100347)
@@ -175,6 +175,14 @@
     CRASH();
 }
 
+static v8::Local<v8::Value> handleMaxRecursionDepthExceeded()
+{
+    v8::Local<v8::String> code = v8::String::New("throw new RangeError('Maximum call stack size exceeded.')");
+    v8::Local<v8::Script> script = v8::Script::Compile(code);
+    script->Run();
+    return v8::Local<v8::Value>();
+}
+
 V8Proxy::V8Proxy(Frame* frame)
     : m_frame(frame)
     , m_windowShell(V8DOMWindowShell::create(frame))
@@ -384,21 +392,12 @@
         return notHandledByInterceptor();
 
     V8GCController::checkMemoryUsage();
-    // Compute the source string and prevent against infinite recursion.
-    if (m_recursion >= kMaxRecursionDepth) {
-        v8::Local<v8::String> code = v8ExternalString("throw RangeError('Recursion too deep')");
-        // FIXME: Ideally, we should be able to re-use the origin of the
-        // script passed to us as the argument instead of using an empty string
-        // and 0 baseLine.
-        script = compileScript(code, "", TextPosition::minimumPosition());
-    }
+    if (m_recursion >= kMaxRecursionDepth)
+        return handleMaxRecursionDepthExceeded();
 
     if (handleOutOfMemory())
         ASSERT(script.IsEmpty());
 
-    if (script.IsEmpty())
-        return notHandledByInterceptor();
-
     // Save the previous value of the inlineCode flag and update the flag for
     // the duration of the script invocation.
     bool previousInlineCode = inlineCode();
@@ -445,22 +444,14 @@
 {
     V8GCController::checkMemoryUsage();
 
+    if (m_recursion >= kMaxRecursionDepth)
+        return handleMaxRecursionDepthExceeded();
+
     // Keep Frame (and therefore ScriptController and V8Proxy) alive.
     RefPtr<Frame> protect(frame());
 
     v8::Local<v8::Value> result;
     {
-        if (m_recursion >= kMaxRecursionDepth) {
-            v8::Local<v8::String> code = v8::String::New("throw new RangeError('Maximum call stack size exceeded.')");
-            if (code.IsEmpty())
-                return result;
-            v8::Local<v8::Script> script = v8::Script::Compile(code);
-            if (script.IsEmpty())
-                return result;
-            script->Run();
-            return result;
-        }
-
         m_recursion++;
         result = V8Proxy::instrumentedCallFunction(m_frame->page(), function, receiver, argc, args);
         m_recursion--;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to