Changeset 92694 in webkit
- Timestamp:
- Aug 9, 2011 12:01:05 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r92693 r92694 1 2011-08-09 Dmitry Lomov <dslomov@google.com> 2 3 https://bugs.webkit.org/show_bug.cgi?id=65778 4 [WebWorkers][chromium] Make statics thread-safe and make sure V8 API accesses correct isolates. 5 6 Reviewed by Dmitry Titov. 7 8 Covered by existing tests. 9 10 * bindings/v8/V8Binding.cpp: 11 (WebCore::V8BindingPerIsolateData::V8BindingPerIsolateData): 12 * bindings/v8/V8Binding.h: 13 (WebCore::V8BindingPerIsolateData::lazyEventListenerToStringTemplate): 14 (WebCore::V8BindingPerIsolateData::hiddenPropertyName): 15 (WebCore::V8BindingPerIsolateData::globalHandleMap): 16 (WebCore::AllowAllocation::AllowAllocation):Moving to V8Binding.h from V8Utilities.h to resolve header dependency. 17 (WebCore::AllowAllocation::~AllowAllocation): 18 (WebCore::AllowAllocation::current): 19 (WebCore::SafeAllocation::newInstance): 20 * bindings/v8/V8GCController.cpp: 21 (WebCore::currentGlobalHandleMap): 22 (WebCore::enumerateGlobalHandles): 23 (WebCore::V8GCController::registerGlobalHandle): 24 (WebCore::V8GCController::unregisterGlobalHandle): 25 * bindings/v8/V8HiddenPropertyName.cpp: 26 (WebCore::V8HiddenPropertyName::createString): 27 * bindings/v8/V8HiddenPropertyName.h: 28 (WebCore::V8HiddenPropertyName::V8HiddenPropertyName): 29 * bindings/v8/V8LazyEventListener.cpp: 30 (WebCore::V8LazyEventListener::prepareListenerObject): 31 * bindings/v8/V8NPObject.cpp: 32 * bindings/v8/V8Proxy.cpp: 33 (WebCore::V8Proxy::checkNewLegal): 34 * bindings/v8/V8Utilities.h: 35 * bindings/v8/WorkerContextExecutionProxy.cpp: 36 (WebCore::WorkerContextExecutionProxy::WorkerContextExecutionProxy): 37 (WebCore::WorkerContextExecutionProxy::initIsolate): 38 * bindings/v8/WorkerContextExecutionProxy.h: 39 * bindings/v8/WorkerScriptController.cpp: 40 (WebCore::WorkerScriptController::scheduleExecutionTermination): 41 1 42 2011-08-09 Steve Block <steveblock@google.com> 2 43 -
trunk/Source/WebCore/bindings/v8/V8Binding.cpp
r92068 r92694 52 52 V8BindingPerIsolateData::V8BindingPerIsolateData(v8::Isolate* isolate) 53 53 : m_domDataStore(0) 54 , m_currentAllocationsAllowed(false) 54 55 { 55 56 } -
trunk/Source/WebCore/bindings/v8/V8Binding.h
r92643 r92694 37 37 #include "PlatformString.h" 38 38 #include "V8DOMWrapper.h" 39 #include "V8GCController.h" 40 #include "V8HiddenPropertyName.h" 39 41 #include <wtf/text/AtomicString.h> 40 42 … … 86 88 }; 87 89 90 class AllowAllocation; 91 92 #ifndef NDEBUG 93 typedef HashMap<v8::Value*, GlobalHandleInfo*> GlobalHandleMap; 94 #endif 95 88 96 class V8BindingPerIsolateData { 89 97 public: … … 108 116 v8::Persistent<v8::String>& toStringName() { return m_toStringName; } 109 117 v8::Persistent<v8::FunctionTemplate>& toStringTemplate() { return m_toStringTemplate; } 118 119 v8::Persistent<v8::FunctionTemplate>& lazyEventListenerToStringTemplate() 120 { 121 return m_lazyEventListenerToStringTemplate; 122 } 123 110 124 StringCache* stringCache() { return &m_stringCache; } 111 125 112 126 DOMDataList& allStores() { return m_domDataList; } 127 128 V8HiddenPropertyName* hiddenPropertyName() { return &m_hiddenPropertyName; } 113 129 114 130 void registerDOMDataStore(DOMDataStore* domDataStore) … … 127 143 // DOMDataStore is owned outside V8BindingPerIsolateData. 128 144 void setDOMDataStore(DOMDataStore* store) { m_domDataStore = store; } 145 146 #ifndef NDEBUG 147 GlobalHandleMap& globalHandleMap() { return m_globalHandleMap; } 148 #endif 129 149 130 150 private: … … 136 156 v8::Persistent<v8::String> m_toStringName; 137 157 v8::Persistent<v8::FunctionTemplate> m_toStringTemplate; 158 v8::Persistent<v8::FunctionTemplate> m_lazyEventListenerToStringTemplate; 138 159 StringCache m_stringCache; 139 160 140 161 DOMDataList m_domDataList; 141 162 DOMDataStore* m_domDataStore; 142 }; 163 164 V8HiddenPropertyName m_hiddenPropertyName; 165 166 bool m_currentAllocationsAllowed; 167 friend class AllowAllocation; 168 169 #ifndef NDEBUG 170 GlobalHandleMap m_globalHandleMap; 171 #endif 172 }; 173 174 class AllowAllocation { 175 public: 176 AllowAllocation() 177 { 178 V8BindingPerIsolateData* data = V8BindingPerIsolateData::current(); 179 m_previous = data->m_currentAllocationsAllowed; 180 data->m_currentAllocationsAllowed = true; 181 } 182 183 ~AllowAllocation() 184 { 185 V8BindingPerIsolateData* data = V8BindingPerIsolateData::current(); 186 data->m_currentAllocationsAllowed = m_previous; 187 } 188 189 static bool current() { return V8BindingPerIsolateData::current()->m_currentAllocationsAllowed; } 190 191 private: 192 bool m_previous; 193 }; 194 195 class SafeAllocation { 196 public: 197 static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>); 198 static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::ObjectTemplate>); 199 static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]); 200 }; 201 202 v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function) 203 { 204 if (function.IsEmpty()) 205 return v8::Local<v8::Object>(); 206 AllowAllocation allow; 207 return function->NewInstance(); 208 } 209 210 v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::ObjectTemplate> objectTemplate) 211 { 212 if (objectTemplate.IsEmpty()) 213 return v8::Local<v8::Object>(); 214 AllowAllocation allow; 215 return objectTemplate->NewInstance(); 216 } 217 218 v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function, int argc, v8::Handle<v8::Value> argv[]) 219 { 220 if (function.IsEmpty()) 221 return v8::Local<v8::Object>(); 222 AllowAllocation allow; 223 return function->NewInstance(argc, argv); 224 } 225 143 226 144 227 -
trunk/Source/WebCore/bindings/v8/V8GCController.cpp
r92643 r92694 82 82 // #endif 83 83 // 84 typedef HashMap<v8::Value*, GlobalHandleInfo*> GlobalHandleMap; 85 86 static GlobalHandleMap& globalHandleMap() 87 { 88 DEFINE_STATIC_LOCAL(GlobalHandleMap, staticGlobalHandleMap, ()); 89 return staticGlobalHandleMap; 84 85 static GlobalHandleMap& currentGlobalHandleMap() 86 { 87 return V8BindingPerIsolateData::current()->globalHandleMap(); 90 88 } 91 89 … … 94 92 static void enumerateGlobalHandles() 95 93 { 96 for (GlobalHandleMap::iterator it = globalHandleMap().begin(), end = globalHandleMap().end(); it != end; ++it) { 94 GlobalHandleMap& globalHandleMap = currentGlobalHandleMap(); 95 for (GlobalHandleMap::iterator it = globalHandleMap.begin(), end = globalHandleMap.end(); it != end; ++it) { 97 96 GlobalHandleInfo* info = it->second; 98 97 UNUSED_PARAM(info); … … 104 103 void V8GCController::registerGlobalHandle(GlobalHandleType type, void* host, v8::Persistent<v8::Value> handle) 105 104 { 106 ASSERT(!globalHandleMap().contains(*handle)); 107 globalHandleMap().set(*handle, new GlobalHandleInfo(host, type)); 105 GlobalHandleMap& globalHandleMap = currentGlobalHandleMap(); 106 ASSERT(!globalHandleMap.contains(*handle)); 107 globalHandleMap.set(*handle, new GlobalHandleInfo(host, type)); 108 108 } 109 109 110 110 void V8GCController::unregisterGlobalHandle(void* host, v8::Persistent<v8::Value> handle) 111 111 { 112 ASSERT(globalHandleMap().contains(*handle)); 113 GlobalHandleInfo* info = globalHandleMap().take(*handle); 112 GlobalHandleMap& globalHandleMap = currentGlobalHandleMap(); 113 ASSERT(globalHandleMap.contains(*handle)); 114 GlobalHandleInfo* info = globalHandleMap.take(*handle); 114 115 ASSERT(info->m_host == host); 115 116 delete info; -
trunk/Source/WebCore/bindings/v8/V8HiddenPropertyName.cpp
r92643 r92694 32 32 #include "V8HiddenPropertyName.h" 33 33 34 #include "V8Binding.h" 34 35 #include <string.h> 35 36 #include <wtf/Vector.h> … … 43 44 v8::Handle<v8::String> V8HiddenPropertyName::name() \ 44 45 { \ 45 static v8::Persistent<v8::String>* string = createString("WebCore::HiddenProperty::" V8_AS_STRING(name)); \ 46 return *string; \ 46 V8HiddenPropertyName* hiddenPropertyName = V8BindingPerIsolateData::current()->hiddenPropertyName(); \ 47 if (hiddenPropertyName->m_##name.IsEmpty()) { \ 48 hiddenPropertyName->m_##name = createString("WebCore::HiddenProperty::" V8_AS_STRING(name)); \ 49 } \ 50 return hiddenPropertyName->m_##name; \ 47 51 } 48 52 … … 60 64 } 61 65 62 v8::Persistent<v8::String> *V8HiddenPropertyName::createString(const char* key)66 v8::Persistent<v8::String> V8HiddenPropertyName::createString(const char* key) 63 67 { 64 68 v8::HandleScope scope; 65 return new v8::Persistent<v8::String>(v8::Persistent<v8::String>::New(v8::String::NewSymbol(key)));69 return v8::Persistent<v8::String>::New(v8::String::NewSymbol(key)); 66 70 } 67 71 -
trunk/Source/WebCore/bindings/v8/V8HiddenPropertyName.h
r92643 r92694 49 49 class V8HiddenPropertyName { 50 50 public: 51 V8HiddenPropertyName() { } 51 52 #define V8_DECLARE_PROPERTY(name) static v8::Handle<v8::String> name(); 52 53 V8_HIDDEN_PROPERTIES(V8_DECLARE_PROPERTY); … … 56 57 57 58 private: 58 static v8::Persistent<v8::String>* createString(const char* key); 59 static v8::Persistent<v8::String> createString(const char* key); 60 #define V8_DECLARE_FIELD(name) v8::Persistent<v8::String> m_##name; 61 V8_HIDDEN_PROPERTIES(V8_DECLARE_FIELD); 62 #undef V8_DECLARE_FIELD 59 63 }; 60 64 -
trunk/Source/WebCore/bindings/v8/V8LazyEventListener.cpp
r92643 r92694 138 138 // other use. That fails miserably if the actual wrapper source is 139 139 // returned. 140 DEFINE_STATIC_LOCAL(v8::Persistent<v8::FunctionTemplate>, toStringTemplate, ()); 140 v8::Persistent<v8::FunctionTemplate>& toStringTemplate = 141 V8BindingPerIsolateData::current()->lazyEventListenerToStringTemplate(); 141 142 if (toStringTemplate.IsEmpty()) 142 143 toStringTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(V8LazyEventListenerToString)); -
trunk/Source/WebCore/bindings/v8/V8NPObject.cpp
r92643 r92694 35 35 #include "HTMLPlugInElement.h" 36 36 #include "NPV8Object.h" 37 #include "V8Binding.h" 37 38 #include "V8DOMMap.h" 38 39 #include "V8HTMLAppletElement.h" -
trunk/Source/WebCore/bindings/v8/V8Proxy.cpp
r92643 r92694 133 133 typedef HashMap<int, v8::FunctionTemplate*> FunctionTemplateMap; 134 134 135 bool AllowAllocation::m_current = false;136 137 135 static void addMessageToConsole(Page* page, const String& message, const String& sourceID, unsigned lineNumber) 138 136 { … … 784 782 v8::Handle<v8::Value> V8Proxy::checkNewLegal(const v8::Arguments& args) 785 783 { 786 if (!AllowAllocation:: m_current)784 if (!AllowAllocation::current()) 787 785 return throwError(TypeError, "Illegal constructor"); 788 786 -
trunk/Source/WebCore/bindings/v8/V8Utilities.h
r92643 r92694 96 96 } 97 97 98 class AllowAllocation {99 public:100 inline AllowAllocation()101 {102 m_previous = m_current;103 m_current = true;104 }105 106 inline ~AllowAllocation()107 {108 m_current = m_previous;109 }110 111 static bool m_current;112 113 private:114 bool m_previous;115 };116 117 class SafeAllocation {118 public:119 static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>);120 static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::ObjectTemplate>);121 static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]);122 };123 124 v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function)125 {126 if (function.IsEmpty())127 return v8::Local<v8::Object>();128 AllowAllocation allow;129 return function->NewInstance();130 }131 132 v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::ObjectTemplate> objectTemplate)133 {134 if (objectTemplate.IsEmpty())135 return v8::Local<v8::Object>();136 AllowAllocation allow;137 return objectTemplate->NewInstance();138 }139 140 v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function, int argc, v8::Handle<v8::Value> argv[])141 {142 if (function.IsEmpty())143 return v8::Local<v8::Object>();144 AllowAllocation allow;145 return function->NewInstance(argc, argv);146 }147 148 98 } // namespace WebCore 149 99 -
trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp
r92643 r92694 84 84 , m_recursion(0) 85 85 { 86 init V8();86 initIsolate(); 87 87 } 88 88 … … 109 109 } 110 110 111 void WorkerContextExecutionProxy::init V8()111 void WorkerContextExecutionProxy::initIsolate() 112 112 { 113 113 // Tell V8 not to call the default OOM handler, binding code will handle it. 114 114 v8::V8::IgnoreOutOfMemoryException(); 115 115 v8::V8::SetFatalErrorHandler(reportFatalErrorInV8); 116 117 v8::V8::SetGlobalGCPrologueCallback(&V8GCController::gcPrologue); 118 v8::V8::SetGlobalGCEpilogueCallback(&V8GCController::gcEpilogue); 116 119 117 120 v8::ResourceConstraints resource_constraints; -
trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.h
r92643 r92694 74 74 75 75 private: 76 void init V8();76 void initIsolate(); 77 77 bool initContextIfNeeded(); 78 78 void dispose(); -
trunk/Source/WebCore/bindings/v8/WorkerScriptController.cpp
r92643 r92694 95 95 void WorkerScriptController::scheduleExecutionTermination() 96 96 { 97 v8::V8::TerminateExecution( );97 v8::V8::TerminateExecution(m_isolate); 98 98 } 99 99 -
trunk/Source/WebKit/chromium/ChangeLog
r92679 r92694 1 2011-08-09 Dmitry Lomov <dslomov@google.com> 2 3 https://bugs.webkit.org/show_bug.cgi?id=65778 4 [WebWorkers][chromium] Make statics thread-safe and make sure V8 API accesses correct isolates 5 6 Reviewed by Dmitry Titov. 7 8 * src/BoundObject.cpp: 9 1 10 2011-08-09 Jochen Eisinger <jochen@chromium.org> 2 11 -
trunk/Source/WebKit/chromium/src/BoundObject.cpp
r92643 r92694 32 32 #include "BoundObject.h" 33 33 34 #include "V8Binding.h" 34 35 #include "V8Proxy.h" 35 36
Note: See TracChangeset
for help on using the changeset viewer.