Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: include/v8.h

Issue 753553002: Phantom references support internal fields (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Don't forget to visit pointers to live objects so they can be updated to new location Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/global-handles.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 21911b460db34b23e5f89a0b1beaa4e221a0f37c..fae62fbeb14e3142debc8d4753848a8cbb198400 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -418,22 +418,57 @@ template <class T> class Eternal {
};
+template<class T>
+class CallbackData {
+ public:
+ V8_INLINE Isolate* GetIsolate() const { return isolate_; }
+ V8_INLINE T* GetParameter() const { return parameter_; }
+
+ protected:
+ CallbackData(Isolate* isolate, T* parameter)
+ : isolate_(isolate), parameter_(parameter) { }
+
+ private:
+ Isolate* isolate_;
+ T* parameter_;
+};
+
template<class T, class P>
-class WeakCallbackData {
+class WeakCallbackData : public CallbackData<P> {
public:
typedef void (*Callback)(const WeakCallbackData<T, P>& data);
- V8_INLINE Isolate* GetIsolate() const { return isolate_; }
V8_INLINE Local<T> GetValue() const { return handle_; }
- V8_INLINE P* GetParameter() const { return parameter_; }
private:
friend class internal::GlobalHandles;
WeakCallbackData(Isolate* isolate, Local<T> handle, P* parameter)
- : isolate_(isolate), handle_(handle), parameter_(parameter) { }
- Isolate* isolate_;
+ : CallbackData<P>(isolate, parameter), handle_(handle) { }
Local<T> handle_;
- P* parameter_;
+};
+
+
+template<typename T>
+class PhantomCallbackData : public CallbackData<T> {
+ public:
+ typedef void (*Callback)(const PhantomCallbackData<T>& data);
+
+ V8_INLINE void* GetInternalField1() const { return internal_field1_; }
+ V8_INLINE void* GetInternalField2() const { return internal_field2_; }
+
+ private:
+ friend class internal::GlobalHandles;
+ PhantomCallbackData(Isolate* isolate, void* internalField1,
+ void* internalField2)
+ : CallbackData<T>(isolate, NULL),
+ internal_field1_(internalField1),
+ internal_field2_(internalField2) { }
+ PhantomCallbackData(Isolate* isolate, T* parameter)
+ : CallbackData<T>(isolate, parameter),
+ internal_field1_(NULL),
+ internal_field2_(NULL) { }
+ void* internal_field1_;
+ void* internal_field2_;
};
@@ -471,7 +506,8 @@ template <class T> class PersistentBase {
template <class S>
V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
- V8_INLINE bool IsEmpty() const { return val_ == 0; }
+ V8_INLINE bool IsEmpty() const { return val_ == NULL; }
+ V8_INLINE void Empty() { val_ = NULL; }
template <class S>
V8_INLINE bool operator==(const PersistentBase<S>& that) const {
@@ -521,12 +557,12 @@ template <class T> class PersistentBase {
// This enables the garbage collector to collect the object and any objects
// it references transitively in one GC cycle.
template <typename P>
- V8_INLINE void SetPhantom(P* parameter,
- typename WeakCallbackData<T, P>::Callback callback);
+ V8_INLINE void SetPhantom(
+ P* parameter, typename PhantomCallbackData<P>::Callback callback);
- template <typename S, typename P>
- V8_INLINE void SetPhantom(P* parameter,
- typename WeakCallbackData<S, P>::Callback callback);
+ V8_INLINE void SetPhantom(
+ typename PhantomCallbackData<void>::Callback callback,
+ int internalFieldOffset1, int internalFieldOffset2);
template<typename P>
V8_INLINE P* ClearWeak();
@@ -2483,6 +2519,8 @@ class V8_EXPORT Object : public Value {
/** Gets the number of internal fields for this Object. */
int InternalFieldCount();
+ static const int kNoInternalFieldIndex = -1;
+
/** Same as above, but works for Persistents */
V8_INLINE static int InternalFieldCount(
const PersistentBase<Object>& object) {
@@ -5487,8 +5525,14 @@ class V8_EXPORT V8 {
static internal::Object** CopyPersistent(internal::Object** handle);
static void DisposeGlobal(internal::Object** global_handle);
typedef WeakCallbackData<Value, void>::Callback WeakCallback;
+ typedef PhantomCallbackData<void>::Callback PhantomCallback;
static void MakeWeak(internal::Object** global_handle, void* data,
- WeakCallback weak_callback, WeakHandleType phantom);
+ WeakCallback weak_callback);
+ static void MakePhantom(
+ internal::Object** global_handle, void* data,
+ PhantomCallback weak_callback,
+ int internal_field_index1 = Object::kNoInternalFieldIndex,
+ int internal_field_index2 = Object::kNoInternalFieldIndex);
static void* ClearWeak(internal::Object** global_handle);
static void Eternalize(Isolate* isolate,
Value* handle,
@@ -6097,12 +6141,12 @@ class Internals {
static const int kNodeClassIdOffset = 1 * kApiPointerSize;
static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
- static const int kNodeStateMask = 0xf;
+ static const int kNodeStateMask = 0x7;
picksi1 2014/11/28 12:15:11 Can you generate this 0x7 mask? e.g. kNodeStateM
Erik Corry 2014/11/28 14:21:25 Could be, but I'm going to stay consistent with th
static const int kNodeStateIsWeakValue = 2;
static const int kNodeStateIsPendingValue = 3;
static const int kNodeStateIsNearDeathValue = 4;
- static const int kNodeIsIndependentShift = 4;
- static const int kNodeIsPartiallyDependentShift = 5;
+ static const int kNodeIsIndependentShift = 3;
+ static const int kNodeIsPartiallyDependentShift = 4;
static const int kJSObjectType = 0xbd;
static const int kFirstNonstringType = 0x80;
@@ -6360,7 +6404,7 @@ void PersistentBase<T>::SetWeak(
TYPE_CHECK(S, T);
typedef typename WeakCallbackData<Value, void>::Callback Callback;
V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
- reinterpret_cast<Callback>(callback), V8::NonphantomHandle);
+ reinterpret_cast<Callback>(callback));
}
@@ -6374,21 +6418,24 @@ void PersistentBase<T>::SetWeak(
template <class T>
-template <typename S, typename P>
+template <typename P>
void PersistentBase<T>::SetPhantom(
- P* parameter, typename WeakCallbackData<S, P>::Callback callback) {
- TYPE_CHECK(S, T);
- typedef typename WeakCallbackData<Value, void>::Callback Callback;
- V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
- reinterpret_cast<Callback>(callback), V8::PhantomHandle);
+ P* parameter, typename PhantomCallbackData<P>::Callback callback) {
+ typedef typename PhantomCallbackData<void>::Callback Callback;
+ V8::MakePhantom(reinterpret_cast<internal::Object**>(this->val_), parameter,
+ reinterpret_cast<Callback>(callback),
+ Object::kNoInternalFieldIndex, Object::kNoInternalFieldIndex);
}
template <class T>
-template <typename P>
void PersistentBase<T>::SetPhantom(
- P* parameter, typename WeakCallbackData<T, P>::Callback callback) {
- SetPhantom<T, P>(parameter, callback);
+ typename PhantomCallbackData<void>::Callback callback,
+ int internal_field_index1, int internal_field_index2) {
+ typedef typename PhantomCallbackData<void>::Callback Callback;
+ V8::MakePhantom(reinterpret_cast<internal::Object**>(this->val_), 0,
+ reinterpret_cast<Callback>(callback), internal_field_index1,
+ internal_field_index2);
}
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/global-handles.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698