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 V8ContextMode { | |
|
haraken
2017/07/04 15:04:20
V8ContextMode => V8ContextSnapshotMode ?
peria
2017/07/07 06:22:04
Done.
| |
| 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 V8ContextMode); | |
| 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 ClearPersistentsForV8Snapshot(); | |
| 158 | |
| 159 v8::SnapshotCreator* GetSnapshotCreator() const { | |
| 160 return isolate_holder_.snapshot_creator(); | |
| 161 } | |
| 162 V8ContextMode GetV8ContextMode() const { return v8_context_mode_; } | |
| 163 | |
| 147 // Accessor to the cache of cross-origin accessible operation's templates. | 164 // Accessor to the cache of cross-origin accessible operation's templates. |
| 148 // Created templates get automatically cached. | 165 // Created templates get automatically cached. |
| 149 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate( | 166 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate( |
| 150 const DOMWrapperWorld&, | 167 const DOMWrapperWorld&, |
| 151 const void* key, | 168 const void* key, |
| 152 v8::FunctionCallback, | 169 v8::FunctionCallback, |
| 153 v8::Local<v8::Value> data, | 170 v8::Local<v8::Value> data, |
| 154 v8::Local<v8::Signature>, | 171 v8::Local<v8::Signature>, |
| 155 int length); | 172 int length); |
| 156 | 173 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 | 234 |
| 218 void SetScriptWrappableVisitor( | 235 void SetScriptWrappableVisitor( |
| 219 std::unique_ptr<ScriptWrappableVisitor> visitor) { | 236 std::unique_ptr<ScriptWrappableVisitor> visitor) { |
| 220 script_wrappable_visitor_ = std::move(visitor); | 237 script_wrappable_visitor_ = std::move(visitor); |
| 221 } | 238 } |
| 222 ScriptWrappableVisitor* GetScriptWrappableVisitor() { | 239 ScriptWrappableVisitor* GetScriptWrappableVisitor() { |
| 223 return script_wrappable_visitor_.get(); | 240 return script_wrappable_visitor_.get(); |
| 224 } | 241 } |
| 225 | 242 |
| 226 private: | 243 private: |
| 227 explicit V8PerIsolateData(WebTaskRunner*); | 244 V8PerIsolateData(WebTaskRunner*, intptr_t* reference_table, V8ContextMode); |
| 245 V8PerIsolateData(intptr_t* reference_table); | |
|
haraken
2017/07/04 15:04:20
Add explicit.
peria
2017/07/07 06:22:04
Done.
| |
| 228 ~V8PerIsolateData(); | 246 ~V8PerIsolateData(); |
| 229 | 247 |
| 230 typedef HashMap<const void*, v8::Eternal<v8::FunctionTemplate>> | 248 using V8FunctionTemplateMap = |
| 231 V8FunctionTemplateMap; | 249 HashMap<const void*, v8::Eternal<v8::FunctionTemplate>>; |
| 232 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&); | 250 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&); |
| 233 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&); | 251 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&); |
| 234 bool HasInstance(const WrapperTypeInfo* untrusted, | 252 bool HasInstance(const WrapperTypeInfo* untrusted, |
| 235 v8::Local<v8::Value>, | 253 v8::Local<v8::Value>, |
| 236 V8FunctionTemplateMap&); | 254 V8FunctionTemplateMap&); |
| 237 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*, | 255 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*, |
| 238 v8::Local<v8::Value>, | 256 v8::Local<v8::Value>, |
| 239 V8FunctionTemplateMap&); | 257 V8FunctionTemplateMap&); |
| 240 | 258 |
| 259 V8ContextMode v8_context_mode_; | |
| 241 gin::IsolateHolder isolate_holder_; | 260 gin::IsolateHolder isolate_holder_; |
| 242 | 261 |
| 243 // m_interfaceTemplateMapFor{,Non}MainWorld holds function templates for | 262 // interface_template_map_for_{,non_}main_world holds function templates for |
| 244 // the inerface objects. | 263 // the inerface objects. |
| 245 V8FunctionTemplateMap interface_template_map_for_main_world_; | 264 V8FunctionTemplateMap interface_template_map_for_main_world_; |
| 246 V8FunctionTemplateMap interface_template_map_for_non_main_world_; | 265 V8FunctionTemplateMap interface_template_map_for_non_main_world_; |
| 266 | |
| 247 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for | 267 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for |
| 248 // the cross-origin accessible DOM operations. | 268 // the cross-origin accessible DOM operations. |
| 249 V8FunctionTemplateMap operation_template_map_for_main_world_; | 269 V8FunctionTemplateMap operation_template_map_for_main_world_; |
| 250 V8FunctionTemplateMap operation_template_map_for_non_main_world_; | 270 V8FunctionTemplateMap operation_template_map_for_non_main_world_; |
| 251 | 271 |
| 252 // Contains lists of eternal names, such as dictionary keys. | 272 // Contains lists of eternal names, such as dictionary keys. |
| 253 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_; | 273 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_; |
| 254 | 274 |
| 275 // Members requried for snapshotted context. | |
|
haraken
2017/07/04 15:04:20
required
... for the V8 context snapshot.
peria
2017/07/07 06:22:04
Done.
| |
| 276 // Snapshotted blob data image to create v8::Context's from. Needs to be | |
| 277 // instantiated before |isoalte_holder_| gets instantiated. | |
|
haraken
2017/07/04 15:04:20
// v8::Context is created from this blob data imag
haraken
2017/07/04 15:04:20
isolate_holder_
peria
2017/07/07 06:22:04
Done.
peria
2017/07/07 06:22:04
Done.
| |
| 278 v8::StartupData startup_data_; | |
| 279 // In taking V8 snapshot, we can't keep V8 objects with eternal handles. | |
|
haraken
2017/07/04 15:04:20
// When taking a V8 context snapshot,
peria
2017/07/07 06:22:04
Done.
| |
| 280 // So we keep some function templates with clearable handles when we take | |
| 281 // snapshots. | |
|
haraken
2017/07/04 15:04:20
// So we use a special interface map that doesn't
peria
2017/07/07 06:22:04
Done.
| |
| 282 V8GlobalValueMap<const WrapperTypeInfo*, v8::FunctionTemplate, v8::kNotWeak> | |
| 283 interface_template_map_for_v8_snapshot_; | |
| 284 | |
| 255 std::unique_ptr<StringCache> string_cache_; | 285 std::unique_ptr<StringCache> string_cache_; |
| 256 std::unique_ptr<V8PrivateProperty> private_property_; | 286 std::unique_ptr<V8PrivateProperty> private_property_; |
| 257 RefPtr<ScriptState> script_regexp_script_state_; | 287 RefPtr<ScriptState> script_regexp_script_state_; |
| 258 | 288 |
| 259 bool constructor_mode_; | 289 bool constructor_mode_; |
| 260 friend class ConstructorMode; | 290 friend class ConstructorMode; |
| 261 | 291 |
| 262 bool use_counter_disabled_; | 292 bool use_counter_disabled_; |
| 263 friend class UseCounterDisabledScope; | 293 friend class UseCounterDisabledScope; |
| 264 | 294 |
| 265 bool is_handling_recursion_level_error_; | 295 bool is_handling_recursion_level_error_; |
| 266 bool is_reporting_exception_; | 296 bool is_reporting_exception_; |
| 267 | 297 |
| 268 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_; | 298 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_; |
| 269 std::unique_ptr<Data> thread_debugger_; | 299 std::unique_ptr<Data> thread_debugger_; |
| 270 | 300 |
| 271 Persistent<ActiveScriptWrappableSet> active_script_wrappables_; | 301 Persistent<ActiveScriptWrappableSet> active_script_wrappables_; |
| 272 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_; | 302 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_; |
| 273 | 303 |
| 274 RuntimeCallStats runtime_call_stats_; | 304 RuntimeCallStats runtime_call_stats_; |
| 275 }; | 305 }; |
| 276 | 306 |
| 277 } // namespace blink | 307 } // namespace blink |
| 278 | 308 |
| 279 #endif // V8PerIsolateData_h | 309 #endif // V8PerIsolateData_h |
| OLD | NEW |