OLD | NEW |
---|---|
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 Loading... | |
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 // TODO(dcarney): make class. | |
981 struct Maybe { | 982 struct Maybe { |
982 Maybe() : has_value(false) {} | 983 Maybe() : has_value(false) {} |
983 explicit Maybe(T t) : has_value(true), value(t) {} | 984 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
| |
985 // TODO(dcarney): remove this constructor, it makes no sense. | |
984 Maybe(bool has, T t) : has_value(has), value(t) {} | 986 Maybe(bool has, T t) : has_value(has), value(t) {} |
985 | 987 |
988 bool HasValue() { return value; } | |
Sven Panne
2015/02/27 12:18:03
This should return has_value, I guess...
| |
989 | |
990 V8_WARN_UNUSED_RESULT V8_INLINE bool ToValue(T* out) const { | |
991 if (has_value) { | |
Sven Panne
2015/02/27 12:18:02
Test is wrong, safer and more obvious way:
*out
| |
992 *out = T(); | |
993 return false; | |
994 } else { | |
995 *out = this->value; | |
996 return true; | |
997 } | |
998 } | |
999 | |
1000 V8_INLINE T ToValueChecked() { | |
1001 // TODO(dcarney): add DCHECK. | |
1002 return value; | |
1003 } | |
1004 | |
1005 // TODO(dcarney): make private. | |
986 bool has_value; | 1006 bool has_value; |
987 T value; | 1007 T value; |
988 }; | 1008 }; |
989 | 1009 |
990 | 1010 |
991 // Convenience wrapper. | 1011 // Convenience wrapper. |
992 template <class T> | 1012 template <class T> |
993 inline Maybe<T> maybe(T t) { | 1013 inline Maybe<T> maybe(T t) { |
994 return Maybe<T>(t); | 1014 return Maybe<T>(t); |
995 } | 1015 } |
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1914 inline Local<Integer> ToInteger() const; | 1934 inline Local<Integer> ToInteger() const; |
1915 inline Local<Uint32> ToUint32() const; | 1935 inline Local<Uint32> ToUint32() const; |
1916 inline Local<Int32> ToInt32() const; | 1936 inline Local<Int32> ToInt32() const; |
1917 | 1937 |
1918 /** | 1938 /** |
1919 * Attempts to convert a string to an array index. | 1939 * Attempts to convert a string to an array index. |
1920 * Returns an empty handle if the conversion fails. | 1940 * Returns an empty handle if the conversion fails. |
1921 */ | 1941 */ |
1922 Local<Uint32> ToArrayIndex() const; | 1942 Local<Uint32> ToArrayIndex() const; |
1923 | 1943 |
1944 Maybe<bool> BooleanValue(Local<Context> context) const; | |
1945 Maybe<double> NumberValue(Local<Context> context) const; | |
1946 Maybe<int64_t> IntegerValue(Local<Context> context) const; | |
1947 Maybe<uint32_t> Uint32Value(Local<Context> context) const; | |
1948 Maybe<int32_t> Int32Value(Local<Context> context) const; | |
1949 | |
1950 // TODO(dcarney): deprecate all these. | |
1924 bool BooleanValue() const; | 1951 bool BooleanValue() const; |
1925 double NumberValue() const; | 1952 double NumberValue() const; |
1926 int64_t IntegerValue() const; | 1953 int64_t IntegerValue() const; |
1927 uint32_t Uint32Value() const; | 1954 uint32_t Uint32Value() const; |
1928 int32_t Int32Value() const; | 1955 int32_t Int32Value() const; |
1929 | 1956 |
1930 /** JS == */ | 1957 /** JS == */ |
1931 bool Equals(Handle<Value> that) const; | 1958 bool Equals(Handle<Value> that) const; |
1932 bool StrictEquals(Handle<Value> that) const; | 1959 bool StrictEquals(Handle<Value> that) const; |
1933 bool SameValue(Handle<Value> that) const; | 1960 bool SameValue(Handle<Value> that) const; |
(...skipping 5671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7605 */ | 7632 */ |
7606 | 7633 |
7607 | 7634 |
7608 } // namespace v8 | 7635 } // namespace v8 |
7609 | 7636 |
7610 | 7637 |
7611 #undef TYPE_CHECK | 7638 #undef TYPE_CHECK |
7612 | 7639 |
7613 | 7640 |
7614 #endif // V8_H_ | 7641 #endif // V8_H_ |
OLD | NEW |