Index: include/v8.h |
diff --git a/include/v8.h b/include/v8.h |
index f012b3bdd1a6137ea8db88d783781590296060f1..6e04f54ca590142ea998489bce8dad3e1a488c21 100644 |
--- a/include/v8.h |
+++ b/include/v8.h |
@@ -379,9 +379,9 @@ template <class T> class Eternal { |
int index_; |
}; |
- |
+// TODO(internal): deprecate this constant soon. |
static const int kInternalFieldsInWeakCallback = 2; |
- |
+static const int kEmbedderFieldsInWeakCallback = 2; |
template <typename T> |
class WeakCallbackInfo { |
@@ -389,25 +389,27 @@ class WeakCallbackInfo { |
typedef void (*Callback)(const WeakCallbackInfo<T>& data); |
WeakCallbackInfo(Isolate* isolate, T* parameter, |
- void* internal_fields[kInternalFieldsInWeakCallback], |
+ void* embedder_fields[kEmbedderFieldsInWeakCallback], |
Callback* callback) |
: isolate_(isolate), parameter_(parameter), callback_(callback) { |
- for (int i = 0; i < kInternalFieldsInWeakCallback; ++i) { |
- internal_fields_[i] = internal_fields[i]; |
+ for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) { |
+ embedder_fields_[i] = embedder_fields[i]; |
} |
} |
V8_INLINE Isolate* GetIsolate() const { return isolate_; } |
V8_INLINE T* GetParameter() const { return parameter_; } |
- V8_INLINE void* GetInternalField(int index) const; |
+ V8_INLINE V8_DEPRECATE_SOON("use GetEmbedderField(int index)", |
+ void* GetInternalField(int index) const); |
+ V8_INLINE void* GetEmbedderField(int index) const; |
- V8_INLINE V8_DEPRECATED("use indexed version", |
+ V8_INLINE V8_DEPRECATED("use GetEmbedderField(int index)", |
void* GetInternalField1() const) { |
- return internal_fields_[0]; |
+ return embedder_fields_[0]; |
} |
- V8_INLINE V8_DEPRECATED("use indexed version", |
+ V8_INLINE V8_DEPRECATED("use GetEmbedderField(int index)", |
void* GetInternalField2() const) { |
- return internal_fields_[1]; |
+ return embedder_fields_[1]; |
} |
V8_DEPRECATED("Not realiable once SetSecondPassCallback() was used.", |
@@ -427,16 +429,20 @@ class WeakCallbackInfo { |
Isolate* isolate_; |
T* parameter_; |
Callback* callback_; |
- void* internal_fields_[kInternalFieldsInWeakCallback]; |
+ void* embedder_fields_[kEmbedderFieldsInWeakCallback]; |
}; |
- |
-// kParameter will pass a void* parameter back to the callback, kInternalFields |
-// will pass the first two internal fields back to the callback, kFinalizer |
+// kParameter will pass a void* parameter back to the callback, kEmbedderFields |
+// will pass the first two embedder fields back to the callback, kFinalizer |
// will pass a void* parameter back, but is invoked before the object is |
// actually collected, so it can be resurrected. In the last case, it is not |
// possible to request a second pass callback. |
-enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer }; |
+enum class WeakCallbackType { |
+ kParameter, |
+ kEmbedderFields, |
+ kInternalFields = kEmbedderFields, // TODO(v8): deprecate |
+ kFinalizer |
+}; |
/** |
* An object reference that is independent of any handle scope. Where |
@@ -866,7 +872,7 @@ class V8_EXPORT HandleScope { |
// Local::New uses CreateHandle with an Isolate* parameter. |
template<class F> friend class Local; |
- // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with |
+ // Object::GetExternalField and Context::GetEmbedderData use CreateHandle with |
// a HeapObject* in their shortcuts. |
friend class Object; |
friend class Context; |
@@ -3115,41 +3121,75 @@ class V8_EXPORT Object : public Value { |
*/ |
Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level); |
- /** Gets the number of internal fields for this Object. */ |
- int InternalFieldCount(); |
+ /** Gets the number of embedder fields for this Object. */ |
+ // TODO(internal): deprecate soon |
+ int V8_DEPRECATE_SOON("use EmbedderFieldCount()", InternalFieldCount()); |
+ int EmbedderFieldCount(); |
/** Same as above, but works for Persistents */ |
- V8_INLINE static int InternalFieldCount( |
- const PersistentBase<Object>& object) { |
+ // TODO(internal): deprecate soon |
+ V8_INLINE static int V8_DEPRECATE_SOON( |
+ "use EmbedderFieldCount()", |
+ InternalFieldCount(const PersistentBase<Object>& object)) { |
return object.val_->InternalFieldCount(); |
} |
- /** Gets the value from an internal field. */ |
- V8_INLINE Local<Value> GetInternalField(int index); |
+ /** Same as above, but works for Persistents */ |
+ V8_INLINE static int EmbedderFieldCount( |
+ const PersistentBase<Object>& object) { |
+ return object.val_->EmbedderFieldCount(); |
+ } |
+ |
+ /** Gets the value from an embedder field. */ |
+ V8_INLINE Local<Value> V8_DEPRECATE_SOON("use GetEmbedderField", |
+ GetInternalField(int index)); |
+ |
+ /** Gets the value from an embedder field. */ |
+ V8_INLINE Local<Value> GetEmbedderField(int index); |
+ |
+ /** Sets the value in an embedder field. */ |
+ void V8_DEPRECATE_SOON("use SetEmbedderField", |
+ SetInternalField(int index, Local<Value> value)); |
- /** Sets the value in an internal field. */ |
- void SetInternalField(int index, Local<Value> value); |
+ /** Sets the value in an embedder field. */ |
+ void SetEmbedderField(int index, Local<Value> value); |
/** |
- * Gets a 2-byte-aligned native pointer from an internal field. This field |
- * must have been set by SetAlignedPointerInInternalField, everything else |
+ * Gets a 2-byte-aligned native pointer from an embedder field. This field |
+ * must have been set by SetAlignedPointerInExternalField, everything else |
* leads to undefined behavior. |
*/ |
- V8_INLINE void* GetAlignedPointerFromInternalField(int index); |
+ V8_INLINE void* V8_DEPRECATE_SOON( |
+ "use GetAlignedPointerFromEmbedderField()", |
+ GetAlignedPointerFromInternalField(int index)); |
+ V8_INLINE void* GetAlignedPointerFromEmbedderField(int index); |
/** Same as above, but works for Persistents */ |
- V8_INLINE static void* GetAlignedPointerFromInternalField( |
+ V8_INLINE static void* GetAlignedPointerFromEmbedderField( |
const PersistentBase<Object>& object, int index) { |
- return object.val_->GetAlignedPointerFromInternalField(index); |
+ return object.val_->GetAlignedPointerFromEmbedderField(index); |
} |
+ V8_INLINE static void* V8_DEPRECATE_SOON( |
+ "use GetAlignedPointerFromEmbedderField", |
+ GetAlignedPointerFromInternalField(const PersistentBase<Object>& object, |
+ int index)) { |
+ return object.val_->GetAlignedPointerFromEmbedderField(index); |
+ } |
/** |
- * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such |
+ * Sets a 2-byte-aligned native pointer in an embedder field. To retrieve such |
* a field, GetAlignedPointerFromInternalField must be used, everything else |
* leads to undefined behavior. |
*/ |
- void SetAlignedPointerInInternalField(int index, void* value); |
- void SetAlignedPointerInInternalFields(int argc, int indices[], |
+ void V8_DEPRECATE_SOON("use SetAlignedPointerInEmbedderField", |
+ SetAlignedPointerInInternalField(int index, |
+ void* value)); |
+ void V8_DEPRECATE_SOON("use SetAlignedPointerInInternalFields", |
+ SetAlignedPointerInInternalFields(int argc, |
+ int indices[], |
+ void* values[])); |
+ void SetAlignedPointerInEmbedderField(int index, void* value); |
+ void SetAlignedPointerInEmbedderFields(int argc, int indices[], |
void* values[]); |
// Testers for local properties. |
@@ -3313,8 +3353,8 @@ class V8_EXPORT Object : public Value { |
private: |
Object(); |
static void CheckCast(Value* obj); |
- Local<Value> SlowGetInternalField(int index); |
- void* SlowGetAlignedPointerFromInternalField(int index); |
+ Local<Value> SlowGetEmbedderField(int index); |
+ void* SlowGetAlignedPointerFromEmbedderField(int index); |
}; |
@@ -3933,12 +3973,21 @@ class V8_EXPORT WasmCompiledModule : public Object { |
static void CheckCast(Value* obj); |
}; |
+#ifndef V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT |
+// The number of required embedder fields for array buffers. |
+#define V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT 2 |
+#endif |
+ |
+// TODO(v8): deprecate this constant in favor of {..._EMBEDDER_FIELD_COUNT} |
#ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT |
-// The number of required internal fields can be defined by embedder. |
+// The number of required embedder fields for array buffers. |
#define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 |
+#else |
+#undef V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT |
+#define V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT \ |
+ V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT |
#endif |
- |
enum class ArrayBufferCreationMode { kInternalized, kExternalized }; |
@@ -4082,7 +4131,9 @@ class V8_EXPORT ArrayBuffer : public Object { |
V8_INLINE static ArrayBuffer* Cast(Value* obj); |
- static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; |
+ // TODO(internal) |
+ static const int kInternalFieldCount = V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT; |
+ static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT; |
private: |
ArrayBuffer(); |
@@ -4091,10 +4142,20 @@ class V8_EXPORT ArrayBuffer : public Object { |
#ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT |
-// The number of required internal fields can be defined by embedder. |
+// The number of required embedder fields can be defined by embedder. |
#define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2 |
#endif |
+// TODO(internal): deprecate this constant in favor of |
+// {..._EMBEDDER_FIELD_COUNT} |
+#ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT |
+// The number of required embedder fields can be defined by embedder. |
+#define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2 |
+#else |
+#undef V8_ARRAY_BUFFER_VIEW_EMBEDDER_FIELD_COUNT |
+#define V8_ARRAY_BUFFER_VIEW_EMBEDDER_FIELD_COUNT \ |
+ V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT |
+#endif |
/** |
* A base class for an instance of one of "views" over ArrayBuffer, |
@@ -4135,7 +4196,9 @@ class V8_EXPORT ArrayBufferView : public Object { |
V8_INLINE static ArrayBufferView* Cast(Value* obj); |
static const int kInternalFieldCount = |
- V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT; |
+ V8_ARRAY_BUFFER_VIEW_EMBEDDER_FIELD_COUNT; |
+ static const int kEmbedderFieldCount = |
+ V8_ARRAY_BUFFER_VIEW_EMBEDDER_FIELD_COUNT; |
private: |
ArrayBufferView(); |
@@ -4424,7 +4487,9 @@ class V8_EXPORT SharedArrayBuffer : public Object { |
V8_INLINE static SharedArrayBuffer* Cast(Value* obj); |
- static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; |
+ // TODO(internal): deprecate |
+ static const int kInternalFieldCount = V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT; |
+ static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_EMBEDDER_FIELD_COUNT; |
private: |
SharedArrayBuffer(); |
@@ -5538,16 +5603,18 @@ class V8_EXPORT ObjectTemplate : public Template { |
Local<Value> data = Local<Value>()); |
/** |
- * Gets the number of internal fields for objects generated from |
+ * Gets the number of embedder fields for objects generated from |
* this template. |
*/ |
int InternalFieldCount(); |
+ int EmbedderFieldCount(); |
/** |
- * Sets the number of internal fields for objects generated from |
+ * Sets the number of embedder fields for objects generated from |
* this template. |
*/ |
void SetInternalFieldCount(int value); |
+ void SetEmbedderFieldCount(int value); |
/** |
* Returns true if the object will be an immutable prototype exotic object. |
@@ -6243,13 +6310,13 @@ class V8_EXPORT EmbedderHeapTracer { |
}; |
/** |
- * Called by v8 to register internal fields of found wrappers. |
+ * Called by v8 to register embedder fields of found wrappers. |
* |
* The embedder is expected to store them somewhere and trace reachable |
* wrappers from them when called through |AdvanceTracing|. |
*/ |
virtual void RegisterV8References( |
- const std::vector<std::pair<void*, void*> >& internal_fields) = 0; |
+ const std::vector<std::pair<void*, void*> >& embedder_fields) = 0; |
/** |
* Called at the beginning of a GC cycle. |
@@ -6301,32 +6368,47 @@ class V8_EXPORT EmbedderHeapTracer { |
/** |
* Callback and supporting data used in SnapshotCreator to implement embedder |
- * logic to serialize internal fields. |
+ * logic to serialize embedder fields. |
*/ |
-struct SerializeInternalFieldsCallback { |
+class SerializeEmbedderFieldsCallback { |
+ public: |
typedef StartupData (*CallbackFunction)(Local<Object> holder, int index, |
void* data); |
- SerializeInternalFieldsCallback(CallbackFunction function = nullptr, |
+ SerializeEmbedderFieldsCallback(CallbackFunction function = nullptr, |
void* data_arg = nullptr) |
: callback(function), data(data_arg) {} |
CallbackFunction callback; |
void* data; |
}; |
+class SerializeInternalFieldsCallback : public SerializeEmbedderFieldsCallback { |
+ public: |
+ SerializeInternalFieldsCallback(CallbackFunction function = nullptr, |
+ void* data_arg = nullptr) |
+ : SerializeEmbedderFieldsCallback(function, data_arg) {} |
+}; |
/** |
* Callback and supporting data used to implement embedder logic to deserialize |
- * internal fields. |
+ * embedder fields. |
*/ |
-struct DeserializeInternalFieldsCallback { |
+class DeserializeEmbedderFieldsCallback { |
+ public: |
typedef void (*CallbackFunction)(Local<Object> holder, int index, |
StartupData payload, void* data); |
- DeserializeInternalFieldsCallback(CallbackFunction function = nullptr, |
+ DeserializeEmbedderFieldsCallback(CallbackFunction function = nullptr, |
void* data_arg = nullptr) |
: callback(function), data(data_arg) {} |
void (*callback)(Local<Object> holder, int index, StartupData payload, |
void* data); |
void* data; |
}; |
+class DeserializeInternalFieldsCallback |
+ : public DeserializeEmbedderFieldsCallback { |
+ public: |
+ DeserializeInternalFieldsCallback(CallbackFunction function = nullptr, |
+ void* data_arg = nullptr) |
+ : DeserializeEmbedderFieldsCallback(function, data_arg) {} |
+}; |
/** |
* Isolate represents an isolated instance of the V8 engine. V8 isolates have |
@@ -7645,9 +7727,9 @@ class V8_EXPORT V8 { |
WeakCallbackType type); |
static void MakeWeak(internal::Object** location, void* data, |
// Must be 0 or -1. |
- int internal_field_index1, |
+ int embedder_field_index1, |
// Must be 1 or -1. |
- int internal_field_index2, |
+ int embedder_field_index2, |
WeakCallbackInfo<void>::Callback weak_callback); |
static void MakeWeak(internal::Object*** location_addr); |
static void* ClearWeak(internal::Object** location); |
@@ -7664,7 +7746,7 @@ class V8_EXPORT V8 { |
static void FromJustIsNothing(); |
static void ToLocalEmpty(); |
- static void InternalFieldOutOfBounds(int index); |
+ static void EmbedderFieldOutOfBounds(int index); |
template <class T> friend class Local; |
template <class T> |
friend class MaybeLocal; |
@@ -7714,13 +7796,13 @@ class V8_EXPORT SnapshotCreator { |
* Add additional context to be included in the snapshot blob. |
* The snapshot will include the global proxy. |
* |
- * \param callback optional callback to serialize internal fields. |
+ * \param callback optional callback to serialize embedder fields. |
* |
* \returns the index of the context in the snapshot blob. |
*/ |
size_t AddContext(Local<Context> context, |
- SerializeInternalFieldsCallback callback = |
- SerializeInternalFieldsCallback()); |
+ SerializeEmbedderFieldsCallback callback = |
+ SerializeEmbedderFieldsCallback()); |
/** |
* Add a template to be included in the snapshot blob. |
@@ -8049,8 +8131,8 @@ class V8_EXPORT Context { |
* \param context_snapshot_index The index of the context snapshot to |
* deserialize from. Use v8::Context::New for the default snapshot. |
* |
- * \param internal_fields_deserializer Optional callback to deserialize |
- * internal fields. It should match the SerializeInternalFieldCallback used |
+ * \param embedder_fields_deserializer Optional callback to deserialize |
+ * embedder fields. It should match the SerializeInternalFieldCallback used |
* to serialize. |
* |
* \param extensions See v8::Context::New. |
@@ -8060,8 +8142,8 @@ class V8_EXPORT Context { |
static MaybeLocal<Context> FromSnapshot( |
Isolate* isolate, size_t context_snapshot_index, |
- DeserializeInternalFieldsCallback internal_fields_deserializer = |
- DeserializeInternalFieldsCallback(), |
+ DeserializeEmbedderFieldsCallback embedder_fields_deserializer = |
+ DeserializeEmbedderFieldsCallback(), |
ExtensionConfiguration* extensions = nullptr, |
MaybeLocal<Value> global_object = MaybeLocal<Value>()); |
@@ -8635,15 +8717,18 @@ Local<T> MaybeLocal<T>::ToLocalChecked() { |
return Local<T>(val_); |
} |
- |
template <class T> |
-void* WeakCallbackInfo<T>::GetInternalField(int index) const { |
+void* WeakCallbackInfo<T>::GetEmbedderField(int index) const { |
#ifdef V8_ENABLE_CHECKS |
- if (index < 0 || index >= kInternalFieldsInWeakCallback) { |
- V8::InternalFieldOutOfBounds(index); |
+ if (index < 0 || index >= kEmbedderFieldsInWeakCallback) { |
+ V8::EmbedderFieldOutOfBounds(index); |
} |
#endif |
- return internal_fields_[index]; |
+ return embedder_fields_[index]; |
+} |
+template <class T> |
+void* WeakCallbackInfo<T>::GetInternalField(int index) const { |
+ return WeakCallbackInfo<T>::GetEmbedderField(index); |
} |
@@ -9066,15 +9151,14 @@ void Template::Set(Isolate* isolate, const char* name, Local<Data> value) { |
value); |
} |
- |
-Local<Value> Object::GetInternalField(int index) { |
+Local<Value> Object::GetEmbedderField(int index) { |
#ifndef V8_ENABLE_CHECKS |
typedef internal::Object O; |
typedef internal::HeapObject HO; |
typedef internal::Internals I; |
O* obj = *reinterpret_cast<O**>(this); |
// Fast path: If the object is a plain JSObject, which is the common case, we |
- // know where to find the internal fields and can return the value directly. |
+ // know where to find the embedder fields and can return the value directly. |
auto instance_type = I::GetInstanceType(obj); |
if (instance_type == I::kJSObjectType || |
instance_type == I::kJSApiObjectType) { |
@@ -9084,17 +9168,20 @@ Local<Value> Object::GetInternalField(int index) { |
return Local<Value>(reinterpret_cast<Value*>(result)); |
} |
#endif |
- return SlowGetInternalField(index); |
+ return SlowGetEmbedderField(index); |
} |
+Local<Value> Object::GetInternalField(int index) { |
+ return GetEmbedderField(index); // non-deprecated method. |
+} |
-void* Object::GetAlignedPointerFromInternalField(int index) { |
+void* Object::GetAlignedPointerFromEmbedderField(int index) { |
#ifndef V8_ENABLE_CHECKS |
typedef internal::Object O; |
typedef internal::Internals I; |
O* obj = *reinterpret_cast<O**>(this); |
// Fast path: If the object is a plain JSObject, which is the common case, we |
- // know where to find the internal fields and can return the value directly. |
+ // know where to find the embedder fields and can return the value directly. |
auto instance_type = I::GetInstanceType(obj); |
if (V8_LIKELY(instance_type == I::kJSObjectType || |
instance_type == I::kJSApiObjectType)) { |
@@ -9102,7 +9189,11 @@ void* Object::GetAlignedPointerFromInternalField(int index) { |
return I::ReadField<void*>(obj, offset); |
} |
#endif |
- return SlowGetAlignedPointerFromInternalField(index); |
+ return SlowGetAlignedPointerFromEmbedderField(index); |
+} |
+ |
+void* Object::GetAlignedPointerFromInternalField(int index) { |
+ return GetAlignedPointerFromEmbedderField(index); // non-deprecated method. |
} |
String* String::Cast(v8::Value* value) { |