OLD | NEW |
| (Empty) |
1 /* | |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | |
3 * Copyright (C) 2006-2014 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 typedef typename v8::Persistent<T> V8Persistent; | |
37 V8ValueHolder() | |
38 { | |
39 reset(); | |
40 } | |
41 V8ValueHolder(v8::Isolate* isolate, v8::Handle<T> value) | |
42 { | |
43 reset(isolate, value); | |
44 } | |
45 ~V8ValueHolder() | |
46 { | |
47 if (this->value.get()) | |
48 { | |
49 this->value->Dispose(this->isolate); | |
50 this->value.reset(0); | |
51 } | |
52 } | |
53 void reset(v8::Isolate* isolate, v8::Handle<T> value) | |
54 { | |
55 reset(isolate, std::auto_ptr<V8Persistent>(new V8Persistent(isolate, val
ue))); | |
56 } | |
57 void reset(v8::Isolate* isolate = nullptr, std::auto_ptr<V8Persistent> value
= std::auto_ptr<V8Persistent>(new V8Persistent())) | |
58 { | |
59 if (this->value.get()) | |
60 { | |
61 this->value->Dispose(this->isolate); | |
62 this->value.reset(0); | |
63 } | |
64 | |
65 if (!value->IsEmpty()) | |
66 { | |
67 this->isolate = isolate; | |
68 this->value = value; | |
69 } | |
70 } | |
71 | |
72 operator V8Persistent&() const | |
73 { | |
74 return *value; | |
75 } | |
76 private: | |
77 v8::Isolate* isolate; | |
78 std::auto_ptr<V8Persistent> value; | |
79 }; | |
80 } | |
81 | |
82 #endif | |
OLD | NEW |