Fix MenuButton for the case where multiple listeners are defined.
[chromium-blink-merge.git] / gin / isolate_holder.cc
blobdb4473ec0f9ee3d3976f8521523fd6a5459dbb18
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
3 // found in the LICENSE file.
5 #include "gin/public/isolate_holder.h"
7 #include <stdlib.h>
8 #include <string.h>
10 #include "base/logging.h"
11 #include "base/rand_util.h"
12 #include "base/sys_info.h"
13 #include "gin/array_buffer.h"
14 #include "gin/debug_impl.h"
15 #include "gin/function_template.h"
16 #include "gin/per_isolate_data.h"
17 #include "gin/public/v8_platform.h"
19 namespace gin {
21 namespace {
23 v8::ArrayBuffer::Allocator* g_array_buffer_allocator = NULL;
25 bool GenerateEntropy(unsigned char* buffer, size_t amount) {
26 base::RandBytes(buffer, amount);
27 return true;
30 } // namespace
32 IsolateHolder::IsolateHolder() {
33 CHECK(g_array_buffer_allocator)
34 << "You need to invoke gin::IsolateHolder::Initialize first";
35 v8::Isolate::CreateParams params;
36 params.entry_hook = DebugImpl::GetFunctionEntryHook();
37 params.code_event_handler = DebugImpl::GetJitCodeEventHandler();
38 params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
39 base::SysInfo::AmountOfVirtualMemory(),
40 base::SysInfo::NumberOfProcessors());
41 isolate_ = v8::Isolate::New(params);
42 isolate_data_.reset(new PerIsolateData(isolate_, g_array_buffer_allocator));
45 IsolateHolder::~IsolateHolder() {
46 isolate_data_.reset();
47 isolate_->Dispose();
50 // static
51 void IsolateHolder::Initialize(ScriptMode mode,
52 v8::ArrayBuffer::Allocator* allocator) {
53 CHECK(allocator);
54 static bool v8_is_initialized = false;
55 if (v8_is_initialized)
56 return;
57 v8::V8::InitializePlatform(V8Platform::Get());
58 v8::V8::SetArrayBufferAllocator(allocator);
59 g_array_buffer_allocator = allocator;
60 if (mode == gin::IsolateHolder::kStrictMode) {
61 static const char v8_flags[] = "--use_strict";
62 v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1);
64 v8::V8::SetEntropySource(&GenerateEntropy);
65 v8::V8::Initialize();
66 v8_is_initialized = true;
69 } // namespace gin