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

Unified Diff: include/v8.h

Issue 959223002: convert Value::*Value() function to return Maybe results (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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 | src/api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index a6b1d4d8b2e097d8bb0a54df346f035881e2b57a..620d8df9bd8a1cd9ac91411d263b600b497ea5e9 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -977,12 +977,31 @@ class V8_EXPORT EscapableHandleScope : public HandleScope {
* A simple Maybe type, representing an object which may or may not have a
* value.
*/
-template<class T>
-struct Maybe {
+template <class T>
+class Maybe {
+ public:
Maybe() : has_value(false) {}
- explicit Maybe(T t) : has_value(true), value(t) {}
- Maybe(bool has, T t) : has_value(has), value(t) {}
+ explicit Maybe(const T& t) : has_value(true), value(t) {}
+ // TODO(dcarney): remove this constructor, it makes no sense.
+ Maybe(bool has, const T& t) : has_value(has), value(t) {}
+
+ V8_INLINE bool HasValue() const { return has_value; }
+ V8_WARN_UNUSED_RESULT V8_INLINE bool ToValue(T* out) const {
+ *out = has_value ? value : T();
+ return has_value;
+ }
+
+ V8_INLINE T ToValueChecked() const {
+ // TODO(dcarney): add DCHECK.
+ return value;
+ }
+
+ V8_INLINE T From(const T& default_value) const {
+ return has_value ? value : default_value;
+ }
+
+ // TODO(dcarney): make private.
bool has_value;
T value;
};
@@ -1921,6 +1940,13 @@ class V8_EXPORT Value : public Data {
*/
Local<Uint32> ToArrayIndex() const;
+ Maybe<bool> BooleanValue(Local<Context> context) const;
+ Maybe<double> NumberValue(Local<Context> context) const;
+ Maybe<int64_t> IntegerValue(Local<Context> context) const;
+ Maybe<uint32_t> Uint32Value(Local<Context> context) const;
+ Maybe<int32_t> Int32Value(Local<Context> context) const;
+
+ // TODO(dcarney): deprecate all these.
bool BooleanValue() const;
double NumberValue() const;
int64_t IntegerValue() const;
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698