forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a Gin class instead of using global functions to control gin
The Gin class holds and controls a v8::Isolate. The isolate is not entered by default, i.e. before you can use gin for a given Gin instance, you need to enter the isolate first, e.g. by using a v8::Isolate::Scope. This has the advantage that we don't rely on the deprecate default isolate, and also support having multiple isolates in one process. BUG=317398 R=abarth@chromium.org TEST=gin_unittests and mojo_js_bindings_unittests pass Review URL: https://codereview.chromium.org/76353002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236029 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
jochen@chromium.org
committed
Nov 19, 2013
1 parent
41494f7
commit 1b93c23
Showing
16 changed files
with
149 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// 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. | ||
|
||
#ifndef GIN_GIN_H_ | ||
#define GIN_GIN_H_ | ||
|
||
#include "base/basictypes.h" | ||
|
||
namespace v8 { | ||
class Isolate; | ||
} | ||
|
||
namespace gin { | ||
|
||
class Gin { | ||
public: | ||
Gin(); | ||
~Gin(); | ||
|
||
v8::Isolate* isolate() { return isolate_; } | ||
|
||
private: | ||
v8::Isolate* isolate_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(Gin); | ||
}; | ||
|
||
} // namespace gin | ||
|
||
#endif // GIN_INITIALIZE_H_ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.