| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 class ObjectTemplate; | 128 class ObjectTemplate; |
| 129 class Data; | 129 class Data; |
| 130 template<typename T> class PropertyCallbackInfo; | 130 template<typename T> class PropertyCallbackInfo; |
| 131 class StackTrace; | 131 class StackTrace; |
| 132 class StackFrame; | 132 class StackFrame; |
| 133 class Isolate; | 133 class Isolate; |
| 134 class DeclaredAccessorDescriptor; | 134 class DeclaredAccessorDescriptor; |
| 135 class ObjectOperationDescriptor; | 135 class ObjectOperationDescriptor; |
| 136 class RawOperationDescriptor; | 136 class RawOperationDescriptor; |
| 137 class CallHandlerHelper; | 137 class CallHandlerHelper; |
| 138 class EscapableHandleScope; |
| 138 | 139 |
| 139 namespace internal { | 140 namespace internal { |
| 140 class Arguments; | 141 class Arguments; |
| 141 class Heap; | 142 class Heap; |
| 142 class HeapObject; | 143 class HeapObject; |
| 143 class Isolate; | 144 class Isolate; |
| 144 class Object; | 145 class Object; |
| 145 template<typename T> class CustomArguments; | 146 template<typename T> class CustomArguments; |
| 146 class PropertyCallbackArguments; | 147 class PropertyCallbackArguments; |
| 147 class FunctionCallbackArguments; | 148 class FunctionCallbackArguments; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 371 |
| 371 template <class S> V8_INLINE Local<S> As() { | 372 template <class S> V8_INLINE Local<S> As() { |
| 372 return Local<S>::Cast(*this); | 373 return Local<S>::Cast(*this); |
| 373 } | 374 } |
| 374 | 375 |
| 375 /** | 376 /** |
| 376 * Create a local handle for the content of another handle. | 377 * Create a local handle for the content of another handle. |
| 377 * The referee is kept alive by the local handle even when | 378 * The referee is kept alive by the local handle even when |
| 378 * the original handle is destroyed/disposed. | 379 * the original handle is destroyed/disposed. |
| 379 */ | 380 */ |
| 380 V8_INLINE static Local<T> New(Handle<T> that); | |
| 381 V8_INLINE static Local<T> New(Isolate* isolate, Handle<T> that); | 381 V8_INLINE static Local<T> New(Isolate* isolate, Handle<T> that); |
| 382 template<class M> | 382 template<class M> |
| 383 V8_INLINE static Local<T> New(Isolate* isolate, | 383 V8_INLINE static Local<T> New(Isolate* isolate, |
| 384 const Persistent<T, M>& that); | 384 const Persistent<T, M>& that); |
| 385 | 385 |
| 386 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | 386 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 387 | 387 |
| 388 private: | 388 private: |
| 389 #endif | 389 #endif |
| 390 template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { } | 390 template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { } |
| 391 | 391 |
| 392 private: | 392 private: |
| 393 friend class Utils; | 393 friend class Utils; |
| 394 template<class F> friend class Eternal; | 394 template<class F> friend class Eternal; |
| 395 template<class F, class M> friend class Persistent; | 395 template<class F, class M> friend class Persistent; |
| 396 template<class F> friend class Handle; | 396 template<class F> friend class Handle; |
| 397 template<class F> friend class FunctionCallbackInfo; | 397 template<class F> friend class FunctionCallbackInfo; |
| 398 template<class F> friend class PropertyCallbackInfo; | 398 template<class F> friend class PropertyCallbackInfo; |
| 399 friend class String; | 399 friend class String; |
| 400 friend class Object; | 400 friend class Object; |
| 401 friend class Context; | 401 friend class Context; |
| 402 template<class F> friend class internal::CustomArguments; | 402 template<class F> friend class internal::CustomArguments; |
| 403 friend class HandleScope; | 403 friend class HandleScope; |
| 404 friend class EscapableHandleScope; |
| 404 | 405 |
| 405 V8_INLINE static Local<T> New(Isolate* isolate, T* that); | 406 V8_INLINE static Local<T> New(Isolate* isolate, T* that); |
| 406 }; | 407 }; |
| 407 | 408 |
| 408 | 409 |
| 409 // Eternal handles are set-once handles that live for the life of the isolate. | 410 // Eternal handles are set-once handles that live for the life of the isolate. |
| 410 template <class T> class Eternal { | 411 template <class T> class Eternal { |
| 411 public: | 412 public: |
| 412 V8_INLINE Eternal() : index_(kInitialValue) { } | 413 V8_INLINE Eternal() : index_(kInitialValue) { } |
| 413 template<class S> | 414 template<class S> |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 * garbage collector will no longer track the object stored in the | 767 * garbage collector will no longer track the object stored in the |
| 767 * handle and may deallocate it. The behavior of accessing a handle | 768 * handle and may deallocate it. The behavior of accessing a handle |
| 768 * for which the handle scope has been deleted is undefined. | 769 * for which the handle scope has been deleted is undefined. |
| 769 */ | 770 */ |
| 770 class V8_EXPORT HandleScope { | 771 class V8_EXPORT HandleScope { |
| 771 public: | 772 public: |
| 772 HandleScope(Isolate* isolate); | 773 HandleScope(Isolate* isolate); |
| 773 | 774 |
| 774 ~HandleScope(); | 775 ~HandleScope(); |
| 775 | 776 |
| 776 /** | 777 // TODO(dcarney): deprecated - use EscapableHandleScope::Escape. |
| 777 * Closes the handle scope and returns the value as a handle in the | |
| 778 * previous scope, which is the new current scope after the call. | |
| 779 */ | |
| 780 template <class T> Local<T> Close(Handle<T> value); | 778 template <class T> Local<T> Close(Handle<T> value); |
| 781 | 779 |
| 782 /** | 780 /** |
| 783 * Counts the number of allocated handles. | 781 * Counts the number of allocated handles. |
| 784 */ | 782 */ |
| 785 static int NumberOfHandles(); | 783 static int NumberOfHandles(); |
| 786 | 784 |
| 785 private: |
| 787 /** | 786 /** |
| 788 * Creates a new handle with the given value. | 787 * Creates a new handle with the given value. |
| 789 */ | 788 */ |
| 790 static internal::Object** CreateHandle(internal::Object* value); | |
| 791 static internal::Object** CreateHandle(internal::Isolate* isolate, | 789 static internal::Object** CreateHandle(internal::Isolate* isolate, |
| 792 internal::Object* value); | 790 internal::Object* value); |
| 793 // Faster version, uses HeapObject to obtain the current Isolate. | 791 // Uses HeapObject to obtain the current Isolate. |
| 794 static internal::Object** CreateHandle(internal::HeapObject* value); | 792 static internal::Object** CreateHandle(internal::HeapObject* heap_object, |
| 793 internal::Object* value); |
| 795 | 794 |
| 796 private: | 795 V8_INLINE HandleScope() {} |
| 796 void Initialize(Isolate* isolate); |
| 797 |
| 797 // Make it hard to create heap-allocated or illegal handle scopes by | 798 // Make it hard to create heap-allocated or illegal handle scopes by |
| 798 // disallowing certain operations. | 799 // disallowing certain operations. |
| 799 HandleScope(const HandleScope&); | 800 HandleScope(const HandleScope&); |
| 800 void operator=(const HandleScope&); | 801 void operator=(const HandleScope&); |
| 801 void* operator new(size_t size); | 802 void* operator new(size_t size); |
| 802 void operator delete(void*, size_t); | 803 void operator delete(void*, size_t); |
| 803 | 804 |
| 804 // This Data class is accessible internally as HandleScopeData through a | 805 // This Data class is accessible internally as HandleScopeData through a |
| 805 // typedef in the ImplementationUtilities class. | 806 // typedef in the ImplementationUtilities class. |
| 806 class V8_EXPORT Data { | 807 class V8_EXPORT Data { |
| 807 public: | 808 public: |
| 808 internal::Object** next; | 809 internal::Object** next; |
| 809 internal::Object** limit; | 810 internal::Object** limit; |
| 810 int level; | 811 int level; |
| 811 V8_INLINE void Initialize() { | 812 V8_INLINE void Initialize() { |
| 812 next = limit = NULL; | 813 next = limit = NULL; |
| 813 level = 0; | 814 level = 0; |
| 814 } | 815 } |
| 815 }; | 816 }; |
| 816 | 817 |
| 817 void Initialize(Isolate* isolate); | |
| 818 void Leave(); | 818 void Leave(); |
| 819 | 819 |
| 820 internal::Isolate* isolate_; | 820 internal::Isolate* isolate_; |
| 821 internal::Object** prev_next_; | 821 internal::Object** prev_next_; |
| 822 internal::Object** prev_limit_; | 822 internal::Object** prev_limit_; |
| 823 | 823 |
| 824 // TODO(dcarney): remove this field |
| 824 // Allow for the active closing of HandleScopes which allows to pass a handle | 825 // Allow for the active closing of HandleScopes which allows to pass a handle |
| 825 // from the HandleScope being closed to the next top most HandleScope. | 826 // from the HandleScope being closed to the next top most HandleScope. |
| 826 bool is_closed_; | 827 bool is_closed_; |
| 827 internal::Object** RawClose(internal::Object** value); | 828 internal::Object** RawClose(internal::Object** value); |
| 828 | 829 |
| 829 friend class ImplementationUtilities; | 830 friend class ImplementationUtilities; |
| 831 friend class EscapableHandleScope; |
| 832 template<class F> friend class Handle; |
| 833 template<class F> friend class Local; |
| 834 friend class Object; |
| 835 friend class Context; |
| 830 }; | 836 }; |
| 831 | 837 |
| 832 | 838 |
| 839 /** |
| 840 * A HandleScope which first allocates a handle in the current scope |
| 841 * which will be later filled with the escape value. |
| 842 */ |
| 843 class V8_EXPORT EscapableHandleScope : public HandleScope { |
| 844 public: |
| 845 EscapableHandleScope(Isolate* isolate); |
| 846 V8_INLINE ~EscapableHandleScope() {} |
| 847 |
| 848 /** |
| 849 * Pushes the value into the previous scope and returns a handle to it. |
| 850 * Cannot be called twice. |
| 851 */ |
| 852 template <class T> |
| 853 V8_INLINE Local<T> Escape(Local<T> value) { |
| 854 internal::Object** slot = |
| 855 Escape(reinterpret_cast<internal::Object**>(*value)); |
| 856 return Local<T>(reinterpret_cast<T*>(slot)); |
| 857 } |
| 858 |
| 859 private: |
| 860 internal::Object** Escape(internal::Object** escape_value); |
| 861 |
| 862 internal::Object** escape_slot_; |
| 863 }; |
| 864 |
| 865 |
| 833 /** | 866 /** |
| 834 * A simple Maybe type, representing an object which may or may not have a | 867 * A simple Maybe type, representing an object which may or may not have a |
| 835 * value. | 868 * value. |
| 836 */ | 869 */ |
| 837 template<class T> | 870 template<class T> |
| 838 struct V8_EXPORT Maybe { | 871 struct V8_EXPORT Maybe { |
| 839 Maybe() : has_value(false) {} | 872 Maybe() : has_value(false) {} |
| 840 explicit Maybe(T t) : has_value(true), value(t) {} | 873 explicit Maybe(T t) : has_value(true), value(t) {} |
| 841 Maybe(bool has, T t) : has_value(has), value(t) {} | 874 Maybe(bool has, T t) : has_value(has), value(t) {} |
| 842 | 875 |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 | 1505 |
| 1473 bool BooleanValue() const; | 1506 bool BooleanValue() const; |
| 1474 double NumberValue() const; | 1507 double NumberValue() const; |
| 1475 int64_t IntegerValue() const; | 1508 int64_t IntegerValue() const; |
| 1476 uint32_t Uint32Value() const; | 1509 uint32_t Uint32Value() const; |
| 1477 int32_t Int32Value() const; | 1510 int32_t Int32Value() const; |
| 1478 | 1511 |
| 1479 /** JS == */ | 1512 /** JS == */ |
| 1480 bool Equals(Handle<Value> that) const; | 1513 bool Equals(Handle<Value> that) const; |
| 1481 bool StrictEquals(Handle<Value> that) const; | 1514 bool StrictEquals(Handle<Value> that) const; |
| 1515 bool SameValue(Handle<Value> that) const; |
| 1482 | 1516 |
| 1483 template <class T> V8_INLINE static Value* Cast(T* value); | 1517 template <class T> V8_INLINE static Value* Cast(T* value); |
| 1484 | 1518 |
| 1485 private: | 1519 private: |
| 1486 V8_INLINE bool QuickIsUndefined() const; | 1520 V8_INLINE bool QuickIsUndefined() const; |
| 1487 V8_INLINE bool QuickIsNull() const; | 1521 V8_INLINE bool QuickIsNull() const; |
| 1488 V8_INLINE bool QuickIsString() const; | 1522 V8_INLINE bool QuickIsString() const; |
| 1489 bool FullIsUndefined() const; | 1523 bool FullIsUndefined() const; |
| 1490 bool FullIsNull() const; | 1524 bool FullIsNull() const; |
| 1491 bool FullIsString() const; | 1525 bool FullIsString() const; |
| (...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2378 V8_INLINE bool IsConstructCall() const; | 2412 V8_INLINE bool IsConstructCall() const; |
| 2379 V8_INLINE Local<Value> Data() const; | 2413 V8_INLINE Local<Value> Data() const; |
| 2380 V8_INLINE Isolate* GetIsolate() const; | 2414 V8_INLINE Isolate* GetIsolate() const; |
| 2381 V8_INLINE ReturnValue<T> GetReturnValue() const; | 2415 V8_INLINE ReturnValue<T> GetReturnValue() const; |
| 2382 // This shouldn't be public, but the arm compiler needs it. | 2416 // This shouldn't be public, but the arm compiler needs it. |
| 2383 static const int kArgsLength = 7; | 2417 static const int kArgsLength = 7; |
| 2384 | 2418 |
| 2385 protected: | 2419 protected: |
| 2386 friend class internal::FunctionCallbackArguments; | 2420 friend class internal::FunctionCallbackArguments; |
| 2387 friend class internal::CustomArguments<FunctionCallbackInfo>; | 2421 friend class internal::CustomArguments<FunctionCallbackInfo>; |
| 2388 static const int kReturnValueIndex = 0; | 2422 static const int kContextSaveIndex = 0; |
| 2389 static const int kReturnValueDefaultValueIndex = -1; | 2423 static const int kCalleeIndex = -1; |
| 2390 static const int kIsolateIndex = -2; | 2424 static const int kDataIndex = -2; |
| 2391 static const int kDataIndex = -3; | 2425 static const int kReturnValueIndex = -3; |
| 2392 static const int kCalleeIndex = -4; | 2426 static const int kReturnValueDefaultValueIndex = -4; |
| 2393 static const int kHolderIndex = -5; | 2427 static const int kIsolateIndex = -5; |
| 2394 static const int kContextSaveIndex = -6; | 2428 static const int kHolderIndex = -6; |
| 2395 | 2429 |
| 2396 V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args, | 2430 V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args, |
| 2397 internal::Object** values, | 2431 internal::Object** values, |
| 2398 int length, | 2432 int length, |
| 2399 bool is_construct_call); | 2433 bool is_construct_call); |
| 2400 internal::Object** implicit_args_; | 2434 internal::Object** implicit_args_; |
| 2401 internal::Object** values_; | 2435 internal::Object** values_; |
| 2402 int length_; | 2436 int length_; |
| 2403 bool is_construct_call_; | 2437 bool is_construct_call_; |
| 2404 }; | 2438 }; |
| (...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3754 ResourceConstraints(); | 3788 ResourceConstraints(); |
| 3755 int max_young_space_size() const { return max_young_space_size_; } | 3789 int max_young_space_size() const { return max_young_space_size_; } |
| 3756 void set_max_young_space_size(int value) { max_young_space_size_ = value; } | 3790 void set_max_young_space_size(int value) { max_young_space_size_ = value; } |
| 3757 int max_old_space_size() const { return max_old_space_size_; } | 3791 int max_old_space_size() const { return max_old_space_size_; } |
| 3758 void set_max_old_space_size(int value) { max_old_space_size_ = value; } | 3792 void set_max_old_space_size(int value) { max_old_space_size_ = value; } |
| 3759 int max_executable_size() { return max_executable_size_; } | 3793 int max_executable_size() { return max_executable_size_; } |
| 3760 void set_max_executable_size(int value) { max_executable_size_ = value; } | 3794 void set_max_executable_size(int value) { max_executable_size_ = value; } |
| 3761 uint32_t* stack_limit() const { return stack_limit_; } | 3795 uint32_t* stack_limit() const { return stack_limit_; } |
| 3762 // Sets an address beyond which the VM's stack may not grow. | 3796 // Sets an address beyond which the VM's stack may not grow. |
| 3763 void set_stack_limit(uint32_t* value) { stack_limit_ = value; } | 3797 void set_stack_limit(uint32_t* value) { stack_limit_ = value; } |
| 3764 Maybe<bool> is_memory_constrained() const { return is_memory_constrained_; } | |
| 3765 // If set to true, V8 will limit it's memory usage, at the potential cost of | |
| 3766 // lower performance. Note, this option is a tentative addition to the API | |
| 3767 // and may be removed or modified without warning. | |
| 3768 void set_memory_constrained(bool value) { | |
| 3769 is_memory_constrained_ = Maybe<bool>(value); | |
| 3770 } | |
| 3771 | 3798 |
| 3772 private: | 3799 private: |
| 3773 int max_young_space_size_; | 3800 int max_young_space_size_; |
| 3774 int max_old_space_size_; | 3801 int max_old_space_size_; |
| 3775 int max_executable_size_; | 3802 int max_executable_size_; |
| 3776 uint32_t* stack_limit_; | 3803 uint32_t* stack_limit_; |
| 3777 Maybe<bool> is_memory_constrained_; | |
| 3778 }; | 3804 }; |
| 3779 | 3805 |
| 3780 | 3806 |
| 3807 /** |
| 3808 * Sets the given ResourceConstraints on the current isolate. |
| 3809 */ |
| 3781 bool V8_EXPORT SetResourceConstraints(ResourceConstraints* constraints); | 3810 bool V8_EXPORT SetResourceConstraints(ResourceConstraints* constraints); |
| 3782 | 3811 |
| 3783 | 3812 |
| 3784 // --- Exceptions --- | 3813 // --- Exceptions --- |
| 3785 | 3814 |
| 3786 | 3815 |
| 3787 typedef void (*FatalErrorCallback)(const char* location, const char* message); | 3816 typedef void (*FatalErrorCallback)(const char* location, const char* message); |
| 3788 | 3817 |
| 3789 | 3818 |
| 3790 typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error); | 3819 typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error); |
| 3791 | 3820 |
| 3792 | 3821 |
| 3793 /** | 3822 // TODO(dcarney): remove. Use Isolate::ThrowException instead. |
| 3794 * Schedules an exception to be thrown when returning to JavaScript. When an | |
| 3795 * exception has been scheduled it is illegal to invoke any JavaScript | |
| 3796 * operation; the caller must return immediately and only after the exception | |
| 3797 * has been handled does it become legal to invoke JavaScript operations. | |
| 3798 */ | |
| 3799 Handle<Value> V8_EXPORT ThrowException(Handle<Value> exception); | 3823 Handle<Value> V8_EXPORT ThrowException(Handle<Value> exception); |
| 3800 | 3824 |
| 3801 /** | 3825 /** |
| 3802 * Create new error objects by calling the corresponding error object | 3826 * Create new error objects by calling the corresponding error object |
| 3803 * constructor with the message. | 3827 * constructor with the message. |
| 3804 */ | 3828 */ |
| 3805 class V8_EXPORT Exception { | 3829 class V8_EXPORT Exception { |
| 3806 public: | 3830 public: |
| 3807 static Local<Value> RangeError(Handle<String> message); | 3831 static Local<Value> RangeError(Handle<String> message); |
| 3808 static Local<Value> ReferenceError(Handle<String> message); | 3832 static Local<Value> ReferenceError(Handle<String> message); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4044 * Returns the context of the calling JavaScript code. That is the | 4068 * Returns the context of the calling JavaScript code. That is the |
| 4045 * context of the top-most JavaScript frame. If there are no | 4069 * context of the top-most JavaScript frame. If there are no |
| 4046 * JavaScript frames an empty handle is returned. | 4070 * JavaScript frames an empty handle is returned. |
| 4047 */ | 4071 */ |
| 4048 Local<Context> GetCallingContext(); | 4072 Local<Context> GetCallingContext(); |
| 4049 | 4073 |
| 4050 /** Returns the last entered context. */ | 4074 /** Returns the last entered context. */ |
| 4051 Local<Context> GetEnteredContext(); | 4075 Local<Context> GetEnteredContext(); |
| 4052 | 4076 |
| 4053 /** | 4077 /** |
| 4078 * Schedules an exception to be thrown when returning to JavaScript. When an |
| 4079 * exception has been scheduled it is illegal to invoke any JavaScript |
| 4080 * operation; the caller must return immediately and only after the exception |
| 4081 * has been handled does it become legal to invoke JavaScript operations. |
| 4082 */ |
| 4083 Local<Value> ThrowException(Local<Value> exception); |
| 4084 |
| 4085 /** |
| 4054 * Allows the host application to group objects together. If one | 4086 * Allows the host application to group objects together. If one |
| 4055 * object in the group is alive, all objects in the group are alive. | 4087 * object in the group is alive, all objects in the group are alive. |
| 4056 * After each garbage collection, object groups are removed. It is | 4088 * After each garbage collection, object groups are removed. It is |
| 4057 * intended to be used in the before-garbage-collection callback | 4089 * intended to be used in the before-garbage-collection callback |
| 4058 * function, for instance to simulate DOM tree connections among JS | 4090 * function, for instance to simulate DOM tree connections among JS |
| 4059 * wrapper objects. Object groups for all dependent handles need to | 4091 * wrapper objects. Object groups for all dependent handles need to |
| 4060 * be provided for kGCTypeMarkSweepCompact collections, for all other | 4092 * be provided for kGCTypeMarkSweepCompact collections, for all other |
| 4061 * garbage collection types it is sufficient to provide object groups | 4093 * garbage collection types it is sufficient to provide object groups |
| 4062 * for partially dependent handles only. | 4094 * for partially dependent handles only. |
| 4063 */ | 4095 */ |
| (...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5164 * // V8 Now no longer locked. | 5196 * // V8 Now no longer locked. |
| 5165 * \endcode | 5197 * \endcode |
| 5166 */ | 5198 */ |
| 5167 class V8_EXPORT Unlocker { | 5199 class V8_EXPORT Unlocker { |
| 5168 public: | 5200 public: |
| 5169 /** | 5201 /** |
| 5170 * Initialize Unlocker for a given Isolate. | 5202 * Initialize Unlocker for a given Isolate. |
| 5171 */ | 5203 */ |
| 5172 V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); } | 5204 V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); } |
| 5173 | 5205 |
| 5174 /** Deprecated. Use Isolate version instead. */ | |
| 5175 V8_DEPRECATED(Unlocker()); | |
| 5176 | |
| 5177 ~Unlocker(); | 5206 ~Unlocker(); |
| 5178 private: | 5207 private: |
| 5179 void Initialize(Isolate* isolate); | 5208 void Initialize(Isolate* isolate); |
| 5180 | 5209 |
| 5181 internal::Isolate* isolate_; | 5210 internal::Isolate* isolate_; |
| 5182 }; | 5211 }; |
| 5183 | 5212 |
| 5184 | 5213 |
| 5185 class V8_EXPORT Locker { | 5214 class V8_EXPORT Locker { |
| 5186 public: | 5215 public: |
| 5187 /** | 5216 /** |
| 5188 * Initialize Locker for a given Isolate. | 5217 * Initialize Locker for a given Isolate. |
| 5189 */ | 5218 */ |
| 5190 V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); } | 5219 V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); } |
| 5191 | 5220 |
| 5192 /** Deprecated. Use Isolate version instead. */ | |
| 5193 V8_DEPRECATED(Locker()); | |
| 5194 | |
| 5195 ~Locker(); | 5221 ~Locker(); |
| 5196 | 5222 |
| 5197 /** | 5223 /** |
| 5198 * Start preemption. | 5224 * Start preemption. |
| 5199 * | 5225 * |
| 5200 * When preemption is started, a timer is fired every n milliseconds | 5226 * When preemption is started, a timer is fired every n milliseconds |
| 5201 * that will switch between multiple threads that are in contention | 5227 * that will switch between multiple threads that are in contention |
| 5202 * for the V8 lock. | 5228 * for the V8 lock. |
| 5203 */ | 5229 */ |
| 5204 static void StartPreemption(int every_n_ms); | 5230 static void StartPreemption(Isolate* isolate, int every_n_ms); |
| 5205 | 5231 |
| 5206 /** | 5232 /** |
| 5207 * Stop preemption. | 5233 * Stop preemption. |
| 5208 */ | 5234 */ |
| 5209 static void StopPreemption(); | 5235 static void StopPreemption(Isolate* isolate); |
| 5210 | 5236 |
| 5211 /** | 5237 /** |
| 5212 * Returns whether or not the locker for a given isolate, is locked by the | 5238 * Returns whether or not the locker for a given isolate, is locked by the |
| 5213 * current thread. | 5239 * current thread. |
| 5214 */ | 5240 */ |
| 5215 static bool IsLocked(Isolate* isolate); | 5241 static bool IsLocked(Isolate* isolate); |
| 5216 | 5242 |
| 5217 /** | 5243 /** |
| 5218 * Returns whether v8::Locker is being used by this V8 instance. | 5244 * Returns whether v8::Locker is being used by this V8 instance. |
| 5219 */ | 5245 */ |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5417 static const int kNodeIsPartiallyDependentShift = 5; | 5443 static const int kNodeIsPartiallyDependentShift = 5; |
| 5418 | 5444 |
| 5419 static const int kJSObjectType = 0xb1; | 5445 static const int kJSObjectType = 0xb1; |
| 5420 static const int kFirstNonstringType = 0x80; | 5446 static const int kFirstNonstringType = 0x80; |
| 5421 static const int kOddballType = 0x83; | 5447 static const int kOddballType = 0x83; |
| 5422 static const int kForeignType = 0x87; | 5448 static const int kForeignType = 0x87; |
| 5423 | 5449 |
| 5424 static const int kUndefinedOddballKind = 5; | 5450 static const int kUndefinedOddballKind = 5; |
| 5425 static const int kNullOddballKind = 3; | 5451 static const int kNullOddballKind = 3; |
| 5426 | 5452 |
| 5427 static void CheckInitializedImpl(v8::Isolate* isolate); | 5453 V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate); |
| 5428 V8_INLINE static void CheckInitialized(v8::Isolate* isolate) { | 5454 V8_INLINE static void CheckInitialized(v8::Isolate* isolate) { |
| 5429 #ifdef V8_ENABLE_CHECKS | 5455 #ifdef V8_ENABLE_CHECKS |
| 5430 CheckInitializedImpl(isolate); | 5456 CheckInitializedImpl(isolate); |
| 5431 #endif | 5457 #endif |
| 5432 } | 5458 } |
| 5433 | 5459 |
| 5434 V8_INLINE static bool HasHeapObjectTag(internal::Object* value) { | 5460 V8_INLINE static bool HasHeapObjectTag(internal::Object* value) { |
| 5435 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 5461 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 5436 kHeapObjectTag); | 5462 kHeapObjectTag); |
| 5437 } | 5463 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5533 }; | 5559 }; |
| 5534 | 5560 |
| 5535 } // namespace internal | 5561 } // namespace internal |
| 5536 | 5562 |
| 5537 | 5563 |
| 5538 template <class T> | 5564 template <class T> |
| 5539 Local<T>::Local() : Handle<T>() { } | 5565 Local<T>::Local() : Handle<T>() { } |
| 5540 | 5566 |
| 5541 | 5567 |
| 5542 template <class T> | 5568 template <class T> |
| 5543 Local<T> Local<T>::New(Handle<T> that) { | |
| 5544 if (that.IsEmpty()) return Local<T>(); | |
| 5545 T* that_ptr = *that; | |
| 5546 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); | |
| 5547 if (internal::Internals::CanCastToHeapObject(that_ptr)) { | |
| 5548 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | |
| 5549 reinterpret_cast<internal::HeapObject*>(*p)))); | |
| 5550 } | |
| 5551 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); | |
| 5552 } | |
| 5553 | |
| 5554 | |
| 5555 template <class T> | |
| 5556 Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { | 5569 Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { |
| 5557 return New(isolate, that.val_); | 5570 return New(isolate, that.val_); |
| 5558 } | 5571 } |
| 5559 | 5572 |
| 5560 template <class T> | 5573 template <class T> |
| 5561 template <class M> | 5574 template <class M> |
| 5562 Local<T> Local<T>::New(Isolate* isolate, const Persistent<T, M>& that) { | 5575 Local<T> Local<T>::New(Isolate* isolate, const Persistent<T, M>& that) { |
| 5563 return New(isolate, that.val_); | 5576 return New(isolate, that.val_); |
| 5564 } | 5577 } |
| 5565 | 5578 |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5886 int length, | 5899 int length, |
| 5887 bool is_construct_call) | 5900 bool is_construct_call) |
| 5888 : implicit_args_(implicit_args), | 5901 : implicit_args_(implicit_args), |
| 5889 values_(values), | 5902 values_(values), |
| 5890 length_(length), | 5903 length_(length), |
| 5891 is_construct_call_(is_construct_call) { } | 5904 is_construct_call_(is_construct_call) { } |
| 5892 | 5905 |
| 5893 | 5906 |
| 5894 template<typename T> | 5907 template<typename T> |
| 5895 Local<Value> FunctionCallbackInfo<T>::operator[](int i) const { | 5908 Local<Value> FunctionCallbackInfo<T>::operator[](int i) const { |
| 5896 if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); | 5909 if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate())); |
| 5897 return Local<Value>(reinterpret_cast<Value*>(values_ - i)); | 5910 return Local<Value>(reinterpret_cast<Value*>(values_ - i)); |
| 5898 } | 5911 } |
| 5899 | 5912 |
| 5900 | 5913 |
| 5901 template<typename T> | 5914 template<typename T> |
| 5902 Local<Function> FunctionCallbackInfo<T>::Callee() const { | 5915 Local<Function> FunctionCallbackInfo<T>::Callee() const { |
| 5903 return Local<Function>(reinterpret_cast<Function*>( | 5916 return Local<Function>(reinterpret_cast<Function*>( |
| 5904 &implicit_args_[kCalleeIndex])); | 5917 &implicit_args_[kCalleeIndex])); |
| 5905 } | 5918 } |
| 5906 | 5919 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5968 Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { | 5981 Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { |
| 5969 return resource_column_offset_; | 5982 return resource_column_offset_; |
| 5970 } | 5983 } |
| 5971 | 5984 |
| 5972 Handle<Boolean> ScriptOrigin::ResourceIsSharedCrossOrigin() const { | 5985 Handle<Boolean> ScriptOrigin::ResourceIsSharedCrossOrigin() const { |
| 5973 return resource_is_shared_cross_origin_; | 5986 return resource_is_shared_cross_origin_; |
| 5974 } | 5987 } |
| 5975 | 5988 |
| 5976 | 5989 |
| 5977 Handle<Boolean> Boolean::New(bool value) { | 5990 Handle<Boolean> Boolean::New(bool value) { |
| 5978 return value ? True() : False(); | 5991 Isolate* isolate = Isolate::GetCurrent(); |
| 5992 return value ? True(isolate) : False(isolate); |
| 5979 } | 5993 } |
| 5980 | 5994 |
| 5981 | 5995 |
| 5982 void Template::Set(const char* name, v8::Handle<Data> value) { | 5996 void Template::Set(const char* name, v8::Handle<Data> value) { |
| 5983 Set(v8::String::New(name), value); | 5997 Set(v8::String::New(name), value); |
| 5984 } | 5998 } |
| 5985 | 5999 |
| 5986 | 6000 |
| 5987 Local<Value> Object::GetInternalField(int index) { | 6001 Local<Value> Object::GetInternalField(int index) { |
| 5988 #ifndef V8_ENABLE_CHECKS | 6002 #ifndef V8_ENABLE_CHECKS |
| 5989 typedef internal::Object O; | 6003 typedef internal::Object O; |
| 6004 typedef internal::HeapObject HO; |
| 5990 typedef internal::Internals I; | 6005 typedef internal::Internals I; |
| 5991 O* obj = *reinterpret_cast<O**>(this); | 6006 O* obj = *reinterpret_cast<O**>(this); |
| 5992 // Fast path: If the object is a plain JSObject, which is the common case, we | 6007 // Fast path: If the object is a plain JSObject, which is the common case, we |
| 5993 // know where to find the internal fields and can return the value directly. | 6008 // know where to find the internal fields and can return the value directly. |
| 5994 if (I::GetInstanceType(obj) == I::kJSObjectType) { | 6009 if (I::GetInstanceType(obj) == I::kJSObjectType) { |
| 5995 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); | 6010 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
| 5996 O* value = I::ReadField<O*>(obj, offset); | 6011 O* value = I::ReadField<O*>(obj, offset); |
| 5997 O** result = HandleScope::CreateHandle(value); | 6012 O** result = HandleScope::CreateHandle(reinterpret_cast<HO*>(obj), value); |
| 5998 return Local<Value>(reinterpret_cast<Value*>(result)); | 6013 return Local<Value>(reinterpret_cast<Value*>(result)); |
| 5999 } | 6014 } |
| 6000 #endif | 6015 #endif |
| 6001 return SlowGetInternalField(index); | 6016 return SlowGetInternalField(index); |
| 6002 } | 6017 } |
| 6003 | 6018 |
| 6004 | 6019 |
| 6005 void* Object::GetAlignedPointerFromInternalField(int index) { | 6020 void* Object::GetAlignedPointerFromInternalField(int index) { |
| 6006 #ifndef V8_ENABLE_CHECKS | 6021 #ifndef V8_ENABLE_CHECKS |
| 6007 typedef internal::Object O; | 6022 typedef internal::Object O; |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6439 | 6454 |
| 6440 void* Isolate::GetData() { | 6455 void* Isolate::GetData() { |
| 6441 typedef internal::Internals I; | 6456 typedef internal::Internals I; |
| 6442 return I::GetEmbedderData(this); | 6457 return I::GetEmbedderData(this); |
| 6443 } | 6458 } |
| 6444 | 6459 |
| 6445 | 6460 |
| 6446 Local<Value> Context::GetEmbedderData(int index) { | 6461 Local<Value> Context::GetEmbedderData(int index) { |
| 6447 #ifndef V8_ENABLE_CHECKS | 6462 #ifndef V8_ENABLE_CHECKS |
| 6448 typedef internal::Object O; | 6463 typedef internal::Object O; |
| 6464 typedef internal::HeapObject HO; |
| 6449 typedef internal::Internals I; | 6465 typedef internal::Internals I; |
| 6450 O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index)); | 6466 HO* context = *reinterpret_cast<HO**>(this); |
| 6467 O** result = |
| 6468 HandleScope::CreateHandle(context, I::ReadEmbedderData<O*>(this, index)); |
| 6451 return Local<Value>(reinterpret_cast<Value*>(result)); | 6469 return Local<Value>(reinterpret_cast<Value*>(result)); |
| 6452 #else | 6470 #else |
| 6453 return SlowGetEmbedderData(index); | 6471 return SlowGetEmbedderData(index); |
| 6454 #endif | 6472 #endif |
| 6455 } | 6473 } |
| 6456 | 6474 |
| 6457 | 6475 |
| 6458 void* Context::GetAlignedPointerFromEmbedderData(int index) { | 6476 void* Context::GetAlignedPointerFromEmbedderData(int index) { |
| 6459 #ifndef V8_ENABLE_CHECKS | 6477 #ifndef V8_ENABLE_CHECKS |
| 6460 typedef internal::Internals I; | 6478 typedef internal::Internals I; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 6477 */ | 6495 */ |
| 6478 | 6496 |
| 6479 | 6497 |
| 6480 } // namespace v8 | 6498 } // namespace v8 |
| 6481 | 6499 |
| 6482 | 6500 |
| 6483 #undef TYPE_CHECK | 6501 #undef TYPE_CHECK |
| 6484 | 6502 |
| 6485 | 6503 |
| 6486 #endif // V8_H_ | 6504 #endif // V8_H_ |
| OLD | NEW |