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

Unified Diff: gin/converter.h

Issue 1106393002: gin: Use V8 Maybe APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@maybe-gin-converter
Patch Set: Created 5 years, 8 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
« no previous file with comments | « no previous file | gin/dictionary.h » ('j') | gin/try_catch.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/converter.h
diff --git a/gin/converter.h b/gin/converter.h
index fa3367dff46eed3a87f5912fd493f0961b88027f..f882980d8b2f5207c50e58195dd9f5dd13ae5290 100644
--- a/gin/converter.h
+++ b/gin/converter.h
@@ -14,6 +14,15 @@
namespace gin {
+template<typename KeyType>
+bool SetProperty(v8::Isolate* isolate,
+ v8::Local<v8::Object> object,
+ KeyType key,
+ v8::Local<v8::Value> value) {
+ auto maybe = object->Set(isolate->GetCurrentContext(), key, value);
+ return !maybe.IsNothing() && maybe.FromJust();
+}
+
template<typename T, typename Enable = void>
struct Converter {};
@@ -145,12 +154,16 @@ struct GIN_EXPORT Converter<v8::Handle<v8::Value> > {
template<typename T>
struct Converter<std::vector<T> > {
+ // If this function fails to set an element due to an exception, this returns
+ // an empty handle.
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
const std::vector<T>& val) {
v8::Handle<v8::Array> result(
v8::Array::New(isolate, static_cast<int>(val.size())));
for (size_t i = 0; i < val.size(); ++i) {
- result->Set(static_cast<int>(i), Converter<T>::ToV8(isolate, val[i]));
+ if (!SetProperty(isolate, result, static_cast<int>(i),
+ Converter<T>::ToV8(isolate, val[i])))
+ return v8::Handle<v8::Value>();
jochen (gone - plz use gerrit) 2015/04/28 11:14:20 we shouldn't return empty handles but MaybeLocal<>
bashi 2015/05/01 03:50:35 Changing return type requires 3-way CLs. 1. Add Ma
}
return result;
}
« no previous file with comments | « no previous file | gin/dictionary.h » ('j') | gin/try_catch.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698