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

Side by Side Diff: gin/gin.cc

Issue 76353002: Introduce a Gin class instead of using global functions to control gin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gin/gin.h ('k') | gin/gin.gyp » ('j') | gin/runner_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « gin/gin.h ('k') | gin/gin.gyp » ('j') | gin/runner_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698