| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gin/public/isolate_holder.h" | 5 #include "gin/public/isolate_holder.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 13 #include "gin/array_buffer.h" | 13 #include "gin/array_buffer.h" |
| 14 #include "gin/function_template.h" | 14 #include "gin/function_template.h" |
| 15 #include "gin/per_isolate_data.h" | 15 #include "gin/per_isolate_data.h" |
| 16 #include "gin/public/v8_platform.h" |
| 16 | 17 |
| 17 namespace gin { | 18 namespace gin { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 bool GenerateEntropy(unsigned char* buffer, size_t amount) { | 22 bool GenerateEntropy(unsigned char* buffer, size_t amount) { |
| 22 base::RandBytes(buffer, amount); | 23 base::RandBytes(buffer, amount); |
| 23 return true; | 24 return true; |
| 24 } | 25 } |
| 25 | 26 |
| 26 | 27 |
| 27 void EnsureV8Initialized(bool gin_managed) { | 28 void EnsureV8Initialized(bool gin_managed) { |
| 28 static bool v8_is_initialized = false; | 29 static bool v8_is_initialized = false; |
| 29 static bool v8_is_gin_managed = false; | 30 static bool v8_is_gin_managed = false; |
| 30 if (v8_is_initialized) { | 31 if (v8_is_initialized) { |
| 31 CHECK_EQ(v8_is_gin_managed, gin_managed); | 32 CHECK_EQ(v8_is_gin_managed, gin_managed); |
| 32 return; | 33 return; |
| 33 } | 34 } |
| 34 v8_is_initialized = true; | 35 v8_is_initialized = true; |
| 35 v8_is_gin_managed = gin_managed; | 36 v8_is_gin_managed = gin_managed; |
| 36 if (!gin_managed) | 37 if (!gin_managed) |
| 37 return; | 38 return; |
| 38 | 39 |
| 40 v8::V8::InitializePlatform(V8Platform::Get()); |
| 39 v8::V8::SetArrayBufferAllocator(ArrayBufferAllocator::SharedInstance()); | 41 v8::V8::SetArrayBufferAllocator(ArrayBufferAllocator::SharedInstance()); |
| 40 static const char v8_flags[] = "--use_strict --harmony"; | 42 static const char v8_flags[] = "--use_strict --harmony"; |
| 41 v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1); | 43 v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1); |
| 42 v8::V8::SetEntropySource(&GenerateEntropy); | 44 v8::V8::SetEntropySource(&GenerateEntropy); |
| 43 v8::V8::Initialize(); | 45 v8::V8::Initialize(); |
| 44 } | 46 } |
| 45 | 47 |
| 46 } // namespace | 48 } // namespace |
| 47 | 49 |
| 48 IsolateHolder::IsolateHolder() | 50 IsolateHolder::IsolateHolder() |
| (...skipping 20 matching lines...) Expand all Loading... |
| 69 isolate_->Dispose(); | 71 isolate_->Dispose(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void IsolateHolder::Init(v8::ArrayBuffer::Allocator* allocator) { | 74 void IsolateHolder::Init(v8::ArrayBuffer::Allocator* allocator) { |
| 73 v8::Isolate::Scope isolate_scope(isolate_); | 75 v8::Isolate::Scope isolate_scope(isolate_); |
| 74 v8::HandleScope handle_scope(isolate_); | 76 v8::HandleScope handle_scope(isolate_); |
| 75 isolate_data_.reset(new PerIsolateData(isolate_, allocator)); | 77 isolate_data_.reset(new PerIsolateData(isolate_, allocator)); |
| 76 } | 78 } |
| 77 | 79 |
| 78 } // namespace gin | 80 } // namespace gin |
| OLD | NEW |