LEFT | RIGHT |
(no file at all) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH |
| 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
| 18 #ifndef ADBLOCK_PLUS_V8_VALUE_HOLDER_H |
| 19 #define ADBLOCK_PLUS_V8_VALUE_HOLDER_H |
| 20 |
| 21 #include <memory> |
| 22 |
| 23 namespace v8 |
| 24 { |
| 25 class Isolate; |
| 26 template <class T> class Handle; |
| 27 template <class T> class Persistent; |
| 28 } |
| 29 |
| 30 namespace AdblockPlus |
| 31 { |
| 32 template<class T> |
| 33 class V8ValueHolder |
| 34 { |
| 35 public: |
| 36 inline V8ValueHolder() {} |
| 37 inline V8ValueHolder(V8ValueHolder& value) |
| 38 { |
| 39 reset(value.isolate, static_cast<v8::Handle<T> >(value)); |
| 40 } |
| 41 inline V8ValueHolder(v8::Isolate* isolate, v8::Persistent<T> value) |
| 42 { |
| 43 reset(isolate, value); |
| 44 } |
| 45 inline V8ValueHolder(v8::Isolate* isolate, v8::Handle<T> value) |
| 46 { |
| 47 reset(isolate, value); |
| 48 } |
| 49 |
| 50 inline ~V8ValueHolder() |
| 51 { |
| 52 reset(0, v8::Persistent<T>()); |
| 53 } |
| 54 |
| 55 inline void reset(v8::Isolate* isolate, v8::Persistent<T> value) |
| 56 { |
| 57 if (this->value.get()) |
| 58 { |
| 59 this->value->Dispose(this->isolate); |
| 60 this->value.reset(0); |
| 61 } |
| 62 |
| 63 if (!value.IsEmpty()) |
| 64 { |
| 65 this->isolate = isolate; |
| 66 this->value.reset(new v8::Persistent<T>(value)); |
| 67 } |
| 68 } |
| 69 |
| 70 inline void reset(v8::Isolate* isolate, v8::Handle<T> value) |
| 71 { |
| 72 reset(isolate, v8::Persistent<T>::New(isolate, value)); |
| 73 } |
| 74 |
| 75 inline T* operator->() const |
| 76 { |
| 77 return **value; |
| 78 } |
| 79 inline operator v8::Handle<T>() const |
| 80 { |
| 81 return *value; |
| 82 } |
| 83 inline operator v8::Persistent<T>() const |
| 84 { |
| 85 return *value; |
| 86 } |
| 87 private: |
| 88 v8::Isolate* isolate; |
| 89 std::auto_ptr<v8::Persistent<T> > value; |
| 90 }; |
| 91 } |
| 92 |
| 93 #endif |
LEFT | RIGHT |