Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: third_party/WebKit/Source/platform/bindings/V8PerIsolateData.cpp

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: . Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 static V8PerIsolateData* g_main_thread_per_isolate_data = 0; 44 static V8PerIsolateData* g_main_thread_per_isolate_data = 0;
45 45
46 static void BeforeCallEnteredCallback(v8::Isolate* isolate) { 46 static void BeforeCallEnteredCallback(v8::Isolate* isolate) {
47 CHECK(!ScriptForbiddenScope::IsScriptForbidden()); 47 CHECK(!ScriptForbiddenScope::IsScriptForbidden());
48 } 48 }
49 49
50 static void MicrotasksCompletedCallback(v8::Isolate* isolate) { 50 static void MicrotasksCompletedCallback(v8::Isolate* isolate) {
51 V8PerIsolateData::From(isolate)->RunEndOfScopeTasks(); 51 V8PerIsolateData::From(isolate)->RunEndOfScopeTasks();
52 } 52 }
53 53
54 V8PerIsolateData::V8PerIsolateData(WebTaskRunner* task_runner) 54 V8PerIsolateData::V8PerIsolateData(WebTaskRunner* task_runner,
55 intptr_t* table,
56 bool take_snapshot)
55 : isolate_holder_( 57 : isolate_holder_(
56 task_runner ? task_runner->ToSingleThreadTaskRunner() : nullptr, 58 task_runner ? task_runner->ToSingleThreadTaskRunner() : nullptr,
57 gin::IsolateHolder::kSingleThread, 59 gin::IsolateHolder::kSingleThread,
58 IsMainThread() ? gin::IsolateHolder::kDisallowAtomicsWait 60 IsMainThread() ? gin::IsolateHolder::kDisallowAtomicsWait
59 : gin::IsolateHolder::kAllowAtomicsWait), 61 : gin::IsolateHolder::kAllowAtomicsWait,
62 table,
63 take_snapshot ? gin::IsolateHolder::kTakeSnapshot
64 : gin::IsolateHolder::kDefault),
60 string_cache_(WTF::WrapUnique(new StringCache(GetIsolate()))), 65 string_cache_(WTF::WrapUnique(new StringCache(GetIsolate()))),
61 private_property_(V8PrivateProperty::Create()), 66 private_property_(V8PrivateProperty::Create()),
62 constructor_mode_(ConstructorMode::kCreateNewObject), 67 constructor_mode_(ConstructorMode::kCreateNewObject),
63 use_counter_disabled_(false), 68 use_counter_disabled_(false),
64 is_handling_recursion_level_error_(false), 69 is_handling_recursion_level_error_(false),
65 is_reporting_exception_(false) { 70 is_reporting_exception_(false) {
66 // FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone. 71 // FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone.
67 GetIsolate()->Enter(); 72 GetIsolate()->Enter();
68 GetIsolate()->AddBeforeCallEnteredCallback(&BeforeCallEnteredCallback); 73 GetIsolate()->AddBeforeCallEnteredCallback(&BeforeCallEnteredCallback);
69 GetIsolate()->AddMicrotasksCompletedCallback(&MicrotasksCompletedCallback); 74 GetIsolate()->AddMicrotasksCompletedCallback(&MicrotasksCompletedCallback);
70 if (IsMainThread()) 75 if (IsMainThread())
71 g_main_thread_per_isolate_data = this; 76 g_main_thread_per_isolate_data = this;
72 } 77 }
73 78
74 V8PerIsolateData::~V8PerIsolateData() {} 79 V8PerIsolateData::~V8PerIsolateData() {}
75 80
76 v8::Isolate* V8PerIsolateData::MainThreadIsolate() { 81 v8::Isolate* V8PerIsolateData::MainThreadIsolate() {
77 DCHECK(g_main_thread_per_isolate_data); 82 DCHECK(g_main_thread_per_isolate_data);
78 return g_main_thread_per_isolate_data->GetIsolate(); 83 return g_main_thread_per_isolate_data->GetIsolate();
79 } 84 }
80 85
81 v8::Isolate* V8PerIsolateData::Initialize(WebTaskRunner* task_runner) { 86 v8::Isolate* V8PerIsolateData::Initialize(WebTaskRunner* task_runner,
82 V8PerIsolateData* data = new V8PerIsolateData(task_runner); 87 intptr_t* table,
88 bool take_snapshot) {
89 V8PerIsolateData* data =
90 new V8PerIsolateData(task_runner, table, take_snapshot);
83 v8::Isolate* isolate = data->GetIsolate(); 91 v8::Isolate* isolate = data->GetIsolate();
84 isolate->SetData(gin::kEmbedderBlink, data); 92 isolate->SetData(gin::kEmbedderBlink, data);
85 return isolate; 93 return isolate;
86 } 94 }
87 95
88 void V8PerIsolateData::EnableIdleTasks( 96 void V8PerIsolateData::EnableIdleTasks(
89 v8::Isolate* isolate, 97 v8::Isolate* isolate,
90 std::unique_ptr<gin::V8IdleTaskRunner> task_runner) { 98 std::unique_ptr<gin::V8IdleTaskRunner> task_runner) {
91 From(isolate)->isolate_holder_.EnableIdleTasks(std::move(task_runner)); 99 From(isolate)->isolate_holder_.EnableIdleTasks(std::move(task_runner));
92 } 100 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 186 }
179 187
180 void V8PerIsolateData::SetInterfaceTemplate( 188 void V8PerIsolateData::SetInterfaceTemplate(
181 const DOMWrapperWorld& world, 189 const DOMWrapperWorld& world,
182 const void* key, 190 const void* key,
183 v8::Local<v8::FunctionTemplate> value) { 191 v8::Local<v8::FunctionTemplate> value) {
184 auto& map = SelectInterfaceTemplateMap(world); 192 auto& map = SelectInterfaceTemplateMap(world);
185 map.insert(key, v8::Eternal<v8::FunctionTemplate>(GetIsolate(), value)); 193 map.insert(key, v8::Eternal<v8::FunctionTemplate>(GetIsolate(), value));
186 } 194 }
187 195
196 v8::Local<v8::FunctionTemplate> V8PerIsolateData::FindInterfaceTemplateTemp(
197 const DOMWrapperWorld& world,
198 const void* key) {
199 auto& map = interface_template_temp_map_;
200 auto result = map.find(key);
201 if (result != map.end())
202 return result->value.Get(GetIsolate());
203 return v8::Local<v8::FunctionTemplate>();
204 }
205
206 void V8PerIsolateData::SetInterfaceTemplateTemp(
207 const DOMWrapperWorld& world,
208 const void* key,
209 v8::Local<v8::FunctionTemplate> value) {
210 auto& map = interface_template_temp_map_;
211 map.insert(key, CopyablePersistent(GetIsolate(), value));
212 }
213
214 void V8PerIsolateData::ClearAll() {
215 interface_template_temp_map_.clear();
216 private_property_.reset();
217 }
218
188 const v8::Eternal<v8::Name>* V8PerIsolateData::FindOrCreateEternalNameCache( 219 const v8::Eternal<v8::Name>* V8PerIsolateData::FindOrCreateEternalNameCache(
189 const void* lookup_key, 220 const void* lookup_key,
190 const char* const names[], 221 const char* const names[],
191 size_t count) { 222 size_t count) {
192 auto it = eternal_name_cache_.find(lookup_key); 223 auto it = eternal_name_cache_.find(lookup_key);
193 const Vector<v8::Eternal<v8::Name>>* vector = nullptr; 224 const Vector<v8::Eternal<v8::Name>>* vector = nullptr;
194 if (UNLIKELY(it == eternal_name_cache_.end())) { 225 if (UNLIKELY(it == eternal_name_cache_.end())) {
195 v8::Isolate* isolate = this->GetIsolate(); 226 v8::Isolate* isolate = this->GetIsolate();
196 Vector<v8::Eternal<v8::Name>> new_vector(count); 227 Vector<v8::Eternal<v8::Name>> new_vector(count);
197 std::transform( 228 std::transform(
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 ScriptWrappableVisitor* current = CurrentVisitor(); 340 ScriptWrappableVisitor* current = CurrentVisitor();
310 if (current) 341 if (current)
311 current->PerformCleanup(); 342 current->PerformCleanup();
312 343
313 V8PerIsolateData::From(isolate_)->script_wrappable_visitor_.swap( 344 V8PerIsolateData::From(isolate_)->script_wrappable_visitor_.swap(
314 saved_visitor_); 345 saved_visitor_);
315 isolate_->SetEmbedderHeapTracer(CurrentVisitor()); 346 isolate_->SetEmbedderHeapTracer(CurrentVisitor());
316 } 347 }
317 348
318 } // namespace blink 349 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698