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

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') | src/api.cc » ('J')
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..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;
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698