Title: [135674] trunk/Source/WebCore
Revision
135674
Author
[email protected]
Date
2012-11-25 16:21:24 -0800 (Sun, 25 Nov 2012)

Log Message

[V8] Move WorkerExecutionContextProxy::initializeIfNeeded() to V8Initializer
https://bugs.webkit.org/show_bug.cgi?id=103061

Reviewed by Adam Barth.

This is an incremental step to remove WorkerExecutionContextProxy.
This patch moves WorkerExecutionContextProxy::initializeIfNeeded() to V8Initializer.
This patch also renames methods so that the names become consistent
between the main thread and workers.

No tests. No change in behavior.

* bindings/v8/V8Initializer.cpp:
(WebCore::reportFatalErrorInMainThread):
(WebCore::messageHandlerInMainThread):
(WebCore::failedAccessCheckCallbackInMainThread):
(WebCore::V8Initializer::initializeMainThreadIfNeeded):
(WebCore::reportFatalErrorInWorker):
(WebCore):
(WebCore::messageHandlerInWorker):
(WebCore::V8Initializer::initializeWorkerIfNeeded):
* bindings/v8/V8Initializer.h:
(V8Initializer):
* bindings/v8/WorkerContextExecutionProxy.cpp:
(WebCore::WorkerContextExecutionProxy::WorkerContextExecutionProxy):
* bindings/v8/WorkerContextExecutionProxy.h:
(WorkerContextExecutionProxy):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (135673 => 135674)


--- trunk/Source/WebCore/ChangeLog	2012-11-25 19:19:08 UTC (rev 135673)
+++ trunk/Source/WebCore/ChangeLog	2012-11-26 00:21:24 UTC (rev 135674)
@@ -1,3 +1,33 @@
+2012-11-22  Kentaro Hara  <[email protected]>
+
+        [V8] Move WorkerExecutionContextProxy::initializeIfNeeded() to V8Initializer
+        https://bugs.webkit.org/show_bug.cgi?id=103061
+
+        Reviewed by Adam Barth.
+
+        This is an incremental step to remove WorkerExecutionContextProxy.
+        This patch moves WorkerExecutionContextProxy::initializeIfNeeded() to V8Initializer.
+        This patch also renames methods so that the names become consistent
+        between the main thread and workers.
+
+        No tests. No change in behavior.
+
+        * bindings/v8/V8Initializer.cpp:
+        (WebCore::reportFatalErrorInMainThread):
+        (WebCore::messageHandlerInMainThread):
+        (WebCore::failedAccessCheckCallbackInMainThread):
+        (WebCore::V8Initializer::initializeMainThreadIfNeeded):
+        (WebCore::reportFatalErrorInWorker):
+        (WebCore):
+        (WebCore::messageHandlerInWorker):
+        (WebCore::V8Initializer::initializeWorkerIfNeeded):
+        * bindings/v8/V8Initializer.h:
+        (V8Initializer):
+        * bindings/v8/WorkerContextExecutionProxy.cpp:
+        (WebCore::WorkerContextExecutionProxy::WorkerContextExecutionProxy):
+        * bindings/v8/WorkerContextExecutionProxy.h:
+        (WorkerContextExecutionProxy):
+
 2012-11-25  Christophe Dumez  <[email protected]>
 
         [EFL] Refactor RenderThemeEfl::ThemePartCacheEntry::reuse()

Modified: trunk/Source/WebCore/bindings/v8/V8Initializer.cpp (135673 => 135674)


--- trunk/Source/WebCore/bindings/v8/V8Initializer.cpp	2012-11-25 19:19:08 UTC (rev 135673)
+++ trunk/Source/WebCore/bindings/v8/V8Initializer.cpp	2012-11-26 00:21:24 UTC (rev 135674)
@@ -39,6 +39,7 @@
 #include "V8GCController.h"
 #include "V8History.h"
 #include "V8Location.h"
+#include "V8PerContextData.h"
 #include <v8.h>
 #include <wtf/RefPtr.h>
 #include <wtf/text/WTFString.h>
@@ -67,14 +68,14 @@
     return 0;
 }
 
