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

Unified 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: updates 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gin/gin.h ('k') | gin/gin.gyp » ('j') | gin/test/file_runner.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/gin.cc
diff --git a/gin/gin.cc b/gin/gin.cc
new file mode 100644
index 0000000000000000000000000000000000000000..28b8d2bb902530bfc8e39a73383cf0abf7c6f34e
--- /dev/null
+++ b/gin/gin.cc
@@ -0,0 +1,55 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gin/gin.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "base/rand_util.h"
+#include "base/sys_info.h"
+#include "gin/array_buffer.h"
+#include "gin/per_isolate_data.h"
+
+namespace gin {
+
+namespace {
+
+bool GenerateEntropy(unsigned char* buffer, size_t amount) {
+ base::RandBytes(buffer, amount);
+ return true;
+}
+
+
+void EnsureV8Initialized() {
+ static bool v8_is_initialized = false;
+ if (v8_is_initialized)
+ return;
+ v8_is_initialized = true;
+
+ v8::V8::SetArrayBufferAllocator(ArrayBufferAllocator::SharedInstance());
+ static const char v8_flags[] = "--use_strict --harmony";
+ v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1);
+ v8::V8::SetEntropySource(&GenerateEntropy);
+ v8::V8::Initialize();
+}
+
+} // namespace
+
+Gin::Gin() {
+ EnsureV8Initialized();
+ isolate_ = v8::Isolate::New();
+ v8::ResourceConstraints constraints;
+ constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory());
+ v8::SetResourceConstraints(isolate_, &constraints);
+ v8::Isolate::Scope isolate_scope(isolate_);
+ v8::HandleScope handle_scope(isolate_);
+ new PerIsolateData(isolate_);
+}
+
+Gin::~Gin() {
+ isolate_->Dispose();
+}
+
+} // namespace gin
« no previous file with comments | « gin/gin.h ('k') | gin/gin.gyp » ('j') | gin/test/file_runner.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698