Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/V8Upgrade.h

Issue 29369365: Issue #4692 - Rewrite `SetTimeout` facility to avoid `JsValuePtr` and `JsValueList`
Patch Set: Created Dec. 19, 2016, 10:24 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« src/JsEngine.cpp ('K') | « src/JsValue.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 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 /**
19 * \file V8Upgrade Facilities to ease the upgrade from old versions of v8
20 */
21
22 #if !defined(V8_UPGRADE_H)
23 #define V8_UPGRADE_H
24
25 #include <v8.h>
26
27 /**
28 * Mimic for the next-generation version of v8::Persistent
29 *
30 * Recent versions of v8 significantly improve the usability of v8::Persistent.
31 * This class provides an interface that mimics the new version.
32 * An upgraded version of v8::Peristent should drop in and replace this class
33 * with no changes to code other than the type declaration.
34 *
35 * Features present in new versions of v8::Persistent that are present here:
36 * - Objects follow conventional C++ scope behavior.
37 * Dispose() is no longer present; its equivalent is called in the destructor.
38 * - Get() is a convenience method to convert to a Local<T>
39 * - A copy constructor.
40 */
41 template<class T>
42 class V8PersistentNG
43 {
44 /**
45 * The underlying Persistent
46 */
47 v8::Persistent<T> persistent;
48 /**
49 * Isolate pointer from which this Persistent was constructed.
50 * This is needed for the copy constructor using the old Persistent class.
51 */
52 v8::Isolate* isolate;
53
54 public:
55 V8PersistentNG() // = default;
56 {}
57
58 template<class S>
59 V8PersistentNG(v8::Isolate* isolate, v8::Local<S> that)
60 : persistent(isolate, that),
61 isolate(isolate)
62 {}
63
64 ~V8PersistentNG()
65 {
66 persistent.Dispose();
67 }
68
69 /**
70 * Copy constructor
71 */
72 V8PersistentNG(const V8PersistentNG<T>& that)
73 : isolate(that.isolate)
74 {
75 persistent.Reset(that.isolate, that.persistent);
76 }
77 /**
78 * Move constructor
79 */
80 V8PersistentNG(V8PersistentNG<T>&& that)
81 : isolate(that.isolate)
82 {
83 persistent.Reset(that.isolate, that.persistent);
84 }
85 /**
86 * Copy assignment
87 */
88 V8PersistentNG& operator=(const V8PersistentNG<T>& that)
89 {
90 isolate = that.isolate;
91 persistent.Reset(that.isolate, that.persistent);
92 return *this;
93 }
94 /**
95 * Move assignment
96 */
97 V8PersistentNG& operator=(V8PersistentNG<T>&& that)
98 {
99 isolate = that.isolate;
100 persistent.Reset(that.isolate, that.persistent);
101 return *this;
102 }
103
104 /**
105 * Create a Local from this Persistent.
106 *
107 * The function signature matches that of the new v8.
108 * The `isolate` argument seems redundant, but that's out of our hands.
109 */
110 v8::Local<T> Get(v8::Isolate* isolate) const
111 {
112 return v8::Local<T>::New(isolate, persistent);
113 }
114 };
115
116 #endif
OLDNEW
« src/JsEngine.cpp ('K') | « src/JsValue.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld