Diff
Modified: trunk/Source/WebCore/ChangeLog (92618 => 92619)
--- trunk/Source/WebCore/ChangeLog 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebCore/ChangeLog 2011-08-08 19:11:33 UTC (rev 92619)
@@ -1,3 +1,41 @@
+2011-08-08 Dmitry Lomov <[email protected]>
+
+ https://bugs.webkit.org/show_bug.cgi?id=65778
+ [WebWorkers][chromium] Make statics thread-safe and make sure V8 API accesses correct isolates.
+
+ Reviewed by David Levin.
+
+ Covered by existing tests.
+
+ * bindings/v8/V8Binding.h:
+ (WebCore::V8BindingPerIsolateData::lazyEventListenerToStringTemplate):
+ (WebCore::V8BindingPerIsolateData::hiddenPropertyName):
+ (WebCore::V8BindingPerIsolateData::globalHandleMap):
+ (WebCore::AllowAllocation::AllowAllocation): Moving to V8Binding.h from V8Utilities.h to resolve header dependency.
+ (WebCore::AllowAllocation::~AllowAllocation):
+ (WebCore::AllowAllocation::current):
+ (WebCore::SafeAllocation::newInstance):
+ * bindings/v8/V8GCController.cpp:
+ (WebCore::currentGlobalHandleMap):
+ (WebCore::enumerateGlobalHandles):
+ (WebCore::V8GCController::registerGlobalHandle):
+ (WebCore::V8GCController::unregisterGlobalHandle):
+ * bindings/v8/V8HiddenPropertyName.cpp:
+ (WebCore::V8HiddenPropertyName::createString):
+ * bindings/v8/V8HiddenPropertyName.h:
+ * bindings/v8/V8LazyEventListener.cpp:
+ (WebCore::V8LazyEventListener::prepareListenerObject):
+ * bindings/v8/V8NPObject.cpp:
+ * bindings/v8/V8Proxy.cpp:
+ (WebCore::V8Proxy::checkNewLegal):
+ * bindings/v8/V8Utilities.h:
+ * bindings/v8/WorkerContextExecutionProxy.cpp:
+ (WebCore::WorkerContextExecutionProxy::WorkerContextExecutionProxy):
+ (WebCore::WorkerContextExecutionProxy::initIsolate):
+ * bindings/v8/WorkerContextExecutionProxy.h:
+ * bindings/v8/WorkerScriptController.cpp:
+ (WebCore::WorkerScriptController::scheduleExecutionTermination):
+
2011-08-08 Sheriff Bot <[email protected]>
Unreviewed, rolling out r92607.
Modified: trunk/Source/WebCore/bindings/v8/V8Binding.h (92618 => 92619)
--- trunk/Source/WebCore/bindings/v8/V8Binding.h 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.h 2011-08-08 19:11:33 UTC (rev 92619)
@@ -36,6 +36,8 @@
#include "MathExtras.h"
#include "PlatformString.h"
#include "V8DOMWrapper.h"
+#include "V8GCController.h"
+#include "V8HiddenPropertyName.h"
#include <wtf/text/AtomicString.h>
#include <v8.h>
@@ -85,6 +87,12 @@
RefPtr<StringImpl> m_lastStringImpl;
};
+ class AllowAllocation;
+
+#ifndef NDEBUG
+ typedef HashMap<v8::Value*, GlobalHandleInfo*> GlobalHandleMap;
+#endif
+
class V8BindingPerIsolateData {
public:
static V8BindingPerIsolateData* create(v8::Isolate*);
@@ -107,10 +115,18 @@
TemplateMap& templateMap() { return m_templates; }
v8::Persistent<v8::String>& toStringName() { return m_toStringName; }
v8::Persistent<v8::FunctionTemplate>& toStringTemplate() { return m_toStringTemplate; }
+
+ v8::Persistent<v8::FunctionTemplate>& lazyEventListenerToStringTemplate()
+ {
+ return m_lazyEventListenerToStringTemplate;
+ }
+
StringCache* stringCache() { return &m_stringCache; }
DOMDataList& allStores() { return m_domDataList; }
+ V8HiddenPropertyName* hiddenPropertyName() { return &m_hiddenPropertyName; }
+
void registerDOMDataStore(DOMDataStore* domDataStore)
{
m_domDataList.append(domDataStore);
@@ -127,6 +143,10 @@
// DOMDataStore is owned outside V8BindingPerIsolateData.
void setDOMDataStore(DOMDataStore* store) { m_domDataStore = store; }
+#ifndef NDEBUG
+ GlobalHandleMap& globalHandleMap() { return m_globalHandleMap; }
+#endif
+
private:
explicit V8BindingPerIsolateData(v8::Isolate*);
~V8BindingPerIsolateData();
@@ -135,13 +155,76 @@
TemplateMap m_templates;
v8::Persistent<v8::String> m_toStringName;
v8::Persistent<v8::FunctionTemplate> m_toStringTemplate;
+ v8::Persistent<v8::FunctionTemplate> m_lazyEventListenerToStringTemplate;
StringCache m_stringCache;
DOMDataList m_domDataList;
DOMDataStore* m_domDataStore;
+
+ V8HiddenPropertyName m_hiddenPropertyName;
+
+ bool m_currentAllocationsAllowed;
+ friend class AllowAllocation;
+
+#ifndef NDEBUG
+ GlobalHandleMap m_globalHandleMap;
+#endif
};
+ class AllowAllocation {
+ public:
+ AllowAllocation()
+ {
+ V8BindingPerIsolateData* data = ""
+ m_previous = data->m_currentAllocationsAllowed;
+ data->m_currentAllocationsAllowed = true;
+ }
+ ~AllowAllocation()
+ {
+ V8BindingPerIsolateData* data = ""
+ data->m_currentAllocationsAllowed = m_previous;
+ }
+
+ static bool current() { return V8BindingPerIsolateData::current()->m_currentAllocationsAllowed; }
+
+ private:
+ bool m_previous;
+ };
+
+ class SafeAllocation {
+ public:
+ static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>);
+ static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::ObjectTemplate>);
+ static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]);
+ };
+
+ v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function)
+ {
+ if (function.IsEmpty())
+ return v8::Local<v8::Object>();
+ AllowAllocation allow;
+ return function->NewInstance();
+ }
+
+ v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::ObjectTemplate> objectTemplate)
+ {
+ if (objectTemplate.IsEmpty())
+ return v8::Local<v8::Object>();
+ AllowAllocation allow;
+ return objectTemplate->NewInstance();
+ }
+
+ v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function, int argc, v8::Handle<v8::Value> argv[])
+ {
+ if (function.IsEmpty())
+ return v8::Local<v8::Object>();
+ AllowAllocation allow;
+ return function->NewInstance(argc, argv);
+ }
+
+
+
enum ExternalMode {
Externalize,
DoNotExternalize
Modified: trunk/Source/WebCore/bindings/v8/V8GCController.cpp (92618 => 92619)
--- trunk/Source/WebCore/bindings/v8/V8GCController.cpp 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebCore/bindings/v8/V8GCController.cpp 2011-08-08 19:11:33 UTC (rev 92619)
@@ -81,19 +81,18 @@
// V8GCController::unregisterGlobalHandle(type, host, handle);
// #endif
//
-typedef HashMap<v8::Value*, GlobalHandleInfo*> GlobalHandleMap;
-static GlobalHandleMap& globalHandleMap()
+static GlobalHandleMap& currentGlobalHandleMap()
{
- DEFINE_STATIC_LOCAL(GlobalHandleMap, staticGlobalHandleMap, ());
- return staticGlobalHandleMap;
+ return V8BindingPerIsolateData::current()->globalHandleMap();
}
// The function is the place to set the break point to inspect
// live global handles. Leaks are often come from leaked global handles.
static void enumerateGlobalHandles()
{
- for (GlobalHandleMap::iterator it = globalHandleMap().begin(), end = globalHandleMap().end(); it != end; ++it) {
+ GlobalHandleMap& globalHandleMap = currentGlobalHandleMap();
+ for (GlobalHandleMap::iterator it = globalHandleMap.begin(), end = globalHandleMap.end(); it != end; ++it) {
GlobalHandleInfo* info = it->second;
UNUSED_PARAM(info);
v8::Value* handle = it->first;
@@ -103,14 +102,16 @@
void V8GCController::registerGlobalHandle(GlobalHandleType type, void* host, v8::Persistent<v8::Value> handle)
{
- ASSERT(!globalHandleMap().contains(*handle));
- globalHandleMap().set(*handle, new GlobalHandleInfo(host, type));
+ GlobalHandleMap& globalHandleMap = currentGlobalHandleMap();
+ ASSERT(!globalHandleMap.contains(*handle));
+ globalHandleMap.set(*handle, new GlobalHandleInfo(host, type));
}
void V8GCController::unregisterGlobalHandle(void* host, v8::Persistent<v8::Value> handle)
{
- ASSERT(globalHandleMap().contains(*handle));
- GlobalHandleInfo* info = globalHandleMap().take(*handle);
+ GlobalHandleMap& globalHandleMap = currentGlobalHandleMap();
+ ASSERT(globalHandleMap.contains(*handle));
+ GlobalHandleInfo* info = globalHandleMap.take(*handle);
ASSERT(info->m_host == host);
delete info;
}
Modified: trunk/Source/WebCore/bindings/v8/V8HiddenPropertyName.cpp (92618 => 92619)
--- trunk/Source/WebCore/bindings/v8/V8HiddenPropertyName.cpp 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebCore/bindings/v8/V8HiddenPropertyName.cpp 2011-08-08 19:11:33 UTC (rev 92619)
@@ -31,6 +31,7 @@
#include "config.h"
#include "V8HiddenPropertyName.h"
+#include "V8Binding.h"
#include <string.h>
#include <wtf/Vector.h>
@@ -42,8 +43,11 @@
#define V8_DEFINE_PROPERTY(name) \
v8::Handle<v8::String> V8HiddenPropertyName::name() \
{ \
- static v8::Persistent<v8::String>* string = createString("WebCore::HiddenProperty::" V8_AS_STRING(name)); \
- return *string; \
+ V8HiddenPropertyName* hiddenPropertyName = V8BindingPerIsolateData::current()->hiddenPropertyName(); \
+ if (hiddenPropertyName->m_##name.IsEmpty()) { \
+ hiddenPropertyName->m_##name = createString("WebCore::HiddenProperty::" V8_AS_STRING(name)); \
+ } \
+ return hiddenPropertyName->m_##name; \
}
V8_HIDDEN_PROPERTIES(V8_DEFINE_PROPERTY);
@@ -59,10 +63,10 @@
return v8::String::NewSymbol(prefixedName.data(), static_cast<int>(prefixedName.size()));
}
-v8::Persistent<v8::String>* V8HiddenPropertyName::createString(const char* key)
+v8::Persistent<v8::String> V8HiddenPropertyName::createString(const char* key)
{
v8::HandleScope scope;
- return new v8::Persistent<v8::String>(v8::Persistent<v8::String>::New(v8::String::NewSymbol(key)));
+ return v8::Persistent<v8::String>::New(v8::String::NewSymbol(key));
}
} // namespace WebCore
Modified: trunk/Source/WebCore/bindings/v8/V8HiddenPropertyName.h (92618 => 92619)
--- trunk/Source/WebCore/bindings/v8/V8HiddenPropertyName.h 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebCore/bindings/v8/V8HiddenPropertyName.h 2011-08-08 19:11:33 UTC (rev 92619)
@@ -55,7 +55,10 @@
static v8::Handle<v8::String> hiddenReferenceName(const char* name);
private:
- static v8::Persistent<v8::String>* createString(const char* key);
+ static v8::Persistent<v8::String> createString(const char* key);
+#define V8_DECLARE_FIELD(name) v8::Persistent<v8::String> m_##name;
+ V8_HIDDEN_PROPERTIES(V8_DECLARE_FIELD);
+#undef V8_DECLARE_FIELD
};
}
Modified: trunk/Source/WebCore/bindings/v8/V8LazyEventListener.cpp (92618 => 92619)
--- trunk/Source/WebCore/bindings/v8/V8LazyEventListener.cpp 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebCore/bindings/v8/V8LazyEventListener.cpp 2011-08-08 19:11:33 UTC (rev 92619)
@@ -137,7 +137,8 @@
// source returned (sometimes a RegExp is applied as well) for some
// other use. That fails miserably if the actual wrapper source is
// returned.
- DEFINE_STATIC_LOCAL(v8::Persistent<v8::FunctionTemplate>, toStringTemplate, ());
+ v8::Persistent<v8::FunctionTemplate>& toStringTemplate =
+ V8BindingPerIsolateData::current()->lazyEventListenerToStringTemplate();
if (toStringTemplate.IsEmpty())
toStringTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(V8LazyEventListenerToString));
v8::Local<v8::Function> toStringFunction;
Modified: trunk/Source/WebCore/bindings/v8/V8NPObject.cpp (92618 => 92619)
--- trunk/Source/WebCore/bindings/v8/V8NPObject.cpp 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebCore/bindings/v8/V8NPObject.cpp 2011-08-08 19:11:33 UTC (rev 92619)
@@ -34,6 +34,7 @@
#include "HTMLPlugInElement.h"
#include "NPV8Object.h"
+#include "V8Binding.h"
#include "V8DOMMap.h"
#include "V8HTMLAppletElement.h"
#include "V8HTMLEmbedElement.h"
Modified: trunk/Source/WebCore/bindings/v8/V8Proxy.cpp (92618 => 92619)
--- trunk/Source/WebCore/bindings/v8/V8Proxy.cpp 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebCore/bindings/v8/V8Proxy.cpp 2011-08-08 19:11:33 UTC (rev 92619)
@@ -132,8 +132,6 @@
typedef HashMap<void*, v8::Object*> DOMObjectMap;
typedef HashMap<int, v8::FunctionTemplate*> FunctionTemplateMap;
-bool AllowAllocation::m_current = false;
-
static void addMessageToConsole(Page* page, const String& message, const String& sourceID, unsigned lineNumber)
{
ASSERT(page);
@@ -783,7 +781,7 @@
v8::Handle<v8::Value> V8Proxy::checkNewLegal(const v8::Arguments& args)
{
- if (!AllowAllocation::m_current)
+ if (!AllowAllocation::current())
return throwError(TypeError, "Illegal constructor");
return args.This();
Modified: trunk/Source/WebCore/bindings/v8/V8Utilities.h (92618 => 92619)
--- trunk/Source/WebCore/bindings/v8/V8Utilities.h 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebCore/bindings/v8/V8Utilities.h 2011-08-08 19:11:33 UTC (rev 92619)
@@ -95,56 +95,6 @@
return V8CallbackType::create(value, getScriptExecutionContext());
}
- class AllowAllocation {
- public:
- inline AllowAllocation()
- {
- m_previous = m_current;
- m_current = true;
- }
-
- inline ~AllowAllocation()
- {
- m_current = m_previous;
- }
-
- static bool m_current;
-
- private:
- bool m_previous;
- };
-
- class SafeAllocation {
- public:
- static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>);
- static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::ObjectTemplate>);
- static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]);
- };
-
- v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function)
- {
- if (function.IsEmpty())
- return v8::Local<v8::Object>();
- AllowAllocation allow;
- return function->NewInstance();
- }
-
- v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::ObjectTemplate> objectTemplate)
- {
- if (objectTemplate.IsEmpty())
- return v8::Local<v8::Object>();
- AllowAllocation allow;
- return objectTemplate->NewInstance();
- }
-
- v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function, int argc, v8::Handle<v8::Value> argv[])
- {
- if (function.IsEmpty())
- return v8::Local<v8::Object>();
- AllowAllocation allow;
- return function->NewInstance(argc, argv);
- }
-
} // namespace WebCore
#endif // V8Utilities_h
Modified: trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp (92618 => 92619)
--- trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp 2011-08-08 19:11:33 UTC (rev 92619)
@@ -83,7 +83,7 @@
: m_workerContext(workerContext)
, m_recursion(0)
{
- initV8();
+ initIsolate();
}
WorkerContextExecutionProxy::~WorkerContextExecutionProxy()
@@ -108,12 +108,15 @@
}
}
-void WorkerContextExecutionProxy::initV8()
+void WorkerContextExecutionProxy::initIsolate()
{
// Tell V8 not to call the default OOM handler, binding code will handle it.
v8::V8::IgnoreOutOfMemoryException();
v8::V8::SetFatalErrorHandler(reportFatalErrorInV8);
+ v8::V8::SetGlobalGCPrologueCallback(&V8GCController::gcPrologue);
+ v8::V8::SetGlobalGCEpilogueCallback(&V8GCController::gcEpilogue);
+
v8::ResourceConstraints resource_constraints;
uint32_t here;
resource_constraints.set_stack_limit(&here - kWorkerMaxStackSize / sizeof(uint32_t*));
Modified: trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.h (92618 => 92619)
--- trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.h 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.h 2011-08-08 19:11:33 UTC (rev 92619)
@@ -73,7 +73,7 @@
v8::Local<v8::Context> context() { return v8::Local<v8::Context>::New(m_context); }
private:
- void initV8();
+ void initIsolate();
bool initContextIfNeeded();
void dispose();
Modified: trunk/Source/WebCore/bindings/v8/WorkerScriptController.cpp (92618 => 92619)
--- trunk/Source/WebCore/bindings/v8/WorkerScriptController.cpp 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebCore/bindings/v8/WorkerScriptController.cpp 2011-08-08 19:11:33 UTC (rev 92619)
@@ -94,7 +94,7 @@
void WorkerScriptController::scheduleExecutionTermination()
{
- v8::V8::TerminateExecution();
+ v8::V8::TerminateExecution(m_isolate);
}
void WorkerScriptController::forbidExecution()
Modified: trunk/Source/WebKit/chromium/ChangeLog (92618 => 92619)
--- trunk/Source/WebKit/chromium/ChangeLog 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebKit/chromium/ChangeLog 2011-08-08 19:11:33 UTC (rev 92619)
@@ -1,3 +1,12 @@
+2011-08-08 Dmitry Lomov <[email protected]>
+
+ https://bugs.webkit.org/show_bug.cgi?id=65778
+ [WebWorkers][chromium] Make statics thread-safe and make sure V8 API accesses correct isolates
+
+ Reviewed by David Levin.
+
+ * src/BoundObject.cpp: AllowAllocation moved from V8Utilities.h to V8Binding.h
+
2011-08-08 Sheriff Bot <[email protected]>
Unreviewed, rolling out r92607.
Modified: trunk/Source/WebKit/chromium/src/BoundObject.cpp (92618 => 92619)
--- trunk/Source/WebKit/chromium/src/BoundObject.cpp 2011-08-08 19:09:51 UTC (rev 92618)
+++ trunk/Source/WebKit/chromium/src/BoundObject.cpp 2011-08-08 19:11:33 UTC (rev 92619)
@@ -31,6 +31,7 @@
#include "config.h"
#include "BoundObject.h"
+#include "V8Binding.h"
#include "V8Proxy.h"
namespace WebKit {