| OLD | NEW |
| 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 Loading... |
| 116 class Date; | 116 class Date; |
| 117 class DeclaredAccessorDescriptor; | 117 class DeclaredAccessorDescriptor; |
| 118 class External; | 118 class External; |
| 119 class Function; | 119 class Function; |
| 120 class FunctionTemplate; | 120 class FunctionTemplate; |
| 121 class HeapProfiler; | 121 class HeapProfiler; |
| 122 class ImplementationUtilities; | 122 class ImplementationUtilities; |
| 123 class Int32; | 123 class Int32; |
| 124 class Integer; | 124 class Integer; |
| 125 class Isolate; | 125 class Isolate; |
| 126 class LocalContext; | |
| 127 class Number; | 126 class Number; |
| 128 class NumberObject; | 127 class NumberObject; |
| 129 class Object; | 128 class Object; |
| 130 class ObjectOperationDescriptor; | 129 class ObjectOperationDescriptor; |
| 131 class ObjectTemplate; | 130 class ObjectTemplate; |
| 132 class Primitive; | 131 class Primitive; |
| 133 class RawOperationDescriptor; | 132 class RawOperationDescriptor; |
| 134 class Signature; | 133 class Signature; |
| 135 class StackFrame; | 134 class StackFrame; |
| 136 class StackTrace; | 135 class StackTrace; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 155 class DeclaredAccessorDescriptor; | 154 class DeclaredAccessorDescriptor; |
| 156 class ObjectOperationDescriptor; | 155 class ObjectOperationDescriptor; |
| 157 class RawOperationDescriptor; | 156 class RawOperationDescriptor; |
| 158 | 157 |
| 159 namespace internal { | 158 namespace internal { |
| 160 class Arguments; | 159 class Arguments; |
| 161 class Heap; | 160 class Heap; |
| 162 class HeapObject; | 161 class HeapObject; |
| 163 class Isolate; | 162 class Isolate; |
| 164 class Object; | 163 class Object; |
| 165 template<typename T> | 164 template<typename T> class CustomArguments; |
| 166 class CustomArguments; | |
| 167 class PropertyCallbackArguments; | 165 class PropertyCallbackArguments; |
| 168 class FunctionCallbackArguments; | 166 class FunctionCallbackArguments; |
| 169 } | 167 } |
| 170 | 168 |
| 171 | 169 |
| 172 /** | 170 /** |
| 173 * General purpose unique identifier. | 171 * General purpose unique identifier. |
| 174 */ | 172 */ |
| 175 class UniqueId { | 173 class UniqueId { |
| 176 public: | 174 public: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 }; | 213 }; |
| 216 | 214 |
| 217 // --- Handles --- | 215 // --- Handles --- |
| 218 | 216 |
| 219 #define TYPE_CHECK(T, S) \ | 217 #define TYPE_CHECK(T, S) \ |
| 220 while (false) { \ | 218 while (false) { \ |
| 221 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ | 219 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
| 222 } | 220 } |
| 223 | 221 |
| 224 | 222 |
| 225 #define V8_USE_UNSAFE_HANDLES | |
| 226 | |
| 227 /** | 223 /** |
| 228 * An object reference managed by the v8 garbage collector. | 224 * An object reference managed by the v8 garbage collector. |
| 229 * | 225 * |
| 230 * All objects returned from v8 have to be tracked by the garbage | 226 * All objects returned from v8 have to be tracked by the garbage |
| 231 * collector so that it knows that the objects are still alive. Also, | 227 * collector so that it knows that the objects are still alive. Also, |
| 232 * because the garbage collector may move objects, it is unsafe to | 228 * because the garbage collector may move objects, it is unsafe to |
| 233 * point directly to an object. Instead, all objects are stored in | 229 * point directly to an object. Instead, all objects are stored in |
| 234 * handles which are known by the garbage collector and updated | 230 * handles which are known by the garbage collector and updated |
| 235 * whenever an object moves. Handles should always be passed by value | 231 * whenever an object moves. Handles should always be passed by value |
| 236 * (except in cases like out-parameters) and they should never be | 232 * (except in cases like out-parameters) and they should never be |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 354 |
| 359 private: | 355 private: |
| 360 #endif | 356 #endif |
| 361 /** | 357 /** |
| 362 * Creates a new handle for the specified value. | 358 * Creates a new handle for the specified value. |
| 363 */ | 359 */ |
| 364 V8_INLINE(explicit Handle(T* val)) : val_(val) {} | 360 V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
| 365 #endif | 361 #endif |
| 366 | 362 |
| 367 private: | 363 private: |
| 364 friend class Utils; |
| 368 template<class F> friend class Persistent; | 365 template<class F> friend class Persistent; |
| 369 template<class F> friend class Local; | 366 template<class F> friend class Local; |
| 370 friend class Arguments; | 367 friend class Arguments; |
| 371 template<class F> friend class FunctionCallbackInfo; | 368 template<class F> friend class FunctionCallbackInfo; |
| 372 template<class F> friend class PropertyCallbackInfo; | 369 template<class F> friend class PropertyCallbackInfo; |
| 373 friend class String; | 370 template<class F> friend class internal::CustomArguments; |
| 374 friend class Object; | |
| 375 friend class AccessorInfo; | 371 friend class AccessorInfo; |
| 376 friend Handle<Primitive> Undefined(Isolate* isolate); | 372 friend Handle<Primitive> Undefined(Isolate* isolate); |
| 377 friend Handle<Primitive> Null(Isolate* isolate); | 373 friend Handle<Primitive> Null(Isolate* isolate); |
| 378 friend Handle<Boolean> True(Isolate* isolate); | 374 friend Handle<Boolean> True(Isolate* isolate); |
| 379 friend Handle<Boolean> False(Isolate* isolate); | 375 friend Handle<Boolean> False(Isolate* isolate); |
| 380 friend class Context; | 376 friend class Context; |
| 381 friend class InternalHandleHelper; | |
| 382 friend class LocalContext; | |
| 383 friend class HandleScope; | 377 friend class HandleScope; |
| 384 | 378 |
| 385 #ifndef V8_USE_UNSAFE_HANDLES | 379 #ifndef V8_USE_UNSAFE_HANDLES |
| 386 V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); | 380 V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); |
| 387 #endif | 381 #endif |
| 388 | 382 |
| 389 T* val_; | 383 T* val_; |
| 390 }; | 384 }; |
| 391 | 385 |
| 392 | 386 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that)); | 441 V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that)); |
| 448 | 442 |
| 449 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | 443 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 450 | 444 |
| 451 private: | 445 private: |
| 452 #endif | 446 #endif |
| 453 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } | 447 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| 454 #endif | 448 #endif |
| 455 | 449 |
| 456 private: | 450 private: |
| 451 friend class Utils; |
| 457 template<class F> friend class Persistent; | 452 template<class F> friend class Persistent; |
| 458 template<class F> friend class Handle; | 453 template<class F> friend class Handle; |
| 459 friend class Arguments; | 454 friend class Arguments; |
| 460 template<class F> friend class FunctionCallbackInfo; | 455 template<class F> friend class FunctionCallbackInfo; |
| 461 template<class F> friend class PropertyCallbackInfo; | 456 template<class F> friend class PropertyCallbackInfo; |
| 462 friend class String; | 457 friend class String; |
| 463 friend class Object; | 458 friend class Object; |
| 464 friend class AccessorInfo; | 459 friend class AccessorInfo; |
| 465 friend class Context; | 460 friend class Context; |
| 466 friend class InternalHandleHelper; | 461 template<class F> friend class internal::CustomArguments; |
| 467 friend class LocalContext; | |
| 468 friend class HandleScope; | 462 friend class HandleScope; |
| 469 | 463 |
| 470 V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); | 464 V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); |
| 471 }; | 465 }; |
| 472 | 466 |
| 473 /** | 467 /** |
| 474 * An object reference that is independent of any handle scope. Where | 468 * An object reference that is independent of any handle scope. Where |
| 475 * a Local handle only lives as long as the HandleScope in which it was | 469 * a Local handle only lives as long as the HandleScope in which it was |
| 476 * allocated, a Persistent handle remains valid until it is explicitly | 470 * allocated, a Persistent handle remains valid until it is explicitly |
| 477 * disposed. | 471 * disposed. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 489 */ | 483 */ |
| 490 template <class T> class Persistent // NOLINT | 484 template <class T> class Persistent // NOLINT |
| 491 #ifdef V8_USE_UNSAFE_HANDLES | 485 #ifdef V8_USE_UNSAFE_HANDLES |
| 492 : public Handle<T> { | 486 : public Handle<T> { |
| 493 #else | 487 #else |
| 494 { // NOLINT | 488 { // NOLINT |
| 495 #endif | 489 #endif |
| 496 public: | 490 public: |
| 497 #ifndef V8_USE_UNSAFE_HANDLES | 491 #ifndef V8_USE_UNSAFE_HANDLES |
| 498 V8_INLINE(Persistent()) : val_(0) { } | 492 V8_INLINE(Persistent()) : val_(0) { } |
| 499 V8_INLINE(~Persistent()) { | 493 // TODO(dcarney): add this back before cutover. |
| 500 // TODO(dcarney): add this back before cutover. | 494 // V8_INLINE(~Persistent()) { |
| 501 // Dispose(); | 495 // Dispose(); |
| 502 } | 496 // } |
| 503 V8_INLINE(bool IsEmpty() const) { return val_ == 0; } | 497 V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
| 504 // TODO(dcarney): remove somehow before cutover | 498 // TODO(dcarney): remove somehow before cutover |
| 505 // The handle should either be 0, or a pointer to a live cell. | 499 // The handle should either be 0, or a pointer to a live cell. |
| 506 V8_INLINE(void Clear()) { val_ = 0; } | 500 V8_INLINE(void Clear()) { val_ = 0; } |
| 507 | 501 |
| 508 /** | 502 /** |
| 509 * A constructor that creates a new global cell pointing to that. In contrast | 503 * A constructor that creates a new global cell pointing to that. In contrast |
| 510 * to the copy constructor, this creates a new persistent handle which needs | 504 * to the copy constructor, this creates a new persistent handle which needs |
| 511 * to be separately disposed. | 505 * to be separately disposed. |
| 512 */ | 506 */ |
| 513 template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) | 507 template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 514 : val_(*New(isolate, that)) { } | 508 : val_(New(isolate, *that)) { } |
| 515 | 509 |
| 516 template <class S> V8_INLINE(Persistent(Isolate* isolate, | 510 template <class S> V8_INLINE(Persistent(Isolate* isolate, |
| 517 Persistent<S>& that)) // NOLINT | 511 Persistent<S>& that)) // NOLINT |
| 518 : val_(*New(isolate, that)) { } | 512 : val_(New(isolate, *that)) { } |
| 519 | 513 |
| 520 #else | 514 #else |
| 521 /** | 515 /** |
| 522 * Creates an empty persistent handle that doesn't point to any | 516 * Creates an empty persistent handle that doesn't point to any |
| 523 * storage cell. | 517 * storage cell. |
| 524 */ | 518 */ |
| 525 V8_INLINE(Persistent()) : Handle<T>() { } | 519 V8_INLINE(Persistent()) : Handle<T>() { } |
| 526 | 520 |
| 527 /** | 521 /** |
| 528 * Creates a persistent handle for the same storage cell as the | 522 * Creates a persistent handle for the same storage cell as the |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 if (!that.IsEmpty()) T::Cast(*that); | 581 if (!that.IsEmpty()) T::Cast(*that); |
| 588 #endif | 582 #endif |
| 589 return reinterpret_cast<Persistent<T>&>(that); | 583 return reinterpret_cast<Persistent<T>&>(that); |
| 590 } | 584 } |
| 591 | 585 |
| 592 template <class S> V8_INLINE(Persistent<S>& As()) { // NOLINT | 586 template <class S> V8_INLINE(Persistent<S>& As()) { // NOLINT |
| 593 return Persistent<S>::Cast(*this); | 587 return Persistent<S>::Cast(*this); |
| 594 } | 588 } |
| 595 #endif | 589 #endif |
| 596 | 590 |
| 591 #ifdef V8_USE_UNSAFE_HANDLES |
| 597 V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); | 592 V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); |
| 598 | |
| 599 /** | |
| 600 * Creates a new persistent handle for an existing local or persistent handle. | |
| 601 */ | |
| 602 // TODO(dcarney): remove before cutover | |
| 603 V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); | 593 V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); |
| 604 #ifndef V8_USE_UNSAFE_HANDLES | |
| 605 // TODO(dcarney): remove before cutover | |
| 606 V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that)); | 594 V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that)); |
| 607 #endif | 595 #endif |
| 608 | 596 |
| 609 #ifndef V8_USE_UNSAFE_HANDLES | 597 #ifndef V8_USE_UNSAFE_HANDLES |
| 610 template <class S> V8_INLINE( | 598 template <class S> V8_INLINE( |
| 611 bool operator==(const Persistent<S>& that) const) { | 599 bool operator==(const Persistent<S>& that) const) { |
| 612 internal::Object** a = reinterpret_cast<internal::Object**>(**this); | 600 internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 613 internal::Object** b = reinterpret_cast<internal::Object**>(*that); | 601 internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 614 if (a == 0) return b == 0; | 602 if (a == 0) return b == 0; |
| 615 if (b == 0) return false; | 603 if (b == 0) return false; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 645 template<typename S, typename P> | 633 template<typename S, typename P> |
| 646 V8_INLINE(void MakeWeak( | 634 V8_INLINE(void MakeWeak( |
| 647 P* parameters, | 635 P* parameters, |
| 648 typename WeakReferenceCallbacks<S, P>::Revivable callback)); | 636 typename WeakReferenceCallbacks<S, P>::Revivable callback)); |
| 649 | 637 |
| 650 template<typename P> | 638 template<typename P> |
| 651 V8_INLINE(void MakeWeak( | 639 V8_INLINE(void MakeWeak( |
| 652 P* parameters, | 640 P* parameters, |
| 653 typename WeakReferenceCallbacks<T, P>::Revivable callback)); | 641 typename WeakReferenceCallbacks<T, P>::Revivable callback)); |
| 654 | 642 |
| 655 // TODO(dcarney): deprecate | |
| 656 template<typename S, typename P> | 643 template<typename S, typename P> |
| 657 V8_INLINE(void MakeWeak( | 644 V8_DEPRECATED(void MakeWeak( |
| 658 Isolate* isolate, | 645 Isolate* isolate, |
| 659 P* parameters, | 646 P* parameters, |
| 660 typename WeakReferenceCallbacks<S, P>::Revivable callback)) { | 647 typename WeakReferenceCallbacks<S, P>::Revivable callback)); |
| 661 MakeWeak<S, P>(parameters, callback); | |
| 662 } | |
| 663 | 648 |
| 664 // TODO(dcarney): deprecate | |
| 665 template<typename P> | 649 template<typename P> |
| 666 V8_INLINE(void MakeWeak( | 650 V8_DEPRECATED(void MakeWeak( |
| 667 Isolate* isolate, | 651 Isolate* isolate, |
| 668 P* parameters, | 652 P* parameters, |
| 669 typename WeakReferenceCallbacks<T, P>::Revivable callback)) { | 653 typename WeakReferenceCallbacks<T, P>::Revivable callback)); |
| 670 MakeWeak<P>(parameters, callback); | |
| 671 } | |
| 672 | 654 |
| 673 V8_INLINE(void ClearWeak()); | 655 V8_INLINE(void ClearWeak()); |
| 674 | 656 |
| 675 // TODO(dcarney): deprecate | 657 // TODO(dcarney): deprecate |
| 676 V8_INLINE(void ClearWeak(Isolate* isolate)) { ClearWeak(); } | 658 V8_INLINE(void ClearWeak(Isolate* isolate)) { ClearWeak(); } |
| 677 | 659 |
| 678 /** | 660 /** |
| 679 * Marks the reference to this object independent. Garbage collector is free | 661 * Marks the reference to this object independent. Garbage collector is free |
| 680 * to ignore any object groups containing this object. Weak callback for an | 662 * to ignore any object groups containing this object. Weak callback for an |
| 681 * independent handle should not assume that it will be preceded by a global | 663 * independent handle should not assume that it will be preceded by a global |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 return *this; | 754 return *this; |
| 773 } | 755 } |
| 774 | 756 |
| 775 public: | 757 public: |
| 776 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | 758 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 777 | 759 |
| 778 private: | 760 private: |
| 779 #endif | 761 #endif |
| 780 // TODO(dcarney): remove before cutover | 762 // TODO(dcarney): remove before cutover |
| 781 template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } | 763 template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } |
| 782 // TODO(dcarney): remove before cutover | 764 |
| 783 template <class S> V8_INLINE(Persistent(Persistent<S> that)) | |
| 784 : val_(*that) { | |
| 785 TYPE_CHECK(T, S); | |
| 786 } | |
| 787 // TODO(dcarney): remove before cutover | 765 // TODO(dcarney): remove before cutover |
| 788 V8_INLINE(T* operator*() const) { return val_; } | 766 V8_INLINE(T* operator*() const) { return val_; } |
| 789 | 767 |
| 790 private: | 768 private: |
| 791 // TODO(dcarney): remove before cutover | 769 // TODO(dcarney): remove before cutover |
| 792 V8_INLINE(T* operator->() const) { return val_; } | 770 V8_INLINE(T* operator->() const) { return val_; } |
| 793 public: | 771 public: |
| 794 #endif | 772 #endif |
| 795 | 773 |
| 796 private: | 774 private: |
| 775 friend class Utils; |
| 797 template<class F> friend class Handle; | 776 template<class F> friend class Handle; |
| 798 template<class F> friend class Local; | 777 template<class F> friend class Local; |
| 778 template<class F> friend class Persistent; |
| 799 template<class F> friend class ReturnValue; | 779 template<class F> friend class ReturnValue; |
| 800 friend class ImplementationUtilities; | |
| 801 friend class ObjectTemplate; | |
| 802 friend class Context; | |
| 803 friend class InternalHandleHelper; | |
| 804 friend class LocalContext; | |
| 805 | 780 |
| 806 V8_INLINE(static Persistent<T> New(Isolate* isolate, T* that)); | 781 V8_INLINE(static T* New(Isolate* isolate, T* that)); |
| 807 | 782 |
| 808 #ifndef V8_USE_UNSAFE_HANDLES | 783 #ifndef V8_USE_UNSAFE_HANDLES |
| 809 T* val_; | 784 T* val_; |
| 810 #endif | 785 #endif |
| 811 }; | 786 }; |
| 812 | 787 |
| 813 | 788 |
| 814 /** | 789 /** |
| 815 * A stack-allocated class that governs a number of local handles. | 790 * A stack-allocated class that governs a number of local handles. |
| 816 * After a handle scope has been created, all local handles will be | 791 * After a handle scope has been created, all local handles will be |
| (...skipping 4509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5326 static const int kExternalTwoByteRepresentationTag = 0x02; | 5301 static const int kExternalTwoByteRepresentationTag = 0x02; |
| 5327 static const int kExternalAsciiRepresentationTag = 0x06; | 5302 static const int kExternalAsciiRepresentationTag = 0x06; |
| 5328 | 5303 |
| 5329 static const int kIsolateStateOffset = 0; | 5304 static const int kIsolateStateOffset = 0; |
| 5330 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; | 5305 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
| 5331 static const int kIsolateRootsOffset = 3 * kApiPointerSize; | 5306 static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
| 5332 static const int kUndefinedValueRootIndex = 5; | 5307 static const int kUndefinedValueRootIndex = 5; |
| 5333 static const int kNullValueRootIndex = 7; | 5308 static const int kNullValueRootIndex = 7; |
| 5334 static const int kTrueValueRootIndex = 8; | 5309 static const int kTrueValueRootIndex = 8; |
| 5335 static const int kFalseValueRootIndex = 9; | 5310 static const int kFalseValueRootIndex = 9; |
| 5336 static const int kEmptyStringRootIndex = 130; | 5311 static const int kEmptyStringRootIndex = 131; |
| 5337 | 5312 |
| 5338 static const int kNodeClassIdOffset = 1 * kApiPointerSize; | 5313 static const int kNodeClassIdOffset = 1 * kApiPointerSize; |
| 5339 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; | 5314 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; |
| 5340 static const int kNodeStateMask = 0xf; | 5315 static const int kNodeStateMask = 0xf; |
| 5341 static const int kNodeStateIsWeakValue = 2; | 5316 static const int kNodeStateIsWeakValue = 2; |
| 5342 static const int kNodeStateIsNearDeathValue = 4; | 5317 static const int kNodeStateIsNearDeathValue = 4; |
| 5343 static const int kNodeIsIndependentShift = 4; | 5318 static const int kNodeIsIndependentShift = 4; |
| 5344 static const int kNodeIsPartiallyDependentShift = 5; | 5319 static const int kNodeIsPartiallyDependentShift = 5; |
| 5345 | 5320 |
| 5346 static const int kJSObjectType = 0xaf; | 5321 static const int kJSObjectType = 0xb0; |
| 5347 static const int kFirstNonstringType = 0x80; | 5322 static const int kFirstNonstringType = 0x80; |
| 5348 static const int kOddballType = 0x83; | 5323 static const int kOddballType = 0x83; |
| 5349 static const int kForeignType = 0x87; | 5324 static const int kForeignType = 0x88; |
| 5350 | 5325 |
| 5351 static const int kUndefinedOddballKind = 5; | 5326 static const int kUndefinedOddballKind = 5; |
| 5352 static const int kNullOddballKind = 3; | 5327 static const int kNullOddballKind = 3; |
| 5353 | 5328 |
| 5354 V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) { | 5329 V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) { |
| 5355 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 5330 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 5356 kHeapObjectTag); | 5331 kHeapObjectTag); |
| 5357 } | 5332 } |
| 5358 | 5333 |
| 5359 V8_INLINE(static int SmiValue(internal::Object* value)) { | 5334 V8_INLINE(static int SmiValue(internal::Object* value)) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5503 template <class T> | 5478 template <class T> |
| 5504 Local<T> Local<T>::New(Isolate* isolate, T* that) { | 5479 Local<T> Local<T>::New(Isolate* isolate, T* that) { |
| 5505 if (that == NULL) return Local<T>(); | 5480 if (that == NULL) return Local<T>(); |
| 5506 T* that_ptr = that; | 5481 T* that_ptr = that; |
| 5507 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); | 5482 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5508 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | 5483 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5509 reinterpret_cast<internal::Isolate*>(isolate), *p))); | 5484 reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5510 } | 5485 } |
| 5511 | 5486 |
| 5512 | 5487 |
| 5488 #ifdef V8_USE_UNSAFE_HANDLES |
| 5513 template <class T> | 5489 template <class T> |
| 5514 Persistent<T> Persistent<T>::New(Handle<T> that) { | 5490 Persistent<T> Persistent<T>::New(Handle<T> that) { |
| 5515 return New(Isolate::GetCurrent(), that.val_); | 5491 return New(Isolate::GetCurrent(), that.val_); |
| 5516 } | 5492 } |
| 5517 | 5493 |
| 5518 | 5494 |
| 5519 template <class T> | 5495 template <class T> |
| 5520 Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { | 5496 Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { |
| 5521 return New(Isolate::GetCurrent(), that.val_); | 5497 return New(Isolate::GetCurrent(), that.val_); |
| 5522 } | 5498 } |
| 5523 | 5499 |
| 5524 #ifndef V8_USE_UNSAFE_HANDLES | |
| 5525 template <class T> | 5500 template <class T> |
| 5526 Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) { | 5501 Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) { |
| 5527 return New(Isolate::GetCurrent(), that.val_); | 5502 return New(Isolate::GetCurrent(), that.val_); |
| 5528 } | 5503 } |
| 5529 #endif | 5504 #endif |
| 5530 | 5505 |
| 5506 |
| 5531 template <class T> | 5507 template <class T> |
| 5532 Persistent<T> Persistent<T>::New(Isolate* isolate, T* that) { | 5508 T* Persistent<T>::New(Isolate* isolate, T* that) { |
| 5533 if (that == NULL) return Persistent<T>(); | 5509 if (that == NULL) return NULL; |
| 5534 internal::Object** p = reinterpret_cast<internal::Object**>(that); | 5510 internal::Object** p = reinterpret_cast<internal::Object**>(that); |
| 5535 return Persistent<T>(reinterpret_cast<T*>( | 5511 return reinterpret_cast<T*>( |
| 5536 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), | 5512 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), |
| 5537 p))); | 5513 p)); |
| 5538 } | 5514 } |
| 5539 | 5515 |
| 5540 | 5516 |
| 5541 template <class T> | 5517 template <class T> |
| 5542 bool Persistent<T>::IsIndependent() const { | 5518 bool Persistent<T>::IsIndependent() const { |
| 5543 typedef internal::Internals I; | 5519 typedef internal::Internals I; |
| 5544 if (this->IsEmpty()) return false; | 5520 if (this->IsEmpty()) return false; |
| 5545 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | 5521 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
| 5546 I::kNodeIsIndependentShift); | 5522 I::kNodeIsIndependentShift); |
| 5547 } | 5523 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5591 template <class T> | 5567 template <class T> |
| 5592 template <typename P> | 5568 template <typename P> |
| 5593 void Persistent<T>::MakeWeak( | 5569 void Persistent<T>::MakeWeak( |
| 5594 P* parameters, | 5570 P* parameters, |
| 5595 typename WeakReferenceCallbacks<T, P>::Revivable callback) { | 5571 typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
| 5596 MakeWeak<T, P>(parameters, callback); | 5572 MakeWeak<T, P>(parameters, callback); |
| 5597 } | 5573 } |
| 5598 | 5574 |
| 5599 | 5575 |
| 5600 template <class T> | 5576 template <class T> |
| 5577 template <typename S, typename P> |
| 5578 void Persistent<T>::MakeWeak( |
| 5579 Isolate* isolate, |
| 5580 P* parameters, |
| 5581 typename WeakReferenceCallbacks<S, P>::Revivable callback) { |
| 5582 MakeWeak<S, P>(parameters, callback); |
| 5583 } |
| 5584 |
| 5585 |
| 5586 template <class T> |
| 5587 template<typename P> |
| 5588 void Persistent<T>::MakeWeak( |
| 5589 Isolate* isolate, |
| 5590 P* parameters, |
| 5591 typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
| 5592 MakeWeak<P>(parameters, callback); |
| 5593 } |
| 5594 |
| 5595 |
| 5596 template <class T> |
| 5601 void Persistent<T>::ClearWeak() { | 5597 void Persistent<T>::ClearWeak() { |
| 5602 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); | 5598 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); |
| 5603 } | 5599 } |
| 5604 | 5600 |
| 5605 | 5601 |
| 5606 template <class T> | 5602 template <class T> |
| 5607 void Persistent<T>::MarkIndependent() { | 5603 void Persistent<T>::MarkIndependent() { |
| 5608 typedef internal::Internals I; | 5604 typedef internal::Internals I; |
| 5609 if (this->IsEmpty()) return; | 5605 if (this->IsEmpty()) return; |
| 5610 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | 5606 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5709 TYPE_CHECK(T, S); | 5705 TYPE_CHECK(T, S); |
| 5710 if (V8_UNLIKELY(handle.IsEmpty())) { | 5706 if (V8_UNLIKELY(handle.IsEmpty())) { |
| 5711 *value_ = GetDefaultValue(); | 5707 *value_ = GetDefaultValue(); |
| 5712 } else { | 5708 } else { |
| 5713 *value_ = *reinterpret_cast<internal::Object**>(*handle); | 5709 *value_ = *reinterpret_cast<internal::Object**>(*handle); |
| 5714 } | 5710 } |
| 5715 } | 5711 } |
| 5716 | 5712 |
| 5717 template<typename T> | 5713 template<typename T> |
| 5718 void ReturnValue<T>::Set(double i) { | 5714 void ReturnValue<T>::Set(double i) { |
| 5715 TYPE_CHECK(T, Number); |
| 5719 Set(Number::New(GetIsolate(), i)); | 5716 Set(Number::New(GetIsolate(), i)); |
| 5720 } | 5717 } |
| 5721 | 5718 |
| 5722 template<typename T> | 5719 template<typename T> |
| 5723 void ReturnValue<T>::Set(int32_t i) { | 5720 void ReturnValue<T>::Set(int32_t i) { |
| 5721 TYPE_CHECK(T, Integer); |
| 5724 typedef internal::Internals I; | 5722 typedef internal::Internals I; |
| 5725 if (V8_LIKELY(I::IsValidSmi(i))) { | 5723 if (V8_LIKELY(I::IsValidSmi(i))) { |
| 5726 *value_ = I::IntToSmi(i); | 5724 *value_ = I::IntToSmi(i); |
| 5727 return; | 5725 return; |
| 5728 } | 5726 } |
| 5729 Set(Integer::New(i, GetIsolate())); | 5727 Set(Integer::New(i, GetIsolate())); |
| 5730 } | 5728 } |
| 5731 | 5729 |
| 5732 template<typename T> | 5730 template<typename T> |
| 5733 void ReturnValue<T>::Set(uint32_t i) { | 5731 void ReturnValue<T>::Set(uint32_t i) { |
| 5732 TYPE_CHECK(T, Integer); |
| 5734 typedef internal::Internals I; | 5733 typedef internal::Internals I; |
| 5735 // Can't simply use INT32_MAX here for whatever reason. | 5734 // Can't simply use INT32_MAX here for whatever reason. |
| 5736 bool fits_into_int32_t = (i & (1 << 31)) == 0; | 5735 bool fits_into_int32_t = (i & (1 << 31)) == 0; |
| 5737 if (V8_LIKELY(fits_into_int32_t)) { | 5736 if (V8_LIKELY(fits_into_int32_t)) { |
| 5738 Set(static_cast<int32_t>(i)); | 5737 Set(static_cast<int32_t>(i)); |
| 5739 return; | 5738 return; |
| 5740 } | 5739 } |
| 5741 Set(Integer::NewFromUnsigned(i, GetIsolate())); | 5740 Set(Integer::NewFromUnsigned(i, GetIsolate())); |
| 5742 } | 5741 } |
| 5743 | 5742 |
| 5744 template<typename T> | 5743 template<typename T> |
| 5745 void ReturnValue<T>::Set(bool value) { | 5744 void ReturnValue<T>::Set(bool value) { |
| 5745 TYPE_CHECK(T, Boolean); |
| 5746 typedef internal::Internals I; | 5746 typedef internal::Internals I; |
| 5747 int root_index; | 5747 int root_index; |
| 5748 if (value) { | 5748 if (value) { |
| 5749 root_index = I::kTrueValueRootIndex; | 5749 root_index = I::kTrueValueRootIndex; |
| 5750 } else { | 5750 } else { |
| 5751 root_index = I::kFalseValueRootIndex; | 5751 root_index = I::kFalseValueRootIndex; |
| 5752 } | 5752 } |
| 5753 *value_ = *I::GetRoot(GetIsolate(), root_index); | 5753 *value_ = *I::GetRoot(GetIsolate(), root_index); |
| 5754 } | 5754 } |
| 5755 | 5755 |
| 5756 template<typename T> | 5756 template<typename T> |
| 5757 void ReturnValue<T>::SetNull() { | 5757 void ReturnValue<T>::SetNull() { |
| 5758 TYPE_CHECK(T, Primitive); |
| 5758 typedef internal::Internals I; | 5759 typedef internal::Internals I; |
| 5759 *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex); | 5760 *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex); |
| 5760 } | 5761 } |
| 5761 | 5762 |
| 5762 template<typename T> | 5763 template<typename T> |
| 5763 void ReturnValue<T>::SetUndefined() { | 5764 void ReturnValue<T>::SetUndefined() { |
| 5765 TYPE_CHECK(T, Primitive); |
| 5764 typedef internal::Internals I; | 5766 typedef internal::Internals I; |
| 5765 *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); | 5767 *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); |
| 5766 } | 5768 } |
| 5767 | 5769 |
| 5768 template<typename T> | 5770 template<typename T> |
| 5769 void ReturnValue<T>::SetEmptyString() { | 5771 void ReturnValue<T>::SetEmptyString() { |
| 5772 TYPE_CHECK(T, String); |
| 5770 typedef internal::Internals I; | 5773 typedef internal::Internals I; |
| 5771 *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex); | 5774 *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex); |
| 5772 } | 5775 } |
| 5773 | 5776 |
| 5774 template<typename T> | 5777 template<typename T> |
| 5775 Isolate* ReturnValue<T>::GetIsolate() { | 5778 Isolate* ReturnValue<T>::GetIsolate() { |
| 5776 // Isolate is always the pointer below the default value on the stack. | 5779 // Isolate is always the pointer below the default value on the stack. |
| 5777 return *reinterpret_cast<Isolate**>(&value_[-2]); | 5780 return *reinterpret_cast<Isolate**>(&value_[-2]); |
| 5778 } | 5781 } |
| 5779 | 5782 |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6369 | 6372 |
| 6370 | 6373 |
| 6371 } // namespace v8 | 6374 } // namespace v8 |
| 6372 | 6375 |
| 6373 | 6376 |
| 6374 #undef V8EXPORT | 6377 #undef V8EXPORT |
| 6375 #undef TYPE_CHECK | 6378 #undef TYPE_CHECK |
| 6376 | 6379 |
| 6377 | 6380 |
| 6378 #endif // V8_H_ | 6381 #endif // V8_H_ |
| OLD | NEW |