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

Unified Diff: gin/modules/module_runner_delegate.cc

Issue 179803007: Refactors parts of gin: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge 2 trunk Created 6 years, 10 months 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
Index: gin/modules/module_runner_delegate.cc
diff --git a/gin/modules/module_runner_delegate.cc b/gin/modules/module_runner_delegate.cc
index 2a9f95cd760575e7be135d2f7f2c4b6482cdcaaf..efc0937046f057fd11967694da7873efed912b36 100644
--- a/gin/modules/module_runner_delegate.cc
+++ b/gin/modules/module_runner_delegate.cc
@@ -6,9 +6,51 @@
#include "gin/modules/module_registry.h"
#include "gin/object_template_builder.h"
+#include "gin/public/context_holder.h"
namespace gin {
+namespace {
+
+// DefaultModuleLoader is a ModuleLoader that forwards to the ModuleRegistry.
+class DefaultModuleLoader : public ModuleLoader {
abarth-chromium 2014/02/26 06:08:44 Is there a better term to use here than "default"?
+ public:
+ explicit DefaultModuleLoader(v8::Handle<v8::Context> context);
+ virtual ~DefaultModuleLoader();
+
+ static void RegisterGlobals(v8::Isolate* isolate,
+ v8::Handle<v8::ObjectTemplate> templ);
+
+ private:
+ // ModuleLoader overrides:
+ virtual void Load(v8::Handle<v8::Context> context,
+ scoped_ptr<PendingModule> pending) OVERRIDE;
+
+ DISALLOW_COPY_AND_ASSIGN(DefaultModuleLoader);
+};
+
+DefaultModuleLoader::~DefaultModuleLoader() {
+}
+
+// static
+void DefaultModuleLoader::RegisterGlobals(
+ v8::Isolate* isolate,
+ v8::Handle<v8::ObjectTemplate> templ) {
+ ModuleLoader::RegisterGlobals(isolate, templ);
+}
+
+DefaultModuleLoader::DefaultModuleLoader(v8::Handle<v8::Context> context)
+ : ModuleLoader(context) {
+}
+
+void DefaultModuleLoader::Load(v8::Handle<v8::Context> context,
+ scoped_ptr<PendingModule> pending) {
+ ModuleRegistry::From(context)->AddPendingModule(context->GetIsolate(),
+ pending.Pass());
+}
+
+} // namespace
+
ModuleRunnerDelegate::ModuleRunnerDelegate(
const std::vector<base::FilePath>& search_paths)
: module_provider_(search_paths) {
@@ -23,34 +65,37 @@ void ModuleRunnerDelegate::AddBuiltinModule(const std::string& id,
}
void ModuleRunnerDelegate::AttemptToLoadMoreModules(Runner* runner) {
- ModuleRegistry* registry = ModuleRegistry::From(runner->context());
- registry->AttemptToLoadMoreModules(runner->isolate());
+ ModuleRegistry* registry = ModuleRegistry::From(
+ runner->GetContextHolder()->context());
+ registry->AttemptToLoadMoreModules(runner->GetContextHolder()->isolate());
module_provider_.AttempToLoadModules(
runner, registry->unsatisfied_dependencies());
}
v8::Handle<v8::ObjectTemplate> ModuleRunnerDelegate::GetGlobalTemplate(
- Runner* runner) {
- v8::Handle<v8::ObjectTemplate> templ =
- ObjectTemplateBuilder(runner->isolate()).Build();
- ModuleRegistry::RegisterGlobals(runner->isolate(), templ);
+ DefaultRunner* runner,
+ v8::Isolate* isolate) {
+ v8::Handle<v8::ObjectTemplate> templ = ObjectTemplateBuilder(isolate).Build();
+ DefaultModuleLoader::RegisterGlobals(isolate, templ);
return templ;
}
-void ModuleRunnerDelegate::DidCreateContext(Runner* runner) {
- RunnerDelegate::DidCreateContext(runner);
+void ModuleRunnerDelegate::DidCreateContext(DefaultRunner* runner) {
+ DefaultRunnerDelegate::DidCreateContext(runner);
- v8::Handle<v8::Context> context = runner->context();
+ v8::Handle<v8::Context> context = runner->GetContextHolder()->context();
+ // DefaultModuleLoader is owned with the context.
+ new DefaultModuleLoader(runner->GetContextHolder()->context());
ModuleRegistry* registry = ModuleRegistry::From(context);
+ v8::Isolate* isolate = runner->GetContextHolder()->isolate();
for (BuiltinModuleMap::const_iterator it = builtin_modules_.begin();
it != builtin_modules_.end(); ++it) {
- registry->AddBuiltinModule(runner->isolate(), it->first,
- it->second(runner->isolate()));
+ registry->AddBuiltinModule(isolate, it->first, it->second(isolate));
}
}
-void ModuleRunnerDelegate::DidRunScript(Runner* runner) {
+void ModuleRunnerDelegate::DidRunScript(DefaultRunner* runner) {
AttemptToLoadMoreModules(runner);
}

Powered by Google App Engine
This is Rietveld 408576698