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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 template<typename P> | 505 template<typename P> |
506 V8_INLINE void SetWeak( | 506 V8_INLINE void SetWeak( |
507 P* parameter, | 507 P* parameter, |
508 typename WeakCallbackData<T, P>::Callback callback); | 508 typename WeakCallbackData<T, P>::Callback callback); |
509 | 509 |
510 template<typename S, typename P> | 510 template<typename S, typename P> |
511 V8_INLINE void SetWeak( | 511 V8_INLINE void SetWeak( |
512 P* parameter, | 512 P* parameter, |
513 typename WeakCallbackData<S, P>::Callback callback); | 513 typename WeakCallbackData<S, P>::Callback callback); |
514 | 514 |
515 // Phantom persistents work like weak persistents, except that the pointer to | |
516 // the object being collected is not available in the finalization callback. | |
517 // This enables the garbage collector to collect the object and any objects | |
518 // it references transitively in one GC cycle. | |
519 template <typename P> | |
520 V8_INLINE void SetPhantom(P* parameter, | |
ulan
2014/10/20 14:03:10
Shouldn't phantom reference be in its own class, s
Erik Corry
2014/10/20 14:25:32
I think you want to allow deref before the object
Erik Corry
2014/10/22 13:21:00
I'll revise my answer to the second part slightly:
| |
521 typename WeakCallbackData<T, P>::Callback callback); | |
522 | |
523 template <typename S, typename P> | |
524 V8_INLINE void SetPhantom(P* parameter, | |
525 typename WeakCallbackData<S, P>::Callback callback); | |
526 | |
515 template<typename P> | 527 template<typename P> |
516 V8_INLINE P* ClearWeak(); | 528 V8_INLINE P* ClearWeak(); |
517 | 529 |
518 // TODO(dcarney): remove this. | 530 // TODO(dcarney): remove this. |
519 V8_INLINE void ClearWeak() { ClearWeak<void>(); } | 531 V8_INLINE void ClearWeak() { ClearWeak<void>(); } |
520 | 532 |
521 /** | 533 /** |
522 * Marks the reference to this object independent. Garbage collector is free | 534 * Marks the reference to this object independent. Garbage collector is free |
523 * to ignore any object groups containing this object. Weak callback for an | 535 * to ignore any object groups containing this object. Weak callback for an |
524 * independent handle should not assume that it will be preceded by a global | 536 * independent handle should not assume that it will be preceded by a global |
(...skipping 4795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5320 | 5332 |
5321 /** | 5333 /** |
5322 * Clears all references to the v8::Platform. This should be invoked after | 5334 * Clears all references to the v8::Platform. This should be invoked after |
5323 * V8 was disposed. | 5335 * V8 was disposed. |
5324 */ | 5336 */ |
5325 static void ShutdownPlatform(); | 5337 static void ShutdownPlatform(); |
5326 | 5338 |
5327 private: | 5339 private: |
5328 V8(); | 5340 V8(); |
5329 | 5341 |
5342 enum WeakHandleType { PhantomHandle, NonphantomHandle }; | |
5343 | |
5330 static internal::Object** GlobalizeReference(internal::Isolate* isolate, | 5344 static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
5331 internal::Object** handle); | 5345 internal::Object** handle); |
5332 static internal::Object** CopyPersistent(internal::Object** handle); | 5346 static internal::Object** CopyPersistent(internal::Object** handle); |
5333 static void DisposeGlobal(internal::Object** global_handle); | 5347 static void DisposeGlobal(internal::Object** global_handle); |
5334 typedef WeakCallbackData<Value, void>::Callback WeakCallback; | 5348 typedef WeakCallbackData<Value, void>::Callback WeakCallback; |
5335 static void MakeWeak(internal::Object** global_handle, | 5349 static void MakeWeak(internal::Object** global_handle, void* data, |
5336 void* data, | 5350 WeakCallback weak_callback, WeakHandleType phantom); |
5337 WeakCallback weak_callback); | |
5338 static void* ClearWeak(internal::Object** global_handle); | 5351 static void* ClearWeak(internal::Object** global_handle); |
5339 static void Eternalize(Isolate* isolate, | 5352 static void Eternalize(Isolate* isolate, |
5340 Value* handle, | 5353 Value* handle, |
5341 int* index); | 5354 int* index); |
5342 static Local<Value> GetEternal(Isolate* isolate, int index); | 5355 static Local<Value> GetEternal(Isolate* isolate, int index); |
5343 | 5356 |
5344 template <class T> friend class Handle; | 5357 template <class T> friend class Handle; |
5345 template <class T> friend class Local; | 5358 template <class T> friend class Local; |
5346 template <class T> friend class Eternal; | 5359 template <class T> friend class Eternal; |
5347 template <class T> friend class PersistentBase; | 5360 template <class T> friend class PersistentBase; |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6190 } | 6203 } |
6191 | 6204 |
6192 | 6205 |
6193 template <class T> | 6206 template <class T> |
6194 template <typename S, typename P> | 6207 template <typename S, typename P> |
6195 void PersistentBase<T>::SetWeak( | 6208 void PersistentBase<T>::SetWeak( |
6196 P* parameter, | 6209 P* parameter, |
6197 typename WeakCallbackData<S, P>::Callback callback) { | 6210 typename WeakCallbackData<S, P>::Callback callback) { |
6198 TYPE_CHECK(S, T); | 6211 TYPE_CHECK(S, T); |
6199 typedef typename WeakCallbackData<Value, void>::Callback Callback; | 6212 typedef typename WeakCallbackData<Value, void>::Callback Callback; |
6200 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), | 6213 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter, |
6201 parameter, | 6214 reinterpret_cast<Callback>(callback), V8::NonphantomHandle); |
6202 reinterpret_cast<Callback>(callback)); | |
6203 } | 6215 } |
6204 | 6216 |
6205 | 6217 |
6206 template <class T> | 6218 template <class T> |
6207 template <typename P> | 6219 template <typename P> |
6208 void PersistentBase<T>::SetWeak( | 6220 void PersistentBase<T>::SetWeak( |
6209 P* parameter, | 6221 P* parameter, |
6210 typename WeakCallbackData<T, P>::Callback callback) { | 6222 typename WeakCallbackData<T, P>::Callback callback) { |
6211 SetWeak<T, P>(parameter, callback); | 6223 SetWeak<T, P>(parameter, callback); |
6212 } | 6224 } |
6213 | 6225 |
6214 | 6226 |
6215 template <class T> | 6227 template <class T> |
6216 template<typename P> | 6228 template <typename S, typename P> |
6229 void PersistentBase<T>::SetPhantom( | |
6230 P* parameter, typename WeakCallbackData<S, P>::Callback callback) { | |
6231 TYPE_CHECK(S, T); | |
6232 typedef typename WeakCallbackData<Value, void>::Callback Callback; | |
6233 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter, | |
6234 reinterpret_cast<Callback>(callback), V8::PhantomHandle); | |
6235 } | |
6236 | |
6237 | |
6238 template <class T> | |
6239 template <typename P> | |
6240 void PersistentBase<T>::SetPhantom( | |
6241 P* parameter, typename WeakCallbackData<T, P>::Callback callback) { | |
6242 SetPhantom<T, P>(parameter, callback); | |
6243 } | |
6244 | |
6245 | |
6246 template <class T> | |
6247 template <typename P> | |
6217 P* PersistentBase<T>::ClearWeak() { | 6248 P* PersistentBase<T>::ClearWeak() { |
6218 return reinterpret_cast<P*>( | 6249 return reinterpret_cast<P*>( |
6219 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_))); | 6250 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_))); |
6220 } | 6251 } |
6221 | 6252 |
6222 | 6253 |
6223 template <class T> | 6254 template <class T> |
6224 void PersistentBase<T>::MarkIndependent() { | 6255 void PersistentBase<T>::MarkIndependent() { |
6225 typedef internal::Internals I; | 6256 typedef internal::Internals I; |
6226 if (this->IsEmpty()) return; | 6257 if (this->IsEmpty()) return; |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7047 */ | 7078 */ |
7048 | 7079 |
7049 | 7080 |
7050 } // namespace v8 | 7081 } // namespace v8 |
7051 | 7082 |
7052 | 7083 |
7053 #undef TYPE_CHECK | 7084 #undef TYPE_CHECK |
7054 | 7085 |
7055 | 7086 |
7056 #endif // V8_H_ | 7087 #endif // V8_H_ |
OLD | NEW |