| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** \mainpage V8 API Reference Guide | 5 /** \mainpage V8 API Reference Guide |
| 6 * | 6 * |
| 7 * V8 is Google's open source JavaScript engine. | 7 * V8 is Google's open source JavaScript engine. |
| 8 * | 8 * |
| 9 * This set of documents provides reference material generated from the | 9 * This set of documents provides reference material generated from the |
| 10 * V8 header file, include/v8.h. | 10 * V8 header file, include/v8.h. |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // Can only be safely called if already set. | 372 // Can only be safely called if already set. |
| 373 V8_INLINE Local<T> Get(Isolate* isolate); | 373 V8_INLINE Local<T> Get(Isolate* isolate); |
| 374 V8_INLINE bool IsEmpty() { return index_ == kInitialValue; } | 374 V8_INLINE bool IsEmpty() { return index_ == kInitialValue; } |
| 375 template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle); | 375 template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle); |
| 376 | 376 |
| 377 private: | 377 private: |
| 378 static const int kInitialValue = -1; | 378 static const int kInitialValue = -1; |
| 379 int index_; | 379 int index_; |
| 380 }; | 380 }; |
| 381 | 381 |
| 382 | 382 // TODO(internal): deprecate this constant soon. |
| 383 static const int kInternalFieldsInWeakCallback = 2; | 383 static const int kInternalFieldsInWeakCallback = 2; |
| 384 | 384 static const int kEmbedderFieldsInWeakCallback = 2; |
| 385 | 385 |
| 386 template <typename T> | 386 template <typename T> |
| 387 class WeakCallbackInfo { | 387 class WeakCallbackInfo { |
| 388 public: | 388 public: |
| 389 typedef void (*Callback)(const WeakCallbackInfo<T>& data); | 389 typedef void (*Callback)(const WeakCallbackInfo<T>& data); |
| 390 | 390 |
| 391 WeakCallbackInfo(Isolate* isolate, T* parameter, | 391 WeakCallbackInfo(Isolate* isolate, T* parameter, |
| 392 void* internal_fields[kInternalFieldsInWeakCallback], | 392 void* embedder_fields[kEmbedderFieldsInWeakCallback], |
| 393 Callback* callback) | 393 Callback* callback) |
| 394 : isolate_(isolate), parameter_(parameter), callback_(callback) { | 394 : isolate_(isolate), parameter_(parameter), callback_(callback) { |
| 395 for (int i = 0; i < kInternalFieldsInWeakCallback; ++i) { | 395 for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) { |
| 396 internal_fields_[i] = internal_fields[i]; | 396 embedder_fields_[i] = embedder_fields[i]; |
| 397 } | 397 } |
| 398 } | 398 } |
| 399 | 399 |
| 400 V8_INLINE Isolate* GetIsolate() const { return isolate_; } | 400 V8_INLINE Isolate* GetIsolate() const { return isolate_; } |
| 401 V8_INLINE T* GetParameter() const { return parameter_; } | 401 V8_INLINE T* GetParameter() const { return parameter_; } |
| 402 V8_INLINE void* GetInternalField(int index) const; | 402 V8_INLINE V8_DEPRECATE_SOON("use GetEmbedderField(int index)", |
| 403 void* GetInternalField(int index) const); |
| 404 V8_INLINE void* GetEmbedderField(int index) const; |
| 403 | 405 |
| 404 V8_INLINE V8_DEPRECATED("use indexed version", | 406 V8_INLINE V8_DEPRECATED("use GetEmbedderField(int index)", |
| 405 void* GetInternalField1() const) { | 407 void* GetInternalField1() const) { |
| 406 return internal_fields_[0]; | 408 return embedder_fields_[0]; |
| 407 } | 409 } |
| 408 V8_INLINE V8_DEPRECATED("use indexed version", | 410 V8_INLINE V8_DEPRECATED("use GetEmbedderField(int index)", |
| 409 void* GetInternalField2() const) { | 411 void* GetInternalField2() const) { |
| 410 return internal_fields_[1]; | 412 return embedder_fields_[1]; |
| 411 } | 413 } |
| 412 | 414 |
| 413 V8_DEPRECATED("Not realiable once SetSecondPassCallback() was used.", | 415 V8_DEPRECATED("Not realiable once SetSecondPassCallback() was used.", |
| 414 bool IsFirstPass() const) { | 416 bool IsFirstPass() const) { |
| 415 return callback_ != nullptr; | 417 return callback_ != nullptr; |
| 416 } | 418 } |
| 417 | 419 |
| 418 // When first called, the embedder MUST Reset() the Global which triggered the | 420 // When first called, the embedder MUST Reset() the Global which triggered the |
| 419 // callback. The Global itself is unusable for anything else. No v8 other api | 421 // callback. The Global itself is unusable for anything else. No v8 other api |
| 420 // calls may be called in the first callback. Should additional work be | 422 // calls may be called in the first callback. Should additional work be |
| 421 // required, the embedder must set a second pass callback, which will be | 423 // required, the embedder must set a second pass callback, which will be |
| 422 // called after all the initial callbacks are processed. | 424 // called after all the initial callbacks are processed. |
| 423 // Calling SetSecondPassCallback on the second pass will immediately crash. | 425 // Calling SetSecondPassCallback on the second pass will immediately crash. |
| 424 void SetSecondPassCallback(Callback callback) const { *callback_ = callback; } | 426 void SetSecondPassCallback(Callback callback) const { *callback_ = callback; } |
| 425 | 427 |
| 426 private: | 428 private: |
| 427 Isolate* isolate_; | 429 Isolate* isolate_; |
| 428 T* parameter_; | 430 T* parameter_; |
| 429 Callback* callback_; | 431 Callback* callback_; |
| 430 void* internal_fields_[kInternalFieldsInWeakCallback]; | 432 void* embedder_fields_[kEmbedderFieldsInWeakCallback]; |
| 431 }; | 433 }; |
| 432 | 434 |
| 433 | 435 // kParameter will pass a void* parameter back to the callback, kEmbedderFields |
| 434 // kParameter will pass a void* parameter back to the callback, kInternalFields | 436 // will pass the first two embedder fields back to the callback, kFinalizer |
| 435 // will pass the first two internal fields back to the callback, kFinalizer | |
| 436 // will pass a void* parameter back, but is invoked before the object is | 437 // will pass a void* parameter back, but is invoked before the object is |
| 437 // actually collected, so it can be resurrected. In the last case, it is not | 438 // actually collected, so it can be resurrected. In the last case, it is not |
| 438 // possible to request a second pass callback. | 439 // possible to request a second pass callback. |
| 439 enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer }; | 440 enum class WeakCallbackType { |
| 441 kParameter, |
| 442 kEmbedderFields, |
| 443 kInternalFields = kEmbedderFields, // TODO(v8): deprecate |
| 444 kFinalizer |
| 445 }; |
| 440 | 446 |
| 441 /** | 447 /** |
| 442 * An object reference that is independent of any handle scope. Where | 448 * An object reference that is independent of any handle scope. Where |
| 443 * a Local handle only lives as long as the HandleScope in which it was | 449 * a Local handle only lives as long as the HandleScope in which it was |
| 444 * allocated, a PersistentBase handle remains valid until it is explicitly | 450 * allocated, a PersistentBase handle remains valid until it is explicitly |
| 445 * disposed. | 451 * disposed. |
| 446 * | 452 * |
| 447 * A persistent handle contains a reference to a storage cell within | 453 * A persistent handle contains a reference to a storage cell within |
| 448 * the v8 engine which holds an object value and which is updated by | 454 * the v8 engine which holds an object value and which is updated by |
| 449 * the garbage collector whenever the object is moved. A new storage | 455 * the garbage collector whenever the object is moved. A new storage |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 static internal::Object** CreateHandle(internal::HeapObject* heap_object, | 865 static internal::Object** CreateHandle(internal::HeapObject* heap_object, |
| 860 internal::Object* value); | 866 internal::Object* value); |
| 861 | 867 |
| 862 internal::Isolate* isolate_; | 868 internal::Isolate* isolate_; |
| 863 internal::Object** prev_next_; | 869 internal::Object** prev_next_; |
| 864 internal::Object** prev_limit_; | 870 internal::Object** prev_limit_; |
| 865 | 871 |
| 866 // Local::New uses CreateHandle with an Isolate* parameter. | 872 // Local::New uses CreateHandle with an Isolate* parameter. |
| 867 template<class F> friend class Local; | 873 template<class F> friend class Local; |
| 868 | 874 |
| 869 // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with | 875 // Object::GetExternalField and Context::GetEmbedderData use CreateHandle with |
| 870 // a HeapObject* in their shortcuts. | 876 // a HeapObject* in their shortcuts. |
| 871 friend class Object; | 877 friend class Object; |
| 872 friend class Context; | 878 friend class Context; |
| 873 }; | 879 }; |
| 874 | 880 |
| 875 | 881 |
| 876 /** | 882 /** |
| 877 * A HandleScope which first allocates a handle in the current scope | 883 * A HandleScope which first allocates a handle in the current scope |
| 878 * which will be later filled with the escape value. | 884 * which will be later filled with the escape value. |
| 879 */ | 885 */ |
| (...skipping 2228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3108 /** | 3114 /** |
| 3109 * Returns the name of the function invoked as a constructor for this object. | 3115 * Returns the name of the function invoked as a constructor for this object. |
| 3110 */ | 3116 */ |
| 3111 Local<String> GetConstructorName(); | 3117 Local<String> GetConstructorName(); |
| 3112 | 3118 |
| 3113 /** | 3119 /** |
| 3114 * Sets the integrity level of the object. | 3120 * Sets the integrity level of the object. |
| 3115 */ | 3121 */ |
| 3116 Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level); | 3122 Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level); |
| 3117 | 3123 |
| 3118 /** Gets the number of internal fields for this Object. */ | 3124 /** Gets the number of embedder fields for this Object. */ |
| 3119 int InternalFieldCount(); | 3125 // TODO(internal): deprecate soon |
| 3126 int V8_DEPRECATE_SOON("use EmbedderFieldCount()", InternalFieldCount()); |
| 3127 int EmbedderFieldCount(); |
| 3120 | 3128 |
| 3121 /** Same as above, but works for Persistents */ | 3129 /** Same as above, but works for Persistents */ |
| 3122 V8_INLINE static int InternalFieldCount( | 3130 // TODO(internal): deprecate soon |
| 3123 const PersistentBase<Object>& object) { | 3131 V8_INLINE static int V8_DEPRECATE_SOON( |
| 3132 "use EmbedderFieldCount()", |
| 3133 InternalFieldCount(const PersistentBase<Object>& object)) { |
| 3124 return object.val_->InternalFieldCount(); | 3134 return object.val_->InternalFieldCount(); |
| 3125 } | 3135 } |
| 3126 | 3136 |
| 3127 /** Gets the value from an internal field. */ | 3137 /** Same as above, but works for Persistents */ |
| 3128 V8_INLINE Local<Value> GetInternalField(int index); | 3138 V8_INLINE static int EmbedderFieldCount( |
| 3139 const PersistentBase<Object>& object) { |
| 3140 return object.val_->EmbedderFieldCount(); |
| 3141 } |
| 3129 | 3142 |
| 3130 /** Sets the value in an internal field. */ | 3143 /** Gets the value from an embedder field. */ |
| 3131 void SetInternalField(int index, Local<Value> value); | 3144 V8_INLINE Local<Value> V8_DEPRECATE_SOON("use GetEmbedderField", |
| 3145 GetInternalField(int index)); |
| 3146 |
| 3147 /** Gets the value from an embedder field. */ |
| 3148 V8_INLINE Local<Value> GetEmbedderField(int index); |
| 3149 |
| 3150 /** Sets the value in an embedder field. */ |
| 3151 void V8_DEPRECATE_SOON("use SetEmbedderField", |
| 3152 SetInternalField(int index, Local<Value> value)); |
| 3153 |
| 3154 /** Sets the value in an embedder field. */ |
| 3155 void SetEmbedderField(int index, Local<Value> value); |
| 3132 | 3156 |
| 3133 /** | 3157 /** |
| 3134 * Gets a 2-byte-aligned native pointer from an internal field. This field | 3158 * Gets a 2-byte-aligned native pointer from an embedder field. This field |
| 3135 * must have been set by SetAlignedPointerInInternalField, everything else | 3159 * must have been set by SetAlignedPointerInExternalField, everything else |
| 3136 * leads to undefined behavior. | 3160 * leads to undefined behavior. |
| 3137 */ | 3161 */ |
| 3138 V8_INLINE void* GetAlignedPointerFromInternalField(int index); | 3162 V8_INLINE void* V8_DEPRECATE_SOON( |
| 3163 "use GetAlignedPointerFromEmbedderField()", |
| 3164 GetAlignedPointerFromInternalField(int index)); |
| 3165 V8_INLINE void* GetAlignedPointerFromEmbedderField(int index); |
| 3139 | 3166 |
| 3140 /** Same as above, but works for Persistents */ | 3167 /** Same as above, but works for Persistents */ |
| 3141 V8_INLINE static void* GetAlignedPointerFromInternalField( | 3168 V8_INLINE static void* GetAlignedPointerFromEmbedderField( |
| 3142 const PersistentBase<Object>& object, int index) { | 3169 const PersistentBase<Object>& object, int index) { |
| 3143 return object.val_->GetAlignedPointerFromInternalField(index); | 3170 return object.val_->GetAlignedPointerFromEmbedderField(index); |
| 3144 } | 3171 } |
| 3145 | 3172 |
| 3173 V8_INLINE static void* V8_DEPRECATE_SOON( |
| 3174 "use GetAlignedPointerFromEmbedderField", |
| 3175 GetAlignedPointerFromInternalField(const PersistentBase<Object>& object, |
| 3176 int index)) { |
| 3177 return object.val_->GetAlignedPointerFromEmbedderField(index); |
| 3178 } |
| 3146 /** | 3179 /** |
| 3147 * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such | 3180 * Sets a 2-byte-aligned native pointer in an embedder field. To retrieve such |
| 3148 * a field, GetAlignedPointerFromInternalField must be used, everything else | 3181 * a field, GetAlignedPointerFromInternalField must be used, everything else |
| 3149 * leads to undefined behavior. | 3182 * leads to undefined behavior. |
| 3150 */ | 3183 */ |
| 3151 void SetAlignedPointerInInternalField(int index, void* value); | 3184 void V8_DEPRECATE_SOON("use SetAlignedPointerInEmbedderField", |
| 3152 void SetAlignedPointerInInternalFields(int argc, int indices[], | 3185 SetAlignedPointerInInternalField(int index, |
| 3186 void* value)); |
| 3187 void V8_DEPRECATE_SOON("use SetAlignedPointerInInternalFields", |
| 3188 SetAlignedPointerInInternalFields(int argc, |
| 3189 int indices[], |
| 3190 void* values[])); |
| 3191 void SetAlignedPointerInEmbedderField(int index, void* value); |
| 3192 void SetAlignedPointerInEmbedderFields(int argc, int indices[], |
| 3153 void* values[]); | 3193 void* values[]); |
| 3154 | 3194 |
| 3155 // Testers for local properties. | 3195 // Testers for local properties. |
| 3156 V8_DEPRECATED("Use maybe version", bool HasOwnProperty(Local<String> key)); | 3196 V8_DEPRECATED("Use maybe version", bool HasOwnProperty(Local<String> key)); |
| 3157 | 3197 |
| 3158 /** | 3198 /** |
| 3159 * HasOwnProperty() is like JavaScript's Object.prototype.hasOwnProperty(). | 3199 * HasOwnProperty() is like JavaScript's Object.prototype.hasOwnProperty(). |
| 3160 * | 3200 * |
| 3161 * See also v8::Object::Has() and v8::Object::HasRealNamedProperty(). | 3201 * See also v8::Object::Has() and v8::Object::HasRealNamedProperty(). |
| 3162 */ | 3202 */ |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3306 */ | 3346 */ |
| 3307 V8_DEPRECATE_SOON("Keep track of isolate correctly", Isolate* GetIsolate()); | 3347 V8_DEPRECATE_SOON("Keep track of isolate correctly", Isolate* GetIsolate()); |
| 3308 | 3348 |
| 3309 static Local<Object> New(Isolate* isolate); | 3349 static Local<Object> New(Isolate* isolate); |
| 3310 | 3350 |
| 3311 V8_INLINE static Object* Cast(Value* obj); | 3351 V8_INLINE static Object* Cast(Value* obj); |
| 3312 | 3352 |
| 3313 private: | 3353 private: |
| 3314 Object(); | 3354 Object(); |
| 3315 static void CheckCast(Value* obj); | 3355 static void CheckCast(Value* obj); |
| 3316 Local<Value> SlowGetInternalField(int index); | 3356 Local<Value> SlowGetEmbedderField(int index); |
| 3317 void* SlowGetAlignedPointerFromInternalField(int index); | 3357 void* SlowGetAlignedPointerFromEmbedderField(int index); |
| 3318 }; | 3358 }; |
| 3319 | 3359 |
| 3320 | 3360 |
| 3321 /** | 3361 /** |
| 3322 * An instance of the built-in array constructor (ECMA-262, 15.4.2). | 3362 * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
| 3323 */ | 3363 */ |
| 3324 class V8_EXPORT Array : public Object { | 3364 class V8_EXPORT Array : public Object { |
| 3325 public: | 3365 public: |
| 3326 uint32_t Length() const; | 3366 uint32_t Length() const; |
| 3327 | 3367 |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3926 static MaybeLocal<WasmCompiledModule> Deserialize( | 3966 static MaybeLocal<WasmCompiledModule> Deserialize( |
| 3927 Isolate* isolate, const CallerOwnedBuffer& serialized_module, | 3967 Isolate* isolate, const CallerOwnedBuffer& serialized_module, |
| 3928 const CallerOwnedBuffer& wire_bytes); | 3968 const CallerOwnedBuffer& wire_bytes); |
| 3929 static MaybeLocal<WasmCompiledModule> Compile(Isolate* isolate, | 3969 static MaybeLocal<WasmCompiledModule> Compile(Isolate* isolate, |
| 3930 const uint8_t* start, | 3970 const uint8_t* start, |
| 3931 size_t length); | 3971 size_t length); |
| 3932 WasmCompiledModule(); | 3972 WasmCompiledModule(); |
| 3933 static void CheckCast(Value* obj); | 3973 static void CheckCast(Value* obj); |
| 3934 }; | 3974 }; |
| 3935 | 3975 |
| 3936 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT | 3976 #ifndef V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT |
| 3937 // The number of required internal fields can be defined by embedder. | 3977 // The number of required embedder fields for array buffers. |
| 3938 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 | 3978 #define V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT 2 |
| 3939 #endif | 3979 #endif |
| 3940 | 3980 |
| 3981 // TODO(v8): deprecate this constant in favor of {..._EMBEDDER_FIELD_COUNT} |
| 3982 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT |
| 3983 // The number of required embedder fields for array buffers. |
| 3984 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 |
| 3985 #else |
| 3986 #undef V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT |
| 3987 #define V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT \ |
| 3988 V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT |
| 3989 #endif |
| 3941 | 3990 |
| 3942 enum class ArrayBufferCreationMode { kInternalized, kExternalized }; | 3991 enum class ArrayBufferCreationMode { kInternalized, kExternalized }; |
| 3943 | 3992 |
| 3944 | 3993 |
| 3945 /** | 3994 /** |
| 3946 * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). | 3995 * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). |
| 3947 */ | 3996 */ |
| 3948 class V8_EXPORT ArrayBuffer : public Object { | 3997 class V8_EXPORT ArrayBuffer : public Object { |
| 3949 public: | 3998 public: |
| 3950 /** | 3999 /** |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4075 * | 4124 * |
| 4076 * The embedder should make sure to hold a strong reference to the | 4125 * The embedder should make sure to hold a strong reference to the |
| 4077 * ArrayBuffer while accessing this pointer. | 4126 * ArrayBuffer while accessing this pointer. |
| 4078 * | 4127 * |
| 4079 * The memory block is guaranteed to be allocated with |Allocator::Allocate|. | 4128 * The memory block is guaranteed to be allocated with |Allocator::Allocate|. |
| 4080 */ | 4129 */ |
| 4081 Contents GetContents(); | 4130 Contents GetContents(); |
| 4082 | 4131 |
| 4083 V8_INLINE static ArrayBuffer* Cast(Value* obj); | 4132 V8_INLINE static ArrayBuffer* Cast(Value* obj); |
| 4084 | 4133 |
| 4085 static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; | 4134 // TODO(internal) |
| 4135 static const int kInternalFieldCount = V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT; |
| 4136 static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT; |
| 4086 | 4137 |
| 4087 private: | 4138 private: |
| 4088 ArrayBuffer(); | 4139 ArrayBuffer(); |
| 4089 static void CheckCast(Value* obj); | 4140 static void CheckCast(Value* obj); |
| 4090 }; | 4141 }; |
| 4091 | 4142 |
| 4092 | 4143 |
| 4093 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT | 4144 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT |
| 4094 // The number of required internal fields can be defined by embedder. | 4145 // The number of required embedder fields can be defined by embedder. |
| 4095 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2 | 4146 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2 |
| 4096 #endif | 4147 #endif |
| 4097 | 4148 |
| 4149 // TODO(internal): deprecate this constant in favor of |
| 4150 // {..._EMBEDDER_FIELD_COUNT} |
| 4151 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT |
| 4152 // The number of required embedder fields can be defined by embedder. |
| 4153 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2 |
| 4154 #else |
| 4155 #undef V8_ARRAY_BUFFER_VIEW_EMBEDDER_FIELD_COUNT |
| 4156 #define V8_ARRAY_BUFFER_VIEW_EMBEDDER_FIELD_COUNT \ |
| 4157 V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT |
| 4158 #endif |
| 4098 | 4159 |
| 4099 /** | 4160 /** |
| 4100 * A base class for an instance of one of "views" over ArrayBuffer, | 4161 * A base class for an instance of one of "views" over ArrayBuffer, |
| 4101 * including TypedArrays and DataView (ES6 draft 15.13). | 4162 * including TypedArrays and DataView (ES6 draft 15.13). |
| 4102 */ | 4163 */ |
| 4103 class V8_EXPORT ArrayBufferView : public Object { | 4164 class V8_EXPORT ArrayBufferView : public Object { |
| 4104 public: | 4165 public: |
| 4105 /** | 4166 /** |
| 4106 * Returns underlying ArrayBuffer. | 4167 * Returns underlying ArrayBuffer. |
| 4107 */ | 4168 */ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4128 | 4189 |
| 4129 /** | 4190 /** |
| 4130 * Returns true if ArrayBufferView's backing ArrayBuffer has already been | 4191 * Returns true if ArrayBufferView's backing ArrayBuffer has already been |
| 4131 * allocated. | 4192 * allocated. |
| 4132 */ | 4193 */ |
| 4133 bool HasBuffer() const; | 4194 bool HasBuffer() const; |
| 4134 | 4195 |
| 4135 V8_INLINE static ArrayBufferView* Cast(Value* obj); | 4196 V8_INLINE static ArrayBufferView* Cast(Value* obj); |
| 4136 | 4197 |
| 4137 static const int kInternalFieldCount = | 4198 static const int kInternalFieldCount = |
| 4138 V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT; | 4199 V8_ARRAY_BUFFER_VIEW_EMBEDDER_FIELD_COUNT; |
| 4200 static const int kEmbedderFieldCount = |
| 4201 V8_ARRAY_BUFFER_VIEW_EMBEDDER_FIELD_COUNT; |
| 4139 | 4202 |
| 4140 private: | 4203 private: |
| 4141 ArrayBufferView(); | 4204 ArrayBufferView(); |
| 4142 static void CheckCast(Value* obj); | 4205 static void CheckCast(Value* obj); |
| 4143 }; | 4206 }; |
| 4144 | 4207 |
| 4145 | 4208 |
| 4146 /** | 4209 /** |
| 4147 * A base class for an instance of TypedArray series of constructors | 4210 * A base class for an instance of TypedArray series of constructors |
| 4148 * (ES6 draft 15.13.6). | 4211 * (ES6 draft 15.13.6). |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4417 * ArrayBuffer while accessing this pointer. | 4480 * ArrayBuffer while accessing this pointer. |
| 4418 * | 4481 * |
| 4419 * The memory block is guaranteed to be allocated with |Allocator::Allocate| | 4482 * The memory block is guaranteed to be allocated with |Allocator::Allocate| |
| 4420 * by the allocator specified in | 4483 * by the allocator specified in |
| 4421 * v8::Isolate::CreateParams::array_buffer_allocator. | 4484 * v8::Isolate::CreateParams::array_buffer_allocator. |
| 4422 */ | 4485 */ |
| 4423 Contents GetContents(); | 4486 Contents GetContents(); |
| 4424 | 4487 |
| 4425 V8_INLINE static SharedArrayBuffer* Cast(Value* obj); | 4488 V8_INLINE static SharedArrayBuffer* Cast(Value* obj); |
| 4426 | 4489 |
| 4427 static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; | 4490 // TODO(internal): deprecate |
| 4491 static const int kInternalFieldCount = V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT; |
| 4492 static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT; |
| 4428 | 4493 |
| 4429 private: | 4494 private: |
| 4430 SharedArrayBuffer(); | 4495 SharedArrayBuffer(); |
| 4431 static void CheckCast(Value* obj); | 4496 static void CheckCast(Value* obj); |
| 4432 }; | 4497 }; |
| 4433 | 4498 |
| 4434 | 4499 |
| 4435 /** | 4500 /** |
| 4436 * An instance of the built-in Date constructor (ECMA-262, 15.9). | 4501 * An instance of the built-in Date constructor (ECMA-262, 15.9). |
| 4437 */ | 4502 */ |
| (...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5531 * either this method or SetAccessCheckCallback, but not both at the same | 5596 * either this method or SetAccessCheckCallback, but not both at the same |
| 5532 * time. | 5597 * time. |
| 5533 */ | 5598 */ |
| 5534 void SetAccessCheckCallbackAndHandler( | 5599 void SetAccessCheckCallbackAndHandler( |
| 5535 AccessCheckCallback callback, | 5600 AccessCheckCallback callback, |
| 5536 const NamedPropertyHandlerConfiguration& named_handler, | 5601 const NamedPropertyHandlerConfiguration& named_handler, |
| 5537 const IndexedPropertyHandlerConfiguration& indexed_handler, | 5602 const IndexedPropertyHandlerConfiguration& indexed_handler, |
| 5538 Local<Value> data = Local<Value>()); | 5603 Local<Value> data = Local<Value>()); |
| 5539 | 5604 |
| 5540 /** | 5605 /** |
| 5541 * Gets the number of internal fields for objects generated from | 5606 * Gets the number of embedder fields for objects generated from |
| 5542 * this template. | 5607 * this template. |
| 5543 */ | 5608 */ |
| 5544 int InternalFieldCount(); | 5609 int InternalFieldCount(); |
| 5610 int EmbedderFieldCount(); |
| 5545 | 5611 |
| 5546 /** | 5612 /** |
| 5547 * Sets the number of internal fields for objects generated from | 5613 * Sets the number of embedder fields for objects generated from |
| 5548 * this template. | 5614 * this template. |
| 5549 */ | 5615 */ |
| 5550 void SetInternalFieldCount(int value); | 5616 void SetInternalFieldCount(int value); |
| 5617 void SetEmbedderFieldCount(int value); |
| 5551 | 5618 |
| 5552 /** | 5619 /** |
| 5553 * Returns true if the object will be an immutable prototype exotic object. | 5620 * Returns true if the object will be an immutable prototype exotic object. |
| 5554 */ | 5621 */ |
| 5555 bool IsImmutableProto(); | 5622 bool IsImmutableProto(); |
| 5556 | 5623 |
| 5557 /** | 5624 /** |
| 5558 * Makes the ObjectTempate for an immutable prototype exotic object, with an | 5625 * Makes the ObjectTempate for an immutable prototype exotic object, with an |
| 5559 * immutable __proto__. | 5626 * immutable __proto__. |
| 5560 */ | 5627 */ |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6236 enum ForceCompletionAction { FORCE_COMPLETION, DO_NOT_FORCE_COMPLETION }; | 6303 enum ForceCompletionAction { FORCE_COMPLETION, DO_NOT_FORCE_COMPLETION }; |
| 6237 | 6304 |
| 6238 struct AdvanceTracingActions { | 6305 struct AdvanceTracingActions { |
| 6239 explicit AdvanceTracingActions(ForceCompletionAction force_completion_) | 6306 explicit AdvanceTracingActions(ForceCompletionAction force_completion_) |
| 6240 : force_completion(force_completion_) {} | 6307 : force_completion(force_completion_) {} |
| 6241 | 6308 |
| 6242 ForceCompletionAction force_completion; | 6309 ForceCompletionAction force_completion; |
| 6243 }; | 6310 }; |
| 6244 | 6311 |
| 6245 /** | 6312 /** |
| 6246 * Called by v8 to register internal fields of found wrappers. | 6313 * Called by v8 to register embedder fields of found wrappers. |
| 6247 * | 6314 * |
| 6248 * The embedder is expected to store them somewhere and trace reachable | 6315 * The embedder is expected to store them somewhere and trace reachable |
| 6249 * wrappers from them when called through |AdvanceTracing|. | 6316 * wrappers from them when called through |AdvanceTracing|. |
| 6250 */ | 6317 */ |
| 6251 virtual void RegisterV8References( | 6318 virtual void RegisterV8References( |
| 6252 const std::vector<std::pair<void*, void*> >& internal_fields) = 0; | 6319 const std::vector<std::pair<void*, void*> >& embedder_fields) = 0; |
| 6253 | 6320 |
| 6254 /** | 6321 /** |
| 6255 * Called at the beginning of a GC cycle. | 6322 * Called at the beginning of a GC cycle. |
| 6256 */ | 6323 */ |
| 6257 virtual void TracePrologue() = 0; | 6324 virtual void TracePrologue() = 0; |
| 6258 | 6325 |
| 6259 /** | 6326 /** |
| 6260 * Called to to make a tracing step in the embedder. | 6327 * Called to to make a tracing step in the embedder. |
| 6261 * | 6328 * |
| 6262 * The embedder is expected to trace its heap starting from wrappers reported | 6329 * The embedder is expected to trace its heap starting from wrappers reported |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6294 * Returns the number of wrappers that are still to be traced by the embedder. | 6361 * Returns the number of wrappers that are still to be traced by the embedder. |
| 6295 */ | 6362 */ |
| 6296 virtual size_t NumberOfWrappersToTrace() { return 0; } | 6363 virtual size_t NumberOfWrappersToTrace() { return 0; } |
| 6297 | 6364 |
| 6298 protected: | 6365 protected: |
| 6299 virtual ~EmbedderHeapTracer() = default; | 6366 virtual ~EmbedderHeapTracer() = default; |
| 6300 }; | 6367 }; |
| 6301 | 6368 |
| 6302 /** | 6369 /** |
| 6303 * Callback and supporting data used in SnapshotCreator to implement embedder | 6370 * Callback and supporting data used in SnapshotCreator to implement embedder |
| 6304 * logic to serialize internal fields. | 6371 * logic to serialize embedder fields. |
| 6305 */ | 6372 */ |
| 6306 struct SerializeInternalFieldsCallback { | 6373 class SerializeEmbedderFieldsCallback { |
| 6374 public: |
| 6307 typedef StartupData (*CallbackFunction)(Local<Object> holder, int index, | 6375 typedef StartupData (*CallbackFunction)(Local<Object> holder, int index, |
| 6308 void* data); | 6376 void* data); |
| 6309 SerializeInternalFieldsCallback(CallbackFunction function = nullptr, | 6377 SerializeEmbedderFieldsCallback(CallbackFunction function = nullptr, |
| 6310 void* data_arg = nullptr) | 6378 void* data_arg = nullptr) |
| 6311 : callback(function), data(data_arg) {} | 6379 : callback(function), data(data_arg) {} |
| 6312 CallbackFunction callback; | 6380 CallbackFunction callback; |
| 6313 void* data; | 6381 void* data; |
| 6314 }; | 6382 }; |
| 6383 class SerializeInternalFieldsCallback : public SerializeEmbedderFieldsCallback { |
| 6384 public: |
| 6385 SerializeInternalFieldsCallback(CallbackFunction function = nullptr, |
| 6386 void* data_arg = nullptr) |
| 6387 : SerializeEmbedderFieldsCallback(function, data_arg) {} |
| 6388 }; |
| 6315 | 6389 |
| 6316 /** | 6390 /** |
| 6317 * Callback and supporting data used to implement embedder logic to deserialize | 6391 * Callback and supporting data used to implement embedder logic to deserialize |
| 6318 * internal fields. | 6392 * embedder fields. |
| 6319 */ | 6393 */ |
| 6320 struct DeserializeInternalFieldsCallback { | 6394 class DeserializeEmbedderFieldsCallback { |
| 6395 public: |
| 6321 typedef void (*CallbackFunction)(Local<Object> holder, int index, | 6396 typedef void (*CallbackFunction)(Local<Object> holder, int index, |
| 6322 StartupData payload, void* data); | 6397 StartupData payload, void* data); |
| 6323 DeserializeInternalFieldsCallback(CallbackFunction function = nullptr, | 6398 DeserializeEmbedderFieldsCallback(CallbackFunction function = nullptr, |
| 6324 void* data_arg = nullptr) | 6399 void* data_arg = nullptr) |
| 6325 : callback(function), data(data_arg) {} | 6400 : callback(function), data(data_arg) {} |
| 6326 void (*callback)(Local<Object> holder, int index, StartupData payload, | 6401 void (*callback)(Local<Object> holder, int index, StartupData payload, |
| 6327 void* data); | 6402 void* data); |
| 6328 void* data; | 6403 void* data; |
| 6329 }; | 6404 }; |
| 6405 class DeserializeInternalFieldsCallback |
| 6406 : public DeserializeEmbedderFieldsCallback { |
| 6407 public: |
| 6408 DeserializeInternalFieldsCallback(CallbackFunction function = nullptr, |
| 6409 void* data_arg = nullptr) |
| 6410 : DeserializeEmbedderFieldsCallback(function, data_arg) {} |
| 6411 }; |
| 6330 | 6412 |
| 6331 /** | 6413 /** |
| 6332 * Isolate represents an isolated instance of the V8 engine. V8 isolates have | 6414 * Isolate represents an isolated instance of the V8 engine. V8 isolates have |
| 6333 * completely separate states. Objects from one isolate must not be used in | 6415 * completely separate states. Objects from one isolate must not be used in |
| 6334 * other isolates. The embedder can create multiple isolates and use them in | 6416 * other isolates. The embedder can create multiple isolates and use them in |
| 6335 * parallel in multiple threads. An isolate can be entered by at most one | 6417 * parallel in multiple threads. An isolate can be entered by at most one |
| 6336 * thread at any given time. The Locker/Unlocker API must be used to | 6418 * thread at any given time. The Locker/Unlocker API must be used to |
| 6337 * synchronize. | 6419 * synchronize. |
| 6338 */ | 6420 */ |
| 6339 class V8_EXPORT Isolate { | 6421 class V8_EXPORT Isolate { |
| (...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7638 | 7720 |
| 7639 static internal::Object** GlobalizeReference(internal::Isolate* isolate, | 7721 static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
| 7640 internal::Object** handle); | 7722 internal::Object** handle); |
| 7641 static internal::Object** CopyPersistent(internal::Object** handle); | 7723 static internal::Object** CopyPersistent(internal::Object** handle); |
| 7642 static void DisposeGlobal(internal::Object** global_handle); | 7724 static void DisposeGlobal(internal::Object** global_handle); |
| 7643 static void MakeWeak(internal::Object** location, void* data, | 7725 static void MakeWeak(internal::Object** location, void* data, |
| 7644 WeakCallbackInfo<void>::Callback weak_callback, | 7726 WeakCallbackInfo<void>::Callback weak_callback, |
| 7645 WeakCallbackType type); | 7727 WeakCallbackType type); |
| 7646 static void MakeWeak(internal::Object** location, void* data, | 7728 static void MakeWeak(internal::Object** location, void* data, |
| 7647 // Must be 0 or -1. | 7729 // Must be 0 or -1. |
| 7648 int internal_field_index1, | 7730 int embedder_field_index1, |
| 7649 // Must be 1 or -1. | 7731 // Must be 1 or -1. |
| 7650 int internal_field_index2, | 7732 int embedder_field_index2, |
| 7651 WeakCallbackInfo<void>::Callback weak_callback); | 7733 WeakCallbackInfo<void>::Callback weak_callback); |
| 7652 static void MakeWeak(internal::Object*** location_addr); | 7734 static void MakeWeak(internal::Object*** location_addr); |
| 7653 static void* ClearWeak(internal::Object** location); | 7735 static void* ClearWeak(internal::Object** location); |
| 7654 static void Eternalize(Isolate* isolate, | 7736 static void Eternalize(Isolate* isolate, |
| 7655 Value* handle, | 7737 Value* handle, |
| 7656 int* index); | 7738 int* index); |
| 7657 static Local<Value> GetEternal(Isolate* isolate, int index); | 7739 static Local<Value> GetEternal(Isolate* isolate, int index); |
| 7658 | 7740 |
| 7659 static void RegisterExternallyReferencedObject(internal::Object** object, | 7741 static void RegisterExternallyReferencedObject(internal::Object** object, |
| 7660 internal::Isolate* isolate); | 7742 internal::Isolate* isolate); |
| 7661 | 7743 |
| 7662 template <class K, class V, class T> | 7744 template <class K, class V, class T> |
| 7663 friend class PersistentValueMapBase; | 7745 friend class PersistentValueMapBase; |
| 7664 | 7746 |
| 7665 static void FromJustIsNothing(); | 7747 static void FromJustIsNothing(); |
| 7666 static void ToLocalEmpty(); | 7748 static void ToLocalEmpty(); |
| 7667 static void InternalFieldOutOfBounds(int index); | 7749 static void EmbedderFieldOutOfBounds(int index); |
| 7668 template <class T> friend class Local; | 7750 template <class T> friend class Local; |
| 7669 template <class T> | 7751 template <class T> |
| 7670 friend class MaybeLocal; | 7752 friend class MaybeLocal; |
| 7671 template <class T> | 7753 template <class T> |
| 7672 friend class Maybe; | 7754 friend class Maybe; |
| 7673 template <class T> | 7755 template <class T> |
| 7674 friend class WeakCallbackInfo; | 7756 friend class WeakCallbackInfo; |
| 7675 template <class T> friend class Eternal; | 7757 template <class T> friend class Eternal; |
| 7676 template <class T> friend class PersistentBase; | 7758 template <class T> friend class PersistentBase; |
| 7677 template <class T, class M> friend class Persistent; | 7759 template <class T, class M> friend class Persistent; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 7707 * Set the default context to be included in the snapshot blob. | 7789 * Set the default context to be included in the snapshot blob. |
| 7708 * The snapshot will not contain the global proxy, and we expect one or a | 7790 * The snapshot will not contain the global proxy, and we expect one or a |
| 7709 * global object template to create one, to be provided upon deserialization. | 7791 * global object template to create one, to be provided upon deserialization. |
| 7710 */ | 7792 */ |
| 7711 void SetDefaultContext(Local<Context> context); | 7793 void SetDefaultContext(Local<Context> context); |
| 7712 | 7794 |
| 7713 /** | 7795 /** |
| 7714 * Add additional context to be included in the snapshot blob. | 7796 * Add additional context to be included in the snapshot blob. |
| 7715 * The snapshot will include the global proxy. | 7797 * The snapshot will include the global proxy. |
| 7716 * | 7798 * |
| 7717 * \param callback optional callback to serialize internal fields. | 7799 * \param callback optional callback to serialize embedder fields. |
| 7718 * | 7800 * |
| 7719 * \returns the index of the context in the snapshot blob. | 7801 * \returns the index of the context in the snapshot blob. |
| 7720 */ | 7802 */ |
| 7721 size_t AddContext(Local<Context> context, | 7803 size_t AddContext(Local<Context> context, |
| 7722 SerializeInternalFieldsCallback callback = | 7804 SerializeEmbedderFieldsCallback callback = |
| 7723 SerializeInternalFieldsCallback()); | 7805 SerializeEmbedderFieldsCallback()); |
| 7724 | 7806 |
| 7725 /** | 7807 /** |
| 7726 * Add a template to be included in the snapshot blob. | 7808 * Add a template to be included in the snapshot blob. |
| 7727 * \returns the index of the template in the snapshot blob. | 7809 * \returns the index of the template in the snapshot blob. |
| 7728 */ | 7810 */ |
| 7729 size_t AddTemplate(Local<Template> template_obj); | 7811 size_t AddTemplate(Local<Template> template_obj); |
| 7730 | 7812 |
| 7731 /** | 7813 /** |
| 7732 * Created a snapshot data blob. | 7814 * Created a snapshot data blob. |
| 7733 * This must not be called from within a handle scope. | 7815 * This must not be called from within a handle scope. |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8042 /** | 8124 /** |
| 8043 * Create a new context from a (non-default) context snapshot. There | 8125 * Create a new context from a (non-default) context snapshot. There |
| 8044 * is no way to provide a global object template since we do not create | 8126 * is no way to provide a global object template since we do not create |
| 8045 * a new global object from template, but we can reuse a global object. | 8127 * a new global object from template, but we can reuse a global object. |
| 8046 * | 8128 * |
| 8047 * \param isolate See v8::Context::New. | 8129 * \param isolate See v8::Context::New. |
| 8048 * | 8130 * |
| 8049 * \param context_snapshot_index The index of the context snapshot to | 8131 * \param context_snapshot_index The index of the context snapshot to |
| 8050 * deserialize from. Use v8::Context::New for the default snapshot. | 8132 * deserialize from. Use v8::Context::New for the default snapshot. |
| 8051 * | 8133 * |
| 8052 * \param internal_fields_deserializer Optional callback to deserialize | 8134 * \param embedder_fields_deserializer Optional callback to deserialize |
| 8053 * internal fields. It should match the SerializeInternalFieldCallback used | 8135 * embedder fields. It should match the SerializeInternalFieldCallback used |
| 8054 * to serialize. | 8136 * to serialize. |
| 8055 * | 8137 * |
| 8056 * \param extensions See v8::Context::New. | 8138 * \param extensions See v8::Context::New. |
| 8057 * | 8139 * |
| 8058 * \param global_object See v8::Context::New. | 8140 * \param global_object See v8::Context::New. |
| 8059 */ | 8141 */ |
| 8060 | 8142 |
| 8061 static MaybeLocal<Context> FromSnapshot( | 8143 static MaybeLocal<Context> FromSnapshot( |
| 8062 Isolate* isolate, size_t context_snapshot_index, | 8144 Isolate* isolate, size_t context_snapshot_index, |
| 8063 DeserializeInternalFieldsCallback internal_fields_deserializer = | 8145 DeserializeEmbedderFieldsCallback embedder_fields_deserializer = |
| 8064 DeserializeInternalFieldsCallback(), | 8146 DeserializeEmbedderFieldsCallback(), |
| 8065 ExtensionConfiguration* extensions = nullptr, | 8147 ExtensionConfiguration* extensions = nullptr, |
| 8066 MaybeLocal<Value> global_object = MaybeLocal<Value>()); | 8148 MaybeLocal<Value> global_object = MaybeLocal<Value>()); |
| 8067 | 8149 |
| 8068 /** | 8150 /** |
| 8069 * Returns an global object that isn't backed by an actual context. | 8151 * Returns an global object that isn't backed by an actual context. |
| 8070 * | 8152 * |
| 8071 * The global template needs to have access checks with handlers installed. | 8153 * The global template needs to have access checks with handlers installed. |
| 8072 * If an existing global object is passed in, the global object is detached | 8154 * If an existing global object is passed in, the global object is detached |
| 8073 * from its context. | 8155 * from its context. |
| 8074 * | 8156 * |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8628 return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_))); | 8710 return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_))); |
| 8629 } | 8711 } |
| 8630 | 8712 |
| 8631 | 8713 |
| 8632 template <class T> | 8714 template <class T> |
| 8633 Local<T> MaybeLocal<T>::ToLocalChecked() { | 8715 Local<T> MaybeLocal<T>::ToLocalChecked() { |
| 8634 if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty(); | 8716 if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty(); |
| 8635 return Local<T>(val_); | 8717 return Local<T>(val_); |
| 8636 } | 8718 } |
| 8637 | 8719 |
| 8638 | 8720 template <class T> |
| 8721 void* WeakCallbackInfo<T>::GetEmbedderField(int index) const { |
| 8722 #ifdef V8_ENABLE_CHECKS |
| 8723 if (index < 0 || index >= kEmbedderFieldsInWeakCallback) { |
| 8724 V8::EmbedderFieldOutOfBounds(index); |
| 8725 } |
| 8726 #endif |
| 8727 return embedder_fields_[index]; |
| 8728 } |
| 8639 template <class T> | 8729 template <class T> |
| 8640 void* WeakCallbackInfo<T>::GetInternalField(int index) const { | 8730 void* WeakCallbackInfo<T>::GetInternalField(int index) const { |
| 8641 #ifdef V8_ENABLE_CHECKS | 8731 return WeakCallbackInfo<T>::GetEmbedderField(index); |
| 8642 if (index < 0 || index >= kInternalFieldsInWeakCallback) { | |
| 8643 V8::InternalFieldOutOfBounds(index); | |
| 8644 } | |
| 8645 #endif | |
| 8646 return internal_fields_[index]; | |
| 8647 } | 8732 } |
| 8648 | 8733 |
| 8649 | 8734 |
| 8650 template <class T> | 8735 template <class T> |
| 8651 T* PersistentBase<T>::New(Isolate* isolate, T* that) { | 8736 T* PersistentBase<T>::New(Isolate* isolate, T* that) { |
| 8652 if (that == NULL) return NULL; | 8737 if (that == NULL) return NULL; |
| 8653 internal::Object** p = reinterpret_cast<internal::Object**>(that); | 8738 internal::Object** p = reinterpret_cast<internal::Object**>(that); |
| 8654 return reinterpret_cast<T*>( | 8739 return reinterpret_cast<T*>( |
| 8655 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), | 8740 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), |
| 8656 p)); | 8741 p)); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9059 Local<Boolean> Boolean::New(Isolate* isolate, bool value) { | 9144 Local<Boolean> Boolean::New(Isolate* isolate, bool value) { |
| 9060 return value ? True(isolate) : False(isolate); | 9145 return value ? True(isolate) : False(isolate); |
| 9061 } | 9146 } |
| 9062 | 9147 |
| 9063 void Template::Set(Isolate* isolate, const char* name, Local<Data> value) { | 9148 void Template::Set(Isolate* isolate, const char* name, Local<Data> value) { |
| 9064 Set(String::NewFromUtf8(isolate, name, NewStringType::kInternalized) | 9149 Set(String::NewFromUtf8(isolate, name, NewStringType::kInternalized) |
| 9065 .ToLocalChecked(), | 9150 .ToLocalChecked(), |
| 9066 value); | 9151 value); |
| 9067 } | 9152 } |
| 9068 | 9153 |
| 9069 | 9154 Local<Value> Object::GetEmbedderField(int index) { |
| 9070 Local<Value> Object::GetInternalField(int index) { | |
| 9071 #ifndef V8_ENABLE_CHECKS | 9155 #ifndef V8_ENABLE_CHECKS |
| 9072 typedef internal::Object O; | 9156 typedef internal::Object O; |
| 9073 typedef internal::HeapObject HO; | 9157 typedef internal::HeapObject HO; |
| 9074 typedef internal::Internals I; | 9158 typedef internal::Internals I; |
| 9075 O* obj = *reinterpret_cast<O**>(this); | 9159 O* obj = *reinterpret_cast<O**>(this); |
| 9076 // Fast path: If the object is a plain JSObject, which is the common case, we | 9160 // Fast path: If the object is a plain JSObject, which is the common case, we |
| 9077 // know where to find the internal fields and can return the value directly. | 9161 // know where to find the embedder fields and can return the value directly. |
| 9078 auto instance_type = I::GetInstanceType(obj); | 9162 auto instance_type = I::GetInstanceType(obj); |
| 9079 if (instance_type == I::kJSObjectType || | 9163 if (instance_type == I::kJSObjectType || |
| 9080 instance_type == I::kJSApiObjectType) { | 9164 instance_type == I::kJSApiObjectType) { |
| 9081 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); | 9165 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
| 9082 O* value = I::ReadField<O*>(obj, offset); | 9166 O* value = I::ReadField<O*>(obj, offset); |
| 9083 O** result = HandleScope::CreateHandle(reinterpret_cast<HO*>(obj), value); | 9167 O** result = HandleScope::CreateHandle(reinterpret_cast<HO*>(obj), value); |
| 9084 return Local<Value>(reinterpret_cast<Value*>(result)); | 9168 return Local<Value>(reinterpret_cast<Value*>(result)); |
| 9085 } | 9169 } |
| 9086 #endif | 9170 #endif |
| 9087 return SlowGetInternalField(index); | 9171 return SlowGetEmbedderField(index); |
| 9088 } | 9172 } |
| 9089 | 9173 |
| 9174 Local<Value> Object::GetInternalField(int index) { |
| 9175 return GetEmbedderField(index); // non-deprecated method. |
| 9176 } |
| 9090 | 9177 |
| 9091 void* Object::GetAlignedPointerFromInternalField(int index) { | 9178 void* Object::GetAlignedPointerFromEmbedderField(int index) { |
| 9092 #ifndef V8_ENABLE_CHECKS | 9179 #ifndef V8_ENABLE_CHECKS |
| 9093 typedef internal::Object O; | 9180 typedef internal::Object O; |
| 9094 typedef internal::Internals I; | 9181 typedef internal::Internals I; |
| 9095 O* obj = *reinterpret_cast<O**>(this); | 9182 O* obj = *reinterpret_cast<O**>(this); |
| 9096 // Fast path: If the object is a plain JSObject, which is the common case, we | 9183 // Fast path: If the object is a plain JSObject, which is the common case, we |
| 9097 // know where to find the internal fields and can return the value directly. | 9184 // know where to find the embedder fields and can return the value directly. |
| 9098 auto instance_type = I::GetInstanceType(obj); | 9185 auto instance_type = I::GetInstanceType(obj); |
| 9099 if (V8_LIKELY(instance_type == I::kJSObjectType || | 9186 if (V8_LIKELY(instance_type == I::kJSObjectType || |
| 9100 instance_type == I::kJSApiObjectType)) { | 9187 instance_type == I::kJSApiObjectType)) { |
| 9101 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); | 9188 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
| 9102 return I::ReadField<void*>(obj, offset); | 9189 return I::ReadField<void*>(obj, offset); |
| 9103 } | 9190 } |
| 9104 #endif | 9191 #endif |
| 9105 return SlowGetAlignedPointerFromInternalField(index); | 9192 return SlowGetAlignedPointerFromEmbedderField(index); |
| 9193 } |
| 9194 |
| 9195 void* Object::GetAlignedPointerFromInternalField(int index) { |
| 9196 return GetAlignedPointerFromEmbedderField(index); // non-deprecated method. |
| 9106 } | 9197 } |
| 9107 | 9198 |
| 9108 String* String::Cast(v8::Value* value) { | 9199 String* String::Cast(v8::Value* value) { |
| 9109 #ifdef V8_ENABLE_CHECKS | 9200 #ifdef V8_ENABLE_CHECKS |
| 9110 CheckCast(value); | 9201 CheckCast(value); |
| 9111 #endif | 9202 #endif |
| 9112 return static_cast<String*>(value); | 9203 return static_cast<String*>(value); |
| 9113 } | 9204 } |
| 9114 | 9205 |
| 9115 | 9206 |
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9816 */ | 9907 */ |
| 9817 | 9908 |
| 9818 | 9909 |
| 9819 } // namespace v8 | 9910 } // namespace v8 |
| 9820 | 9911 |
| 9821 | 9912 |
| 9822 #undef TYPE_CHECK | 9913 #undef TYPE_CHECK |
| 9823 | 9914 |
| 9824 | 9915 |
| 9825 #endif // INCLUDE_V8_H_ | 9916 #endif // INCLUDE_V8_H_ |
| OLD | NEW |