| 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_UNSAFE_PERSISTENT_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_UNSAFE_PERSISTENT_H_ |
| 6 #define CHROME_RENDERER_EXTENSIONS_UNSAFE_PERSISTENT_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_UNSAFE_PERSISTENT_H_ |
| 7 | 7 |
| 8 #include "v8/include/v8.h" | 8 #include "v8/include/v8.h" |
| 9 | 9 |
| 10 namespace extensions { | 10 namespace extensions { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 UnsafePersistent(v8::Isolate* isolate, const v8::Handle<T>& handle) { | 25 UnsafePersistent(v8::Isolate* isolate, const v8::Handle<T>& handle) { |
| 26 v8::Persistent<T> persistent(isolate, handle); | 26 v8::Persistent<T> persistent(isolate, handle); |
| 27 value_ = persistent.ClearAndLeak(); | 27 value_ = persistent.ClearAndLeak(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 // Usage of this function requires | 30 // Usage of this function requires |
| 31 // V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR to be defined | 31 // V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR to be defined |
| 32 void dispose() { | 32 void dispose() { |
| 33 v8::Persistent<T> handle(value_); | 33 v8::Persistent<T> handle(value_); |
| 34 handle.Dispose(); | 34 handle.Reset(); |
| 35 value_ = 0; | 35 value_ = 0; |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Usage of this function requires | 38 // Usage of this function requires |
| 39 // V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR to be defined | 39 // V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR to be defined |
| 40 v8::Local<T> newLocal(v8::Isolate* isolate) { | 40 v8::Local<T> newLocal(v8::Isolate* isolate) { |
| 41 return v8::Local<T>::New(isolate, v8::Local<T>(value_)); | 41 return v8::Local<T>::New(isolate, v8::Local<T>(value_)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 T* value_; | 45 T* value_; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 } // namespace extensions | 48 } // namespace extensions |
| 49 | 49 |
| 50 #endif // CHROME_RENDERER_EXTENSIONS_UNSAFE_PERSISTENT_H_ | 50 #endif // CHROME_RENDERER_EXTENSIONS_UNSAFE_PERSISTENT_H_ |
| OLD | NEW |