Chromium Code Reviews| Index: include/v8.h |
| diff --git a/include/v8.h b/include/v8.h |
| index a6b1d4d8b2e097d8bb0a54df346f035881e2b57a..a9cdc261921dbd42c2d432024b1917310ef92990 100644 |
| --- a/include/v8.h |
| +++ b/include/v8.h |
| @@ -977,12 +977,32 @@ class V8_EXPORT EscapableHandleScope : public HandleScope { |
| * A simple Maybe type, representing an object which may or may not have a |
| * value. |
| */ |
| -template<class T> |
| +template <class T> |
| +// TODO(dcarney): make class. |
| struct Maybe { |
| Maybe() : has_value(false) {} |
| explicit Maybe(T t) : has_value(true), value(t) {} |
|
Sven Panne
2015/02/27 12:18:02
While we're here: Make this a "const T& t", the cu
|
| + // TODO(dcarney): remove this constructor, it makes no sense. |
| Maybe(bool has, T t) : has_value(has), value(t) {} |
| + bool HasValue() { return value; } |
|
Sven Panne
2015/02/27 12:18:03
This should return has_value, I guess...
|
| + |
| + V8_WARN_UNUSED_RESULT V8_INLINE bool ToValue(T* out) const { |
| + if (has_value) { |
|
Sven Panne
2015/02/27 12:18:02
Test is wrong, safer and more obvious way:
*out
|
| + *out = T(); |
| + return false; |
| + } else { |
| + *out = this->value; |
| + return true; |
| + } |
| + } |
| + |
| + V8_INLINE T ToValueChecked() { |
| + // TODO(dcarney): add DCHECK. |
| + return value; |
| + } |
| + |
| + // TODO(dcarney): make private. |
| bool has_value; |
| T value; |
| }; |
| @@ -1921,6 +1941,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; |