Changeset 88729 in webkit
- Timestamp:
- Jun 13, 2011 4:06:56 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r88727 r88729 1 2011-06-13 Dmitry Lomov <dslomov@google.com> 2 3 Reviewed by Adam Barth. 4 5 https://bugs.webkit.org/show_bug.cgi?id=62345 6 Use per-isolate embedder data instead of statics for caches in bindings. 7 This is a prerequisite for more than one v8 isolate per process. 8 9 * bindings/scripts/CodeGeneratorV8.pm: 10 * bindings/v8/IDBBindingUtilities.cpp: 11 (WebCore::createIDBKeyFromSerializedValueAndKeyPath): 12 (WebCore::injectIDBKeyIntoSerializedValue): 13 * bindings/v8/V8Binding.cpp: 14 (WebCore::V8BindingPerIsolateData::V8BindingPerIsolateData): 15 (WebCore::V8BindingPerIsolateData::~V8BindingPerIsolateData): 16 (WebCore::V8BindingPerIsolateData::create): 17 (WebCore::V8BindingPerIsolateData::ensureInitialized): 18 (WebCore::V8BindingPerIsolateData::dispose): 19 (WebCore::getToStringName): 20 (WebCore::getToStringTemplate): 21 * bindings/v8/V8Binding.h: 22 (WebCore::V8BindingPerIsolateData::get): 23 (WebCore::V8BindingPerIsolateData::current): 24 (WebCore::V8BindingPerIsolateData::rawTemplateMap): 25 (WebCore::V8BindingPerIsolateData::templateMap): 26 (WebCore::V8BindingPerIsolateData::toStringName): 27 (WebCore::V8BindingPerIsolateData::toStringTemplate): 28 * bindings/v8/V8DOMWindowShell.cpp: 29 (WebCore::V8DOMWindowShell::initContextIfNeeded): 30 * bindings/v8/V8Utilities.cpp: 31 (WebCore::V8LocalContext::V8LocalContext): 32 (WebCore::V8LocalContext::~V8LocalContext): 33 * bindings/v8/V8Utilities.h: 34 * bindings/v8/WorkerContextExecutionProxy.cpp: 35 (WebCore::WorkerContextExecutionProxy::initV8IfNeeded): 36 1 37 2011-06-13 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> 2 38 -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
r87138 r88729 2202 2202 v8::Persistent<v8::FunctionTemplate> ${className}::GetRawTemplate() 2203 2203 { 2204 static v8::Persistent<v8::FunctionTemplate> ${className}RawCache = createRawTemplate(); 2205 return ${className}RawCache; 2206 } 2207 2208 v8::Persistent<v8::FunctionTemplate> ${className}::GetTemplate()\ 2209 { 2210 static v8::Persistent<v8::FunctionTemplate> ${className}Cache = Configure${className}Template(GetRawTemplate()); 2211 return ${className}Cache; 2204 V8BindingPerIsolateData* data = V8BindingPerIsolateData::current(); 2205 V8BindingPerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info); 2206 if (result != data->rawTemplateMap().end()) 2207 return result->second; 2208 2209 v8::HandleScope handleScope; 2210 v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate(); 2211 data->rawTemplateMap().add(&info, templ); 2212 return templ; 2213 } 2214 2215 v8::Persistent<v8::FunctionTemplate> ${className}::GetTemplate() 2216 { 2217 V8BindingPerIsolateData* data = V8BindingPerIsolateData::current(); 2218 V8BindingPerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info); 2219 if (result != data->templateMap().end()) 2220 return result->second; 2221 2222 v8::HandleScope handleScope; 2223 v8::Persistent<v8::FunctionTemplate> templ = 2224 Configure${className}Template(GetRawTemplate()); 2225 data->templateMap().add(&info, templ); 2226 return templ; 2212 2227 } 2213 2228 -
trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.cpp
r78721 r88729 99 99 } 100 100 101 class LocalContext {102 public:103 LocalContext()104 : m_context(v8::Context::New())105 {106 m_context->Enter();107 }108 109 ~LocalContext()110 {111 m_context->Exit();112 m_context.Dispose();113 }114 115 private:116 v8::HandleScope m_scope;117 v8::Persistent<v8::Context> m_context;118 };119 120 101 v8::Handle<v8::Value> getNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const Vector<IDBKeyPathElement>& keyPathElements, size_t index) 121 102 { … … 135 116 PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> value, const Vector<IDBKeyPathElement>& keyPath) 136 117 { 137 LocalContext localContext;118 V8LocalContext localContext; 138 119 v8::Handle<v8::Value> v8Value(value->deserialize()); 139 120 v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPath, keyPath.size())); … … 145 126 PassRefPtr<SerializedScriptValue> injectIDBKeyIntoSerializedValue(PassRefPtr<IDBKey> key, PassRefPtr<SerializedScriptValue> value, const Vector<IDBKeyPathElement>& keyPath) 146 127 { 147 LocalContext localContext;128 V8LocalContext localContext; 148 129 if (!keyPath.size()) 149 130 return 0; -
trunk/Source/WebCore/bindings/v8/V8Binding.cpp
r77597 r88729 48 48 namespace WebCore { 49 49 50 51 V8BindingPerIsolateData::V8BindingPerIsolateData(v8::Isolate* isolate) 52 { 53 } 54 55 V8BindingPerIsolateData::~V8BindingPerIsolateData() 56 { 57 } 58 59 V8BindingPerIsolateData* V8BindingPerIsolateData::create(v8::Isolate* isolate) 60 { 61 ASSERT(isolate); 62 ASSERT(!isolate->GetData()); 63 V8BindingPerIsolateData* data = new V8BindingPerIsolateData(isolate); 64 isolate->SetData(data); 65 return data; 66 } 67 68 void V8BindingPerIsolateData::ensureInitialized(v8::Isolate* isolate) 69 { 70 ASSERT(isolate); 71 if (!isolate->GetData()) 72 create(isolate); 73 } 74 75 void V8BindingPerIsolateData::dispose(v8::Isolate* isolate) 76 { 77 void* data = isolate->GetData(); 78 delete static_cast<V8BindingPerIsolateData*>(data); 79 isolate->SetData(0); 80 } 81 82 83 50 84 // WebCoreStringResource is a helper class for v8ExternalString. It is used 51 85 // to manage the life-cycle of the underlying buffer of the external string. … … 541 575 v8::Persistent<v8::String> getToStringName() 542 576 { 543 DEFINE_STATIC_LOCAL(v8::Persistent<v8::String>, value, ()); 544 if (value.IsEmpty()) 545 value = v8::Persistent<v8::String>::New(v8::String::New("toString")); 546 return value; 577 v8::Persistent<v8::String>& toStringName = V8BindingPerIsolateData::current()->toStringName(); 578 if (toStringName.IsEmpty()) 579 toStringName = v8::Persistent<v8::String>::New(v8::String::New("toString")); 580 return *toStringName; 581 547 582 } 548 583 … … 565 600 v8::Persistent<v8::FunctionTemplate> getToStringTemplate() 566 601 { 567 DEFINE_STATIC_LOCAL(v8::Persistent<v8::FunctionTemplate>, toStringTemplate, ());602 v8::Persistent<v8::FunctionTemplate>& toStringTemplate = V8BindingPerIsolateData::current()->toStringTemplate(); 568 603 if (toStringTemplate.IsEmpty()) 569 604 toStringTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(constructorToString)); -
trunk/Source/WebCore/bindings/v8/V8Binding.h
r77597 r88729 51 51 typedef BindingSecurity<V8Binding> V8BindingSecurity; 52 52 53 class V8BindingPerIsolateData { 54 public: 55 static V8BindingPerIsolateData* create(v8::Isolate*); 56 static void ensureInitialized(v8::Isolate*); 57 static V8BindingPerIsolateData* get(v8::Isolate* isolate) 58 { 59 ASSERT(isolate->GetData()); 60 return static_cast<V8BindingPerIsolateData*>(isolate->GetData()); 61 } 62 63 static V8BindingPerIsolateData* current() 64 { 65 return get(v8::Isolate::GetCurrent()); 66 } 67 static void dispose(v8::Isolate*); 68 69 typedef HashMap<WrapperTypeInfo*, v8::Persistent<v8::FunctionTemplate> > TemplateMap; 70 71 TemplateMap& rawTemplateMap() { return m_rawTemplates; } 72 TemplateMap& templateMap() { return m_templates; } 73 v8::Persistent<v8::String>& toStringName() { return m_toStringName; } 74 v8::Persistent<v8::FunctionTemplate>& toStringTemplate() { return m_toStringTemplate; } 75 76 private: 77 explicit V8BindingPerIsolateData(v8::Isolate*); 78 ~V8BindingPerIsolateData(); 79 80 TemplateMap m_rawTemplates; 81 TemplateMap m_templates; 82 v8::Persistent<v8::String> m_toStringName; 83 v8::Persistent<v8::FunctionTemplate> m_toStringTemplate; 84 }; 85 86 53 87 enum ExternalMode { 54 88 Externalize, -
trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp
r85484 r88729 300 300 301 301 ScriptProfiler::initialize(); 302 302 303 V8BindingPerIsolateData::ensureInitialized(v8::Isolate::GetCurrent()); 304 303 305 isV8Initialized = true; 304 306 } 305 306 307 307 308 m_context = createNewContext(m_global, 0); -
trunk/Source/WebCore/bindings/v8/V8Utilities.cpp
r82940 r88729 48 48 49 49 namespace WebCore { 50 51 V8LocalContext::V8LocalContext() 52 { 53 V8BindingPerIsolateData::ensureInitialized(v8::Isolate::GetCurrent()); 54 m_context.set(v8::Context::New()); 55 m_context.get()->Enter(); 56 } 57 58 59 V8LocalContext::~V8LocalContext() 60 { 61 m_context.get()->Exit(); 62 } 50 63 51 64 // Use an array to hold dependents. It works like a ref-counted scheme. -
trunk/Source/WebCore/bindings/v8/V8Utilities.h
r83115 r88729 35 35 #include <v8.h> 36 36 37 #include "OwnHandle.h" 38 37 39 namespace WebCore { 38 40 … … 64 66 65 67 typedef unsigned CallbackAllowedValueFlags; 68 69 class V8LocalContext { 70 public: 71 V8LocalContext(); 72 virtual ~V8LocalContext(); 73 private: 74 v8::HandleScope m_handleScope; 75 OwnHandle<v8::Context> m_context; 76 }; 66 77 67 78 // 'FunctionOnly' is assumed for the created callback. -
trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp
r83900 r88729 125 125 v8::SetResourceConstraints(&resource_constraints); 126 126 127 V8BindingPerIsolateData::create(v8::Isolate::GetCurrent()); 128 127 129 v8Initialized = true; 128 130 } -
trunk/Source/WebKit/chromium/ChangeLog
- Property svn:executable deleted
r88728 r88729 1 2011-06-13 Dmitry Lomov <dslomov@google.com> 2 3 Reviewed by Adam Barth. 4 5 https://bugs.webkit.org/show_bug.cgi?id=62345 6 Use per-isolate embedder data instead of statics for caches in bindings. 7 This is a prerequisite for more than one v8 isolate per process. 8 9 * tests/IDBBindingUtilitiesTest.cpp: 10 (WebCore::TEST): 11 1 12 2011-06-13 Lei Zhang <thestig@chromium.org> 2 13 -
trunk/Source/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp
r83331 r88729 29 29 #include "IDBKeyPath.h" 30 30 #include "SerializedScriptValue.h" 31 #include "V8Utilities.h" 31 32 32 33 #include <gtest/gtest.h> … … 38 39 39 40 namespace { 40 41 class LocalContext {42 public:43 LocalContext()44 : m_context(v8::Context::New())45 {46 m_context->Enter();47 }48 49 virtual ~LocalContext()50 {51 m_context->Exit();52 m_context.Dispose();53 }54 55 private:56 v8::HandleScope m_scope;57 v8::Persistent<v8::Context> m_context;58 };59 41 60 42 PassRefPtr<IDBKey> checkKeyFromValueAndKeyPathInternal(SerializedScriptValue* value, const String& keyPath) … … 114 96 TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyStringValue) 115 97 { 116 LocalContext v8context;98 V8LocalContext v8context; 117 99 v8::Local<v8::Object> object = v8::Object::New(); 118 100 object->Set(v8::String::New("foo"), v8::String::New("zoo")); … … 127 109 TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyNumberValue) 128 110 { 129 LocalContext v8context;111 V8LocalContext v8context; 130 112 v8::Local<v8::Object> object = v8::Object::New(); 131 113 object->Set(v8::String::New("foo"), v8::Number::New(456)); … … 140 122 TEST(IDBKeyFromValueAndKeyPathTest, TopLevelArrayElement) 141 123 { 142 LocalContext v8context;124 V8LocalContext v8context; 143 125 v8::Local<v8::Array> array = v8::Array::New(); 144 126 array->Set(3, v8::String::New("zoo")); … … 153 135 TEST(IDBKeyFromValueAndKeyPathTest, SubProperty) 154 136 { 155 LocalContext v8context;137 V8LocalContext v8context; 156 138 v8::Local<v8::Object> object = v8::Object::New(); 157 139 v8::Local<v8::Object> subProperty = v8::Object::New(); … … 168 150 TEST(IDBKeyFromValueAndKeyPathTest, Array2D) 169 151 { 170 LocalContext v8context;152 V8LocalContext v8context; 171 153 v8::Local<v8::Object> object = v8::Object::New(); 172 154 v8::Local<v8::Array> array = v8::Array::New(); … … 185 167 TEST(InjectIDBKeyTest, TopLevelPropertyStringValue) 186 168 { 187 LocalContext v8context;169 V8LocalContext v8context; 188 170 v8::Local<v8::Object> object = v8::Object::New(); 189 171 object->Set(v8::String::New("foo"), v8::String::New("zoo")); … … 198 180 TEST(InjectIDBKeyTest, TopLevelArrayElement) 199 181 { 200 LocalContext v8context;182 V8LocalContext v8context; 201 183 v8::Local<v8::Array> array = v8::Array::New(); 202 184 array->Set(3, v8::String::New("zoo")); … … 211 193 TEST(InjectIDBKeyTest, SubProperty) 212 194 { 213 LocalContext v8context;195 V8LocalContext v8context; 214 196 v8::Local<v8::Object> object = v8::Object::New(); 215 197 v8::Local<v8::Object> subProperty = v8::Object::New(); … … 228 210 TEST(InjectIDBKeyTest, Array2D) 229 211 { 230 LocalContext v8context;212 V8LocalContext v8context; 231 213 v8::Local<v8::Object> object = v8::Object::New(); 232 214 v8::Local<v8::Array> array = v8::Array::New();
Note: See TracChangeset
for help on using the changeset viewer.