Chromium Code Reviews| Index: third_party/WebKit/Source/platform/bindings/V8PerIsolateData.cpp |
| diff --git a/third_party/WebKit/Source/platform/bindings/V8PerIsolateData.cpp b/third_party/WebKit/Source/platform/bindings/V8PerIsolateData.cpp |
| index 19eee733f61eadc76f64c8a9cac86fa1179742cb..5b5c60fe5ccefb324a89048f826ac8491264a367 100644 |
| --- a/third_party/WebKit/Source/platform/bindings/V8PerIsolateData.cpp |
| +++ b/third_party/WebKit/Source/platform/bindings/V8PerIsolateData.cpp |
| @@ -27,6 +27,7 @@ |
| #include <memory> |
| +#include "platform/RuntimeEnabledFeatures.h" |
| #include "platform/ScriptForbiddenScope.h" |
| #include "platform/WebTaskRunner.h" |
| #include "platform/bindings/DOMDataStore.h" |
| @@ -51,12 +52,17 @@ static void MicrotasksCompletedCallback(v8::Isolate* isolate) { |
| V8PerIsolateData::From(isolate)->RunEndOfScopeTasks(); |
| } |
| -V8PerIsolateData::V8PerIsolateData(WebTaskRunner* task_runner) |
| +V8PerIsolateData::V8PerIsolateData( |
| + WebTaskRunner* task_runner, |
| + intptr_t* table, |
| + gin::IsolateHolder::V8ContextMode context_mode) |
| : isolate_holder_( |
| task_runner ? task_runner->ToSingleThreadTaskRunner() : nullptr, |
| gin::IsolateHolder::kSingleThread, |
| IsMainThread() ? gin::IsolateHolder::kDisallowAtomicsWait |
| - : gin::IsolateHolder::kAllowAtomicsWait), |
| + : gin::IsolateHolder::kAllowAtomicsWait, |
| + table, |
| + context_mode), |
| string_cache_(WTF::WrapUnique(new StringCache(GetIsolate()))), |
| private_property_(V8PrivateProperty::Create()), |
| constructor_mode_(ConstructorMode::kCreateNewObject), |
| @@ -78,8 +84,19 @@ v8::Isolate* V8PerIsolateData::MainThreadIsolate() { |
| return g_main_thread_per_isolate_data->GetIsolate(); |
| } |
| -v8::Isolate* V8PerIsolateData::Initialize(WebTaskRunner* task_runner) { |
| - V8PerIsolateData* data = new V8PerIsolateData(task_runner); |
| +v8::Isolate* V8PerIsolateData::Initialize( |
| + WebTaskRunner* task_runner, |
| + intptr_t* table, |
| + gin::IsolateHolder::V8ContextMode context_mode) { |
| + CHECK(context_mode == gin::IsolateHolder::kUseSnapshot || |
| + context_mode == gin::IsolateHolder::kTakeSnapshot); |
| + if (context_mode == gin::IsolateHolder::kUseSnapshot && |
| + !RuntimeEnabledFeatures::v8ContextSnapshotEnabled()) { |
| + context_mode = gin::IsolateHolder::kDefault; |
| + } |
| + |
| + V8PerIsolateData* data = |
| + new V8PerIsolateData(task_runner, table, context_mode); |
| v8::Isolate* isolate = data->GetIsolate(); |
| isolate->SetData(gin::kEmbedderBlink, data); |
| return isolate; |
| @@ -163,6 +180,14 @@ v8::Local<v8::FunctionTemplate> V8PerIsolateData::FindOrCreateOperationTemplate( |
| v8::Local<v8::FunctionTemplate> V8PerIsolateData::FindInterfaceTemplate( |
| const DOMWrapperWorld& world, |
| const void* key) { |
| + if (GetV8ContextMode() == gin::IsolateHolder::kTakeSnapshot) { |
|
haraken
2017/05/20 19:10:03
I don't fully understand this code. Would you help
peria
2017/05/30 08:25:44
We have to remove all references from the embedder
|
| + auto& map = interface_template_persistent_map_; |
| + auto result = map.find(key); |
| + if (result != map.end()) |
| + return result->value.Get(GetIsolate()); |
| + return v8::Local<v8::FunctionTemplate>(); |
| + } |
| + |
| auto& map = SelectInterfaceTemplateMap(world); |
| auto result = map.find(key); |
| if (result != map.end()) |
| @@ -174,8 +199,18 @@ void V8PerIsolateData::SetInterfaceTemplate( |
| const DOMWrapperWorld& world, |
| const void* key, |
| v8::Local<v8::FunctionTemplate> value) { |
| - auto& map = SelectInterfaceTemplateMap(world); |
| - map.insert(key, v8::Eternal<v8::FunctionTemplate>(GetIsolate(), value)); |
| + if (GetV8ContextMode() == gin::IsolateHolder::kTakeSnapshot) { |
| + auto& map = interface_template_persistent_map_; |
| + map.insert(key, CopyablePersistent(GetIsolate(), value)); |
| + } else { |
| + auto& map = SelectInterfaceTemplateMap(world); |
| + map.insert(key, v8::Eternal<v8::FunctionTemplate>(GetIsolate(), value)); |
| + } |
| +} |
| + |
| +void V8PerIsolateData::ClearPersistents() { |
| + interface_template_persistent_map_.clear(); |
| + private_property_.reset(); |
|
haraken
2017/05/20 19:10:03
Why do we need to clear private_property_?
peria
2017/05/30 08:25:44
To clear WindowDocumentCachedAccessor.
https://chr
|
| } |
| const v8::Eternal<v8::Name>* V8PerIsolateData::FindOrCreateEternalNameCache( |