Index: Source/bindings/v8/GarbageCollected.h |
diff --git a/Source/bindings/v8/ScopedPersistent.h b/Source/bindings/v8/GarbageCollected.h |
similarity index 77% |
copy from Source/bindings/v8/ScopedPersistent.h |
copy to Source/bindings/v8/GarbageCollected.h |
index faef97d9451ac5489b571cbc877a19310b130814..6c31cfc8a821294148e0a19e716f0c4b48bb406a 100644 |
--- a/Source/bindings/v8/ScopedPersistent.h |
+++ b/Source/bindings/v8/GarbageCollected.h |
@@ -28,26 +28,26 @@ |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
-#ifndef ScopedPersistent_h |
-#define ScopedPersistent_h |
+#ifndef GarbageCollected_h |
+#define GarbageCollected_h |
-#include <v8.h> |
#include "wtf/Noncopyable.h" |
+#include <v8.h> |
namespace WebCore { |
template<typename T> |
-class ScopedPersistent { |
- WTF_MAKE_NONCOPYABLE(ScopedPersistent); |
+class GarbageCollected { |
abarth-chromium
2013/08/15 00:22:11
Oh, sorry. I meant that GarbageCollected would ha
|
+ WTF_MAKE_NONCOPYABLE(GarbageCollected); |
public: |
- ScopedPersistent() { } |
+ GarbageCollected() { } |
- explicit ScopedPersistent(v8::Handle<T> handle) |
+ explicit GarbageCollected(v8::Handle<T> handle) |
: m_handle(v8::Isolate::GetCurrent(), handle) |
{ |
} |
- ~ScopedPersistent() |
+ ~GarbageCollected() |
{ |
clear(); |
} |
@@ -57,19 +57,13 @@ public: |
return v8::Local<T>::New(isolate, m_handle); |
} |
- template<typename P> |
- void makeWeak(P* parameters, void (*callback)(v8::Isolate*, v8::Persistent<T>*, P*)) |
- { |
- m_handle.MakeWeak(parameters, callback); |
- } |
- |
bool isEmpty() const { return m_handle.IsEmpty(); } |
void set(v8::Isolate* isolate, v8::Handle<T> handle) |
{ |
m_handle.Reset(isolate, handle); |
+ m_handle.MakeWeak(this, &weakCallback); |
} |
- |
// Note: This is clear in the OwnPtr sense, not the v8::Handle sense. |
void clear() |
{ |
@@ -79,18 +73,15 @@ public: |
m_handle.Clear(); |
} |
- bool operator==(const ScopedPersistent<T>& other) |
+ bool operator==(const GarbageCollected<T>& other) |
{ |
return m_handle == other.m_handle; |
} |
private: |
- // FIXME: This function does an unsafe handle access. Remove it. |
- friend class V8AbstractEventListener; |
- friend class V8PerIsolateData; |
- ALWAYS_INLINE v8::Persistent<T>& getUnsafe() |
+ static void weakCallback(v8::Isolate*, v8::Persistent<T>*, GarbageCollected<T>* self) |
{ |
- return m_handle; |
+ self->clear(); |
} |
v8::Persistent<T> m_handle; |
@@ -98,4 +89,4 @@ private: |
} // namespace WebCore |
-#endif // ScopedPersistent_h |
+#endif // GarbageCollected_h |