Merge V8 5.2.361.47  DO NOT MERGE

https://chromium.googlesource.com/v8/v8/+/5.2.361.47

FPIIM-449

Change-Id: Ibec421b85a9b88cb3a432ada642e469fe7e78346
(cherry picked from commit bcf72ee8e3b26f1d0726869c7ddb3921c68b09a8)
diff --git a/src/global-handles.h b/src/global-handles.h
index ac8487b..24a2273 100644
--- a/src/global-handles.h
+++ b/src/global-handles.h
@@ -96,19 +96,21 @@
   RetainedObjectInfo* info;
 };
 
-
 enum WeaknessType {
-  NORMAL_WEAK,  // Embedder gets a handle to the dying object.
+  // Embedder gets a handle to the dying object.
+  FINALIZER_WEAK,
   // In the following cases, the embedder gets the parameter they passed in
   // earlier, and 0 or 2 first internal fields. Note that the internal
   // fields must contain aligned non-V8 pointers.  Getting pointers to V8
   // objects through this interface would be GC unsafe so in that case the
   // embedder gets a null pointer instead.
   PHANTOM_WEAK,
-  PHANTOM_WEAK_2_INTERNAL_FIELDS
+  PHANTOM_WEAK_2_INTERNAL_FIELDS,
+  // The handle is automatically reset by the garbage collector when
+  // the object is no longer reachable.
+  PHANTOM_WEAK_RESET_HANDLE
 };
 
-
 class GlobalHandles {
  public:
   ~GlobalHandles();
@@ -122,14 +124,6 @@
   // Destroy a global handle.
   static void Destroy(Object** location);
 
-  typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback;
-
-  // For a phantom weak reference, the callback does not have access to the
-  // dying object.  Phantom weak references are preferred because they allow
-  // memory to be reclaimed in one GC cycle rather than two.  However, for
-  // historical reasons the default is non-phantom.
-  enum PhantomState { Nonphantom, Phantom };
-
   // Make the global handle weak and set the callback parameter for the
   // handle.  When the garbage collector recognizes that only weak global
   // handles point to an object the callback function is invoked (for each
@@ -140,14 +134,11 @@
   // before the callback is invoked, but the handle can still be identified
   // in the callback by using the location() of the handle.
   static void MakeWeak(Object** location, void* parameter,
-                       WeakCallback weak_callback);
-
-  // It would be nice to template this one, but it's really hard to get
-  // the template instantiator to work right if you do.
-  static void MakeWeak(Object** location, void* parameter,
                        WeakCallbackInfo<void>::Callback weak_callback,
                        v8::WeakCallbackType type);
 
+  static void MakeWeak(Object*** location_addr);
+
   void RecordStats(HeapStats* stats);
 
   // Returns the current number of weak handles.
@@ -162,6 +153,14 @@
     return number_of_global_handles_;
   }
 
+  size_t NumberOfPhantomHandleResets() {
+    return number_of_phantom_handle_resets_;
+  }
+
+  void ResetNumberOfPhantomHandleResets() {
+    number_of_phantom_handle_resets_ = 0;
+  }
+
   // Clear the weakness of a global handle.
   static void* ClearWeakness(Object** location);
 
@@ -344,6 +343,8 @@
 
   int post_gc_processing_count_;
 
+  size_t number_of_phantom_handle_resets_;
+
   // Object groups and implicit references, public and more efficient
   // representation.
   List<ObjectGroup*> object_groups_;