| 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/debug_impl.h" |
| 14 #include "gin/function_template.h" | 15 #include "gin/function_template.h" |
| 15 #include "gin/per_isolate_data.h" | 16 #include "gin/per_isolate_data.h" |
| 16 #include "gin/public/v8_platform.h" | 17 #include "gin/public/v8_platform.h" |
| 17 | 18 |
| 18 namespace gin { | 19 namespace gin { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 v8::ArrayBuffer::Allocator* g_array_buffer_allocator = NULL; | 23 v8::ArrayBuffer::Allocator* g_array_buffer_allocator = NULL; |
| 23 | 24 |
| 24 bool GenerateEntropy(unsigned char* buffer, size_t amount) { | 25 bool GenerateEntropy(unsigned char* buffer, size_t amount) { |
| 25 base::RandBytes(buffer, amount); | 26 base::RandBytes(buffer, amount); |
| 26 return true; | 27 return true; |
| 27 } | 28 } |
| 28 | 29 |
| 29 } // namespace | 30 } // namespace |
| 30 | 31 |
| 31 IsolateHolder::IsolateHolder() { | 32 IsolateHolder::IsolateHolder() { |
| 32 CHECK(g_array_buffer_allocator) | 33 CHECK(g_array_buffer_allocator) |
| 33 << "You need to invoke gin::IsolateHolder::Initialize first"; | 34 << "You need to invoke gin::IsolateHolder::Initialize first"; |
| 34 isolate_ = v8::Isolate::New(); | 35 v8::Isolate::CreateParams params; |
| 36 params.entry_hook = DebugImpl::GetFunctionEntryHook(); |
| 37 params.code_event_handler = DebugImpl::GetJitCodeEventHandler(); |
| 38 isolate_ = v8::Isolate::New(params); |
| 35 v8::ResourceConstraints constraints; | 39 v8::ResourceConstraints constraints; |
| 36 constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(), | 40 constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(), |
| 37 base::SysInfo::AmountOfVirtualMemory(), | 41 base::SysInfo::AmountOfVirtualMemory(), |
| 38 base::SysInfo::NumberOfProcessors()); | 42 base::SysInfo::NumberOfProcessors()); |
| 39 v8::SetResourceConstraints(isolate_, &constraints); | 43 v8::SetResourceConstraints(isolate_, &constraints); |
| 40 isolate_data_.reset(new PerIsolateData(isolate_, g_array_buffer_allocator)); | 44 isolate_data_.reset(new PerIsolateData(isolate_, g_array_buffer_allocator)); |
| 41 } | 45 } |
| 42 | 46 |
| 43 IsolateHolder::~IsolateHolder() { | 47 IsolateHolder::~IsolateHolder() { |
| 44 isolate_data_.reset(); | 48 isolate_data_.reset(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 58 if (mode == gin::IsolateHolder::kStrictMode) { | 62 if (mode == gin::IsolateHolder::kStrictMode) { |
| 59 static const char v8_flags[] = "--use_strict"; | 63 static const char v8_flags[] = "--use_strict"; |
| 60 v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1); | 64 v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1); |
| 61 } | 65 } |
| 62 v8::V8::SetEntropySource(&GenerateEntropy); | 66 v8::V8::SetEntropySource(&GenerateEntropy); |
| 63 v8::V8::Initialize(); | 67 v8::V8::Initialize(); |
| 64 v8_is_initialized = true; | 68 v8_is_initialized = true; |
| 65 } | 69 } |
| 66 | 70 |
| 67 } // namespace gin | 71 } // namespace gin |
| OLD | NEW |