OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/base/module_system_test.h" | 5 #include "chrome/test/base/module_system_test.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 void RegisterModule(const std::string& name, const std::string& source) { | 114 void RegisterModule(const std::string& name, const std::string& source) { |
115 CHECK_EQ(0u, source_map_.count(name)) << "Module " << name << " not found"; | 115 CHECK_EQ(0u, source_map_.count(name)) << "Module " << name << " not found"; |
116 source_map_[name] = source; | 116 source_map_[name] = source; |
117 } | 117 } |
118 | 118 |
119 private: | 119 private: |
120 std::map<std::string, std::string> source_map_; | 120 std::map<std::string, std::string> source_map_; |
121 }; | 121 }; |
122 | 122 |
123 ModuleSystemTest::ModuleSystemTest() | 123 ModuleSystemTest::ModuleSystemTest() |
124 : isolate_(v8::Isolate::GetCurrent()), | 124 : isolate_holder_(v8::Isolate::GetCurrent(), NULL), |
not at google - send to devlin
2014/07/01 18:13:05
actually test requireAsync somewhere?
Sam McNally
2014/07/02 03:26:35
Done.
| |
125 handle_scope_(isolate_), | 125 context_holder_(isolate_holder_.isolate()), |
126 context_( | 126 handle_scope_(isolate_holder_.isolate()), |
127 new extensions::ChromeV8Context( | |
128 v8::Context::New( | |
129 isolate_, | |
130 g_v8_extension_configurator.Get().GetConfiguration()), | |
131 NULL, // WebFrame | |
132 NULL, // Extension | |
133 extensions::Feature::UNSPECIFIED_CONTEXT)), | |
134 source_map_(new StringSourceMap()), | 127 source_map_(new StringSourceMap()), |
135 should_assertions_be_made_(true) { | 128 should_assertions_be_made_(true) { |
129 context_holder_.SetContext( | |
130 v8::Context::New(isolate_holder_.isolate(), | |
131 g_v8_extension_configurator.Get().GetConfiguration())); | |
132 context_.reset(new extensions::ChromeV8Context( | |
133 context_holder_.context(), | |
134 NULL, // WebFrame | |
135 NULL, // Extension | |
136 extensions::Feature::UNSPECIFIED_CONTEXT)); | |
136 context_->v8_context()->Enter(); | 137 context_->v8_context()->Enter(); |
137 assert_natives_ = new AssertNatives(context_.get()); | 138 assert_natives_ = new AssertNatives(context_.get()); |
138 | 139 |
139 { | 140 { |
140 scoped_ptr<ModuleSystem> module_system( | 141 scoped_ptr<ModuleSystem> module_system( |
141 new ModuleSystem(context_.get(), source_map_.get())); | 142 new ModuleSystem(context_.get(), source_map_.get())); |
142 context_->set_module_system(module_system.Pass()); | 143 context_->set_module_system(module_system.Pass()); |
143 } | 144 } |
144 ModuleSystem* module_system = context_->module_system(); | 145 ModuleSystem* module_system = context_->module_system(); |
145 module_system->RegisterNativeHandler("assert", scoped_ptr<NativeHandler>( | 146 module_system->RegisterNativeHandler("assert", scoped_ptr<NativeHandler>( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 } | 198 } |
198 | 199 |
199 v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) { | 200 v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) { |
200 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 201 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
201 v8::EscapableHandleScope handle_scope(isolate); | 202 v8::EscapableHandleScope handle_scope(isolate); |
202 v8::Local<v8::Object> object = v8::Object::New(isolate); | 203 v8::Local<v8::Object> object = v8::Object::New(isolate); |
203 isolate->GetCurrentContext()->Global()->Set( | 204 isolate->GetCurrentContext()->Global()->Set( |
204 v8::String::NewFromUtf8(isolate, name.c_str()), object); | 205 v8::String::NewFromUtf8(isolate, name.c_str()), object); |
205 return handle_scope.Escape(object); | 206 return handle_scope.Escape(object); |
206 } | 207 } |
OLD | NEW |