Transforming PersistentHandleVisitor to not need to copy Persistent handles.
authordcarney@chromium.org <dcarney@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 29 May 2013 08:48:37 +0000 (08:48 +0000)
committerdcarney@chromium.org <dcarney@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 29 May 2013 08:48:37 +0000 (08:48 +0000)
This gets rid of more places where Persistent handles are copied
(see crbug.com/236290 ).

Transition plan: after this CL, Blink will be modified to work both with and
without the #define, then the #define will be removed from V8.

The corresponding Blink side changes are in https://codereview.chromium.org/15670010/ .

BUG=
R=dcarney@chromium.org, svenpanne@chromium.org

Review URL: https://codereview.chromium.org/15974006

Patch from Marja Hölttä <marja@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14871 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

include/v8.h
src/api.cc
test/cctest/test-api.cc

index 7481a81..021c05a 100644 (file)
@@ -228,6 +228,7 @@ typedef void (*NearDeathCallback)(Isolate* isolate,
 
 
 #define V8_USE_UNSAFE_HANDLES
+#define V8_USE_OLD_STYLE_PERSISTENT_HANDLE_VISITORS
 
 /**
  * An object reference managed by the v8 garbage collector.
@@ -4135,8 +4136,13 @@ class V8EXPORT ExternalResourceVisitor {  // NOLINT
 class V8EXPORT PersistentHandleVisitor {  // NOLINT
  public:
   virtual ~PersistentHandleVisitor() {}
+#ifdef V8_USE_OLD_STYLE_PERSISTENT_HANDLE_VISITORS
   virtual void VisitPersistentHandle(Persistent<Value> value,
                                      uint16_t class_id) {}
+#else
+  virtual void VisitPersistentHandle(Persistent<Value>* value,
+                                     uint16_t class_id) {}
+#endif
 };
 
 
index 7d798fb..ec5fbde 100644 (file)
@@ -5100,8 +5100,14 @@ class VisitorAdapter : public i::ObjectVisitor {
     UNREACHABLE();
   }
   virtual void VisitEmbedderReference(i::Object** p, uint16_t class_id) {
+#ifdef V8_USE_OLD_STYLE_PERSISTENT_HANDLE_VISITORS
     visitor_->VisitPersistentHandle(ToApi<Value>(i::Handle<i::Object>(p)),
                                     class_id);
+#else
+    Value* value = ToApi<Value>(i::Handle<i::Object>(p));
+    visitor_->VisitPersistentHandle(
+        reinterpret_cast<Persistent<Value>*>(&value), class_id);
+#endif
   }
  private:
   PersistentHandleVisitor* visitor_;
index 36ce60b..a34a4e5 100644 (file)
@@ -17785,12 +17785,19 @@ class Visitor42 : public v8::PersistentHandleVisitor {
   explicit Visitor42(v8::Persistent<v8::Object> object)
       : counter_(0), object_(object) { }
 
+#ifdef V8_USE_OLD_STYLE_PERSISTENT_HANDLE_VISITORS
   virtual void VisitPersistentHandle(Persistent<Value> value,
                                      uint16_t class_id) {
+    VisitPersistentHandle(&value, class_id);
+  }
+#endif
+
+  virtual void VisitPersistentHandle(Persistent<Value>* value,
+                                     uint16_t class_id) {
     if (class_id == 42) {
-      CHECK(value->IsObject());
+      CHECK((*value)->IsObject());
       v8::Persistent<v8::Object> visited =
-          v8::Persistent<v8::Object>::Cast(value);
+          v8::Persistent<v8::Object>::Cast(*value);
       CHECK_EQ(42, visited.WrapperClassId(v8::Isolate::GetCurrent()));
       CHECK_EQ(Handle<Value>(*object_), Handle<Value>(*visited));
       ++counter_;