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

Side by Side 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, 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 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 void operator delete(void*, size_t); 970 void operator delete(void*, size_t);
971 971
972 internal::Object** escape_slot_; 972 internal::Object** escape_slot_;
973 }; 973 };
974 974
975 975
976 /** 976 /**
977 * A simple Maybe type, representing an object which may or may not have a 977 * A simple Maybe type, representing an object which may or may not have a
978 * value. 978 * value.
979 */ 979 */
980 template<class T> 980 template <class T>
981 struct Maybe { 981 class Maybe {
982 public:
982 Maybe() : has_value(false) {} 983 Maybe() : has_value(false) {}
983 explicit Maybe(T t) : has_value(true), value(t) {} 984 explicit Maybe(const T& t) : has_value(true), value(t) {}
984 Maybe(bool has, T t) : has_value(has), value(t) {} 985 // TODO(dcarney): remove this constructor, it makes no sense.
986 Maybe(bool has, const T& t) : has_value(has), value(t) {}
985 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.
986 bool has_value; 1005 bool has_value;
987 T value; 1006 T value;
988 }; 1007 };
989 1008
990 1009
991 // Convenience wrapper. 1010 // Convenience wrapper.
992 template <class T> 1011 template <class T>
993 inline Maybe<T> maybe(T t) { 1012 inline Maybe<T> maybe(T t) {
994 return Maybe<T>(t); 1013 return Maybe<T>(t);
995 } 1014 }
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 inline Local<Integer> ToInteger() const; 1933 inline Local<Integer> ToInteger() const;
1915 inline Local<Uint32> ToUint32() const; 1934 inline Local<Uint32> ToUint32() const;
1916 inline Local<Int32> ToInt32() const; 1935 inline Local<Int32> ToInt32() const;
1917 1936
1918 /** 1937 /**
1919 * Attempts to convert a string to an array index. 1938 * Attempts to convert a string to an array index.
1920 * Returns an empty handle if the conversion fails. 1939 * Returns an empty handle if the conversion fails.
1921 */ 1940 */
1922 Local<Uint32> ToArrayIndex() const; 1941 Local<Uint32> ToArrayIndex() const;
1923 1942
1943 Maybe<bool> BooleanValue(Local<Context> context) const;
1944 Maybe<double> NumberValue(Local<Context> context) const;
1945 Maybe<int64_t> IntegerValue(Local<Context> context) const;
1946 Maybe<uint32_t> Uint32Value(Local<Context> context) const;
1947 Maybe<int32_t> Int32Value(Local<Context> context) const;
1948
1949 // TODO(dcarney): deprecate all these.
1924 bool BooleanValue() const; 1950 bool BooleanValue() const;
1925 double NumberValue() const; 1951 double NumberValue() const;
1926 int64_t IntegerValue() const; 1952 int64_t IntegerValue() const;
1927 uint32_t Uint32Value() const; 1953 uint32_t Uint32Value() const;
1928 int32_t Int32Value() const; 1954 int32_t Int32Value() const;
1929 1955
1930 /** JS == */ 1956 /** JS == */
1931 bool Equals(Handle<Value> that) const; 1957 bool Equals(Handle<Value> that) const;
1932 bool StrictEquals(Handle<Value> that) const; 1958 bool StrictEquals(Handle<Value> that) const;
1933 bool SameValue(Handle<Value> that) const; 1959 bool SameValue(Handle<Value> that) const;
(...skipping 5671 matching lines...) Expand 10 before | Expand all | Expand 10 after
7605 */ 7631 */
7606 7632
7607 7633
7608 } // namespace v8 7634 } // namespace v8
7609 7635
7610 7636
7611 #undef TYPE_CHECK 7637 #undef TYPE_CHECK
7612 7638
7613 7639
7614 #endif // V8_H_ 7640 #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