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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 template<class F> friend class internal::CustomArguments; | 323 template<class F> friend class internal::CustomArguments; |
324 friend Local<Primitive> Undefined(Isolate* isolate); | 324 friend Local<Primitive> Undefined(Isolate* isolate); |
325 friend Local<Primitive> Null(Isolate* isolate); | 325 friend Local<Primitive> Null(Isolate* isolate); |
326 friend Local<Boolean> True(Isolate* isolate); | 326 friend Local<Boolean> True(Isolate* isolate); |
327 friend Local<Boolean> False(Isolate* isolate); | 327 friend Local<Boolean> False(Isolate* isolate); |
328 friend class HandleScope; | 328 friend class HandleScope; |
329 friend class EscapableHandleScope; | 329 friend class EscapableHandleScope; |
330 template <class F1, class F2, class F3> | 330 template <class F1, class F2, class F3> |
331 friend class PersistentValueMapBase; | 331 friend class PersistentValueMapBase; |
332 template<class F1, class F2> friend class PersistentValueVector; | 332 template<class F1, class F2> friend class PersistentValueVector; |
| 333 template <class F> |
| 334 friend class ReturnValue; |
333 | 335 |
334 explicit V8_INLINE Local(T* that) : val_(that) {} | 336 explicit V8_INLINE Local(T* that) : val_(that) {} |
335 V8_INLINE static Local<T> New(Isolate* isolate, T* that); | 337 V8_INLINE static Local<T> New(Isolate* isolate, T* that); |
336 T* val_; | 338 T* val_; |
337 }; | 339 }; |
338 | 340 |
339 | 341 |
340 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS) | 342 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS) |
341 // Local is an alias for Local for historical reasons. | 343 // Local is an alias for Local for historical reasons. |
342 template <class T> | 344 template <class T> |
(...skipping 2786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3129 // Fast primitive setters | 3131 // Fast primitive setters |
3130 V8_INLINE void Set(bool value); | 3132 V8_INLINE void Set(bool value); |
3131 V8_INLINE void Set(double i); | 3133 V8_INLINE void Set(double i); |
3132 V8_INLINE void Set(int32_t i); | 3134 V8_INLINE void Set(int32_t i); |
3133 V8_INLINE void Set(uint32_t i); | 3135 V8_INLINE void Set(uint32_t i); |
3134 // Fast JS primitive setters | 3136 // Fast JS primitive setters |
3135 V8_INLINE void SetNull(); | 3137 V8_INLINE void SetNull(); |
3136 V8_INLINE void SetUndefined(); | 3138 V8_INLINE void SetUndefined(); |
3137 V8_INLINE void SetEmptyString(); | 3139 V8_INLINE void SetEmptyString(); |
3138 // Convenience getter for Isolate | 3140 // Convenience getter for Isolate |
3139 V8_INLINE Isolate* GetIsolate(); | 3141 V8_INLINE Isolate* GetIsolate() const; |
3140 | 3142 |
3141 // Pointer setter: Uncompilable to prevent inadvertent misuse. | 3143 // Pointer setter: Uncompilable to prevent inadvertent misuse. |
3142 template <typename S> | 3144 template <typename S> |
3143 V8_INLINE void Set(S* whatever); | 3145 V8_INLINE void Set(S* whatever); |
3144 | 3146 |
| 3147 // Getter. Creates a new Local<> so it comes with a certain performance |
| 3148 // hit. If the ReturnValue was not yet set, this will return the undefined |
| 3149 // value. |
| 3150 V8_INLINE Local<Value> Get() const; |
| 3151 |
3145 private: | 3152 private: |
3146 template<class F> friend class ReturnValue; | 3153 template<class F> friend class ReturnValue; |
3147 template<class F> friend class FunctionCallbackInfo; | 3154 template<class F> friend class FunctionCallbackInfo; |
3148 template<class F> friend class PropertyCallbackInfo; | 3155 template<class F> friend class PropertyCallbackInfo; |
3149 template <class F, class G, class H> | 3156 template <class F, class G, class H> |
3150 friend class PersistentValueMapBase; | 3157 friend class PersistentValueMapBase; |
3151 V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; } | 3158 V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; } |
3152 V8_INLINE internal::Object* GetDefaultValue(); | 3159 V8_INLINE internal::Object* GetDefaultValue(); |
3153 V8_INLINE explicit ReturnValue(internal::Object** slot); | 3160 V8_INLINE explicit ReturnValue(internal::Object** slot); |
3154 internal::Object** value_; | 3161 internal::Object** value_; |
(...skipping 4181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7336 | 7343 |
7337 static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize; | 7344 static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize; |
7338 static const int kAmountOfExternalAllocatedMemoryOffset = | 7345 static const int kAmountOfExternalAllocatedMemoryOffset = |
7339 4 * kApiPointerSize; | 7346 4 * kApiPointerSize; |
7340 static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset = | 7347 static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset = |
7341 kAmountOfExternalAllocatedMemoryOffset + kApiInt64Size; | 7348 kAmountOfExternalAllocatedMemoryOffset + kApiInt64Size; |
7342 static const int kIsolateRootsOffset = | 7349 static const int kIsolateRootsOffset = |
7343 kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset + kApiInt64Size + | 7350 kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset + kApiInt64Size + |
7344 kApiPointerSize; | 7351 kApiPointerSize; |
7345 static const int kUndefinedValueRootIndex = 4; | 7352 static const int kUndefinedValueRootIndex = 4; |
| 7353 static const int kTheHoleValueRootIndex = 5; |
7346 static const int kNullValueRootIndex = 6; | 7354 static const int kNullValueRootIndex = 6; |
7347 static const int kTrueValueRootIndex = 7; | 7355 static const int kTrueValueRootIndex = 7; |
7348 static const int kFalseValueRootIndex = 8; | 7356 static const int kFalseValueRootIndex = 8; |
7349 static const int kEmptyStringRootIndex = 9; | 7357 static const int kEmptyStringRootIndex = 9; |
7350 | 7358 |
7351 // The external allocation limit should be below 256 MB on all architectures | 7359 // The external allocation limit should be below 256 MB on all architectures |
7352 // to avoid that resource-constrained embedders run low on memory. | 7360 // to avoid that resource-constrained embedders run low on memory. |
7353 static const int kExternalAllocationLimit = 192 * 1024 * 1024; | 7361 static const int kExternalAllocationLimit = 192 * 1024 * 1024; |
7354 | 7362 |
7355 static const int kNodeClassIdOffset = 1 * kApiPointerSize; | 7363 static const int kNodeClassIdOffset = 1 * kApiPointerSize; |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7815 *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); | 7823 *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); |
7816 } | 7824 } |
7817 | 7825 |
7818 template<typename T> | 7826 template<typename T> |
7819 void ReturnValue<T>::SetEmptyString() { | 7827 void ReturnValue<T>::SetEmptyString() { |
7820 TYPE_CHECK(T, String); | 7828 TYPE_CHECK(T, String); |
7821 typedef internal::Internals I; | 7829 typedef internal::Internals I; |
7822 *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex); | 7830 *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex); |
7823 } | 7831 } |
7824 | 7832 |
7825 template<typename T> | 7833 template <typename T> |
7826 Isolate* ReturnValue<T>::GetIsolate() { | 7834 Isolate* ReturnValue<T>::GetIsolate() const { |
7827 // Isolate is always the pointer below the default value on the stack. | 7835 // Isolate is always the pointer below the default value on the stack. |
7828 return *reinterpret_cast<Isolate**>(&value_[-2]); | 7836 return *reinterpret_cast<Isolate**>(&value_[-2]); |
7829 } | 7837 } |
7830 | 7838 |
7831 template<typename T> | 7839 template <typename T> |
7832 template<typename S> | 7840 Local<Value> ReturnValue<T>::Get() const { |
| 7841 typedef internal::Internals I; |
| 7842 if (*value_ == *I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex)) |
| 7843 return Local<Value>(*Undefined(GetIsolate())); |
| 7844 return Local<Value>::New(GetIsolate(), reinterpret_cast<Value*>(value_)); |
| 7845 } |
| 7846 |
| 7847 template <typename T> |
| 7848 template <typename S> |
7833 void ReturnValue<T>::Set(S* whatever) { | 7849 void ReturnValue<T>::Set(S* whatever) { |
7834 // Uncompilable to prevent inadvertent misuse. | 7850 // Uncompilable to prevent inadvertent misuse. |
7835 TYPE_CHECK(S*, Primitive); | 7851 TYPE_CHECK(S*, Primitive); |
7836 } | 7852 } |
7837 | 7853 |
7838 template<typename T> | 7854 template<typename T> |
7839 internal::Object* ReturnValue<T>::GetDefaultValue() { | 7855 internal::Object* ReturnValue<T>::GetDefaultValue() { |
7840 // Default value is always the pointer below value_ on the stack. | 7856 // Default value is always the pointer below value_ on the stack. |
7841 return value_[-1]; | 7857 return value_[-1]; |
7842 } | 7858 } |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8758 */ | 8774 */ |
8759 | 8775 |
8760 | 8776 |
8761 } // namespace v8 | 8777 } // namespace v8 |
8762 | 8778 |
8763 | 8779 |
8764 #undef TYPE_CHECK | 8780 #undef TYPE_CHECK |
8765 | 8781 |
8766 | 8782 |
8767 #endif // INCLUDE_V8_H_ | 8783 #endif // INCLUDE_V8_H_ |
OLD | NEW |