OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 #include <memory> | 34 #include <memory> |
35 | 35 |
36 #include "platform/bindings/ScriptWrappableVisitor.h" | 36 #include "platform/bindings/ScriptWrappableVisitor.h" |
37 #include "platform/wtf/Allocator.h" | 37 #include "platform/wtf/Allocator.h" |
38 #include "platform/wtf/Noncopyable.h" | 38 #include "platform/wtf/Noncopyable.h" |
39 #include "v8/include/v8.h" | 39 #include "v8/include/v8.h" |
40 | 40 |
41 namespace blink { | 41 namespace blink { |
42 | 42 |
| 43 // Holds a persistent handle to a V8 object; use ScopedPersistent instead of |
| 44 // directly using v8::Persistent. Introducing a (non-weak) ScopedPersistent |
| 45 // has a risk of producing memory leaks, ask blink-reviews-bindings@ for a |
| 46 // review. |
43 template <typename T> | 47 template <typename T> |
44 class ScopedPersistent { | 48 class ScopedPersistent { |
45 USING_FAST_MALLOC(ScopedPersistent); | 49 USING_FAST_MALLOC(ScopedPersistent); |
46 WTF_MAKE_NONCOPYABLE(ScopedPersistent); | 50 WTF_MAKE_NONCOPYABLE(ScopedPersistent); |
47 | 51 |
48 public: | 52 public: |
49 ScopedPersistent() {} | 53 ScopedPersistent() {} |
50 | 54 |
51 ScopedPersistent(v8::Isolate* isolate, v8::Local<T> handle) | 55 ScopedPersistent(v8::Isolate* isolate, v8::Local<T> handle) |
52 : handle_(isolate, handle) {} | 56 : handle_(isolate, handle) {} |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 103 |
100 ALWAYS_INLINE v8::Persistent<T>& Get() { return handle_; } | 104 ALWAYS_INLINE v8::Persistent<T>& Get() { return handle_; } |
101 | 105 |
102 private: | 106 private: |
103 v8::Persistent<T> handle_; | 107 v8::Persistent<T> handle_; |
104 }; | 108 }; |
105 | 109 |
106 } // namespace blink | 110 } // namespace blink |
107 | 111 |
108 #endif // ScopedPersistent_h | 112 #endif // ScopedPersistent_h |
OLD | NEW |