Add V8 locks at the v8 entry points for use with workers.
diff --git a/V8Binding/binding/NPV8Object.cpp b/V8Binding/binding/NPV8Object.cpp
index 6dccae1..d856a43 100644
--- a/V8Binding/binding/NPV8Object.cpp
+++ b/V8Binding/binding/NPV8Object.cpp
@@ -125,6 +125,8 @@
     if (!npobj)
         return false;
 
+    LOCK_V8;
+
     if (npobj->_class == npScriptObjectClass) {
         V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj);
 
@@ -195,6 +197,8 @@
     if (!npobj)
         return false;
 
+    LOCK_V8;
+
     if (npobj->_class == npScriptObjectClass) {
         V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj);
 
@@ -255,6 +259,8 @@
     if (npobj->_class != npScriptObjectClass)
         return false;
 
+    LOCK_V8;
+
     v8::HandleScope handleScope;
     v8::Handle<v8::Context> context = getV8Context(npp, npobj);
     if (context.IsEmpty())
@@ -298,6 +304,8 @@
     if (!npobj)
         return false;
 
+    LOCK_V8;
+
     if (npobj->_class == npScriptObjectClass) {
         V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj);
 
@@ -329,6 +337,8 @@
     if (!npobj)
         return false;
 
+    LOCK_V8;
+
     if (npobj->_class == npScriptObjectClass) {
         V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj);
 
@@ -358,6 +368,8 @@
     if (npobj->_class != npScriptObjectClass)
         return false;
 
+    LOCK_V8;
+
     V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj);
 
     v8::HandleScope handleScope;
@@ -377,6 +389,8 @@
     if (!npobj)
         return false;
 
+    LOCK_V8;
+
     if (npobj->_class == npScriptObjectClass) {
         V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj);
 
@@ -400,6 +414,8 @@
     if (!npobj)
         return false;
 
+    LOCK_V8;
+
     if (npobj->_class == npScriptObjectClass) {
         V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj);
 