-static void reportFatalError(const char* location, const char* message)
+static void reportFatalErrorInMainThread(const char* location, const char* message)
 {
     int memoryUsageMB = MemoryUsageSupport::actualMemoryUsageMB();
     printf("V8 error: %s (%s).  Current memory usage: %d MB\n", message, location, memoryUsageMB);
     CRASH();
 }
 
-static void reportUncaughtException(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data)
+static void messageHandlerInMainThread(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data)
 {
     DOMWindow* firstWindow = firstDOMWindow(BindingState::instance());
     if (!firstWindow->isCurrentlyDisplayedInFrame())
@@ -94,7 +95,7 @@
     firstWindow->document()->reportException(errorMessage, message->GetLineNumber(), resource, callStack);
 }
 
-static void reportUnsafeJavaScriptAccess(v8::Local<v8::Object> host, v8::AccessType type, v8::Local<v8::Value> data)
+static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8::AccessType type, v8::Local<v8::Value> data)
 {
     Frame* target = findFrame(host, data);
     if (!target)
@@ -113,11 +114,11 @@
     initialized = true;
 
     v8::V8::IgnoreOutOfMemoryException();
-    v8::V8::SetFatalErrorHandler(reportFatalError);
-    v8::V8::AddGCPrologueCallback(&V8GCController::gcPrologue);
-    v8::V8::AddGCEpilogueCallback(&V8GCController::gcEpilogue);
-    v8::V8::AddMessageListener(&reportUncaughtException);
-    v8::V8::SetFailedAccessCheckCallbackFunction(reportUnsafeJavaScriptAccess);
+    v8::V8::SetFatalErrorHandler(reportFatalErrorInMainThread);
+    v8::V8::AddGCPrologueCallback(V8GCController::gcPrologue);
+    v8::V8::AddGCEpilogueCallback(V8GCController::gcEpilogue);
+    v8::V8::AddMessageListener(messageHandlerInMainThread);
+    v8::V8::SetFailedAccessCheckCallbackFunction(failedAccessCheckCallbackInMainThread);
 #if ENABLE(_javascript__DEBUGGER)
     ScriptProfiler::initialize();
 #endif
@@ -128,4 +129,53 @@
     v8::V8::SetFlagsFromString(es5ReadonlyFlag, sizeof(es5ReadonlyFlag));
 }
 
+static void reportFatalErrorInWorker(const char* location, const char* message)
+{
+    // FIXME: We temporarily deal with V8 internal error situations such as out-of-memory by crashing the worker.
+    CRASH();
+}
+
+static void messageHandlerInWorker(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data)
+{
+    static bool isReportingException = false;
+    // Exceptions that occur in error handler should be ignored since in that case
+    // WorkerContext::reportException will send the exception to the worker object.
+    if (isReportingException)
+        return;
+    isReportingException = true;
+
+    // During the frame teardown, there may not be a valid context.
+    if (ScriptExecutionContext* context = getScriptExecutionContext()) {
+        String errorMessage = toWebCoreString(message->Get());
+        int lineNumber = message->GetLineNumber();
+        String sourceURL = toWebCoreString(message->GetScriptResourceName());
+        context->reportException(errorMessage, lineNumber, sourceURL, 0);
+    }
+
+    isReportingException = false;
+}
+
+static const int kWorkerMaxStackSize = 500 * 1024;
+
+void V8Initializer::initializeWorker()
+{
+    v8::V8::AddMessageListener(messageHandlerInWorker);
+    v8::V8::IgnoreOutOfMemoryException();
+    v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker);
+
+    v8::V8::AddGCPrologueCallback(V8GCController::gcPrologue);
+    v8::V8::AddGCEpilogueCallback(V8GCController::gcEpilogue);
+
+    // FIXME: Remove the following 2 lines when V8 default has changed.
+    const char es5ReadonlyFlag[] = "--es5_readonly";
+    v8::V8::SetFlagsFromString(es5ReadonlyFlag, sizeof(es5ReadonlyFlag));
+
+    v8::ResourceConstraints resourceConstraints;
+    uint32_t here;
+    resourceConstraints.set_stack_limit(&here - kWorkerMaxStackSize / sizeof(uint32_t*));
+    v8::SetResourceConstraints(&resourceConstraints);
+
+    V8PerIsolateData::ensureInitialized(v8::Isolate::GetCurrent());
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/v8/V8Initializer.h (135673 => 135674)


