OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "gin/modules/module_runner_delegate.h" | 5 #include "gin/modules/module_runner_delegate.h" |
6 | 6 |
7 #include "gin/modules/module_registry.h" | 7 #include "gin/modules/module_registry.h" |
8 | 8 |
9 namespace gin { | 9 namespace gin { |
10 | 10 |
11 ModuleRunnerDelegate::ModuleRunnerDelegate(const base::FilePath& module_base) | 11 ModuleRunnerDelegate::ModuleRunnerDelegate(const base::FilePath& module_base) |
12 : module_provider_(module_base) { | 12 : module_provider_(module_base) { |
13 } | 13 } |
14 | 14 |
15 ModuleRunnerDelegate::~ModuleRunnerDelegate() { | 15 ModuleRunnerDelegate::~ModuleRunnerDelegate() { |
16 } | 16 } |
17 | 17 |
| 18 void ModuleRunnerDelegate::AddBuiltinModule(const std::string& id, |
| 19 ModuleTemplateGetter templ) { |
| 20 builtin_modules_[id] = templ; |
| 21 } |
| 22 |
18 v8::Handle<v8::ObjectTemplate> ModuleRunnerDelegate::GetGlobalTemplate( | 23 v8::Handle<v8::ObjectTemplate> ModuleRunnerDelegate::GetGlobalTemplate( |
19 Runner* runner) { | 24 Runner* runner) { |
20 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 25 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); |
21 ModuleRegistry::RegisterGlobals(runner->isolate(), templ); | 26 ModuleRegistry::RegisterGlobals(runner->isolate(), templ); |
22 return templ; | 27 return templ; |
23 } | 28 } |
24 | 29 |
| 30 void ModuleRunnerDelegate::DidCreateContext(Runner* runner) { |
| 31 RunnerDelegate::DidCreateContext(runner); |
| 32 |
| 33 v8::Handle<v8::Context> context = runner->context(); |
| 34 ModuleRegistry* registry = ModuleRegistry::From(context); |
| 35 |
| 36 for (BuiltinModuleMap::const_iterator it = builtin_modules_.begin(); |
| 37 it != builtin_modules_.end(); ++it) { |
| 38 registry->AddBuiltinModule(runner->isolate(), it->first, |
| 39 it->second(runner->isolate())); |
| 40 } |
| 41 } |
| 42 |
25 void ModuleRunnerDelegate::DidRunScript(Runner* runner, | 43 void ModuleRunnerDelegate::DidRunScript(Runner* runner, |
26 v8::Handle<v8::Script> script) { | 44 v8::Handle<v8::Script> script) { |
27 ModuleRegistry* registry = ModuleRegistry::From(runner->context()); | 45 ModuleRegistry* registry = ModuleRegistry::From(runner->context()); |
28 registry->AttemptToLoadMoreModules(runner->isolate()); | 46 registry->AttemptToLoadMoreModules(runner->isolate()); |
29 module_provider_.AttempToLoadModules( | 47 module_provider_.AttempToLoadModules( |
30 runner, registry->unsatisfied_dependencies()); | 48 runner, registry->unsatisfied_dependencies()); |
31 } | 49 } |
32 | 50 |
33 } // namespace gin | 51 } // namespace gin |
OLD | NEW |