| 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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 } | 432 } |
| 433 | 433 |
| 434 V8_INLINE bool IsEmpty() const { return val_ == nullptr; } | 434 V8_INLINE bool IsEmpty() const { return val_ == nullptr; } |
| 435 | 435 |
| 436 template <class S> | 436 template <class S> |
| 437 V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const { | 437 V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const { |
| 438 out->val_ = IsEmpty() ? nullptr : this->val_; | 438 out->val_ = IsEmpty() ? nullptr : this->val_; |
| 439 return !IsEmpty(); | 439 return !IsEmpty(); |
| 440 } | 440 } |
| 441 | 441 |
| 442 // Will crash when checks are enabled if the MaybeLocal<> is empty. | 442 // Will crash if the MaybeLocal<> is empty. |
| 443 V8_INLINE Local<T> ToLocalChecked(); | 443 V8_INLINE Local<T> ToLocalChecked(); |
| 444 | 444 |
| 445 template <class S> | 445 template <class S> |
| 446 V8_INLINE Local<S> FromMaybe(Local<S> default_value) const { | 446 V8_INLINE Local<S> FromMaybe(Local<S> default_value) const { |
| 447 return IsEmpty() ? default_value : Local<S>(val_); | 447 return IsEmpty() ? default_value : Local<S>(val_); |
| 448 } | 448 } |
| 449 | 449 |
| 450 private: | 450 private: |
| 451 T* val_; | 451 T* val_; |
| 452 }; | 452 }; |
| (...skipping 5614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6067 int internal_field_index1, | 6067 int internal_field_index1, |
| 6068 // Must be 1 or -1. | 6068 // Must be 1 or -1. |
| 6069 int internal_field_index2, | 6069 int internal_field_index2, |
| 6070 WeakCallbackInfo<void>::Callback weak_callback); | 6070 WeakCallbackInfo<void>::Callback weak_callback); |
| 6071 static void* ClearWeak(internal::Object** global_handle); | 6071 static void* ClearWeak(internal::Object** global_handle); |
| 6072 static void Eternalize(Isolate* isolate, | 6072 static void Eternalize(Isolate* isolate, |
| 6073 Value* handle, | 6073 Value* handle, |
| 6074 int* index); | 6074 int* index); |
| 6075 static Local<Value> GetEternal(Isolate* isolate, int index); | 6075 static Local<Value> GetEternal(Isolate* isolate, int index); |
| 6076 | 6076 |
| 6077 static void CheckIsJust(bool is_just); | 6077 static void FromJustIsNothing(); |
| 6078 static void ToLocalEmpty(); | 6078 static void ToLocalEmpty(); |
| 6079 static void InternalFieldOutOfBounds(int index); | 6079 static void InternalFieldOutOfBounds(int index); |
| 6080 | 6080 |
| 6081 template <class T> friend class Handle; | 6081 template <class T> friend class Handle; |
| 6082 template <class T> friend class Local; | 6082 template <class T> friend class Local; |
| 6083 template <class T> | 6083 template <class T> |
| 6084 friend class MaybeLocal; | 6084 friend class MaybeLocal; |
| 6085 template <class T> | 6085 template <class T> |
| 6086 friend class Maybe; | 6086 friend class Maybe; |
| 6087 template <class T> | 6087 template <class T> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 6102 * e.g. because a previous API call threw an exception that hasn't been caught | 6102 * e.g. because a previous API call threw an exception that hasn't been caught |
| 6103 * yet, or because a TerminateExecution exception was thrown. In that case, a | 6103 * yet, or because a TerminateExecution exception was thrown. In that case, a |
| 6104 * "Nothing" value is returned. | 6104 * "Nothing" value is returned. |
| 6105 */ | 6105 */ |
| 6106 template <class T> | 6106 template <class T> |
| 6107 class Maybe { | 6107 class Maybe { |
| 6108 public: | 6108 public: |
| 6109 V8_INLINE bool IsNothing() const { return !has_value; } | 6109 V8_INLINE bool IsNothing() const { return !has_value; } |
| 6110 V8_INLINE bool IsJust() const { return has_value; } | 6110 V8_INLINE bool IsJust() const { return has_value; } |
| 6111 | 6111 |
| 6112 // Will crash when checks are enabled if the Maybe<> is nothing. | 6112 // Will crash if the Maybe<> is nothing. |
| 6113 V8_INLINE T FromJust() const { | 6113 V8_INLINE T FromJust() const { |
| 6114 #ifdef V8_ENABLE_CHECKS | 6114 if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing(); |
| 6115 V8::CheckIsJust(IsJust()); | |
| 6116 #endif | |
| 6117 return value; | 6115 return value; |
| 6118 } | 6116 } |
| 6119 | 6117 |
| 6120 V8_INLINE T FromMaybe(const T& default_value) const { | 6118 V8_INLINE T FromMaybe(const T& default_value) const { |
| 6121 return has_value ? value : default_value; | 6119 return has_value ? value : default_value; |
| 6122 } | 6120 } |
| 6123 | 6121 |
| 6124 V8_INLINE bool operator==(const Maybe& other) const { | 6122 V8_INLINE bool operator==(const Maybe& other) const { |
| 6125 return (IsJust() == other.IsJust()) && | 6123 return (IsJust() == other.IsJust()) && |
| 6126 (!IsJust() || FromJust() == other.FromJust()); | 6124 (!IsJust() || FromJust() == other.FromJust()); |
| (...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6924 | 6922 |
| 6925 | 6923 |
| 6926 template<class T> | 6924 template<class T> |
| 6927 Local<T> Eternal<T>::Get(Isolate* isolate) { | 6925 Local<T> Eternal<T>::Get(Isolate* isolate) { |
| 6928 return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_))); | 6926 return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_))); |
| 6929 } | 6927 } |
| 6930 | 6928 |
| 6931 | 6929 |
| 6932 template <class T> | 6930 template <class T> |
| 6933 Local<T> MaybeLocal<T>::ToLocalChecked() { | 6931 Local<T> MaybeLocal<T>::ToLocalChecked() { |
| 6934 #ifdef V8_ENABLE_CHECKS | 6932 if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty(); |
| 6935 if (val_ == nullptr) V8::ToLocalEmpty(); | |
| 6936 #endif | |
| 6937 return Local<T>(val_); | 6933 return Local<T>(val_); |
| 6938 } | 6934 } |
| 6939 | 6935 |
| 6940 | 6936 |
| 6941 template <class T> | 6937 template <class T> |
| 6942 void* WeakCallbackInfo<T>::GetInternalField(int index) const { | 6938 void* WeakCallbackInfo<T>::GetInternalField(int index) const { |
| 6943 #ifdef V8_ENABLE_CHECKS | 6939 #ifdef V8_ENABLE_CHECKS |
| 6944 if (index < 0 || index >= kInternalFieldsInWeakCallback) { | 6940 if (index < 0 || index >= kInternalFieldsInWeakCallback) { |
| 6945 V8::InternalFieldOutOfBounds(index); | 6941 V8::InternalFieldOutOfBounds(index); |
| 6946 } | 6942 } |
| (...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8092 */ | 8088 */ |
| 8093 | 8089 |
| 8094 | 8090 |
| 8095 } // namespace v8 | 8091 } // namespace v8 |
| 8096 | 8092 |
| 8097 | 8093 |
| 8098 #undef TYPE_CHECK | 8094 #undef TYPE_CHECK |
| 8099 | 8095 |
| 8100 | 8096 |
| 8101 #endif // V8_H_ | 8097 #endif // V8_H_ |
| OLD | NEW |