Chromium Code Reviews| Index: gin/modules/module_registry.cc |
| diff --git a/gin/modules/module_registry.cc b/gin/modules/module_registry.cc |
| index d868dec5bb15203d3d351d0ed141376e9b735862..4df04d59d8607631401252bae53fd23cf5a78781 100644 |
| --- a/gin/modules/module_registry.cc |
| +++ b/gin/modules/module_registry.cc |
| @@ -135,6 +135,20 @@ void ModuleRegistry::AddPendingModule(Isolate* isolate, |
| AttemptToLoad(isolate, pending.Pass()); |
| } |
| +void ModuleRegistry::LoadModule(Isolate* isolate, |
| + const std::string& id, |
| + ModuleLoadCallback callback) { |
| + if (available_modules_.count(id)) { |
|
Aaron Boodman
2013/11/27 19:02:41
I think that the implicit int->bool conversion wil
abarth-chromium
2013/11/27 19:18:09
Done.
|
| + // Should we call the callback asynchronously? |
|
Aaron Boodman
2013/11/27 19:02:41
I think so, but slightlyoff would be able to answe
abarth-chromium
2013/11/27 19:18:09
This is just used by C++, so we can change out min
|
| + callback.Run(GetModule(isolate, id)); |
| + return; |
| + } |
| + // Should we support multiple callers waiting on the same module? |
|
Aaron Boodman
2013/11/27 19:02:41
Couldn't you easily write JavaScript programs that
abarth-chromium
2013/11/27 19:18:09
This API is just for C++. The JavaScript API is a
|
| + DCHECK(waiting_callbacks_.find(id) == waiting_callbacks_.end()); |
| + waiting_callbacks_[id] = callback; |
| + unsatisfied_dependencies_.insert(id); |
| +} |
| + |
| void ModuleRegistry::RegisterModule(Isolate* isolate, |
| const std::string& id, |
| v8::Handle<Value> module) { |
| @@ -145,6 +159,12 @@ void ModuleRegistry::RegisterModule(Isolate* isolate, |
| available_modules_.insert(id); |
| v8::Handle<Object> modules = Local<Object>::New(isolate, modules_); |
| modules->Set(StringToSymbol(isolate, id), module); |
| + |
| + ModuleLoadCallbackMap::iterator it = waiting_callbacks_.find(id); |
| + if (it == waiting_callbacks_.end()) |
| + return; |
| + // Should we call the callback asynchronously? |
| + it->second.Run(module); |
| } |
| void ModuleRegistry::Detach(v8::Handle<Context> context) { |
| @@ -169,14 +189,10 @@ void ModuleRegistry::Load(Isolate* isolate, scoped_ptr<PendingModule> pending) { |
| if (!pending->id.empty() && available_modules_.count(pending->id)) |
| return; // We've already loaded this module. |
| - v8::Handle<Object> modules = Local<Object>::New(isolate, modules_); |
| uint32_t argc = static_cast<uint32_t>(pending->dependencies.size()); |
| std::vector<v8::Handle<Value> > argv(argc); |
| - for (uint32_t i = 0; i < argc; ++i) { |
| - v8::Handle<String> key = StringToSymbol(isolate, pending->dependencies[i]); |
| - DCHECK(modules->HasOwnProperty(key)); |
| - argv[i] = modules->Get(key); |
| - } |
| + for (uint32_t i = 0; i < argc; ++i) |
| + argv[i] = GetModule(isolate, pending->dependencies[i]); |
| v8::Handle<Value> module = Local<Value>::New(isolate, pending->factory); |
| @@ -202,6 +218,14 @@ bool ModuleRegistry::AttemptToLoad(Isolate* isolate, |
| return true; |
| } |
| +v8::Handle<v8::Value> ModuleRegistry::GetModule(v8::Isolate* isolate, |
| + const std::string& id) { |
| + v8::Handle<Object> modules = Local<Object>::New(isolate, modules_); |
| + v8::Handle<String> key = StringToSymbol(isolate, id); |
| + DCHECK(modules->HasOwnProperty(key)); |
| + return modules->Get(key); |
| +} |
| + |
| void ModuleRegistry::AttemptToLoadMoreModules(Isolate* isolate) { |
| bool keep_trying = true; |
| while (keep_trying) { |