Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 | 53 |
| 54 typedef WTF::Vector<DOMDataStore*> DOMDataStoreList; | 54 typedef WTF::Vector<DOMDataStore*> DOMDataStoreList; |
| 55 | 55 |
| 56 // Used to hold data that is associated with a single v8::Isolate object, and | 56 // Used to hold data that is associated with a single v8::Isolate object, and |
| 57 // has a 1:1 relationship with v8::Isolate. | 57 // has a 1:1 relationship with v8::Isolate. |
| 58 class PLATFORM_EXPORT V8PerIsolateData { | 58 class PLATFORM_EXPORT V8PerIsolateData { |
| 59 USING_FAST_MALLOC(V8PerIsolateData); | 59 USING_FAST_MALLOC(V8PerIsolateData); |
| 60 WTF_MAKE_NONCOPYABLE(V8PerIsolateData); | 60 WTF_MAKE_NONCOPYABLE(V8PerIsolateData); |
| 61 | 61 |
| 62 public: | 62 public: |
| 63 enum class V8ContextSnapshotMode { | |
| 64 kTakeSnapshot, | |
| 65 kDontUseSnapshot, | |
| 66 kUseSnapshot, | |
| 67 }; | |
| 68 | |
| 63 class EndOfScopeTask { | 69 class EndOfScopeTask { |
| 64 USING_FAST_MALLOC(EndOfScopeTask); | 70 USING_FAST_MALLOC(EndOfScopeTask); |
| 65 | 71 |
| 66 public: | 72 public: |
| 67 virtual ~EndOfScopeTask() {} | 73 virtual ~EndOfScopeTask() {} |
| 68 virtual void Run() = 0; | 74 virtual void Run() = 0; |
| 69 }; | 75 }; |
| 70 | 76 |
| 71 // Disables the UseCounter. | 77 // Disables the UseCounter. |
| 72 // UseCounter depends on the current context, but it's not available during | 78 // UseCounter depends on the current context, but it's not available during |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 94 }; | 100 }; |
| 95 | 101 |
| 96 // Use this class to abstract away types of members that are pointers to core/ | 102 // Use this class to abstract away types of members that are pointers to core/ |
| 97 // objects, which are simply owned and released by V8PerIsolateData (see | 103 // objects, which are simply owned and released by V8PerIsolateData (see |
| 98 // m_threadDebugger for an example). | 104 // m_threadDebugger for an example). |
| 99 class PLATFORM_EXPORT Data { | 105 class PLATFORM_EXPORT Data { |
| 100 public: | 106 public: |
| 101 virtual ~Data() = default; | 107 virtual ~Data() = default; |
| 102 }; | 108 }; |
| 103 | 109 |
| 104 static v8::Isolate* Initialize(WebTaskRunner*); | 110 static v8::Isolate* Initialize(WebTaskRunner*, |
| 111 intptr_t* refernce_table, | |
| 112 V8ContextSnapshotMode); | |
| 105 | 113 |
| 106 static V8PerIsolateData* From(v8::Isolate* isolate) { | 114 static V8PerIsolateData* From(v8::Isolate* isolate) { |
| 107 DCHECK(isolate); | 115 DCHECK(isolate); |
| 108 DCHECK(isolate->GetData(gin::kEmbedderBlink)); | 116 DCHECK(isolate->GetData(gin::kEmbedderBlink)); |
| 109 return static_cast<V8PerIsolateData*>( | 117 return static_cast<V8PerIsolateData*>( |
| 110 isolate->GetData(gin::kEmbedderBlink)); | 118 isolate->GetData(gin::kEmbedderBlink)); |
| 111 } | 119 } |
| 112 | 120 |
| 113 static void WillBeDestroyed(v8::Isolate*); | 121 static void WillBeDestroyed(v8::Isolate*); |
| 114 static void Destroy(v8::Isolate*); | 122 static void Destroy(v8::Isolate*); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 137 | 145 |
| 138 V8PrivateProperty* PrivateProperty() { return private_property_.get(); } | 146 V8PrivateProperty* PrivateProperty() { return private_property_.get(); } |
| 139 | 147 |
| 140 // Accessors to the cache of interface templates. | 148 // Accessors to the cache of interface templates. |
| 141 v8::Local<v8::FunctionTemplate> FindInterfaceTemplate(const DOMWrapperWorld&, | 149 v8::Local<v8::FunctionTemplate> FindInterfaceTemplate(const DOMWrapperWorld&, |
| 142 const void* key); | 150 const void* key); |
| 143 void SetInterfaceTemplate(const DOMWrapperWorld&, | 151 void SetInterfaceTemplate(const DOMWrapperWorld&, |
| 144 const void* key, | 152 const void* key, |
| 145 v8::Local<v8::FunctionTemplate>); | 153 v8::Local<v8::FunctionTemplate>); |
| 146 | 154 |
| 155 // When v8::SnapshotCreator::CreateBlob() is called, we must not have | |
| 156 // persistent handles in Blink. This method clears them. | |
| 157 void ClearPersistentsForV8ContextSnapshot(); | |
| 158 | |
| 159 v8::SnapshotCreator* GetSnapshotCreator() const { | |
| 160 return isolate_holder_.snapshot_creator(); | |
| 161 } | |
| 162 V8ContextSnapshotMode GetV8ContextSnapshotMode() const { | |
| 163 return v8_context_snapshot_mode_; | |
| 164 } | |
| 165 | |
| 147 // Accessor to the cache of cross-origin accessible operation's templates. | 166 // Accessor to the cache of cross-origin accessible operation's templates. |
| 148 // Created templates get automatically cached. | 167 // Created templates get automatically cached. |
| 149 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate( | 168 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate( |
| 150 const DOMWrapperWorld&, | 169 const DOMWrapperWorld&, |
| 151 const void* key, | 170 const void* key, |
| 152 v8::FunctionCallback, | 171 v8::FunctionCallback, |
| 153 v8::Local<v8::Value> data, | 172 v8::Local<v8::Value> data, |
| 154 v8::Local<v8::Signature>, | 173 v8::Local<v8::Signature>, |
| 155 int length); | 174 int length); |
| 156 | 175 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 | 236 |
| 218 void SetScriptWrappableVisitor( | 237 void SetScriptWrappableVisitor( |
| 219 std::unique_ptr<ScriptWrappableVisitor> visitor) { | 238 std::unique_ptr<ScriptWrappableVisitor> visitor) { |
| 220 script_wrappable_visitor_ = std::move(visitor); | 239 script_wrappable_visitor_ = std::move(visitor); |
| 221 } | 240 } |
| 222 ScriptWrappableVisitor* GetScriptWrappableVisitor() { | 241 ScriptWrappableVisitor* GetScriptWrappableVisitor() { |
| 223 return script_wrappable_visitor_.get(); | 242 return script_wrappable_visitor_.get(); |
| 224 } | 243 } |
| 225 | 244 |
| 226 private: | 245 private: |
| 227 explicit V8PerIsolateData(WebTaskRunner*); | 246 V8PerIsolateData(WebTaskRunner*, |
| 247 intptr_t* reference_table, | |
| 248 V8ContextSnapshotMode); | |
| 249 explicit V8PerIsolateData(intptr_t* reference_table); | |
| 228 ~V8PerIsolateData(); | 250 ~V8PerIsolateData(); |
| 229 | 251 |
| 230 typedef HashMap<const void*, v8::Eternal<v8::FunctionTemplate>> | 252 using V8FunctionTemplateMap = |
| 231 V8FunctionTemplateMap; | 253 HashMap<const void*, v8::Eternal<v8::FunctionTemplate>>; |
| 232 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&); | 254 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&); |
| 233 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&); | 255 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&); |
| 234 bool HasInstance(const WrapperTypeInfo* untrusted, | 256 bool HasInstance(const WrapperTypeInfo* untrusted, |
| 235 v8::Local<v8::Value>, | 257 v8::Local<v8::Value>, |
| 236 V8FunctionTemplateMap&); | 258 V8FunctionTemplateMap&); |
| 237 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*, | 259 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*, |
| 238 v8::Local<v8::Value>, | 260 v8::Local<v8::Value>, |
| 239 V8FunctionTemplateMap&); | 261 V8FunctionTemplateMap&); |
| 240 | 262 |
| 263 V8ContextSnapshotMode v8_context_snapshot_mode_; | |
| 241 gin::IsolateHolder isolate_holder_; | 264 gin::IsolateHolder isolate_holder_; |
|
haraken
2017/07/10 06:52:09
// This isolate_holder_ must be initialized before
peria
2017/07/10 10:18:44
Done.
| |
| 242 | 265 |
| 243 // m_interfaceTemplateMapFor{,Non}MainWorld holds function templates for | 266 // interface_template_map_for_{,non_}main_world holds function templates for |
| 244 // the inerface objects. | 267 // the inerface objects. |
| 245 V8FunctionTemplateMap interface_template_map_for_main_world_; | 268 V8FunctionTemplateMap interface_template_map_for_main_world_; |
| 246 V8FunctionTemplateMap interface_template_map_for_non_main_world_; | 269 V8FunctionTemplateMap interface_template_map_for_non_main_world_; |
| 270 | |
| 247 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for | 271 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for |
| 248 // the cross-origin accessible DOM operations. | 272 // the cross-origin accessible DOM operations. |
| 249 V8FunctionTemplateMap operation_template_map_for_main_world_; | 273 V8FunctionTemplateMap operation_template_map_for_main_world_; |
| 250 V8FunctionTemplateMap operation_template_map_for_non_main_world_; | 274 V8FunctionTemplateMap operation_template_map_for_non_main_world_; |
| 251 | 275 |
| 252 // Contains lists of eternal names, such as dictionary keys. | 276 // Contains lists of eternal names, such as dictionary keys. |
| 253 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_; | 277 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_; |
| 254 | 278 |
| 279 // Members required for the V8 context snapshot. | |
| 280 // v8::Context is created from this blob data image. This needs to be | |
| 281 // instantiated before |isolate_holder_| gets instantiated. | |
| 282 v8::StartupData startup_data_; | |
| 283 // When taking a V8 context snapshot, we can't keep V8 objects with eternal | |
| 284 // handles. So we use a special interface map that doesn't use eternal handles | |
| 285 // instead of the default V8FunctionTemplateMap. | |
| 286 V8GlobalValueMap<const WrapperTypeInfo*, v8::FunctionTemplate, v8::kNotWeak> | |
| 287 interface_template_map_for_v8_context_snapshot_; | |
| 288 | |
| 255 std::unique_ptr<StringCache> string_cache_; | 289 std::unique_ptr<StringCache> string_cache_; |
| 256 std::unique_ptr<V8PrivateProperty> private_property_; | 290 std::unique_ptr<V8PrivateProperty> private_property_; |
| 257 RefPtr<ScriptState> script_regexp_script_state_; | 291 RefPtr<ScriptState> script_regexp_script_state_; |
| 258 | 292 |
| 259 bool constructor_mode_; | 293 bool constructor_mode_; |
| 260 friend class ConstructorMode; | 294 friend class ConstructorMode; |
| 261 | 295 |
| 262 bool use_counter_disabled_; | 296 bool use_counter_disabled_; |
| 263 friend class UseCounterDisabledScope; | 297 friend class UseCounterDisabledScope; |
| 264 | 298 |
| 265 bool is_handling_recursion_level_error_; | 299 bool is_handling_recursion_level_error_; |
| 266 bool is_reporting_exception_; | 300 bool is_reporting_exception_; |
| 267 | 301 |
| 268 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_; | 302 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_; |
| 269 std::unique_ptr<Data> thread_debugger_; | 303 std::unique_ptr<Data> thread_debugger_; |
| 270 | 304 |
| 271 Persistent<ActiveScriptWrappableSet> active_script_wrappables_; | 305 Persistent<ActiveScriptWrappableSet> active_script_wrappables_; |
| 272 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_; | 306 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_; |
| 273 | 307 |
| 274 RuntimeCallStats runtime_call_stats_; | 308 RuntimeCallStats runtime_call_stats_; |
| 275 }; | 309 }; |
| 276 | 310 |
| 277 } // namespace blink | 311 } // namespace blink |
| 278 | 312 |
| 279 #endif // V8PerIsolateData_h | 313 #endif // V8PerIsolateData_h |
| OLD | NEW |