| 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_registry.h" | 5 #include "gin/modules/module_registry.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 void ModuleRegistry::RegisterGlobals(Isolate* isolate, | 104 void ModuleRegistry::RegisterGlobals(Isolate* isolate, |
| 105 v8::Handle<ObjectTemplate> templ) { | 105 v8::Handle<ObjectTemplate> templ) { |
| 106 templ->Set(StringToSymbol(isolate, "define"), GetDefineTemplate(isolate)); | 106 templ->Set(StringToSymbol(isolate, "define"), GetDefineTemplate(isolate)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 ModuleRegistry* ModuleRegistry::From(v8::Handle<Context> context) { | 109 ModuleRegistry* ModuleRegistry::From(v8::Handle<Context> context) { |
| 110 Isolate* isolate = context->GetIsolate(); | 110 Isolate* isolate = context->GetIsolate(); |
| 111 v8::Handle<String> key = GetHiddenValueKey(isolate); | 111 v8::Handle<String> key = GetHiddenValueKey(isolate); |
| 112 v8::Handle<Value> value = context->Global()->GetHiddenValue(key); | 112 v8::Handle<Value> value = context->Global()->GetHiddenValue(key); |
| 113 v8::Handle<External> external; | 113 v8::Handle<External> external; |
| 114 if (value.IsEmpty() || !ConvertFromV8(value, &external)) { | 114 if (value.IsEmpty() || !ConvertFromV8(isolate, value, &external)) { |
| 115 PerContextData* data = PerContextData::From(context); | 115 PerContextData* data = PerContextData::From(context); |
| 116 if (!data) | 116 if (!data) |
| 117 return NULL; | 117 return NULL; |
| 118 ModuleRegistry* registry = new ModuleRegistry(isolate); | 118 ModuleRegistry* registry = new ModuleRegistry(isolate); |
| 119 context->Global()->SetHiddenValue(key, External::New(isolate, registry)); | 119 context->Global()->SetHiddenValue(key, External::New(isolate, registry)); |
| 120 data->AddSupplement(scoped_ptr<ContextSupplement>(registry)); | 120 data->AddSupplement(scoped_ptr<ContextSupplement>(registry)); |
| 121 return registry; | 121 return registry; |
| 122 } | 122 } |
| 123 return static_cast<ModuleRegistry*>(external->Value()); | 123 return static_cast<ModuleRegistry*>(external->Value()); |
| 124 } | 124 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 std::vector<v8::Handle<Value> > argv(argc); | 174 std::vector<v8::Handle<Value> > argv(argc); |
| 175 for (uint32_t i = 0; i < argc; ++i) { | 175 for (uint32_t i = 0; i < argc; ++i) { |
| 176 v8::Handle<String> key = StringToSymbol(isolate, pending->dependencies[i]); | 176 v8::Handle<String> key = StringToSymbol(isolate, pending->dependencies[i]); |
| 177 DCHECK(modules->HasOwnProperty(key)); | 177 DCHECK(modules->HasOwnProperty(key)); |
| 178 argv[i] = modules->Get(key); | 178 argv[i] = modules->Get(key); |
| 179 } | 179 } |
| 180 | 180 |
| 181 v8::Handle<Value> module = Local<Value>::New(isolate, pending->factory); | 181 v8::Handle<Value> module = Local<Value>::New(isolate, pending->factory); |
| 182 | 182 |
| 183 v8::Handle<Function> factory; | 183 v8::Handle<Function> factory; |
| 184 if (ConvertFromV8(module, &factory)) { | 184 if (ConvertFromV8(isolate, module, &factory)) { |
| 185 PerContextData* data = PerContextData::From(isolate->GetCurrentContext()); | 185 PerContextData* data = PerContextData::From(isolate->GetCurrentContext()); |
| 186 Runner* runner = data->runner(); | 186 Runner* runner = data->runner(); |
| 187 module = runner->Call(factory, runner->global(), argc, argv.data()); | 187 module = runner->Call(factory, runner->global(), argc, argv.data()); |
| 188 if (pending->id.empty()) | 188 if (pending->id.empty()) |
| 189 ConvertFromV8(factory->GetScriptOrigin().ResourceName(), &pending->id); | 189 ConvertFromV8(isolate, factory->GetScriptOrigin().ResourceName(), |
| 190 &pending->id); |
| 190 } | 191 } |
| 191 | 192 |
| 192 RegisterModule(isolate, pending->id, module); | 193 RegisterModule(isolate, pending->id, module); |
| 193 } | 194 } |
| 194 | 195 |
| 195 bool ModuleRegistry::AttemptToLoad(Isolate* isolate, | 196 bool ModuleRegistry::AttemptToLoad(Isolate* isolate, |
| 196 scoped_ptr<PendingModule> pending) { | 197 scoped_ptr<PendingModule> pending) { |
| 197 if (!CheckDependencies(pending.get())) { | 198 if (!CheckDependencies(pending.get())) { |
| 198 pending_modules_.push_back(pending.release()); | 199 pending_modules_.push_back(pending.release()); |
| 199 return false; | 200 return false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 211 for (size_t i = 0; i < pending_modules.size(); ++i) { | 212 for (size_t i = 0; i < pending_modules.size(); ++i) { |
| 212 scoped_ptr<PendingModule> pending(pending_modules[i]); | 213 scoped_ptr<PendingModule> pending(pending_modules[i]); |
| 213 pending_modules[i] = NULL; | 214 pending_modules[i] = NULL; |
| 214 if (AttemptToLoad(isolate, pending.Pass())) | 215 if (AttemptToLoad(isolate, pending.Pass())) |
| 215 keep_trying = true; | 216 keep_trying = true; |
| 216 } | 217 } |
| 217 } | 218 } |
| 218 } | 219 } |
| 219 | 220 |
| 220 } // namespace gin | 221 } // namespace gin |
| OLD | NEW |