diff options
author | bashi <bashi@chromium.org> | 2015-05-28 21:06:05 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-29 04:06:44 +0000 |
commit | 7a6acf6c7d45e24f07781c69249d90967013bbe4 (patch) | |
tree | 6389c0ac1910a4674fbf2c791a1efa3eaa4c4059 /gin/modules | |
parent | a719b2b6e63d2bc558db5392934de984fcd91e8c (diff) | |
download | chromium_src-7a6acf6c7d45e24f07781c69249d90967013bbe4.zip chromium_src-7a6acf6c7d45e24f07781c69249d90967013bbe4.tar.gz chromium_src-7a6acf6c7d45e24f07781c69249d90967013bbe4.tar.bz2 |
gin: Use V8 Maybe APIs
TEST=gin_unittests
BUG=479439
Review URL: https://codereview.chromium.org/1106393002
Cr-Commit-Position: refs/heads/master@{#331923}
Diffstat (limited to 'gin/modules')
-rw-r--r-- | gin/modules/console.cc | 2 | ||||
-rw-r--r-- | gin/modules/module_registry.cc | 33 | ||||
-rw-r--r-- | gin/modules/module_registry.h | 6 |
3 files changed, 23 insertions, 18 deletions
diff --git a/gin/modules/console.cc b/gin/modules/console.cc index d172373..75241df 100644 --- a/gin/modules/console.cc +++ b/gin/modules/console.cc @@ -43,7 +43,7 @@ v8::Local<v8::Value> Console::GetModule(v8::Isolate* isolate) { .Build(); data->SetObjectTemplate(&g_wrapper_info, templ); } - return templ->NewInstance(); + return templ->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); } } // namespace gin diff --git a/gin/modules/module_registry.cc b/gin/modules/module_registry.cc index 6c3e898..036e98d 100644 --- a/gin/modules/module_registry.cc +++ b/gin/modules/module_registry.cc @@ -113,10 +113,14 @@ void ModuleRegistry::RegisterGlobals(Isolate* isolate, } // static -void ModuleRegistry::InstallGlobals(v8::Isolate* isolate, +bool ModuleRegistry::InstallGlobals(v8::Isolate* isolate, v8::Local<v8::Object> obj) { - obj->Set(StringToSymbol(isolate, "define"), - GetDefineTemplate(isolate)->GetFunction()); + v8::Local<v8::Function> function; + auto maybe_function = + GetDefineTemplate(isolate)->GetFunction(isolate->GetCurrentContext()); + if (!maybe_function.ToLocal(&function)) + return false; + return SetProperty(isolate, obj, StringToSymbol(isolate, "define"), function); } // static @@ -177,16 +181,17 @@ void ModuleRegistry::LoadModule(Isolate* isolate, unsatisfied_dependencies_.insert(id); } -void ModuleRegistry::RegisterModule(Isolate* isolate, +bool ModuleRegistry::RegisterModule(Isolate* isolate, const std::string& id, v8::Local<Value> module) { if (id.empty() || module.IsEmpty()) - return; + return false; + v8::Local<Object> modules = Local<Object>::New(isolate, modules_); + if (!SetProperty(isolate, modules, StringToSymbol(isolate, id), module)) + return false; unsatisfied_dependencies_.erase(id); available_modules_.insert(id); - v8::Local<Object> modules = Local<Object>::New(isolate, modules_); - modules->Set(StringToSymbol(isolate, id), module); std::pair<LoadModuleCallbackMap::iterator, LoadModuleCallbackMap::iterator> range = waiting_callbacks_.equal_range(id); @@ -203,6 +208,7 @@ void ModuleRegistry::RegisterModule(Isolate* isolate, // Should we call the callback asynchronously? it->Run(module); } + return true; } bool ModuleRegistry::CheckDependencies(PendingModule* pending) { @@ -218,9 +224,9 @@ bool ModuleRegistry::CheckDependencies(PendingModule* pending) { return num_missing_dependencies == 0; } -void ModuleRegistry::Load(Isolate* isolate, scoped_ptr<PendingModule> pending) { +bool ModuleRegistry::Load(Isolate* isolate, scoped_ptr<PendingModule> pending) { if (!pending->id.empty() && available_modules_.count(pending->id)) - return; // We've already loaded this module. + return true; // We've already loaded this module. uint32_t argc = static_cast<uint32_t>(pending->dependencies.size()); std::vector<v8::Local<Value> > argv(argc); @@ -240,7 +246,7 @@ void ModuleRegistry::Load(Isolate* isolate, scoped_ptr<PendingModule> pending) { &pending->id); } - RegisterModule(isolate, pending->id, module); + return RegisterModule(isolate, pending->id, module); } bool ModuleRegistry::AttemptToLoad(Isolate* isolate, @@ -249,16 +255,15 @@ bool ModuleRegistry::AttemptToLoad(Isolate* isolate, pending_modules_.push_back(pending.release()); return false; } - Load(isolate, pending.Pass()); - return true; + return Load(isolate, pending.Pass()); } v8::Local<v8::Value> ModuleRegistry::GetModule(v8::Isolate* isolate, const std::string& id) { v8::Local<Object> modules = Local<Object>::New(isolate, modules_); v8::Local<String> key = StringToSymbol(isolate, id); - DCHECK(modules->HasOwnProperty(key)); - return modules->Get(key); + DCHECK(modules->HasOwnProperty(isolate->GetCurrentContext(), key).FromJust()); + return modules->Get(isolate->GetCurrentContext(), key).ToLocalChecked(); } void ModuleRegistry::AttemptToLoadMoreModules(Isolate* isolate) { diff --git a/gin/modules/module_registry.h b/gin/modules/module_registry.h index c53155a..b67387b 100644 --- a/gin/modules/module_registry.h +++ b/gin/modules/module_registry.h @@ -47,7 +47,7 @@ class GIN_EXPORT ModuleRegistry { // Installs the necessary functions needed for modules. // WARNING: this may execute script in the page. - static void InstallGlobals(v8::Isolate* isolate, v8::Local<v8::Object> obj); + static bool InstallGlobals(v8::Isolate* isolate, v8::Local<v8::Object> obj); void AddObserver(ModuleRegistryObserver* observer); void RemoveObserver(ModuleRegistryObserver* observer); @@ -81,8 +81,8 @@ class GIN_EXPORT ModuleRegistry { explicit ModuleRegistry(v8::Isolate* isolate); - void Load(v8::Isolate* isolate, scoped_ptr<PendingModule> pending); - void RegisterModule(v8::Isolate* isolate, + bool Load(v8::Isolate* isolate, scoped_ptr<PendingModule> pending); + bool RegisterModule(v8::Isolate* isolate, const std::string& id, v8::Local<v8::Value> module); |