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

Side by Side Diff: include/v8.h

Issue 967243002: Polish Maybe API a bit, removing useless creativity and fixing some signatures. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Simplified friendship. Added check in FromJust. 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 class Data; 74 class Data;
75 class Date; 75 class Date;
76 class External; 76 class External;
77 class Function; 77 class Function;
78 class FunctionTemplate; 78 class FunctionTemplate;
79 class HeapProfiler; 79 class HeapProfiler;
80 class ImplementationUtilities; 80 class ImplementationUtilities;
81 class Int32; 81 class Int32;
82 class Integer; 82 class Integer;
83 class Isolate; 83 class Isolate;
84 template <class T>
85 class Maybe;
84 class Name; 86 class Name;
85 class Number; 87 class Number;
86 class NumberObject; 88 class NumberObject;
87 class Object; 89 class Object;
88 class ObjectOperationDescriptor; 90 class ObjectOperationDescriptor;
89 class ObjectTemplate; 91 class ObjectTemplate;
90 class Platform; 92 class Platform;
91 class Primitive; 93 class Primitive;
92 class Promise; 94 class Promise;
93 class RawOperationDescriptor; 95 class RawOperationDescriptor;
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 // disallowing certain operations. 968 // disallowing certain operations.
967 EscapableHandleScope(const EscapableHandleScope&); 969 EscapableHandleScope(const EscapableHandleScope&);
968 void operator=(const EscapableHandleScope&); 970 void operator=(const EscapableHandleScope&);
969 void* operator new(size_t size); 971 void* operator new(size_t size);
970 void operator delete(void*, size_t); 972 void operator delete(void*, size_t);
971 973
972 internal::Object** escape_slot_; 974 internal::Object** escape_slot_;
973 }; 975 };
974 976
975 977
976 /**
977 * A simple Maybe type, representing an object which may or may not have a
978 * value.
979 */
980 template <class T>
981 class Maybe {
982 public:
983 Maybe() : has_value(false) {}
984 explicit Maybe(const T& t) : has_value(true), value(t) {}
985 // TODO(dcarney): remove this constructor, it makes no sense.
986 Maybe(bool has, const T& t) : has_value(has), value(t) {}
987
988 V8_INLINE bool HasValue() const { return has_value; }
989
990 V8_WARN_UNUSED_RESULT V8_INLINE bool ToValue(T* out) const {
991 *out = has_value ? value : T();
992 return has_value;
993 }
994
995 V8_INLINE T ToValueChecked() const {
996 // TODO(dcarney): add DCHECK.
997 return value;
998 }
999
1000 V8_INLINE T From(const T& default_value) const {
1001 return has_value ? value : default_value;
1002 }
1003
1004 // TODO(dcarney): make private.
1005 bool has_value;
1006 T value;
1007 };
1008
1009
1010 // Convenience wrapper.
1011 template <class T>
1012 inline Maybe<T> maybe(T t) {
1013 return Maybe<T>(t);
1014 }
1015
1016
1017 // --- Special objects --- 978 // --- Special objects ---
1018 979
1019 980
1020 /** 981 /**
1021 * The superclass of values and API object templates. 982 * The superclass of values and API object templates.
1022 */ 983 */
1023 class V8_EXPORT Data { 984 class V8_EXPORT Data {
1024 private: 985 private:
1025 Data(); 986 Data();
1026 }; 987 };
(...skipping 4716 matching lines...) Expand 10 before | Expand all | Expand 10 after
5743 int internal_field_index1, 5704 int internal_field_index1,
5744 // Must be 1 or kNoInternalFieldIndex. 5705 // Must be 1 or kNoInternalFieldIndex.
5745 int internal_field_index2, 5706 int internal_field_index2,
5746 PhantomCallbackData<void>::Callback weak_callback); 5707 PhantomCallbackData<void>::Callback weak_callback);
5747 static void* ClearWeak(internal::Object** global_handle); 5708 static void* ClearWeak(internal::Object** global_handle);
5748 static void Eternalize(Isolate* isolate, 5709 static void Eternalize(Isolate* isolate,
5749 Value* handle, 5710 Value* handle,
5750 int* index); 5711 int* index);
5751 static Local<Value> GetEternal(Isolate* isolate, int index); 5712 static Local<Value> GetEternal(Isolate* isolate, int index);
5752 5713
5714 static void CheckIsJust(bool is_just);
5715
5753 template <class T> friend class Handle; 5716 template <class T> friend class Handle;
5754 template <class T> friend class Local; 5717 template <class T> friend class Local;
5718 template <class T>
5719 friend class Maybe;
5755 template <class T> friend class Eternal; 5720 template <class T> friend class Eternal;
5756 template <class T> friend class PersistentBase; 5721 template <class T> friend class PersistentBase;
5757 template <class T, class M> friend class Persistent; 5722 template <class T, class M> friend class Persistent;
5758 friend class Context; 5723 friend class Context;
5759 }; 5724 };
5760 5725
5761 5726
5762 /** 5727 /**
5728 * A simple Maybe type, representing an object which may or may not have a
5729 * value.
5730 */
5731 template <class T>
5732 class Maybe {
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; }
Nico 2016/02/26 19:18:26 I saw this since someone made a similar name chang
5738
5739 V8_INLINE T FromJust() const {
5740 #ifdef V8_ENABLE_CHECKS
5741 V8::CheckIsJust(IsJust());
5742 #endif
5743 return value;
5744 }
5745
5746 V8_INLINE T FromMaybe(const T& default_value) const {
5747 return has_value ? value : default_value;
5748 }
5749
5750 // TODO(dcarney): make private.
5751 bool has_value;
5752 T value;
5753
5754 private:
5755 template <class U>
5756 friend Maybe<U> Nothing();
5757 template <class U>
5758 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 };
5763
5764
5765 template <class T>
5766 inline Maybe<T> Nothing() {
5767 return Maybe<T>();
5768 }
5769
5770
5771 template <class T>
5772 inline Maybe<T> Just(const T& t) {
5773 return Maybe<T>(t);
5774 }
5775
5776
5777 /**
5763 * An external exception handler. 5778 * An external exception handler.
5764 */ 5779 */
5765 class V8_EXPORT TryCatch { 5780 class V8_EXPORT TryCatch {
5766 public: 5781 public:
5767 /** 5782 /**
5768 * Creates a new try/catch block and registers it with v8. Note that 5783 * Creates a new try/catch block and registers it with v8. Note that
5769 * all TryCatch blocks should be stack allocated because the memory 5784 * all TryCatch blocks should be stack allocated because the memory
5770 * location itself is compared against JavaScript try/catch blocks. 5785 * location itself is compared against JavaScript try/catch blocks.
5771 */ 5786 */
5772 // TODO(dcarney): deprecate. 5787 // TODO(dcarney): deprecate.
(...skipping 1858 matching lines...) Expand 10 before | Expand all | Expand 10 after
7631 */ 7646 */
7632 7647
7633 7648
7634 } // namespace v8 7649 } // namespace v8
7635 7650
7636 7651
7637 #undef TYPE_CHECK 7652 #undef TYPE_CHECK
7638 7653
7639 7654
7640 #endif // V8_H_ 7655 #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