@@ -423,6 +439,9 @@
 {
     if (npobj->_class != npScriptObjectClass)
         return;
+
+    LOCK_V8;
+
     v8::HandleScope handleScope;
     v8::Handle<v8::Context> context = getV8Context(0, npobj);
     if (context.IsEmpty())
@@ -437,6 +456,8 @@
     if (!npobj)
         return false;
 
+    LOCK_V8;
+
     if (npobj->_class == npScriptObjectClass) {
         V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj);
 
@@ -493,6 +514,8 @@
     if (!npobj)
         return false;
 
+    LOCK_V8;
+
     if (npobj->_class == npScriptObjectClass) {
         V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj);
 
diff --git a/V8Binding/binding/V8NPObject.cpp b/V8Binding/binding/V8NPObject.cpp
index 8d3a518..dd9af69 100644
--- a/V8Binding/binding/V8NPObject.cpp
+++ b/V8Binding/binding/V8NPObject.cpp
@@ -363,6 +363,7 @@
 void forgetV8ObjectForNPObject(NPObject* object)
 {
     if (staticNPObjectMap.contains(object)) {
+        LOCK_V8;
         v8::HandleScope scope;
         v8::Persistent<v8::Object> handle(staticNPObjectMap.get(object));
         WebCore::V8Proxy::SetDOMWrapper(handle, WebCore::V8ClassIndex::NPOBJECT, 0);
diff --git a/V8Binding/binding/v8_proxy.cpp b/V8Binding/binding/v8_proxy.cpp
index d8d6b66..37e3dbb 100644
--- a/V8Binding/binding/v8_proxy.cpp
+++ b/V8Binding/binding/v8_proxy.cpp
@@ -1078,7 +1078,7 @@
 v8::Local<v8::Value> V8Proxy::evaluate(const ScriptSourceCode& source, Node* n)
 {
     ASSERT(v8::Context::InContext());
-
+    LOCK_V8;
     // Compile the script.
     v8::Local<v8::String> code = v8ExternalString(source.source());
 #if PLATFORM(CHROMIUM)
@@ -1905,6 +1905,7 @@
 
 void V8Proxy::UpdateDocumentWrapperCache()
 {
+    LOCK_V8;
     v8::HandleScope handle_scope;
     v8::Context::Scope context_scope(GetContext());
     v8::Handle<v8::Value> document_wrapper = NodeToV8Object(m_frame->document());
@@ -1947,6 +1948,7 @@
 void V8Proxy::clearForClose()
 {
     if (!m_context.IsEmpty()) {
+        LOCK_V8;
         v8::HandleScope handle_scope;
 
         ClearDocumentWrapper();
@@ -1961,6 +1963,7 @@
     DisconnectEventListeners();
 
     if (!m_context.IsEmpty()) {
+        LOCK_V8;
         v8::HandleScope handle;
         ClearDocumentWrapper();
 
@@ -2039,6 +2042,7 @@
 
 void V8Proxy::updateSecurityOrigin()
 {
+    LOCK_V8;
     v8::HandleScope scope;
     SetSecurityToken();
 }
@@ -2216,7 +2220,7 @@
 #ifdef ANDROID_INSTRUMENT
     android::TimeCounter::start(android::TimeCounter::JavaScriptInitTimeCounter);
 #endif
-
+    LOCK_V8;
   // Create a handle scope for all local handles.
   v8::HandleScope handle_scope;
 
diff --git a/WebCore/bindings/v8/ScheduledAction.cpp b/WebCore/bindings/v8/ScheduledAction.cpp
index ab51600..b1db8cf 100644
--- a/WebCore/bindings/v8/ScheduledAction.cpp
+++ b/WebCore/bindings/v8/ScheduledAction.cpp
@@ -105,6 +105,7 @@
 {
     ASSERT(proxy);
 
+    LOCK_V8;
     v8::HandleScope handleScope;
     v8::Local<v8::Context> v8Context = proxy->GetContext();
     if (v8Context.IsEmpty())
@@ -133,6 +134,7 @@
     WorkerScriptController* scriptController = workerContext->script();
 
     if (!m_function.IsEmpty() && m_function->IsFunction()) {
+        LOCK_V8;
         v8::HandleScope handleScope;
         v8::Local<v8::Context> v8Context = scriptController->proxy()->GetContext();
         ASSERT(!v8Context.IsEmpty());
diff --git a/WebCore/bindings/v8/ScriptController.cpp b/WebCore/bindings/v8/ScriptController.cpp
index 833c99f..97bb8ec 100644
--- a/WebCore/bindings/v8/ScriptController.cpp
+++ b/WebCore/bindings/v8/ScriptController.cpp
@@ -191,6 +191,7 @@
 // Evaluate a script file in the environment of this proxy.
 ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode)
 {
+    LOCK_V8;
     v8::HandleScope handleScope;
     v8::Handle<v8::Context> context = V8Proxy::GetContext(m_proxy->frame());
     if (context.IsEmpty())
@@ -225,6 +226,7 @@
 // Create a V8 object with an interceptor of NPObjectPropertyGetter.
 void ScriptController::bindToWindowObject(Frame* frame, const String& key, NPObject* object)
 {
+    LOCK_V8;
     v8::HandleScope handleScope;
 
     v8::Handle<v8::Context> context = V8Proxy::GetContext(frame);
@@ -371,6 +373,7 @@
     if (!isEnabled())
         return createNoScriptObject();
 
+    LOCK_V8;
     v8::HandleScope handleScope;
     v8::Handle<v8::Context> context = V8Proxy::GetContext(m_frame);
     if (context.IsEmpty())
diff --git a/WebCore/bindings/v8/V8AbstractEventListener.cpp b/WebCore/bindings/v8/V8AbstractEventListener.cpp
index 462a729..07e944d 100644
--- a/WebCore/bindings/v8/V8AbstractEventListener.cpp
+++ b/WebCore/bindings/v8/V8AbstractEventListener.cpp
@@ -110,6 +110,7 @@
     // See issue 889829.
     RefPtr<V8AbstractEventListener> protect(this);
 
+    LOCK_V8;
     v8::HandleScope handleScope;
 
     v8::Handle<v8::Context> context = V8Proxy::GetContext(m_frame);
diff --git a/WebCore/bindings/v8/V8Utilities.h b/WebCore/bindings/v8/V8Utilities.h
index 5769910..fdabc7a 100644
--- a/WebCore/bindings/v8/V8Utilities.h
+++ b/WebCore/bindings/v8/V8Utilities.h
@@ -33,6 +33,11 @@
 
 // FIXME: Remove once chromium dependencies on v8_utility.h are removed.
 #define V8UTILITIES_DEFINED 1
+#if ENABLE(V8_LOCKERS)
+#define LOCK_V8 v8::Locker lock
+#else
+#define LOCK_V8 ((void) 0)
+#endif
 
 #include <v8.h>
 
diff --git a/WebCore/bindings/v8/V8WorkerContextEventListener.cpp b/WebCore/bindings/v8/V8WorkerContextEventListener.cpp
index 9bb48fb..a21d3eb 100644
--- a/WebCore/bindings/v8/V8WorkerContextEventListener.cpp
+++ b/WebCore/bindings/v8/V8WorkerContextEventListener.cpp
@@ -35,6 +35,7 @@
 #include "V8WorkerContextEventListener.h"
 
 #include "Event.h"
+#include "V8Utilities.h"
 #include "WorkerContextExecutionProxy.h"
 
 namespace WebCore {
@@ -62,6 +63,7 @@
     // See issue 889829.
     RefPtr<V8AbstractEventListener> protect(this);
 
+    LOCK_V8;
     v8::HandleScope handleScope;
 
     v8::Handle<v8::Context> context = m_proxy->GetContext();
diff --git a/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp b/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp
index 7af9536..c87cdea 100644
--- a/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp
+++ b/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp
@@ -141,6 +141,7 @@
 {
     static bool v8Initialized = false;
 
+    LOCK_V8;
     if (v8Initialized)
         return;
 
@@ -151,6 +152,10 @@
     // Set up the handler for V8 error message.
     v8::V8::AddMessageListener(handleConsoleMessage);
 
+#if PLATFORM(ANDROID)
+    const int workerThreadPreemptionIntervalMs = 5;
+    v8::Locker::StartPreemption(workerThreadPreemptionIntervalMs);
+#endif
     v8Initialized = true;
 }
 
@@ -337,6 +342,7 @@
 
 v8::Local<v8::Value> WorkerContextExecutionProxy::evaluate(const String& script, const String& fileName, int baseLine)
 {
+    LOCK_V8;
     v8::HandleScope hs;
 
     initContextIfNeeded();
@@ -394,6 +400,7 @@
         newListener = V8WorkerContextObjectEventListener::create(this, v8::Local<v8::Object>::Cast(object), isInline);
     else
         newListener = V8WorkerContextEventListener::create(this, v8::Local<v8::Object>::Cast(object), isInline);
+
     m_listeners->add(newListener.get());
 
     return newListener.release();
diff --git a/WebCore/config.h b/WebCore/config.h
index 24a4e6a..c921d68 100644
--- a/WebCore/config.h
+++ b/WebCore/config.h
@@ -105,6 +105,8 @@
 #define ENABLE_SVG 0
 #undef ENABLE_WORKERS
 #define ENABLE_WORKERS 1
+#undef ENABLE_V8_LOCKERS
+#define ENABLE_V8_LOCKERS 1
 #endif
 #if ENABLE_SVG
 #if !defined(ENABLE_SVG_ANIMATION)