OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "gin/gin.h" | |
6 | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 | |
10 #include "base/rand_util.h" | |
11 #include "base/sys_info.h" | |
12 #include "gin/array_buffer.h" | |
13 #include "gin/per_isolate_data.h" | |
14 | |
15 namespace gin { | |
16 | |
17 namespace { | |
18 | |
19 bool GenerateEntropy(unsigned char* buffer, size_t amount) { | |
20 base::RandBytes(buffer, amount); | |
abarth-chromium
2013/11/19 15:49:21
Thanks!
| |
21 return true; | |
22 } | |
23 | |
24 | |
25 void EnsureV8Initialized() { | |
26 static bool v8_is_initialized = false; | |
27 if (v8_is_initialized) | |
28 return; | |
29 v8_is_initialized = true; | |
30 | |
31 v8::V8::SetArrayBufferAllocator(ArrayBufferAllocator::SharedInstance()); | |
32 static const char v8_flags[] = "--use_strict --harmony"; | |
33 v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1); | |
34 v8::V8::SetEntropySource(&GenerateEntropy); | |
35 v8::V8::Initialize(); | |
36 } | |
37 | |
38 } // namespace | |
39 | |
40 Gin::Gin() { | |
41 EnsureV8Initialized(); | |
42 isolate_ = v8::Isolate::New(); | |
43 v8::ResourceConstraints constraints; | |
44 constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory()); | |
45 v8::SetResourceConstraints(isolate_, &constraints); | |
46 v8::Isolate::Scope isolate_scope(isolate_); | |
47 v8::HandleScope handle_scope(isolate_); | |
48 new PerIsolateData(isolate_); | |
49 } | |
50 | |
51 Gin::~Gin() { | |
52 isolate_->Dispose(); | |
53 } | |
54 | |
55 } // namespace gin | |
OLD | NEW |