OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_RENDERER_EXTENSIONS_SCOPED_PERSISTENT_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_SCOPED_PERSISTENT_H_ |
6 #define CHROME_RENDERER_EXTENSIONS_SCOPED_PERSISTENT_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_SCOPED_PERSISTENT_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "v8/include/v8.h" | 9 #include "v8/include/v8.h" |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 v8::Persistent<T> operator->() const { | 40 v8::Persistent<T> operator->() const { |
41 return handle_; | 41 return handle_; |
42 } | 42 } |
43 | 43 |
44 v8::Persistent<T> get() const { | 44 v8::Persistent<T> get() const { |
45 return handle_; | 45 return handle_; |
46 } | 46 } |
47 | 47 |
48 void MakeWeak(void* parameters, v8::NearDeathCallback callback) { | 48 template<typename P> |
| 49 void MakeWeak(P* parameters, |
| 50 typename v8::WeakReferenceCallbacks<T, P>::Revivable callback) { |
49 handle_.MakeWeak(GetIsolate(handle_), parameters, callback); | 51 handle_.MakeWeak(GetIsolate(handle_), parameters, callback); |
50 } | 52 } |
51 | 53 |
52 private: | 54 private: |
53 template <typename U> | 55 template <typename U> |
54 static v8::Isolate* GetIsolate(v8::Handle<U> object_handle) { | 56 static v8::Isolate* GetIsolate(v8::Handle<U> object_handle) { |
55 // Only works for v8::Object and its subclasses. Add specialisations for | 57 // Only works for v8::Object and its subclasses. Add specialisations for |
56 // anything else. | 58 // anything else. |
57 return GetIsolate(object_handle->CreationContext()); | 59 return GetIsolate(object_handle->CreationContext()); |
58 } | 60 } |
59 static v8::Isolate* GetIsolate(v8::Handle<v8::Context> context_handle) { | 61 static v8::Isolate* GetIsolate(v8::Handle<v8::Context> context_handle) { |
60 return context_handle->GetIsolate(); | 62 return context_handle->GetIsolate(); |
61 } | 63 } |
62 static v8::Isolate* GetIsolate( | 64 static v8::Isolate* GetIsolate( |
63 v8::Handle<v8::ObjectTemplate> template_handle) { | 65 v8::Handle<v8::ObjectTemplate> template_handle) { |
64 return v8::Isolate::GetCurrent(); | 66 return v8::Isolate::GetCurrent(); |
65 } | 67 } |
66 | 68 |
67 v8::Persistent<T> handle_; | 69 v8::Persistent<T> handle_; |
68 | 70 |
69 DISALLOW_COPY_AND_ASSIGN(ScopedPersistent); | 71 DISALLOW_COPY_AND_ASSIGN(ScopedPersistent); |
70 }; | 72 }; |
71 | 73 |
72 } // namespace extensions | 74 } // namespace extensions |
73 | 75 |
74 #endif // CHROME_RENDERER_EXTENSIONS_SCOPED_PERSISTENT_H_ | 76 #endif // CHROME_RENDERER_EXTENSIONS_SCOPED_PERSISTENT_H_ |
OLD | NEW |