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 |
11 namespace extensions { | 11 namespace extensions { |
12 | 12 |
13 // A v8::Persistent handle to a V8 value which destroys and clears the | 13 // A v8::Persistent handle to a V8 value which destroys and clears the |
14 // underlying handle on destruction. | 14 // underlying handle on destruction. |
15 template <typename T> | 15 template <typename T> |
16 class ScopedPersistent { | 16 class ScopedPersistent { |
17 public: | 17 public: |
18 ScopedPersistent() { | 18 ScopedPersistent() { |
19 } | 19 } |
20 | 20 |
21 explicit ScopedPersistent(v8::Handle<T> handle) { | 21 explicit ScopedPersistent(v8::Handle<T> handle) { |
22 reset(handle); | 22 reset(handle); |
23 } | 23 } |
24 | 24 |
25 ~ScopedPersistent() { | 25 ~ScopedPersistent() { |
26 reset(); | 26 reset(); |
27 } | 27 } |
28 | 28 |
29 void reset(v8::Handle<T> handle) { | 29 void reset(v8::Handle<T> handle) { |
30 reset(); | 30 reset(); |
jochen (gone - plz use gerrit)
2013/05/13 14:07:40
this call is not needed anymore, right?
marja
2013/05/13 14:16:04
Done.
| |
31 handle_ = v8::Persistent<T>::New(GetIsolate(handle), handle); | 31 handle_.Reset(GetIsolate(handle), handle); |
32 } | 32 } |
33 | 33 |
34 void reset() { | 34 void reset() { |
35 if (handle_.IsEmpty()) | 35 if (handle_.IsEmpty()) |
36 return; | 36 return; |
37 handle_.Dispose(GetIsolate(handle_)); | 37 handle_.Dispose(GetIsolate(handle_)); |
jochen (gone - plz use gerrit)
2013/05/13 14:07:40
can this now be something like Reset(GetIsolate(),
marja
2013/05/13 14:16:04
We can Reset to an empty handle, but not NULL, so
| |
38 handle_.Clear(); | 38 handle_.Clear(); |
39 } | 39 } |
40 | 40 |
41 v8::Persistent<T> operator->() const { | 41 v8::Persistent<T> operator->() const { |
42 return handle_; | 42 return handle_; |
43 } | 43 } |
44 | 44 |
45 v8::Persistent<T> get() const { | 45 v8::Persistent<T> get() const { |
46 return handle_; | 46 return handle_; |
47 } | 47 } |
(...skipping 18 matching lines...) Expand all Loading... | |
66 } | 66 } |
67 | 67 |
68 v8::Persistent<T> handle_; | 68 v8::Persistent<T> handle_; |
69 | 69 |
70 DISALLOW_COPY_AND_ASSIGN(ScopedPersistent); | 70 DISALLOW_COPY_AND_ASSIGN(ScopedPersistent); |
71 }; | 71 }; |
72 | 72 |
73 } // namespace extensions | 73 } // namespace extensions |
74 | 74 |
75 #endif // CHROME_RENDERER_EXTENSIONS_SCOPED_PERSISTENT_H_ | 75 #endif // CHROME_RENDERER_EXTENSIONS_SCOPED_PERSISTENT_H_ |
OLD | NEW |