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

Unified Diff: include/v8.h

Issue 2194793003: Introduce Maybe::To/ToChecked (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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 | test/cctest/test-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 4eb7614210fd1fb3120428e65f7c9ed97394f3b9..9a7e95a002cad14d82c1d97473371758e187a6d1 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -6908,17 +6908,25 @@ class SnapshotCreator {
template <class T>
class Maybe {
public:
- V8_INLINE bool IsNothing() const { return !has_value; }
- V8_INLINE bool IsJust() const { return has_value; }
+ V8_INLINE bool IsNothing() const { return !has_value_; }
+ V8_INLINE bool IsJust() const { return has_value_; }
+
+ // Will crash if the Maybe<> is nothing.
+ V8_INLINE T ToChecked() const { return FromJust(); }
+
+ V8_WARN_UNUSED_RESULT V8_INLINE bool To(T& out) const {
+ if (V8_LIKELY(IsJust())) out = value_;
+ return IsJust();
+ }
// Will crash if the Maybe<> is nothing.
V8_INLINE T FromJust() const {
if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
- return value;
+ return value_;
}
V8_INLINE T FromMaybe(const T& default_value) const {
- return has_value ? value : default_value;
+ return has_value_ ? value_ : default_value;
}
V8_INLINE bool operator==(const Maybe& other) const {
@@ -6931,11 +6939,11 @@ class Maybe {
}
private:
- Maybe() : has_value(false) {}
- explicit Maybe(const T& t) : has_value(true), value(t) {}
+ Maybe() : has_value_(false) {}
+ explicit Maybe(const T& t) : has_value_(true), value_(t) {}
- bool has_value;
- T value;
+ bool has_value_;
+ T value_;
template <class U>
friend Maybe<U> Nothing();
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698