Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: include/v8.h

Issue 88013002: Split Persistent into Persistent and UniquePersistent (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: comments Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 class Symbol; 116 class Symbol;
117 class SymbolObject; 117 class SymbolObject;
118 class Private; 118 class Private;
119 class Uint32; 119 class Uint32;
120 class Utils; 120 class Utils;
121 class Value; 121 class Value;
122 template <class T> class Handle; 122 template <class T> class Handle;
123 template <class T> class Local; 123 template <class T> class Local;
124 template <class T> class Eternal; 124 template <class T> class Eternal;
125 template<class T> class NonCopyablePersistentTraits; 125 template<class T> class NonCopyablePersistentTraits;
126 template<class T> class PersistentBase;
126 template<class T, 127 template<class T,
127 class M = NonCopyablePersistentTraits<T> > class Persistent; 128 class M = NonCopyablePersistentTraits<T> > class Persistent;
129 template<class T> class UniquePersistent;
128 template<class T, class P> class WeakCallbackObject; 130 template<class T, class P> class WeakCallbackObject;
129 class FunctionTemplate; 131 class FunctionTemplate;
130 class ObjectTemplate; 132 class ObjectTemplate;
131 class Data; 133 class Data;
132 template<typename T> class PropertyCallbackInfo; 134 template<typename T> class PropertyCallbackInfo;
133 class StackTrace; 135 class StackTrace;
134 class StackFrame; 136 class StackFrame;
135 class Isolate; 137 class Isolate;
136 class DeclaredAccessorDescriptor; 138 class DeclaredAccessorDescriptor;
137 class ObjectOperationDescriptor; 139 class ObjectOperationDescriptor;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 252
251 V8_INLINE T* operator*() const { return val_; } 253 V8_INLINE T* operator*() const { return val_; }
252 254
253 /** 255 /**
254 * Checks whether two handles are the same. 256 * Checks whether two handles are the same.
255 * Returns true if both are empty, or if the objects 257 * Returns true if both are empty, or if the objects
256 * to which they refer are identical. 258 * to which they refer are identical.
257 * The handles' references are not checked. 259 * The handles' references are not checked.
258 */ 260 */
259 template <class S> V8_INLINE bool operator==(const Handle<S>& that) const { 261 template <class S> V8_INLINE bool operator==(const Handle<S>& that) const {
260 internal::Object** a = reinterpret_cast<internal::Object**>(**this); 262 internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
261 internal::Object** b = reinterpret_cast<internal::Object**>(*that); 263 internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
262 if (a == 0) return b == 0; 264 if (a == 0) return b == 0;
263 if (b == 0) return false; 265 if (b == 0) return false;
264 return *a == *b; 266 return *a == *b;
265 } 267 }
266 268
267 template <class S> V8_INLINE bool operator==( 269 template <class S> V8_INLINE bool operator==(
268 const Persistent<S>& that) const { 270 const PersistentBase<S>& that) const {
269 internal::Object** a = reinterpret_cast<internal::Object**>(**this); 271 internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
270 internal::Object** b = reinterpret_cast<internal::Object**>(*that); 272 internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
271 if (a == 0) return b == 0; 273 if (a == 0) return b == 0;
272 if (b == 0) return false; 274 if (b == 0) return false;
273 return *a == *b; 275 return *a == *b;
274 } 276 }
275 277
276 /** 278 /**
277 * Checks whether two handles are different. 279 * Checks whether two handles are different.
278 * Returns true if only one of the handles is empty, or if 280 * Returns true if only one of the handles is empty, or if
279 * the objects to which they refer are different. 281 * the objects to which they refer are different.
280 * The handles' references are not checked. 282 * The handles' references are not checked.
(...skipping 16 matching lines...) Expand all
297 return Handle<T>(T::Cast(*that)); 299 return Handle<T>(T::Cast(*that));
298 } 300 }
299 301
300 template <class S> V8_INLINE Handle<S> As() { 302 template <class S> V8_INLINE Handle<S> As() {
301 return Handle<S>::Cast(*this); 303 return Handle<S>::Cast(*this);
302 } 304 }
303 305
304 V8_INLINE static Handle<T> New(Isolate* isolate, Handle<T> that) { 306 V8_INLINE static Handle<T> New(Isolate* isolate, Handle<T> that) {
305 return New(isolate, that.val_); 307 return New(isolate, that.val_);
306 } 308 }
307 V8_INLINE static Handle<T> New(Isolate* isolate, const Persistent<T>& that) { 309 V8_INLINE static Handle<T> New(Isolate* isolate,
310 const PersistentBase<T>& that) {
308 return New(isolate, that.val_); 311 return New(isolate, that.val_);
309 } 312 }
310 313
311 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR 314 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
312 315
313 private: 316 private:
314 #endif 317 #endif
315 /** 318 /**
316 * Creates a new handle for the specified value. 319 * Creates a new handle for the specified value.
317 */ 320 */
318 V8_INLINE explicit Handle(T* val) : val_(val) {} 321 V8_INLINE explicit Handle(T* val) : val_(val) {}
319 322
320 private: 323 private:
321 friend class Utils; 324 friend class Utils;
322 template<class F, class M> friend class Persistent; 325 template<class F, class M> friend class Persistent;
326 template<class F> friend class PersistentBase;
327 template<class F> friend class Handle;
323 template<class F> friend class Local; 328 template<class F> friend class Local;
324 template<class F> friend class FunctionCallbackInfo; 329 template<class F> friend class FunctionCallbackInfo;
325 template<class F> friend class PropertyCallbackInfo; 330 template<class F> friend class PropertyCallbackInfo;
326 template<class F> friend class internal::CustomArguments; 331 template<class F> friend class internal::CustomArguments;
327 friend Handle<Primitive> Undefined(Isolate* isolate); 332 friend Handle<Primitive> Undefined(Isolate* isolate);
328 friend Handle<Primitive> Null(Isolate* isolate); 333 friend Handle<Primitive> Null(Isolate* isolate);
329 friend Handle<Boolean> True(Isolate* isolate); 334 friend Handle<Boolean> True(Isolate* isolate);
330 friend Handle<Boolean> False(Isolate* isolate); 335 friend Handle<Boolean> False(Isolate* isolate);
331 friend class Context; 336 friend class Context;
332 friend class HandleScope; 337 friend class HandleScope;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 template <class S> V8_INLINE Local<S> As() { 381 template <class S> V8_INLINE Local<S> As() {
377 return Local<S>::Cast(*this); 382 return Local<S>::Cast(*this);
378 } 383 }
379 384
380 /** 385 /**
381 * Create a local handle for the content of another handle. 386 * Create a local handle for the content of another handle.
382 * The referee is kept alive by the local handle even when 387 * The referee is kept alive by the local handle even when
383 * the original handle is destroyed/disposed. 388 * the original handle is destroyed/disposed.
384 */ 389 */
385 V8_INLINE static Local<T> New(Isolate* isolate, Handle<T> that); 390 V8_INLINE static Local<T> New(Isolate* isolate, Handle<T> that);
386 template<class M>
Paweł Hajdan Jr. 2013/12/20 11:47:51 Is this change backward-compatible? It seems that
Sven Panne 2013/12/20 11:49:50 As mentioned in another CL comment, we aim for a d
387 V8_INLINE static Local<T> New(Isolate* isolate, 391 V8_INLINE static Local<T> New(Isolate* isolate,
388 const Persistent<T, M>& that); 392 const PersistentBase<T>& that);
389 393
390 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR 394 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
391 395
392 private: 396 private:
393 #endif 397 #endif
394 template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { } 398 template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { }
395 399
396 private: 400 private:
397 friend class Utils; 401 friend class Utils;
398 template<class F> friend class Eternal; 402 template<class F> friend class Eternal;
403 template<class F> friend class PersistentBase;
399 template<class F, class M> friend class Persistent; 404 template<class F, class M> friend class Persistent;
400 template<class F> friend class Handle; 405 template<class F> friend class Handle;
406 template<class F> friend class Local;
401 template<class F> friend class FunctionCallbackInfo; 407 template<class F> friend class FunctionCallbackInfo;
402 template<class F> friend class PropertyCallbackInfo; 408 template<class F> friend class PropertyCallbackInfo;
403 friend class String; 409 friend class String;
404 friend class Object; 410 friend class Object;
405 friend class Context; 411 friend class Context;
406 template<class F> friend class internal::CustomArguments; 412 template<class F> friend class internal::CustomArguments;
407 friend class HandleScope; 413 friend class HandleScope;
408 friend class EscapableHandleScope; 414 friend class EscapableHandleScope;
409 415
410 V8_INLINE static Local<T> New(Isolate* isolate, T* that); 416 V8_INLINE static Local<T> New(Isolate* isolate, T* that);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 typename M = NonCopyablePersistentTraits<T> > 461 typename M = NonCopyablePersistentTraits<T> >
456 class WeakReferenceCallbacks { 462 class WeakReferenceCallbacks {
457 public: 463 public:
458 typedef void (*Revivable)(Isolate* isolate, 464 typedef void (*Revivable)(Isolate* isolate,
459 Persistent<T, M>* object, 465 Persistent<T, M>* object,
460 P* parameter); 466 P* parameter);
461 }; 467 };
462 468
463 469
464 /** 470 /**
471 * An object reference that is independent of any handle scope. Where
472 * a Local handle only lives as long as the HandleScope in which it was
473 * allocated, a PersistentBase handle remains valid until it is explicitly
474 * disposed.
475 *
476 * A persistent handle contains a reference to a storage cell within
477 * the v8 engine which holds an object value and which is updated by
478 * the garbage collector whenever the object is moved. A new storage
479 * cell can be created using the constructor or PersistentBase::Reset and
480 * existing handles can be disposed using PersistentBase::Reset.
481 *
482 */
483 template <class T> class PersistentBase {
484 public:
485 /**
486 * If non-empty, destroy the underlying storage cell
487 * IsEmpty() will return true after this call.
488 */
489 V8_INLINE void Reset();
490 /**
491 * If non-empty, destroy the underlying storage cell
492 * and create a new one with the contents of other if other is non empty
493 */
494 template <class S>
495 V8_INLINE void Reset(Isolate* isolate, const Handle<S>& other);
496
497 /**
498 * If non-empty, destroy the underlying storage cell
499 * and create a new one with the contents of other if other is non empty
500 */
501 template <class S>
502 V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
503
504 V8_INLINE bool IsEmpty() const { return val_ == 0; }
505
506 template <class S>
507 V8_INLINE bool operator==(const PersistentBase<S>& that) const {
508 internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
509 internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
510 if (a == 0) return b == 0;
511 if (b == 0) return false;
512 return *a == *b;
513 }
514
515 template <class S> V8_INLINE bool operator==(const Handle<S>& that) const {
516 internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
517 internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
518 if (a == 0) return b == 0;
519 if (b == 0) return false;
520 return *a == *b;
521 }
522
523 template <class S>
524 V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
525 return !operator==(that);
526 }
527
528 template <class S> V8_INLINE bool operator!=(const Handle<S>& that) const {
529 return !operator==(that);
530 }
531
532 template<typename P>
533 V8_INLINE void SetWeak(
534 P* parameter,
535 typename WeakCallbackData<T, P>::Callback callback);
536
537 template<typename S, typename P>
538 V8_INLINE void SetWeak(
539 P* parameter,
540 typename WeakCallbackData<S, P>::Callback callback);
541
542 V8_INLINE void ClearWeak();
543
544 /**
545 * Marks the reference to this object independent. Garbage collector is free
546 * to ignore any object groups containing this object. Weak callback for an
547 * independent handle should not assume that it will be preceded by a global
548 * GC prologue callback or followed by a global GC epilogue callback.
549 */
550 V8_INLINE void MarkIndependent();
551
552 /**
553 * Marks the reference to this object partially dependent. Partially dependent
554 * handles only depend on other partially dependent handles and these
555 * dependencies are provided through object groups. It provides a way to build
556 * smaller object groups for young objects that represent only a subset of all
557 * external dependencies. This mark is automatically cleared after each
558 * garbage collection.
559 */
560 V8_INLINE void MarkPartiallyDependent();
561
562 V8_INLINE bool IsIndependent() const;
563
564 /** Checks if the handle holds the only reference to an object. */
565 V8_INLINE bool IsNearDeath() const;
566
567 /** Returns true if the handle's reference is weak. */
568 V8_INLINE bool IsWeak() const;
569
570 /**
571 * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface
572 * description in v8-profiler.h for details.
573 */
574 V8_INLINE void SetWrapperClassId(uint16_t class_id);
575
576 /**
577 * Returns the class ID previously assigned to this handle or 0 if no class ID
578 * was previously assigned.
579 */
580 V8_INLINE uint16_t WrapperClassId() const;
581
582 private:
583 friend class Isolate;
584 friend class Utils;
585 template<class F> friend class Handle;
586 template<class F> friend class Local;
587 template<class F1, class F2> friend class Persistent;
588 template<class F> friend class UniquePersistent;
589 template<class F> friend class PersistentBase;
590 template<class F> friend class ReturnValue;
591
592 explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
593 PersistentBase(PersistentBase& other); // NOLINT
594 void operator=(PersistentBase&);
595 V8_INLINE static T* New(Isolate* isolate, T* that);
596
597 T* val_;
598 };
599
600
601 /**
465 * Default traits for Persistent. This class does not allow 602 * Default traits for Persistent. This class does not allow
466 * use of the copy constructor or assignment operator. 603 * use of the copy constructor or assignment operator.
467 * At present kResetInDestructor is not set, but that will change in a future 604 * At present kResetInDestructor is not set, but that will change in a future
468 * version. 605 * version.
469 */ 606 */
470 template<class T> 607 template<class T>
471 class NonCopyablePersistentTraits { 608 class NonCopyablePersistentTraits {
472 public: 609 public:
473 typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent; 610 typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent;
474 static const bool kResetInDestructor = false; 611 static const bool kResetInDestructor = false;
(...skipping 19 matching lines...) Expand all
494 static const bool kResetInDestructor = true; 631 static const bool kResetInDestructor = true;
495 template<class S, class M> 632 template<class S, class M>
496 static V8_INLINE void Copy(const Persistent<S, M>& source, 633 static V8_INLINE void Copy(const Persistent<S, M>& source,
497 CopyablePersistent* dest) { 634 CopyablePersistent* dest) {
498 // do nothing, just allow copy 635 // do nothing, just allow copy
499 } 636 }
500 }; 637 };
501 638
502 639
503 /** 640 /**
504 * An object reference that is independent of any handle scope. Where 641 * A PersistentBase which allows copy and assignment.
505 * a Local handle only lives as long as the HandleScope in which it was
506 * allocated, a Persistent handle remains valid until it is explicitly
507 * disposed.
508 *
509 * A persistent handle contains a reference to a storage cell within
510 * the v8 engine which holds an object value and which is updated by
511 * the garbage collector whenever the object is moved. A new storage
512 * cell can be created using the constructor or Persistent::Reset and
513 * existing handles can be disposed using Persistent::Reset.
514 * 642 *
515 * Copy, assignment and destructor bevavior is controlled by the traits 643 * Copy, assignment and destructor bevavior is controlled by the traits
516 * class M. 644 * class M.
645 *
646 * Note: Persistent class hierarchy is subject to future changes.
517 */ 647 */
518 template <class T, class M> class Persistent { 648 template <class T, class M> class Persistent : public PersistentBase<T> {
519 public: 649 public:
520 /** 650 /**
521 * A Persistent with no storage cell. 651 * A Persistent with no storage cell.
522 */ 652 */
523 V8_INLINE Persistent() : val_(0) { } 653 V8_INLINE Persistent() : PersistentBase<T>(0) { }
524 /** 654 /**
525 * Construct a Persistent from a Handle. 655 * Construct a Persistent from a Handle.
526 * When the Handle is non-empty, a new storage cell is created 656 * When the Handle is non-empty, a new storage cell is created
527 * pointing to the same object, and no flags are set. 657 * pointing to the same object, and no flags are set.
528 */ 658 */
529 template <class S> V8_INLINE Persistent(Isolate* isolate, Handle<S> that) 659 template <class S> V8_INLINE Persistent(Isolate* isolate, Handle<S> that)
530 : val_(New(isolate, *that)) { 660 : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
531 TYPE_CHECK(T, S); 661 TYPE_CHECK(T, S);
532 } 662 }
533 /** 663 /**
534 * Construct a Persistent from a Persistent. 664 * Construct a Persistent from a Persistent.
535 * When the Persistent is non-empty, a new storage cell is created 665 * When the Persistent is non-empty, a new storage cell is created
536 * pointing to the same object, and no flags are set. 666 * pointing to the same object, and no flags are set.
537 */ 667 */
538 template <class S, class M2> 668 template <class S, class M2>
539 V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that) 669 V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
540 : val_(New(isolate, *that)) { 670 : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
541 TYPE_CHECK(T, S); 671 TYPE_CHECK(T, S);
542 } 672 }
543 /** 673 /**
544 * The copy constructors and assignment operator create a Persistent 674 * The copy constructors and assignment operator create a Persistent
545 * exactly as the Persistent constructor, but the Copy function from the 675 * exactly as the Persistent constructor, but the Copy function from the
546 * traits class is called, allowing the setting of flags based on the 676 * traits class is called, allowing the setting of flags based on the
547 * copied Persistent. 677 * copied Persistent.
548 */ 678 */
549 V8_INLINE Persistent(const Persistent& that) : val_(0) { 679 V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(0) {
550 Copy(that); 680 Copy(that);
551 } 681 }
552 template <class S, class M2> 682 template <class S, class M2>
553 V8_INLINE Persistent(const Persistent<S, M2>& that) : val_(0) { 683 V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) {
554 Copy(that); 684 Copy(that);
555 } 685 }
556 V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT 686 V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
557 Copy(that); 687 Copy(that);
558 return *this; 688 return *this;
559 } 689 }
560 template <class S, class M2> 690 template <class S, class M2>
561 V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT 691 V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT
562 Copy(that); 692 Copy(that);
563 return *this; 693 return *this;
564 } 694 }
565 /** 695 /**
566 * The destructor will dispose the Persistent based on the 696 * The destructor will dispose the Persistent based on the
567 * kResetInDestructor flags in the traits class. Since not calling dispose 697 * kResetInDestructor flags in the traits class. Since not calling dispose
568 * can result in a memory leak, it is recommended to always set this flag. 698 * can result in a memory leak, it is recommended to always set this flag.
569 */ 699 */
570 V8_INLINE ~Persistent() { 700 V8_INLINE ~Persistent() {
571 if (M::kResetInDestructor) Reset(); 701 if (M::kResetInDestructor) this->Reset();
572 } 702 }
573 703
574 /**
575 * If non-empty, destroy the underlying storage cell
576 * IsEmpty() will return true after this call.
577 */
578 V8_INLINE void Reset();
579 /**
580 * If non-empty, destroy the underlying storage cell
581 * and create a new one with the contents of other if other is non empty
582 */
583 template <class S>
584 V8_INLINE void Reset(Isolate* isolate, const Handle<S>& other);
585 /**
586 * If non-empty, destroy the underlying storage cell
587 * and create a new one with the contents of other if other is non empty
588 */
589 template <class S, class M2>
590 V8_INLINE void Reset(Isolate* isolate, const Persistent<S, M2>& other);
591
592 V8_DEPRECATED("Use Reset instead", 704 V8_DEPRECATED("Use Reset instead",
593 V8_INLINE void Dispose()) { Reset(); } 705 V8_INLINE void Dispose()) { this->Reset(); }
594
595 V8_INLINE bool IsEmpty() const { return val_ == 0; }
596 706
597 // TODO(dcarney): this is pretty useless, fix or remove 707 // TODO(dcarney): this is pretty useless, fix or remove
598 template <class S> 708 template <class S>
599 V8_INLINE static Persistent<T>& Cast(Persistent<S>& that) { // NOLINT 709 V8_INLINE static Persistent<T>& Cast(Persistent<S>& that) { // NOLINT
600 #ifdef V8_ENABLE_CHECKS 710 #ifdef V8_ENABLE_CHECKS
601 // If we're going to perform the type check then we have to check 711 // If we're going to perform the type check then we have to check
602 // that the handle isn't empty before doing the checked cast. 712 // that the handle isn't empty before doing the checked cast.
603 if (!that.IsEmpty()) T::Cast(*that); 713 if (!that.IsEmpty()) T::Cast(*that);
604 #endif 714 #endif
605 return reinterpret_cast<Persistent<T>&>(that); 715 return reinterpret_cast<Persistent<T>&>(that);
606 } 716 }
607 717
608 // TODO(dcarney): this is pretty useless, fix or remove 718 // TODO(dcarney): this is pretty useless, fix or remove
609 template <class S> V8_INLINE Persistent<S>& As() { // NOLINT 719 template <class S> V8_INLINE Persistent<S>& As() { // NOLINT
610 return Persistent<S>::Cast(*this); 720 return Persistent<S>::Cast(*this);
611 } 721 }
612 722
613 template <class S, class M2>
614 V8_INLINE bool operator==(const Persistent<S, M2>& that) const {
615 internal::Object** a = reinterpret_cast<internal::Object**>(**this);
616 internal::Object** b = reinterpret_cast<internal::Object**>(*that);
617 if (a == 0) return b == 0;
618 if (b == 0) return false;
619 return *a == *b;
620 }
621
622 template <class S> V8_INLINE bool operator==(const Handle<S>& that) const {
623 internal::Object** a = reinterpret_cast<internal::Object**>(**this);
624 internal::Object** b = reinterpret_cast<internal::Object**>(*that);
625 if (a == 0) return b == 0;
626 if (b == 0) return false;
627 return *a == *b;
628 }
629
630 template <class S, class M2>
631 V8_INLINE bool operator!=(const Persistent<S, M2>& that) const {
632 return !operator==(that);
633 }
634
635 template <class S> V8_INLINE bool operator!=(const Handle<S>& that) const {
636 return !operator==(that);
637 }
638
639 template<typename P>
640 V8_INLINE void SetWeak(
641 P* parameter,
642 typename WeakCallbackData<T, P>::Callback callback);
643
644 template<typename S, typename P>
645 V8_INLINE void SetWeak(
646 P* parameter,
647 typename WeakCallbackData<S, P>::Callback callback);
648
649 template<typename S, typename P> 723 template<typename S, typename P>
650 V8_DEPRECATED( 724 V8_DEPRECATED(
651 "Use SetWeak instead", 725 "Use SetWeak instead",
652 V8_INLINE void MakeWeak( 726 V8_INLINE void MakeWeak(
653 P* parameter, 727 P* parameter,
654 typename WeakReferenceCallbacks<S, P>::Revivable callback)); 728 typename WeakReferenceCallbacks<S, P>::Revivable callback));
655 729
656 template<typename P> 730 template<typename P>
657 V8_DEPRECATED( 731 V8_DEPRECATED(
658 "Use SetWeak instead", 732 "Use SetWeak instead",
659 V8_INLINE void MakeWeak( 733 V8_INLINE void MakeWeak(
660 P* parameter, 734 P* parameter,
661 typename WeakReferenceCallbacks<T, P>::Revivable callback)); 735 typename WeakReferenceCallbacks<T, P>::Revivable callback));
662 736
663 V8_INLINE void ClearWeak();
664
665 /**
666 * Marks the reference to this object independent. Garbage collector is free
667 * to ignore any object groups containing this object. Weak callback for an
668 * independent handle should not assume that it will be preceded by a global
669 * GC prologue callback or followed by a global GC epilogue callback.
670 */
671 V8_INLINE void MarkIndependent();
672
673 /**
674 * Marks the reference to this object partially dependent. Partially dependent
675 * handles only depend on other partially dependent handles and these
676 * dependencies are provided through object groups. It provides a way to build
677 * smaller object groups for young objects that represent only a subset of all
678 * external dependencies. This mark is automatically cleared after each
679 * garbage collection.
680 */
681 V8_INLINE void MarkPartiallyDependent();
682
683 V8_INLINE bool IsIndependent() const;
684
685 /** Checks if the handle holds the only reference to an object. */
686 V8_INLINE bool IsNearDeath() const;
687
688 /** Returns true if the handle's reference is weak. */
689 V8_INLINE bool IsWeak() const;
690
691 /**
692 * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface
693 * description in v8-profiler.h for details.
694 */
695 V8_INLINE void SetWrapperClassId(uint16_t class_id);
696
697 /**
698 * Returns the class ID previously assigned to this handle or 0 if no class ID
699 * was previously assigned.
700 */
701 V8_INLINE uint16_t WrapperClassId() const;
702
703 V8_DEPRECATED("This will be removed", 737 V8_DEPRECATED("This will be removed",
704 V8_INLINE T* ClearAndLeak()); 738 V8_INLINE T* ClearAndLeak());
705 739
706 V8_DEPRECATED("This will be removed", 740 V8_DEPRECATED("This will be removed",
707 V8_INLINE void Clear()) { val_ = 0; } 741 V8_INLINE void Clear()) { this->val_ = 0; }
708 742
709 // TODO(dcarney): remove 743 // TODO(dcarney): remove
710 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR 744 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
711 745
712 private: 746 private:
713 #endif 747 #endif
714 template <class S> V8_INLINE Persistent(S* that) : val_(that) { } 748 template <class S> V8_INLINE Persistent(S* that) : PersistentBase<T>(that) { }
715 749
716 V8_INLINE T* operator*() const { return val_; } 750 V8_INLINE T* operator*() const { return this->val_; }
717 751
718 private: 752 private:
719 friend class Isolate; 753 friend class Isolate;
720 friend class Utils; 754 friend class Utils;
721 template<class F> friend class Handle; 755 template<class F> friend class Handle;
722 template<class F> friend class Local; 756 template<class F> friend class Local;
723 template<class F1, class F2> friend class Persistent; 757 template<class F1, class F2> friend class Persistent;
724 template<class F> friend class ReturnValue; 758 template<class F> friend class ReturnValue;
725 759
726 V8_INLINE static T* New(Isolate* isolate, T* that);
727 template<class S, class M2> 760 template<class S, class M2>
728 V8_INLINE void Copy(const Persistent<S, M2>& that); 761 V8_INLINE void Copy(const Persistent<S, M2>& that);
762 };
729 763
730 T* val_; 764
765 /**
766 * A PersistentBase which has move semantics.
767 *
768 * Note: Persistent class hierarchy is subject to future changes.
769 */
770 template<class T>
771 class UniquePersistent : public PersistentBase<T> {
772 struct RValue {
773 V8_INLINE explicit RValue(UniquePersistent* object) : object(object) {}
774 UniquePersistent* object;
775 };
776
777 public:
778 /**
779 * A UniquePersistent with no storage cell.
780 */
781 V8_INLINE UniquePersistent() : PersistentBase<T>(0) { }
782 /**
783 * Construct a UniquePersistent from a Handle.
784 * When the Handle is non-empty, a new storage cell is created
785 * pointing to the same object, and no flags are set.
786 */
787 template <class S>
788 V8_INLINE UniquePersistent(Isolate* isolate, Handle<S> that)
789 : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
790 TYPE_CHECK(T, S);
791 }
792 /**
793 * Construct a UniquePersistent from a PersistentBase.
794 * When the Persistent is non-empty, a new storage cell is created
795 * pointing to the same object, and no flags are set.
796 */
797 template <class S>
798 V8_INLINE UniquePersistent(Isolate* isolate, const PersistentBase<S>& that)
799 : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
800 TYPE_CHECK(T, S);
801 }
802 /**
803 * Move constructor.
804 */
805 V8_INLINE UniquePersistent(RValue rvalue)
806 : PersistentBase<T>(rvalue.object->val_) {
807 rvalue.object->val_ = 0;
808 }
809 V8_INLINE ~UniquePersistent() { this->Reset(); }
810 /**
811 * Move via assignment.
812 */
813 template<class S>
814 V8_INLINE UniquePersistent& operator=(UniquePersistent<S> rhs) {
815 TYPE_CHECK(T, S);
816 this->val_ = rhs.val_;
817 rhs.val_ = 0;
818 return *this;
819 }
820 /**
821 * Cast operator for moves.
822 */
823 V8_INLINE operator RValue() { return RValue(this); }
824 /**
825 * Pass allows returning uniques from functions, etc.
826 */
827 V8_INLINE UniquePersistent Pass() { return UniquePersistent(RValue(this)); }
828
829 private:
830 UniquePersistent(UniquePersistent&);
831 void operator=(UniquePersistent&);
731 }; 832 };
732 833
834
733 /** 835 /**
734 * A stack-allocated class that governs a number of local handles. 836 * A stack-allocated class that governs a number of local handles.
735 * After a handle scope has been created, all local handles will be 837 * After a handle scope has been created, all local handles will be
736 * allocated within that handle scope until either the handle scope is 838 * allocated within that handle scope until either the handle scope is
737 * deleted or another handle scope is created. If there is already a 839 * deleted or another handle scope is created. If there is already a
738 * handle scope and a new one is created, all allocations will take 840 * handle scope and a new one is created, all allocations will take
739 * place in the new handle scope until it is deleted. After that, 841 * place in the new handle scope until it is deleted. After that,
740 * new handles will again be allocated in the original handle scope. 842 * new handles will again be allocated in the original handle scope.
741 * 843 *
742 * After the handle scope of a local handle has been deleted the 844 * After the handle scope of a local handle has been deleted the
(...skipping 4078 matching lines...) Expand 10 before | Expand all | Expand 10 after
4821 RevivableCallback weak_reference_callback); 4923 RevivableCallback weak_reference_callback);
4822 static void ClearWeak(internal::Object** global_handle); 4924 static void ClearWeak(internal::Object** global_handle);
4823 static void Eternalize(Isolate* isolate, 4925 static void Eternalize(Isolate* isolate,
4824 Value* handle, 4926 Value* handle,
4825 int* index); 4927 int* index);
4826 static Local<Value> GetEternal(Isolate* isolate, int index); 4928 static Local<Value> GetEternal(Isolate* isolate, int index);
4827 4929
4828 template <class T> friend class Handle; 4930 template <class T> friend class Handle;
4829 template <class T> friend class Local; 4931 template <class T> friend class Local;
4830 template <class T> friend class Eternal; 4932 template <class T> friend class Eternal;
4933 template <class T> friend class PersistentBase;
4831 template <class T, class M> friend class Persistent; 4934 template <class T, class M> friend class Persistent;
4832 friend class Context; 4935 friend class Context;
4833 }; 4936 };
4834 4937
4835 4938
4836 /** 4939 /**
4837 * An external exception handler. 4940 * An external exception handler.
4838 */ 4941 */
4839 class V8_EXPORT TryCatch { 4942 class V8_EXPORT TryCatch {
4840 public: 4943 public:
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
5613 template <class T> 5716 template <class T>
5614 Local<T>::Local() : Handle<T>() { } 5717 Local<T>::Local() : Handle<T>() { }
5615 5718
5616 5719
5617 template <class T> 5720 template <class T>
5618 Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { 5721 Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) {
5619 return New(isolate, that.val_); 5722 return New(isolate, that.val_);
5620 } 5723 }
5621 5724
5622 template <class T> 5725 template <class T>
5623 template <class M> 5726 Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) {
5624 Local<T> Local<T>::New(Isolate* isolate, const Persistent<T, M>& that) {
5625 return New(isolate, that.val_); 5727 return New(isolate, that.val_);
5626 } 5728 }
5627 5729
5628 template <class T> 5730 template <class T>
5629 Handle<T> Handle<T>::New(Isolate* isolate, T* that) { 5731 Handle<T> Handle<T>::New(Isolate* isolate, T* that) {
5630 if (that == NULL) return Handle<T>(); 5732 if (that == NULL) return Handle<T>();
5631 T* that_ptr = that; 5733 T* that_ptr = that;
5632 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); 5734 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
5633 return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( 5735 return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
5634 reinterpret_cast<internal::Isolate*>(isolate), *p))); 5736 reinterpret_cast<internal::Isolate*>(isolate), *p)));
(...skipping 17 matching lines...) Expand all
5652 V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle), &this->index_); 5754 V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle), &this->index_);
5653 } 5755 }
5654 5756
5655 5757
5656 template<class T> 5758 template<class T>
5657 Local<T> Eternal<T>::Get(Isolate* isolate) { 5759 Local<T> Eternal<T>::Get(Isolate* isolate) {
5658 return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_))); 5760 return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_)));
5659 } 5761 }
5660 5762
5661 5763
5662 template <class T, class M> 5764 template <class T>
5663 T* Persistent<T, M>::New(Isolate* isolate, T* that) { 5765 T* PersistentBase<T>::New(Isolate* isolate, T* that) {
5664 if (that == NULL) return NULL; 5766 if (that == NULL) return NULL;
5665 internal::Object** p = reinterpret_cast<internal::Object**>(that); 5767 internal::Object** p = reinterpret_cast<internal::Object**>(that);
5666 return reinterpret_cast<T*>( 5768 return reinterpret_cast<T*>(
5667 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), 5769 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
5668 p)); 5770 p));
5669 } 5771 }
5670 5772
5671 5773
5672 template <class T, class M> 5774 template <class T, class M>
5673 template <class S, class M2> 5775 template <class S, class M2>
5674 void Persistent<T, M>::Copy(const Persistent<S, M2>& that) { 5776 void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
5675 TYPE_CHECK(T, S); 5777 TYPE_CHECK(T, S);
5676 Reset(); 5778 this->Reset();
5677 if (that.IsEmpty()) return; 5779 if (that.IsEmpty()) return;
5678 internal::Object** p = reinterpret_cast<internal::Object**>(that.val_); 5780 internal::Object** p = reinterpret_cast<internal::Object**>(that.val_);
5679 this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p)); 5781 this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p));
5680 M::Copy(that, this); 5782 M::Copy(that, this);
5681 } 5783 }
5682 5784
5683 5785
5684 template <class T, class M> 5786 template <class T>
5685 bool Persistent<T, M>::IsIndependent() const { 5787 bool PersistentBase<T>::IsIndependent() const {
5686 typedef internal::Internals I; 5788 typedef internal::Internals I;
5687 if (this->IsEmpty()) return false; 5789 if (this->IsEmpty()) return false;
5688 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), 5790 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
5689 I::kNodeIsIndependentShift); 5791 I::kNodeIsIndependentShift);
5690 } 5792 }
5691 5793
5692 5794
5693 template <class T, class M> 5795 template <class T>
5694 bool Persistent<T, M>::IsNearDeath() const { 5796 bool PersistentBase<T>::IsNearDeath() const {
5695 typedef internal::Internals I; 5797 typedef internal::Internals I;
5696 if (this->IsEmpty()) return false; 5798 if (this->IsEmpty()) return false;
5697 uint8_t node_state = 5799 uint8_t node_state =
5698 I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)); 5800 I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_));
5699 return node_state == I::kNodeStateIsNearDeathValue || 5801 return node_state == I::kNodeStateIsNearDeathValue ||
5700 node_state == I::kNodeStateIsPendingValue; 5802 node_state == I::kNodeStateIsPendingValue;
5701 } 5803 }
5702 5804
5703 5805
5704 template <class T, class M> 5806 template <class T>
5705 bool Persistent<T, M>::IsWeak() const { 5807 bool PersistentBase<T>::IsWeak() const {
5706 typedef internal::Internals I; 5808 typedef internal::Internals I;
5707 if (this->IsEmpty()) return false; 5809 if (this->IsEmpty()) return false;
5708 return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == 5810 return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) ==
5709 I::kNodeStateIsWeakValue; 5811 I::kNodeStateIsWeakValue;
5710 } 5812 }
5711 5813
5712 5814
5713 template <class T, class M> 5815 template <class T>
5714 void Persistent<T, M>::Reset() { 5816 void PersistentBase<T>::Reset() {
5715 if (this->IsEmpty()) return; 5817 if (this->IsEmpty()) return;
5716 V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); 5818 V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
5717 val_ = 0; 5819 val_ = 0;
5718 } 5820 }
5719 5821
5720 5822
5721 template <class T, class M> 5823 template <class T>
5722 template <class S> 5824 template <class S>
5723 void Persistent<T, M>::Reset(Isolate* isolate, const Handle<S>& other) { 5825 void PersistentBase<T>::Reset(Isolate* isolate, const Handle<S>& other) {
5724 TYPE_CHECK(T, S); 5826 TYPE_CHECK(T, S);
5725 Reset(); 5827 Reset();
5726 if (other.IsEmpty()) return; 5828 if (other.IsEmpty()) return;
5727 this->val_ = New(isolate, other.val_); 5829 this->val_ = New(isolate, other.val_);
5728 } 5830 }
5729 5831
5730 5832
5731 template <class T, class M> 5833 template <class T>
5732 template <class S, class M2> 5834 template <class S>
5733 void Persistent<T, M>::Reset(Isolate* isolate, 5835 void PersistentBase<T>::Reset(Isolate* isolate,
5734 const Persistent<S, M2>& other) { 5836 const PersistentBase<S>& other) {
5735 TYPE_CHECK(T, S); 5837 TYPE_CHECK(T, S);
5736 Reset(); 5838 Reset();
5737 if (other.IsEmpty()) return; 5839 if (other.IsEmpty()) return;
5738 this->val_ = New(isolate, other.val_); 5840 this->val_ = New(isolate, other.val_);
5739 } 5841 }
5740 5842
5741 5843
5742 template <class T, class M> 5844 template <class T>
5743 template <typename S, typename P> 5845 template <typename S, typename P>
5744 void Persistent<T, M>::SetWeak( 5846 void PersistentBase<T>::SetWeak(
5745 P* parameter, 5847 P* parameter,
5746 typename WeakCallbackData<S, P>::Callback callback) { 5848 typename WeakCallbackData<S, P>::Callback callback) {
5747 TYPE_CHECK(S, T); 5849 TYPE_CHECK(S, T);
5748 typedef typename WeakCallbackData<Value, void>::Callback Callback; 5850 typedef typename WeakCallbackData<Value, void>::Callback Callback;
5749 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), 5851 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_),
5750 parameter, 5852 parameter,
5751 reinterpret_cast<Callback>(callback), 5853 reinterpret_cast<Callback>(callback),
5752 NULL); 5854 NULL);
5753 } 5855 }
5754 5856
5755 5857
5756 template <class T, class M> 5858 template <class T>
5757 template <typename P> 5859 template <typename P>
5758 void Persistent<T, M>::SetWeak( 5860 void PersistentBase<T>::SetWeak(
5759 P* parameter, 5861 P* parameter,
5760 typename WeakCallbackData<T, P>::Callback callback) { 5862 typename WeakCallbackData<T, P>::Callback callback) {
5761 SetWeak<T, P>(parameter, callback); 5863 SetWeak<T, P>(parameter, callback);
5762 } 5864 }
5763 5865
5764 5866
5765 template <class T, class M> 5867 template <class T, class M>
5766 template <typename S, typename P> 5868 template <typename S, typename P>
5767 void Persistent<T, M>::MakeWeak( 5869 void Persistent<T, M>::MakeWeak(
5768 P* parameters, 5870 P* parameters,
5769 typename WeakReferenceCallbacks<S, P>::Revivable callback) { 5871 typename WeakReferenceCallbacks<S, P>::Revivable callback) {
5770 TYPE_CHECK(S, T); 5872 TYPE_CHECK(S, T);
5771 typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; 5873 typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable;
5772 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), 5874 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_),
5773 parameters, 5875 parameters,
5774 NULL, 5876 NULL,
5775 reinterpret_cast<Revivable>(callback)); 5877 reinterpret_cast<Revivable>(callback));
5776 } 5878 }
5777 5879
5778 5880
5779 template <class T, class M> 5881 template <class T, class M>
5780 template <typename P> 5882 template <typename P>
5781 void Persistent<T, M>::MakeWeak( 5883 void Persistent<T, M>::MakeWeak(
5782 P* parameters, 5884 P* parameters,
5783 typename WeakReferenceCallbacks<T, P>::Revivable callback) { 5885 typename WeakReferenceCallbacks<T, P>::Revivable callback) {
5784 MakeWeak<T, P>(parameters, callback); 5886 MakeWeak<T, P>(parameters, callback);
5785 } 5887 }
5786 5888
5787 5889
5788 template <class T, class M> 5890 template <class T>
5789 void Persistent<T, M>::ClearWeak() { 5891 void PersistentBase<T>::ClearWeak() {
5790 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); 5892 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_));
5791 } 5893 }
5792 5894
5793 5895
5794 template <class T, class M> 5896 template <class T>
5795 void Persistent<T, M>::MarkIndependent() { 5897 void PersistentBase<T>::MarkIndependent() {
5796 typedef internal::Internals I; 5898 typedef internal::Internals I;
5797 if (this->IsEmpty()) return; 5899 if (this->IsEmpty()) return;
5798 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), 5900 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
5799 true, 5901 true,
5800 I::kNodeIsIndependentShift); 5902 I::kNodeIsIndependentShift);
5801 } 5903 }
5802 5904
5803 5905
5804 template <class T, class M> 5906 template <class T>
5805 void Persistent<T, M>::MarkPartiallyDependent() { 5907 void PersistentBase<T>::MarkPartiallyDependent() {
5806 typedef internal::Internals I; 5908 typedef internal::Internals I;
5807 if (this->IsEmpty()) return; 5909 if (this->IsEmpty()) return;
5808 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), 5910 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
5809 true, 5911 true,
5810 I::kNodeIsPartiallyDependentShift); 5912 I::kNodeIsPartiallyDependentShift);
5811 } 5913 }
5812 5914
5813 5915
5814 template <class T, class M> 5916 template <class T, class M>
5815 T* Persistent<T, M>::ClearAndLeak() { 5917 T* Persistent<T, M>::ClearAndLeak() {
5816 T* old; 5918 T* old;
5817 old = val_; 5919 old = this->val_;
5818 val_ = NULL; 5920 this->val_ = NULL;
5819 return old; 5921 return old;
5820 } 5922 }
5821 5923
5822 5924
5823 template <class T, class M> 5925 template <class T>
5824 void Persistent<T, M>::SetWrapperClassId(uint16_t class_id) { 5926 void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
5825 typedef internal::Internals I; 5927 typedef internal::Internals I;
5826 if (this->IsEmpty()) return; 5928 if (this->IsEmpty()) return;
5827 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); 5929 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
5828 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; 5930 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
5829 *reinterpret_cast<uint16_t*>(addr) = class_id; 5931 *reinterpret_cast<uint16_t*>(addr) = class_id;
5830 } 5932 }
5831 5933
5832 5934
5833 template <class T, class M> 5935 template <class T>
5834 uint16_t Persistent<T, M>::WrapperClassId() const { 5936 uint16_t PersistentBase<T>::WrapperClassId() const {
5835 typedef internal::Internals I; 5937 typedef internal::Internals I;
5836 if (this->IsEmpty()) return 0; 5938 if (this->IsEmpty()) return 0;
5837 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); 5939 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
5838 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; 5940 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
5839 return *reinterpret_cast<uint16_t*>(addr); 5941 return *reinterpret_cast<uint16_t*>(addr);
5840 } 5942 }
5841 5943
5842 5944
5843 template<typename T> 5945 template<typename T>
5844 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} 5946 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
6597 */ 6699 */
6598 6700
6599 6701
6600 } // namespace v8 6702 } // namespace v8
6601 6703
6602 6704
6603 #undef TYPE_CHECK 6705 #undef TYPE_CHECK
6604 6706
6605 6707
6606 #endif // V8_H_ 6708 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698