30 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
31 #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the
32 build configuration to ensure that at most one of these is set
35 #ifdef BUILDING_V8_SHARED
36 # define V8_EXPORT __declspec(dllexport)
38 # define V8_EXPORT __declspec(dllimport)
46 #if V8_HAS_ATTRIBUTE_VISIBILITY
&& defined(V8_SHARED)
47 # ifdef BUILDING_V8_SHARED
48 # define V8_EXPORT __attribute__ ((visibility("default")))
76 class ImplementationUtilities;
100 template <
class T>
class Handle;
101 template <
class T>
class Local;
102 template <
class T>
class Eternal;
103 template<
class T>
class NonCopyablePersistentTraits;
106 class M = NonCopyablePersistentTraits<T> >
class Persistent;
110 template<
class T,
class P>
class WeakCallbackObject;
122 class CallHandlerHelper;
133 class PropertyCallbackArguments;
134 class FunctionCallbackArguments;
148 return data_ == other.data_;
152 return data_ != other.data_;
156 return data_ < other.data_;
165 #define TYPE_CHECK(T, S)
167 *(static_cast<T* volatile*>(0
)) = static_cast<S*>(0
);
214 : val_(
reinterpret_cast<T*>(*that)) {
246 if (a == 0)
return b == 0;
247 if (b == 0)
return false;
255 if (a == 0)
return b == 0;
256 if (b == 0)
return false;
267 return !operator==(that);
272 return !operator==(that);
276 #ifdef V8_ENABLE_CHECKS
279 if (that.IsEmpty())
return Handle<T>();
281 return Handle<T>(T::Cast(*that));
285 return Handle<S>::Cast(*
this);
289 return New(isolate, that.val_);
293 return New(isolate, that.val_);
301 template<
class F>
friend class Local;
317 V8_INLINE explicit Handle(T* val) : val_(val) {}
336 :
Handle<T>(
reinterpret_cast<T*>(*that)) {
347 #ifdef V8_ENABLE_CHECKS
350 if (that.IsEmpty())
return Local<T>();
352 return Local<T>(T::Cast(*that));
355 :
Handle<T>(
reinterpret_cast<T*>(*that)) {
360 return Local<S>::Cast(*
this);
378 template<
class F>
friend class Local;
401 Set(isolate, handle);
409 static const int kInitialValue = -1;
414 template<
class T,
class P>
425 WeakCallbackData(
Isolate* isolate,
Local<T> handle, P* parameter)
426 : isolate_(isolate), handle_(handle), parameter_(parameter) { }
473 if (a == 0)
return b == 0;
474 if (b == 0)
return false;
481 if (a == 0)
return b == 0;
482 if (b == 0)
return false;
488 return !operator==(that);
492 return !operator==(that);
507 template<
typename S,
typename P>
560 template<
class F>
friend class Local;
569 explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
585 class NonCopyablePersistentTraits {
589 template<
class S,
class M>
609 template<
class S,
class M>
645 template <
class S,
class M2>
659 template <
class S,
class M2>
667 template <
class S,
class M2>
678 if (M::kResetInDestructor)
this->Reset();
684 #ifdef V8_ENABLE_CHECKS
687 if (!that.IsEmpty()) T::Cast(*that);
689 return reinterpret_cast<
Persistent<T>&>(that);
704 template<
class F>
friend class Local;
709 V8_INLINE T* operator*()
const {
return this->val_; }
710 template<
class S,
class M2>
757 rvalue.object->val_ = 0;
767 this->val_ = rhs.val_;
812 return reinterpret_cast<
Isolate*>(isolate_);
832 void* operator
new(size_t size);
833 void operator
delete(
void*, size_t);
840 template<
class F>
friend class Local;
865 Escape(
reinterpret_cast<
internal::Object**>(*value));
866 return Local<T>(
reinterpret_cast<T*>(slot));
876 void* operator
new(size_t size);
877 void operator
delete(
void*, size_t);
928 : resource_name_(resource_name),
929 resource_line_offset_(resource_line_offset),
930 resource_column_offset_(resource_column_offset),
931 resource_is_shared_cross_origin_(resource_is_shared_cross_origin),
932 script_id_(script_id) { }
1570 V8_INLINE bool QuickIsUndefined()
const;
1573 bool FullIsUndefined()
const;
1574 bool FullIsNull()
const;
1575 bool FullIsString()
const;
1680 int* nchars_ref = NULL,
1739 virtual const uint16_t*
data()
const = 0;
1770 virtual const char*
data()
const = 0;
1814 const uint8_t* data,
1821 const uint16_t* data,
1921 Value(
const Value&);
1922 void operator=(
const Value&);
1929 static void CheckCast(
v8::
Value* obj);
1961 static void CheckCast(
v8::
Value* obj);
2003 static void CheckCast(
v8::
Value* obj);
2018 static void CheckCast(
v8::
Value* obj);
2360 int number_of_elements);
2394 static void CheckCast(
Value* obj);
2395 Local<
Value> SlowGetInternalField(
int index);
2396 void* SlowGetAlignedPointerFromInternalField(
int index);
2422 static void CheckCast(
Value* obj);
2426 template<
typename T>
2430 : value_(that.value_) {
2449 template <
typename S>
2470 template<
typename T>
2499 bool is_construct_call);
2511 template<
typename T>
2523 friend class MacroAssembler;
2608 static void CheckCast(
Value* obj);
2641 static void CheckCast(
Value* obj);
2658 static void CheckCast(
Value* obj);
2662 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
2664 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
2699 virtual void Free(
void* data, size_t length) = 0;
2716 void*
Data()
const {
return data_; }
2721 size_t byte_length_;
2747 size_t byte_length);
2780 static void CheckCast(
Value* obj);
2784 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
2786 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
2818 static void CheckCast(
Value* obj);
2839 static void CheckCast(
Value* obj);
2850 size_t byte_offset, size_t length);
2855 static void CheckCast(
Value* obj);
2866 size_t byte_offset, size_t length);
2870 Uint8ClampedArray();
2871 static void CheckCast(
Value* obj);
2881 size_t byte_offset, size_t length);
2886 static void CheckCast(
Value* obj);
2897 size_t byte_offset, size_t length);
2902 static void CheckCast(
Value* obj);
2913 size_t byte_offset, size_t length);
2918 static void CheckCast(
Value* obj);
2929 size_t byte_offset, size_t length);
2934 static void CheckCast(
Value* obj);
2945 size_t byte_offset, size_t length);
2950 static void CheckCast(
Value* obj);
2961 size_t byte_offset, size_t length);
2966 static void CheckCast(
Value* obj);
2977 size_t byte_offset, size_t length);
2982 static void CheckCast(
Value* obj);
2993 size_t byte_offset, size_t length);
2998 static void CheckCast(
Value* obj);
3032 static void CheckCast(
v8::
Value* obj);
3048 static void CheckCast(
v8::
Value* obj);
3064 static void CheckCast(
v8::
Value* obj);
3080 static void CheckCast(
v8::
Value* obj);
3098 static void CheckCast(
v8::
Value* obj);
3144 static void CheckCast(
v8::
Value* obj);
3158 static void CheckCast(
v8::
Value* obj);
3670 bool turned_on_by_default =
true);
3720 AccessorSignature();
3726 DeclaredAccessorDescriptor();
3735 int internal_field);
3737 ObjectOperationDescriptor();
3755 int16_t byte_offset);
3757 void* compare_value);
3761 uint8_t bool_offset = 0);
3764 uint8_t compare_value);
3768 uint16_t compare_value);
3772 uint32_t compare_value);
3775 RawOperationDescriptor();
3800 : data_(data), length_(length) {}
3801 const char*
data()
const {
return data_; }
3817 const char* source = 0,
3819 const char** deps = 0,
3820 int source_length = -1);
3827 const char*
name()
const {
return name_; }
3838 size_t source_length_;
3886 uint64_t virtual_memory_limit,
3887 uint32_t number_of_processors);
3901 max_available_threads_ = value;
3905 code_range_size_ = value;
3909 int max_semi_space_size_;
3910 int max_old_space_size_;
3911 int max_executable_size_;
3912 uint32_t* stack_limit_;
3913 int max_available_threads_;
3914 size_t code_range_size_;
4049 size_t total_heap_size_;
4050 size_t total_heap_size_executable_;
4051 size_t total_physical_size_;
4052 size_t used_heap_size_;
4053 size_t heap_size_limit_;
4089 Scope(
const Scope&);
4124 void* internal_throws_;
4125 void* internal_assert_;
4322 template<
typename T,
typename S>
4498 void* operator
new(size_t size);
4499 void operator
delete(
void*, size_t);
4504 void CollectAllGarbage(
const char* gc_reason);
4537 const char* compressed_data,
4538 int compressed_data_size) = 0;
4565 typedef uintptr_t (*ReturnAddressLocationResolver)(
4566 uintptr_t return_addr_location);
4581 uintptr_t return_addr_location);
4686 uint16_t class_id) {}
4784 int frame_limit = 10,
4874 ReturnAddressLocationResolver return_address_resolver);
5017 static void DisposeGlobal(
internal::Object** global_handle);
5019 static void MakeWeak(
internal::Object** global_handle,
5021 WeakCallback weak_callback);
5022 static void* ClearWeak(
internal::Object** global_handle);
5023 static void Eternalize(
Isolate* isolate,
5156 if (handler == NULL)
return NULL;
5157 return handler->js_stack_comparable_address_;
5161 void ResetInternal();
5166 void* operator
new(size_t size);
5167 void operator
delete(
void*, size_t);
5173 void* message_script_;
5174 void* js_stack_comparable_address_;
5175 int message_start_pos_;
5176 int message_end_pos_;
5177 bool is_verbose_ : 1;
5178 bool can_continue_ : 1;
5179 bool capture_message_ : 1;
5181 bool has_terminated_ : 1;
5197 : name_count_(name_count), names_(names) { }
5199 const char**
begin()
const {
return &names_[0]; }
5200 const char**
end()
const {
return &names_[name_count_]; }
5203 const int name_count_;
5204 const char** names_;
5366 void* SlowGetAlignedPointerFromEmbedderData(
int index);
5455 void Initialize(
Isolate* isolate);
5482 void Initialize(
Isolate* isolate);
5488 static bool active_;
5492 void operator=(
const Locker&);
5515 template <size_t ptr_size>
struct SmiTagging;
5517 template<
int kSmiShiftSize>
5520 intptr_t tagged_value =
5521 (
static_cast<intptr_t>(value) << smi_shift_bits) |
kSmiTag;
5522 return reinterpret_cast<
internal::Object*>(tagged_value);
5526 template <>
struct SmiTagging<4> {
5532 return static_cast<
int>(
reinterpret_cast<intptr_t>(value)) >> shift_bits;
5549 return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U;
5554 template <>
struct SmiTagging<8> {
5560 return static_cast<
int>(
reinterpret_cast<intptr_t>(value) >> shift_bits);
5567 return (value ==
static_cast<int32_t>(value));
5641 #ifdef V8_ENABLE_CHECKS
5642 CheckInitializedImpl(isolate);
5683 return *addr &
static_cast<uint8_t>(1U << shift);
5687 bool value,
int shift) {
5689 uint8_t mask =
static_cast<uint8_t>(1 << shift);
5690 *addr =
static_cast<uint8_t>((*addr & ~mask) | (value << shift));
5707 uint8_t *addr =
reinterpret_cast<uint8_t *>(isolate) +
5709 *
reinterpret_cast<
void**>(addr) = data;
5714 const uint8_t* addr =
reinterpret_cast<
const uint8_t*>(isolate) +
5716 return *
reinterpret_cast<
void*
const*>(addr);
5725 template <
typename T>
5727 const uint8_t* addr =
5729 return *
reinterpret_cast<
const T*>(addr);
5732 template <
typename T>
5736 O* ctx = *
reinterpret_cast<O*
const*>(context);
5742 return I::ReadField<T>(embedder_data, value_offset);
5755 return New(isolate, that.val_);
5760 return New(isolate, that.val_);
5765 if (that == NULL)
return Handle<T>();
5769 reinterpret_cast<
internal::Isolate*>(isolate)
, *p
)));
5775 if (that == NULL)
return Local<T>();
5779 reinterpret_cast<
internal::Isolate*>(isolate)
, *p
)));
5787 V8::Eternalize(isolate,
reinterpret_cast<
Value*>(*handle), &
this->index_);
5793 return Local<T>(
reinterpret_cast<T*>(
*V8::GetEternal(isolate, index_)));
5799 if (that == NULL)
return NULL;
5801 return reinterpret_cast<T*>(
5802 V8::GlobalizeReference(
reinterpret_cast<
internal::Isolate*>(isolate),
5807 template <
class T,
class M>
5808 template <
class S,
class M2>
5812 if (that.IsEmpty())
return;
5814 this->val_ =
reinterpret_cast<T*>(
V8::CopyPersistent(p));
5815 M::Copy(that,
this);
5822 if (
this->IsEmpty())
return false;
5831 if (
this->IsEmpty())
return false;
5832 uint8_t node_state =
5842 if (
this->IsEmpty())
return false;
5850 if (
this->IsEmpty())
return;
5851 V8::DisposeGlobal(
reinterpret_cast<
internal::Object**>(
this->val_));
5861 if (other.IsEmpty())
return;
5862 this->val_ = New(isolate, other.val_);
5872 if (other.IsEmpty())
return;
5873 this->val_ = New(isolate, other.val_);
5878 template <
typename S,
typename P>
5884 V8::MakeWeak(
reinterpret_cast<
internal::Object**>(
this->val_),
5886 reinterpret_cast<Callback>(callback));
5891 template <
typename P>
5895 SetWeak<T, P>(parameter, callback);
5900 template<
typename P>
5902 return reinterpret_cast<P*>(
5903 V8::ClearWeak(
reinterpret_cast<
internal::Object**>(
this->val_)));
5910 if (
this->IsEmpty())
return;
5920 if (
this->IsEmpty())
return;
5927 template <
class T,
class M>
5939 if (
this->IsEmpty())
return;
5942 *
reinterpret_cast<uint16_t*>(addr) = class_id;
5949 if (
this->IsEmpty())
return 0;
5952 return *
reinterpret_cast<uint16_t*>(addr);
5956 template<
typename T>
5959 template<
typename T>
5960 template<
typename S>
5964 *value_ = GetDefaultValue();
5966 *value_ = *
reinterpret_cast<
internal::Object**>(*handle);
5970 template<
typename T>
5971 template<
typename S>
5975 *value_ = GetDefaultValue();
5977 *value_ = *
reinterpret_cast<
internal::Object**>(*handle);
5981 template<
typename T>
5987 template<
typename T>
5998 template<
typename T>
6002 bool fits_into_int32_t = (i & (1U << 31)) == 0;
6004 Set(
static_cast<int32_t>(i));
6010 template<
typename T>
6023 template<
typename T>
6030 template<
typename T>
6037 template<
typename T>
6044 template<
typename T>
6047 return *
reinterpret_cast<
Isolate**>(&value_[-2]);
6050 template<
typename T>
6051 template<
typename S>
6057 template<
typename T>
6064 template<
typename T>
6068 bool is_construct_call)
6075 template<
typename T>
6082 template<
typename T>
6089 template<
typename T>
6095 template<
typename T>
6102 template<
typename T>
6108 template<
typename T>
6114 template<
typename T>
6120 template<
typename T>
6126 template<
typename T>
6133 return resource_name_;
6138 return resource_line_offset_;
6143 return resource_column_offset_;
6148 return resource_is_shared_cross_origin_;
6159 : source_string(string),
6164 cached_data(data) {}
6169 : source_string(string), cached_data(data) {}
6194 #ifndef V8_ENABLE_CHECKS
6198 O* obj = *
reinterpret_cast<O**>(
this);
6204 O** result =
HandleScope::CreateHandle(
reinterpret_cast<HO*>(obj), value);
6208 return SlowGetInternalField(index);
6213 #ifndef V8_ENABLE_CHECKS
6216 O* obj = *
reinterpret_cast<O**>(
this);
6224 return SlowGetAlignedPointerFromInternalField(index);
6229 #ifdef V8_ENABLE_CHECKS
6232 return static_cast<
String*>(value);
6248 O* obj = *
reinterpret_cast<O*
const*>(
this);
6256 #ifdef V8_ENABLE_CHECKS
6257 VerifyExternalStringResource(result);
6267 O* obj = *
reinterpret_cast<O*
const*>(
this);
6276 #ifdef V8_ENABLE_CHECKS
6277 VerifyExternalStringResourceBase(resource, *encoding_out);
6284 #ifdef V8_ENABLE_CHECKS
6285 return FullIsUndefined();
6287 return QuickIsUndefined();
6291 bool Value::QuickIsUndefined()
const {
6294 O* obj = *
reinterpret_cast<O*
const*>(
this);
6302 #ifdef V8_ENABLE_CHECKS
6303 return FullIsNull();
6305 return QuickIsNull();
6309 bool Value::QuickIsNull()
const {
6312 O* obj = *
reinterpret_cast<O*
const*>(
this);
6320 #ifdef V8_ENABLE_CHECKS
6321 return FullIsString();
6323 return QuickIsString();
6327 bool Value::QuickIsString()
const {
6330 O* obj = *
reinterpret_cast<O*
const*>(
this);
6337 return static_cast<
Value*>(value);
6342 #ifdef V8_ENABLE_CHECKS
6345 return static_cast<
Symbol*>(value);
6350 #ifdef V8_ENABLE_CHECKS
6353 return static_cast<
Number*>(value);
6358 #ifdef V8_ENABLE_CHECKS
6361 return static_cast<
Integer*>(value);
6366 #ifdef V8_ENABLE_CHECKS
6369 return static_cast<
Date*>(value);
6374 #ifdef V8_ENABLE_CHECKS
6382 #ifdef V8_ENABLE_CHECKS
6390 #ifdef V8_ENABLE_CHECKS
6398 #ifdef V8_ENABLE_CHECKS
6406 #ifdef V8_ENABLE_CHECKS
6409 return static_cast<
RegExp*>(value);
6414 #ifdef V8_ENABLE_CHECKS
6417 return static_cast<
Object*>(value);
6422 #ifdef V8_ENABLE_CHECKS
6425 return static_cast<
Array*>(value);
6430 #ifdef V8_ENABLE_CHECKS
6433 return static_cast<
Promise*>(value);
6438 #ifdef V8_ENABLE_CHECKS
6446 #ifdef V8_ENABLE_CHECKS
6454 #ifdef V8_ENABLE_CHECKS
6462 #ifdef V8_ENABLE_CHECKS
6470 #ifdef V8_ENABLE_CHECKS
6478 #ifdef V8_ENABLE_CHECKS
6486 #ifdef V8_ENABLE_CHECKS
6494 #ifdef V8_ENABLE_CHECKS
6502 #ifdef V8_ENABLE_CHECKS
6510 #ifdef V8_ENABLE_CHECKS
6518 #ifdef V8_ENABLE_CHECKS
6526 #ifdef V8_ENABLE_CHECKS
6534 #ifdef V8_ENABLE_CHECKS
6542 #ifdef V8_ENABLE_CHECKS
6545 return static_cast<
DataView*>(value);
6550 #ifdef V8_ENABLE_CHECKS
6553 return static_cast<
Function*>(value);
6558 #ifdef V8_ENABLE_CHECKS
6561 return static_cast<
External*>(value);
6565 template<
typename T>
6571 template<
typename T>
6577 template<
typename T>
6583 template<
typename T>
6589 template<
typename T>
6650 int64_t change_in_bytes) {
6652 int64_t* amount_of_external_allocated_memory =
6653 reinterpret_cast<int64_t*>(
reinterpret_cast<uint8_t*>(
this) +
6655 int64_t* amount_of_external_allocated_memory_at_last_global_gc =
6656 reinterpret_cast<int64_t*>(
6657 reinterpret_cast<uint8_t*>(
this) +
6659 int64_t amount = *amount_of_external_allocated_memory + change_in_bytes;
6660 if (change_in_bytes > 0 &&
6661 amount - *amount_of_external_allocated_memory_at_last_global_gc >
6663 CollectAllGarbage(
"external memory allocation limit reached.");
6665 *amount_of_external_allocated_memory = amount;
6667 return *amount_of_external_allocated_memory;
6671 template<
typename T>
6675 SetObjectGroupId(
reinterpret_cast<
v8::
internal::Object**>(object.val_), id);
6679 template<
typename T>
6683 SetReferenceFromGroup(id,
6684 reinterpret_cast<
v8::
internal::Object**>(object.val_));
6688 template<
typename T,
typename S>
6693 SetReference(
reinterpret_cast<
v8::
internal::Object**>(parent.val_),
6694 reinterpret_cast<
v8::
internal::Object**>(child.val_));
6699 #ifndef V8_ENABLE_CHECKS
6703 HO* context = *
reinterpret_cast<HO**>(
this);
6708 return SlowGetEmbedderData(index);
6714 #ifndef V8_ENABLE_CHECKS
6718 return SlowGetAlignedPointerFromEmbedderData(index);