--- trunk/Source/WebCore/bindings/v8/V8Initializer.h	2012-11-25 19:19:08 UTC (rev 135673)
+++ trunk/Source/WebCore/bindings/v8/V8Initializer.h	2012-11-26 00:21:24 UTC (rev 135674)
@@ -31,6 +31,7 @@
 class V8Initializer {
 public:
     static void initializeMainThreadIfNeeded();
+    static void initializeWorker();
 };
     
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp (135673 => 135674)


--- trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp	2012-11-25 19:19:08 UTC (rev 135673)
+++ trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp	2012-11-26 00:21:24 UTC (rev 135674)
@@ -46,6 +46,7 @@
 #include "V8DOMWindowShell.h"
 #include "V8DedicatedWorkerContext.h"
 #include "V8GCController.h"
+#include "V8Initializer.h"
 #include "V8ObjectConstructor.h"
 #include "V8PerContextData.h"
 #include "V8RecursionScope.h"
@@ -58,37 +59,11 @@
 
 namespace WebCore {
 
-static void reportFatalErrorInV8(const char* location, const char* message)
-{
-    // FIXME: We temporarily deal with V8 internal error situations such as out-of-memory by crashing the worker.
-    CRASH();
-}
-
-static void v8MessageHandler(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data)
-{
-    static bool isReportingException = false;
-    // Exceptions that occur in error handler should be ignored since in that case
-    // WorkerContext::reportException will send the exception to the worker object.
-    if (isReportingException)
-        return;
-    isReportingException = true;
-
-    // During the frame teardown, there may not be a valid context.
-    if (ScriptExecutionContext* context = getScriptExecutionContext()) {
-        String errorMessage = toWebCoreString(message->Get());
-        int lineNumber = message->GetLineNumber();
-        String sourceURL = toWebCoreString(message->GetScriptResourceName());
-        context->reportException(errorMessage, lineNumber, sourceURL, 0);
-    }
-
-    isReportingException = false;
-}
-
 WorkerContextExecutionProxy::WorkerContextExecutionProxy(WorkerContext* workerContext)
     : m_workerContext(workerContext)
     , m_disableEvalPending(String())
 {
-    initIsolate();
+    V8Initializer::initializeWorker();
 }
 
 WorkerContextExecutionProxy::~WorkerContextExecutionProxy()
@@ -102,30 +77,6 @@
     m_context.clear();
 }
 
-void WorkerContextExecutionProxy::initIsolate()
-{
-    // Setup the security handlers and message listener.
-    v8::V8::AddMessageListener(&v8MessageHandler);
-
-    // Tell V8 not to call the default OOM handler, binding code will handle it.
-    v8::V8::IgnoreOutOfMemoryException();
-    v8::V8::SetFatalErrorHandler(reportFatalErrorInV8);
-
-    v8::V8::AddGCPrologueCallback(&V8GCController::gcPrologue);
-    v8::V8::AddGCEpilogueCallback(&V8GCController::gcEpilogue);
-
-    // FIXME: Remove the following 2 lines when V8 default has changed.
-    const char es5ReadonlyFlag[] = "--es5_readonly";
-    v8::V8::SetFlagsFromString(es5ReadonlyFlag, sizeof(es5ReadonlyFlag));
-
-    v8::ResourceConstraints resource_constraints;
-    uint32_t here;
-    resource_constraints.set_stack_limit(&here - kWorkerMaxStackSize / sizeof(uint32_t*));
-    v8::SetResourceConstraints(&resource_constraints);
-
-    V8PerIsolateData::ensureInitialized(v8::Isolate::GetCurrent());
-}
-
 bool WorkerContextExecutionProxy::initializeIfNeeded()
 {
     // Bail out if the context has already been initialized.

Modified: trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.h (135673 => 135674)


--- trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.h	2012-11-25 19:19:08 UTC (rev 135673)
+++ trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.h	2012-11-26 00:21:24 UTC (rev 135674)
@@ -81,8 +81,6 @@
         bool initializeIfNeeded();
         void dispose();
 
-        static const int kWorkerMaxStackSize = 500 * 1024;
-
         WorkerContext* m_workerContext;
         ScopedPersistent<v8::Context> m_context;
         OwnPtr<V8PerContextData> m_perContextData;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to