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 2777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3120 // Fast primitive setters | 3122 // Fast primitive setters |
3121 V8_INLINE void Set(bool value); | 3123 V8_INLINE void Set(bool value); |
3122 V8_INLINE void Set(double i); | 3124 V8_INLINE void Set(double i); |
3123 V8_INLINE void Set(int32_t i); | 3125 V8_INLINE void Set(int32_t i); |
3124 V8_INLINE void Set(uint32_t i); | 3126 V8_INLINE void Set(uint32_t i); |
3125 // Fast JS primitive setters | 3127 // Fast JS primitive setters |
3126 V8_INLINE void SetNull(); | 3128 V8_INLINE void SetNull(); |
3127 V8_INLINE void SetUndefined(); | 3129 V8_INLINE void SetUndefined(); |
3128 V8_INLINE void SetEmptyString(); | 3130 V8_INLINE void SetEmptyString(); |
3129 // Convenience getter for Isolate | 3131 // Convenience getter for Isolate |
3130 V8_INLINE Isolate* GetIsolate(); | 3132 V8_INLINE Isolate* GetIsolate() const; |
3131 | 3133 |
3132 // Pointer setter: Uncompilable to prevent inadvertent misuse. | 3134 // Pointer setter: Uncompilable to prevent inadvertent misuse. |
3133 template <typename S> | 3135 template <typename S> |
3134 V8_INLINE void Set(S* whatever); | 3136 V8_INLINE void Set(S* whatever); |
3135 | 3137 |
| 3138 // Getter. Creates a new Local<> so it comes with a certain performance |
| 3139 // hit. If the ReturnValue was not yet set, this will return the undefined |
| 3140 // value. |
| 3141 V8_INLINE Local<Value> Get() const; |
| 3142 |
3136 private: | 3143 private: |
3137 template<class F> friend class ReturnValue; | 3144 template<class F> friend class ReturnValue; |
3138 template<class F> friend class FunctionCallbackInfo; | 3145 template<class F> friend class FunctionCallbackInfo; |
3139 template<class F> friend class PropertyCallbackInfo; | 3146 template<class F> friend class PropertyCallbackInfo; |
3140 template <class F, class G, class H> | 3147 template <class F, class G, class H> |
3141 friend class PersistentValueMapBase; | 3148 friend class PersistentValueMapBase; |
3142 V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; } | 3149 V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; } |
3143 V8_INLINE internal::Object* GetDefaultValue(); | 3150 V8_INLINE internal::Object* GetDefaultValue(); |
3144 V8_INLINE explicit ReturnValue(internal::Object** slot); | 3151 V8_INLINE explicit ReturnValue(internal::Object** slot); |
3145 internal::Object** value_; | 3152 internal::Object** value_; |
(...skipping 4181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7327 | 7334 |
7328 static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize; | 7335 static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize; |
7329 static const int kAmountOfExternalAllocatedMemoryOffset = | 7336 static const int kAmountOfExternalAllocatedMemoryOffset = |
7330 4 * kApiPointerSize; | 7337 4 * kApiPointerSize; |
7331 static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset = | 7338 static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset = |
7332 kAmountOfExternalAllocatedMemoryOffset + kApiInt64Size; | 7339 kAmountOfExternalAllocatedMemoryOffset + kApiInt64Size; |
7333 static const int kIsolateRootsOffset = | 7340 static const int kIsolateRootsOffset = |
7334 kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset + kApiInt64Size + | 7341 kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset + kApiInt64Size + |
7335 kApiPointerSize; | 7342 kApiPointerSize; |
7336 static const int kUndefinedValueRootIndex = 4; | 7343 static const int kUndefinedValueRootIndex = 4; |
| 7344 static const int kTheHoleValueRootIndex = 5; |
7337 static const int kNullValueRootIndex = 6; | 7345 static const int kNullValueRootIndex = 6; |
7338 static const int kTrueValueRootIndex = 7; | 7346 static const int kTrueValueRootIndex = 7; |
7339 static const int kFalseValueRootIndex = 8; | 7347 static const int kFalseValueRootIndex = 8; |
7340 static const int kEmptyStringRootIndex = 9; | 7348 static const int kEmptyStringRootIndex = 9; |
7341 | 7349 |
7342 // The external allocation limit should be below 256 MB on all architectures | 7350 // The external allocation limit should be below 256 MB on all architectures |
7343 // to avoid that resource-constrained embedders run low on memory. | 7351 // to avoid that resource-constrained embedders run low on memory. |
7344 static const int kExternalAllocationLimit = 192 * 1024 * 1024; | 7352 static const int kExternalAllocationLimit = 192 * 1024 * 1024; |
7345 | 7353 |
7346 static const int kNodeClassIdOffset = 1 * kApiPointerSize; | 7354 static const int kNodeClassIdOffset = 1 * kApiPointerSize; |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7806 *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); | 7814 *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); |
7807 } | 7815 } |
7808 | 7816 |
7809 template<typename T> | 7817 template<typename T> |
7810 void ReturnValue<T>::SetEmptyString() { | 7818 void ReturnValue<T>::SetEmptyString() { |
7811 TYPE_CHECK(T, String); | 7819 TYPE_CHECK(T, String); |
7812 typedef internal::Internals I; | 7820 typedef internal::Internals I; |
7813 *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex); | 7821 *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex); |
7814 } | 7822 } |
7815 | 7823 |
7816 template<typename T> | 7824 template <typename T> |
7817 Isolate* ReturnValue<T>::GetIsolate() { | 7825 Isolate* ReturnValue<T>::GetIsolate() const { |
7818 // Isolate is always the pointer below the default value on the stack. | 7826 // Isolate is always the pointer below the default value on the stack. |
7819 return *reinterpret_cast<Isolate**>(&value_[-2]); | 7827 return *reinterpret_cast<Isolate**>(&value_[-2]); |
7820 } | 7828 } |
7821 | 7829 |
7822 template<typename T> | 7830 template <typename T> |
7823 template<typename S> | 7831 Local<Value> ReturnValue<T>::Get() const { |
| 7832 typedef internal::Internals I; |
| 7833 if (*value_ == *I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex)) |
| 7834 return Local<Value>(*Undefined(GetIsolate())); |
| 7835 return Local<Value>::New(GetIsolate(), reinterpret_cast<Value*>(value_)); |
| 7836 } |
| 7837 |
| 7838 template <typename T> |
| 7839 template <typename S> |
7824 void ReturnValue<T>::Set(S* whatever) { | 7840 void ReturnValue<T>::Set(S* whatever) { |
7825 // Uncompilable to prevent inadvertent misuse. | 7841 // Uncompilable to prevent inadvertent misuse. |
7826 TYPE_CHECK(S*, Primitive); | 7842 TYPE_CHECK(S*, Primitive); |
7827 } | 7843 } |
7828 | 7844 |
7829 template<typename T> | 7845 template<typename T> |
7830 internal::Object* ReturnValue<T>::GetDefaultValue() { | 7846 internal::Object* ReturnValue<T>::GetDefaultValue() { |
7831 // Default value is always the pointer below value_ on the stack. | 7847 // Default value is always the pointer below value_ on the stack. |
7832 return value_[-1]; | 7848 return value_[-1]; |
7833 } | 7849 } |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8749 */ | 8765 */ |
8750 | 8766 |
8751 | 8767 |
8752 } // namespace v8 | 8768 } // namespace v8 |
8753 | 8769 |
8754 | 8770 |
8755 #undef TYPE_CHECK | 8771 #undef TYPE_CHECK |
8756 | 8772 |
8757 | 8773 |
8758 #endif // INCLUDE_V8_H_ | 8774 #endif // INCLUDE_V8_H_ |
OLD | NEW |