diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-08 23:58:15 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-08 23:58:15 +0000 |
commit | 6b395fee22239c0fedd1974ea4fad5a5031fc469 (patch) | |
tree | 91e4cb28ea1500dcf6abc88dbc2d8d0e4f758b4f /gin | |
parent | 193149cfeb82bf67a677cade990249e5dd7ebf23 (diff) | |
download | chromium_src-6b395fee22239c0fedd1974ea4fad5a5031fc469.zip chromium_src-6b395fee22239c0fedd1974ea4fad5a5031fc469.tar.gz chromium_src-6b395fee22239c0fedd1974ea4fad5a5031fc469.tar.bz2 |
Make net use v8 through gin
- no longer try to use the default isolate (we want to remove it from v8)
- add the option to gin to manage an isolate in non-strict mode
BUG=359977
R=eroman@chromium.org,abarth@chromium.org
Review URL: https://codereview.chromium.org/227233006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262559 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin')
-rw-r--r-- | gin/isolate_holder.cc | 17 | ||||
-rw-r--r-- | gin/public/isolate_holder.h | 8 | ||||
-rw-r--r-- | gin/shell/gin_main.cc | 2 | ||||
-rw-r--r-- | gin/shell_runner_unittest.cc | 2 | ||||
-rw-r--r-- | gin/test/file_runner.cc | 2 | ||||
-rw-r--r-- | gin/test/v8_test.cc | 2 |
6 files changed, 21 insertions, 12 deletions
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc index 3bda7f5..805ab27 100644 --- a/gin/isolate_holder.cc +++ b/gin/isolate_holder.cc @@ -24,8 +24,8 @@ bool GenerateEntropy(unsigned char* buffer, size_t amount) { return true; } - -void EnsureV8Initialized(bool gin_managed) { +void EnsureV8Initialized(gin::IsolateHolder::ScriptMode mode, + bool gin_managed) { static bool v8_is_initialized = false; static bool v8_is_gin_managed = false; if (v8_is_initialized) { @@ -39,17 +39,20 @@ void EnsureV8Initialized(bool gin_managed) { v8::V8::InitializePlatform(V8Platform::Get()); v8::V8::SetArrayBufferAllocator(ArrayBufferAllocator::SharedInstance()); - static const char v8_flags[] = "--use_strict --harmony"; - v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1); + if (mode == gin::IsolateHolder::kStrictMode) { + // TODO(jochen): drop --harmony. it's really too unstable and broad to use. + 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 -IsolateHolder::IsolateHolder() +IsolateHolder::IsolateHolder(ScriptMode mode) : isolate_owner_(true) { - EnsureV8Initialized(true); + EnsureV8Initialized(mode, true); isolate_ = v8::Isolate::New(); v8::ResourceConstraints constraints; constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(), @@ -61,7 +64,7 @@ IsolateHolder::IsolateHolder() IsolateHolder::IsolateHolder(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator) : isolate_owner_(false), isolate_(isolate) { - EnsureV8Initialized(false); + EnsureV8Initialized(kNonStrictMode, false); Init(allocator); } diff --git a/gin/public/isolate_holder.h b/gin/public/isolate_holder.h index eebafa7..f82a53a 100644 --- a/gin/public/isolate_holder.h +++ b/gin/public/isolate_holder.h @@ -26,7 +26,13 @@ class PerIsolateData; // It is not possible to mix the two. class GIN_EXPORT IsolateHolder { public: - IsolateHolder(); + // Controls whether or not V8 should only accept strict mode scripts. + enum ScriptMode { + kNonStrictMode, + kStrictMode + }; + + explicit IsolateHolder(ScriptMode mode); IsolateHolder(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator); ~IsolateHolder(); diff --git a/gin/shell/gin_main.cc b/gin/shell/gin_main.cc index 6673b6a..8fc9465 100644 --- a/gin/shell/gin_main.cc +++ b/gin/shell/gin_main.cc @@ -61,7 +61,7 @@ int main(int argc, char** argv) { CommandLine::Init(argc, argv); base::i18n::InitializeICU(); - gin::IsolateHolder instance; + gin::IsolateHolder instance(gin::IsolateHolder::kStrictMode); base::MessageLoop message_loop; diff --git a/gin/shell_runner_unittest.cc b/gin/shell_runner_unittest.cc index 93c071f..95403ec 100644 --- a/gin/shell_runner_unittest.cc +++ b/gin/shell_runner_unittest.cc @@ -19,7 +19,7 @@ namespace gin { TEST(RunnerTest, Run) { std::string source = "this.result = 'PASS';\n"; - gin::IsolateHolder instance; + gin::IsolateHolder instance(gin::IsolateHolder::kStrictMode); ShellRunnerDelegate delegate; Isolate* isolate = instance.isolate(); diff --git a/gin/test/file_runner.cc b/gin/test/file_runner.cc index 858fb39..c2d3510 100644 --- a/gin/test/file_runner.cc +++ b/gin/test/file_runner.cc @@ -55,7 +55,7 @@ void RunTestFromFile(const base::FilePath& path, FileRunnerDelegate* delegate, base::MessageLoop message_loop; - gin::IsolateHolder instance; + gin::IsolateHolder instance(gin::IsolateHolder::kStrictMode); gin::ShellRunner runner(delegate, instance.isolate()); { gin::Runner::Scope scope(&runner); diff --git a/gin/test/v8_test.cc b/gin/test/v8_test.cc index 95f4e74..c27154b 100644 --- a/gin/test/v8_test.cc +++ b/gin/test/v8_test.cc @@ -19,7 +19,7 @@ V8Test::~V8Test() { } void V8Test::SetUp() { - instance_.reset(new gin::IsolateHolder); + instance_.reset(new gin::IsolateHolder(gin::IsolateHolder::kStrictMode)); instance_->isolate()->Enter(); HandleScope handle_scope(instance_->isolate()); context_.Reset(instance_->isolate(), Context::New(instance_->isolate())); |