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

Unified Diff: gin/isolate_holder.cc

Issue 553903003: Refactor IsolateHolder to be able to always create the isolate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gin/array_buffer.h ('k') | gin/public/isolate_holder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/isolate_holder.cc
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc
index d0ebbb84bf274055c474b7f9d077ccc6a7d5e947..8655c4bd7f79f64da7eb98b478ff297847784471 100644
--- a/gin/isolate_holder.cc
+++ b/gin/isolate_holder.cc
@@ -24,8 +24,7 @@ bool GenerateEntropy(unsigned char* buffer, size_t amount) {
return true;
}
-void EnsureV8Initialized(gin::IsolateHolder::ScriptMode mode,
- bool gin_managed) {
+void EnsureV8Initialized(bool gin_managed) {
static bool v8_is_initialized = false;
static bool v8_is_gin_managed = false;
if (v8_is_initialized) {
@@ -34,24 +33,13 @@ void EnsureV8Initialized(gin::IsolateHolder::ScriptMode mode,
}
v8_is_initialized = true;
v8_is_gin_managed = gin_managed;
- if (!gin_managed)
- return;
-
- v8::V8::InitializePlatform(V8Platform::Get());
- v8::V8::SetArrayBufferAllocator(ArrayBufferAllocator::SharedInstance());
- if (mode == gin::IsolateHolder::kStrictMode) {
- static const char v8_flags[] = "--use_strict";
- v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1);
- }
- v8::V8::SetEntropySource(&GenerateEntropy);
- v8::V8::Initialize();
}
} // namespace
-IsolateHolder::IsolateHolder(ScriptMode mode)
+IsolateHolder::IsolateHolder()
: isolate_owner_(true) {
- EnsureV8Initialized(mode, true);
+ EnsureV8Initialized(true);
isolate_ = v8::Isolate::New();
v8::ResourceConstraints constraints;
constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
@@ -64,7 +52,7 @@ IsolateHolder::IsolateHolder(ScriptMode mode)
IsolateHolder::IsolateHolder(v8::Isolate* isolate,
v8::ArrayBuffer::Allocator* allocator)
: isolate_owner_(false), isolate_(isolate) {
- EnsureV8Initialized(kNonStrictMode, false);
+ EnsureV8Initialized(false);
Init(allocator);
}
@@ -74,6 +62,23 @@ IsolateHolder::~IsolateHolder() {
isolate_->Dispose();
}
+// static
+void IsolateHolder::Initialize(ScriptMode mode,
+ v8::ArrayBuffer::Allocator* allocator) {
+ static bool v8_is_initialized = false;
+ if (v8_is_initialized)
+ return;
+ v8::V8::InitializePlatform(V8Platform::Get());
+ v8::V8::SetArrayBufferAllocator(allocator);
+ if (mode == gin::IsolateHolder::kStrictMode) {
+ static const char v8_flags[] = "--use_strict";
+ v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1);
+ }
+ v8::V8::SetEntropySource(&GenerateEntropy);
+ v8::V8::Initialize();
+ v8_is_initialized = true;
+}
+
void IsolateHolder::Init(v8::ArrayBuffer::Allocator* allocator) {
v8::Isolate::Scope isolate_scope(isolate_);
v8::HandleScope handle_scope(isolate_);
« no previous file with comments | « gin/array_buffer.h ('k') | gin/public/isolate_holder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698