Diff
Modified: trunk/Source/WebCore/ChangeLog (88728 => 88729)
--- trunk/Source/WebCore/ChangeLog 2011-06-13 22:56:57 UTC (rev 88728)
+++ trunk/Source/WebCore/ChangeLog 2011-06-13 23:06:56 UTC (rev 88729)
@@ -1,3 +1,39 @@
+2011-06-13 Dmitry Lomov <[email protected]>
+
+ Reviewed by Adam Barth.
+
+ https://bugs.webkit.org/show_bug.cgi?id=62345
+ Use per-isolate embedder data instead of statics for caches in bindings.
+ This is a prerequisite for more than one v8 isolate per process.
+
+ * bindings/scripts/CodeGeneratorV8.pm:
+ * bindings/v8/IDBBindingUtilities.cpp:
+ (WebCore::createIDBKeyFromSerializedValueAndKeyPath):
+ (WebCore::injectIDBKeyIntoSerializedValue):
+ * bindings/v8/V8Binding.cpp:
+ (WebCore::V8BindingPerIsolateData::V8BindingPerIsolateData):
+ (WebCore::V8BindingPerIsolateData::~V8BindingPerIsolateData):
+ (WebCore::V8BindingPerIsolateData::create):
+ (WebCore::V8BindingPerIsolateData::ensureInitialized):
+ (WebCore::V8BindingPerIsolateData::dispose):
+ (WebCore::getToStringName):
+ (WebCore::getToStringTemplate):
+ * bindings/v8/V8Binding.h:
+ (WebCore::V8BindingPerIsolateData::get):
+ (WebCore::V8BindingPerIsolateData::current):
+ (WebCore::V8BindingPerIsolateData::rawTemplateMap):
+ (WebCore::V8BindingPerIsolateData::templateMap):
+ (WebCore::V8BindingPerIsolateData::toStringName):
+ (WebCore::V8BindingPerIsolateData::toStringTemplate):
+ * bindings/v8/V8DOMWindowShell.cpp:
+ (WebCore::V8DOMWindowShell::initContextIfNeeded):
+ * bindings/v8/V8Utilities.cpp:
+ (WebCore::V8LocalContext::V8LocalContext):
+ (WebCore::V8LocalContext::~V8LocalContext):
+ * bindings/v8/V8Utilities.h:
+ * bindings/v8/WorkerContextExecutionProxy.cpp:
+ (WebCore::WorkerContextExecutionProxy::initV8IfNeeded):
+
2011-06-13 Caio Marcelo de Oliveira Filho <[email protected]>
Reviewed by Adam Barth.
Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm (88728 => 88729)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm 2011-06-13 22:56:57 UTC (rev 88728)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm 2011-06-13 23:06:56 UTC (rev 88729)
@@ -2201,14 +2201,29 @@
v8::Persistent<v8::FunctionTemplate> ${className}::GetRawTemplate()
{
- static v8::Persistent<v8::FunctionTemplate> ${className}RawCache = createRawTemplate();
- return ${className}RawCache;
+ V8BindingPerIsolateData* data = ""
+ V8BindingPerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
+ if (result != data->rawTemplateMap().end())
+ return result->second;
+
+ v8::HandleScope handleScope;
+ v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
+ data->rawTemplateMap().add(&info, templ);
+ return templ;
}
-v8::Persistent<v8::FunctionTemplate> ${className}::GetTemplate()\
+v8::Persistent<v8::FunctionTemplate> ${className}::GetTemplate()
{
- static v8::Persistent<v8::FunctionTemplate> ${className}Cache = Configure${className}Template(GetRawTemplate());
- return ${className}Cache;
+ V8BindingPerIsolateData* data = ""
+ V8BindingPerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
+ if (result != data->templateMap().end())
+ return result->second;
+
+ v8::HandleScope handleScope;
+ v8::Persistent<v8::FunctionTemplate> templ =
+ Configure${className}Template(GetRawTemplate());
+ data->templateMap().add(&info, templ);
+ return templ;
}
bool ${className}::HasInstance(v8::Handle<v8::Value> value)
Modified: trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.cpp (88728 => 88729)
--- trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.cpp 2011-06-13 22:56:57 UTC (rev 88728)
+++ trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.cpp 2011-06-13 23:06:56 UTC (rev 88729)
@@ -98,25 +98,6 @@
return false;
}
-class LocalContext {
-public:
- LocalContext()
- : m_context(v8::Context::New())
- {
- m_context->Enter();
- }
-
- ~LocalContext()
- {
- m_context->Exit();
- m_context.Dispose();
- }
-
-private:
- v8::HandleScope m_scope;
- v8::Persistent<v8::Context> m_context;
-};
-
v8::Handle<v8::Value> getNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const Vector<IDBKeyPathElement>& keyPathElements, size_t index)
{
v8::Handle<v8::Value> currentValue(rootValue);
@@ -134,7 +115,7 @@
PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> value, const Vector<IDBKeyPathElement>& keyPath)
{
- LocalContext localContext;
+ V8LocalContext localContext;
v8::Handle<v8::Value> v8Value(value->deserialize());
v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPath, keyPath.size()));
if (v8Key.IsEmpty())
@@ -144,7 +125,7 @@
PassRefPtr<SerializedScriptValue> injectIDBKeyIntoSerializedValue(PassRefPtr<IDBKey> key, PassRefPtr<SerializedScriptValue> value, const Vector<IDBKeyPathElement>& keyPath)
{
- LocalContext localContext;
+ V8LocalContext localContext;
if (!keyPath.size())
return 0;
Modified: trunk/Source/WebCore/bindings/v8/V8Binding.cpp (88728 => 88729)
--- trunk/Source/WebCore/bindings/v8/V8Binding.cpp 2011-06-13 22:56:57 UTC (rev 88728)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.cpp 2011-06-13 23:06:56 UTC (rev 88729)
@@ -47,6 +47,40 @@
namespace WebCore {
+
+V8BindingPerIsolateData::V8BindingPerIsolateData(v8::Isolate* isolate)
+{
+}
+
+V8BindingPerIsolateData::~V8BindingPerIsolateData()
+{
+}
+
+V8BindingPerIsolateData* V8BindingPerIsolateData::create(v8::Isolate* isolate)
+{
+ ASSERT(isolate);
+ ASSERT(!isolate->GetData());
+ V8BindingPerIsolateData* data = "" V8BindingPerIsolateData(isolate);
+ isolate->SetData(data);
+ return data;
+}
+
+void V8BindingPerIsolateData::ensureInitialized(v8::Isolate* isolate)
+{
+ ASSERT(isolate);
+ if (!isolate->GetData())
+ create(isolate);
+}
+
+void V8BindingPerIsolateData::dispose(v8::Isolate* isolate)
+{
+ void* data = ""
+ delete static_cast<V8BindingPerIsolateData*>(data);
+ isolate->SetData(0);
+}
+
+
+
// WebCoreStringResource is a helper class for v8ExternalString. It is used
// to manage the life-cycle of the underlying buffer of the external string.
class WebCoreStringResource : public v8::String::ExternalStringResource {
@@ -540,10 +574,11 @@
v8::Persistent<v8::String> getToStringName()
{
- DEFINE_STATIC_LOCAL(v8::Persistent<v8::String>, value, ());
- if (value.IsEmpty())
- value = v8::Persistent<v8::String>::New(v8::String::New("toString"));
- return value;
+ v8::Persistent<v8::String>& toStringName = V8BindingPerIsolateData::current()->toStringName();
+ if (toStringName.IsEmpty())
+ toStringName = v8::Persistent<v8::String>::New(v8::String::New("toString"));
+ return *toStringName;
+
}
static v8::Handle<v8::Value> constructorToString(const v8::Arguments& args)
@@ -564,7 +599,7 @@
v8::Persistent<v8::FunctionTemplate> getToStringTemplate()
{
- DEFINE_STATIC_LOCAL(v8::Persistent<v8::FunctionTemplate>, toStringTemplate, ());
+ v8::Persistent<v8::FunctionTemplate>& toStringTemplate = V8BindingPerIsolateData::current()->toStringTemplate();
if (toStringTemplate.IsEmpty())
toStringTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(constructorToString));
return toStringTemplate;
Modified: trunk/Source/WebCore/bindings/v8/V8Binding.h (88728 => 88729)
--- trunk/Source/WebCore/bindings/v8/V8Binding.h 2011-06-13 22:56:57 UTC (rev 88728)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.h 2011-06-13 23:06:56 UTC (rev 88729)
@@ -50,6 +50,40 @@
};
typedef BindingSecurity<V8Binding> V8BindingSecurity;
+ class V8BindingPerIsolateData {
+ public:
+ static V8BindingPerIsolateData* create(v8::Isolate*);
+ static void ensureInitialized(v8::Isolate*);
+ static V8BindingPerIsolateData* get(v8::Isolate* isolate)
+ {
+ ASSERT(isolate->GetData());
+ return static_cast<V8BindingPerIsolateData*>(isolate->GetData());
+ }
+
+ static V8BindingPerIsolateData* current()
+ {
+ return get(v8::Isolate::GetCurrent());
+ }
+ static void dispose(v8::Isolate*);
+
+ typedef HashMap<WrapperTypeInfo*, v8::Persistent<v8::FunctionTemplate> > TemplateMap;
+
+ TemplateMap& rawTemplateMap() { return m_rawTemplates; }
+ TemplateMap& templateMap() { return m_templates; }
+ v8::Persistent<v8::String>& toStringName() { return m_toStringName; }
+ v8::Persistent<v8::FunctionTemplate>& toStringTemplate() { return m_toStringTemplate; }
+
+ private:
+ explicit V8BindingPerIsolateData(v8::Isolate*);
+ ~V8BindingPerIsolateData();
+
+ TemplateMap m_rawTemplates;
+ TemplateMap m_templates;
+ v8::Persistent<v8::String> m_toStringName;
+ v8::Persistent<v8::FunctionTemplate> m_toStringTemplate;
+ };
+
+
enum ExternalMode {
Externalize,
DoNotExternalize
Modified: trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp (88728 => 88729)
--- trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp 2011-06-13 22:56:57 UTC (rev 88728)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp 2011-06-13 23:06:56 UTC (rev 88729)
@@ -299,11 +299,12 @@
v8::V8::SetFailedAccessCheckCallbackFunction(reportUnsafeJavaScriptAccess);
ScriptProfiler::initialize();
-
+
+ V8BindingPerIsolateData::ensureInitialized(v8::Isolate::GetCurrent());
+
isV8Initialized = true;
}
-
m_context = createNewContext(m_global, 0);
if (m_context.IsEmpty())
return false;
Modified: trunk/Source/WebCore/bindings/v8/V8Utilities.cpp (88728 => 88729)
--- trunk/Source/WebCore/bindings/v8/V8Utilities.cpp 2011-06-13 22:56:57 UTC (rev 88728)
+++ trunk/Source/WebCore/bindings/v8/V8Utilities.cpp 2011-06-13 23:06:56 UTC (rev 88729)
@@ -48,6 +48,19 @@
namespace WebCore {
+V8LocalContext::V8LocalContext()
+{
+ V8BindingPerIsolateData::ensureInitialized(v8::Isolate::GetCurrent());
+ m_context.set(v8::Context::New());
+ m_context.get()->Enter();
+}
+
+
+V8LocalContext::~V8LocalContext()
+{
+ m_context.get()->Exit();
+}
+
// Use an array to hold dependents. It works like a ref-counted scheme.
// A value can be added more than once to the DOM object.
void createHiddenDependency(v8::Handle<v8::Object> object, v8::Local<v8::Value> value, int cacheIndex)
Modified: trunk/Source/WebCore/bindings/v8/V8Utilities.h (88728 => 88729)
--- trunk/Source/WebCore/bindings/v8/V8Utilities.h 2011-06-13 22:56:57 UTC (rev 88728)
+++ trunk/Source/WebCore/bindings/v8/V8Utilities.h 2011-06-13 23:06:56 UTC (rev 88729)
@@ -34,6 +34,8 @@
#include <wtf/Forward.h>
#include <v8.h>
+#include "OwnHandle.h"
+
namespace WebCore {
class EventListener;
@@ -64,6 +66,15 @@
typedef unsigned CallbackAllowedValueFlags;
+ class V8LocalContext {
+ public:
+ V8LocalContext();
+ virtual ~V8LocalContext();
+ private:
+ v8::HandleScope m_handleScope;
+ OwnHandle<v8::Context> m_context;
+ };
+
// 'FunctionOnly' is assumed for the created callback.
template <typename V8CallbackType>
PassRefPtr<V8CallbackType> createFunctionOnlyCallback(v8::Local<v8::Value> value, bool& succeeded, CallbackAllowedValueFlags acceptedValues = 0)
Modified: trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp (88728 => 88729)
--- trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp 2011-06-13 22:56:57 UTC (rev 88728)
+++ trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp 2011-06-13 23:06:56 UTC (rev 88729)
@@ -124,6 +124,8 @@
resource_constraints.set_stack_limit(&here - kWorkerMaxStackSize / sizeof(uint32_t*));
v8::SetResourceConstraints(&resource_constraints);
+ V8BindingPerIsolateData::create(v8::Isolate::GetCurrent());
+
v8Initialized = true;
}
Modified: trunk/Source/WebKit/chromium/ChangeLog (88728 => 88729)
--- trunk/Source/WebKit/chromium/ChangeLog 2011-06-13 22:56:57 UTC (rev 88728)
+++ trunk/Source/WebKit/chromium/ChangeLog 2011-06-13 23:06:56 UTC (rev 88729)
@@ -1,3 +1,14 @@
+2011-06-13 Dmitry Lomov <[email protected]>
+
+ Reviewed by Adam Barth.
+
+ https://bugs.webkit.org/show_bug.cgi?id=62345
+ Use per-isolate embedder data instead of statics for caches in bindings.
+ This is a prerequisite for more than one v8 isolate per process.
+
+ * tests/IDBBindingUtilitiesTest.cpp:
+ (WebCore::TEST):
+
2011-06-13 Lei Zhang <[email protected]>
Reviewed by Darin Fisher.
Property changes on: trunk/Source/WebKit/chromium/ChangeLog
___________________________________________________________________
Deleted: svn:executable
Modified: trunk/Source/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp (88728 => 88729)
--- trunk/Source/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp 2011-06-13 22:56:57 UTC (rev 88728)
+++ trunk/Source/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp 2011-06-13 23:06:56 UTC (rev 88729)
@@ -28,6 +28,7 @@
#include "IDBKey.h"
#include "IDBKeyPath.h"
#include "SerializedScriptValue.h"
+#include "V8Utilities.h"
#include <gtest/gtest.h>
#include <wtf/Vector.h>
@@ -38,25 +39,6 @@
namespace {
-class LocalContext {
-public:
- LocalContext()
- : m_context(v8::Context::New())
- {
- m_context->Enter();
- }
-
- virtual ~LocalContext()
- {
- m_context->Exit();
- m_context.Dispose();
- }
-
-private:
- v8::HandleScope m_scope;
- v8::Persistent<v8::Context> m_context;
-};
-
PassRefPtr<IDBKey> checkKeyFromValueAndKeyPathInternal(SerializedScriptValue* value, const String& keyPath)
{
Vector<IDBKeyPathElement> idbKeyPath;
@@ -113,7 +95,7 @@
TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyStringValue)
{
- LocalContext v8context;
+ V8LocalContext v8context;
v8::Local<v8::Object> object = v8::Object::New();
object->Set(v8::String::New("foo"), v8::String::New("zoo"));
@@ -126,7 +108,7 @@
TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyNumberValue)
{
- LocalContext v8context;
+ V8LocalContext v8context;
v8::Local<v8::Object> object = v8::Object::New();
object->Set(v8::String::New("foo"), v8::Number::New(456));
@@ -139,7 +121,7 @@
TEST(IDBKeyFromValueAndKeyPathTest, TopLevelArrayElement)
{
- LocalContext v8context;
+ V8LocalContext v8context;
v8::Local<v8::Array> array = v8::Array::New();
array->Set(3, v8::String::New("zoo"));
@@ -152,7 +134,7 @@
TEST(IDBKeyFromValueAndKeyPathTest, SubProperty)
{
- LocalContext v8context;
+ V8LocalContext v8context;
v8::Local<v8::Object> object = v8::Object::New();
v8::Local<v8::Object> subProperty = v8::Object::New();
subProperty->Set(v8::String::New("bar"), v8::String::New("zee"));
@@ -167,7 +149,7 @@
TEST(IDBKeyFromValueAndKeyPathTest, Array2D)
{
- LocalContext v8context;
+ V8LocalContext v8context;
v8::Local<v8::Object> object = v8::Object::New();
v8::Local<v8::Array> array = v8::Array::New();
v8::Local<v8::Array> subArray = v8::Array::New();
@@ -184,7 +166,7 @@
TEST(InjectIDBKeyTest, TopLevelPropertyStringValue)
{
- LocalContext v8context;
+ V8LocalContext v8context;
v8::Local<v8::Object> object = v8::Object::New();
object->Set(v8::String::New("foo"), v8::String::New("zoo"));
@@ -197,7 +179,7 @@
TEST(InjectIDBKeyTest, TopLevelArrayElement)
{
- LocalContext v8context;
+ V8LocalContext v8context;
v8::Local<v8::Array> array = v8::Array::New();
array->Set(3, v8::String::New("zoo"));
@@ -210,7 +192,7 @@
TEST(InjectIDBKeyTest, SubProperty)
{
- LocalContext v8context;
+ V8LocalContext v8context;
v8::Local<v8::Object> object = v8::Object::New();
v8::Local<v8::Object> subProperty = v8::Object::New();
subProperty->Set(v8::String::New("bar"), v8::String::New("zee"));
@@ -227,7 +209,7 @@
TEST(InjectIDBKeyTest, Array2D)
{
- LocalContext v8context;
+ V8LocalContext v8context;
v8::Local<v8::Object> object = v8::Object::New();
v8::Local<v8::Array> array = v8::Array::New();
v8::Local<v8::Array> subArray = v8::Array::New();