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

Side by Side Diff: include/v8.h

Issue 958053003: Removed funky Maybe constructor and made fields private. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** \mainpage V8 API Reference Guide 5 /** \mainpage V8 API Reference Guide
6 * 6 *
7 * V8 is Google's open source JavaScript engine. 7 * V8 is Google's open source JavaScript engine.
8 * 8 *
9 * This set of documents provides reference material generated from the 9 * This set of documents provides reference material generated from the
10 * V8 header file, include/v8.h. 10 * V8 header file, include/v8.h.
(...skipping 5708 matching lines...) Expand 10 before | Expand all | Expand 10 after
5719 friend class Maybe; 5719 friend class Maybe;
5720 template <class T> friend class Eternal; 5720 template <class T> friend class Eternal;
5721 template <class T> friend class PersistentBase; 5721 template <class T> friend class PersistentBase;
5722 template <class T, class M> friend class Persistent; 5722 template <class T, class M> friend class Persistent;
5723 friend class Context; 5723 friend class Context;
5724 }; 5724 };
5725 5725
5726 5726
5727 /** 5727 /**
5728 * A simple Maybe type, representing an object which may or may not have a 5728 * A simple Maybe type, representing an object which may or may not have a
5729 * value. 5729 * value, see https://hackage.haskell.org/package/base/docs/Data-Maybe.html.
5730 */ 5730 */
5731 template <class T> 5731 template <class T>
5732 class Maybe { 5732 class Maybe {
5733 public: 5733 public:
5734 // TODO(dcarney): remove this constructor, it makes no sense.
5735 Maybe(bool has, const T& t) : has_value(has), value(t) {}
5736
5737 V8_INLINE bool IsJust() const { return has_value; } 5734 V8_INLINE bool IsJust() const { return has_value; }
5738 5735
5739 V8_INLINE T FromJust() const { 5736 V8_INLINE T FromJust() const {
5740 #ifdef V8_ENABLE_CHECKS 5737 #ifdef V8_ENABLE_CHECKS
5741 V8::CheckIsJust(IsJust()); 5738 V8::CheckIsJust(IsJust());
5742 #endif 5739 #endif
5743 return value; 5740 return value;
5744 } 5741 }
5745 5742
5746 V8_INLINE T FromMaybe(const T& default_value) const { 5743 V8_INLINE T FromMaybe(const T& default_value) const {
5747 return has_value ? value : default_value; 5744 return has_value ? value : default_value;
5748 } 5745 }
5749 5746
5750 // TODO(dcarney): make private. 5747 V8_INLINE bool operator==(const Maybe& other) const {
5748 return (IsJust() == other.IsJust()) &&
5749 (!IsJust() || FromJust() == other.FromJust());
5750 }
5751
5752 V8_INLINE bool operator!=(const Maybe& other) const {
5753 return !operator==(other);
5754 }
5755
5756 private:
5757 Maybe() : has_value(false) {}
5758 explicit Maybe(const T& t) : has_value(true), value(t) {}
5759
5751 bool has_value; 5760 bool has_value;
5752 T value; 5761 T value;
5753 5762
5754 private:
5755 template <class U> 5763 template <class U>
5756 friend Maybe<U> Nothing(); 5764 friend Maybe<U> Nothing();
5757 template <class U> 5765 template <class U>
5758 friend Maybe<U> Just(const U& u); 5766 friend Maybe<U> Just(const U& u);
5759
5760 Maybe() : has_value(false) {}
5761 explicit Maybe(const T& t) : has_value(true), value(t) {}
5762 }; 5767 };
5763 5768
5764 5769
5765 template <class T> 5770 template <class T>
5766 inline Maybe<T> Nothing() { 5771 inline Maybe<T> Nothing() {
5767 return Maybe<T>(); 5772 return Maybe<T>();
5768 } 5773 }
5769 5774
5770 5775
5771 template <class T> 5776 template <class T>
(...skipping 1874 matching lines...) Expand 10 before | Expand all | Expand 10 after
7646 */ 7651 */
7647 7652
7648 7653
7649 } // namespace v8 7654 } // namespace v8
7650 7655
7651 7656
7652 #undef TYPE_CHECK 7657 #undef TYPE_CHECK
7653 7658
7654 7659
7655 #endif // V8_H_ 7660 #endif // V8_H_
OLDNEW
« 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