| Index: src/V8Upgrade.h | 
| =================================================================== | 
| new file mode 100644 | 
| --- /dev/null | 
| +++ b/src/V8Upgrade.h | 
| @@ -0,0 +1,116 @@ | 
| +/* | 
| + * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| + * Copyright (C) 2006-2016 Eyeo GmbH | 
| + * | 
| + * Adblock Plus is free software: you can redistribute it and/or modify | 
| + * it under the terms of the GNU General Public License version 3 as | 
| + * published by the Free Software Foundation. | 
| + * | 
| + * Adblock Plus is distributed in the hope that it will be useful, | 
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| + * GNU General Public License for more details. | 
| + * | 
| + * You should have received a copy of the GNU General Public License | 
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 
| + */ | 
| + | 
| +/** | 
| + * \file V8Upgrade Facilities to ease the upgrade from old versions of v8 | 
| + */ | 
| + | 
| +#if !defined(V8_UPGRADE_H) | 
| +#define V8_UPGRADE_H | 
| + | 
| +#include <v8.h> | 
| + | 
| +/** | 
| + * Mimic for the next-generation version of v8::Persistent | 
| + * | 
| + * Recent versions of v8 significantly improve the usability of v8::Persistent. | 
| + * This class provides an interface that mimics the new version. | 
| + * An upgraded version of v8::Peristent should drop in and replace this class | 
| + * with no changes to code other than the type declaration. | 
| + * | 
| + * Features present in new versions of v8::Persistent that are present here: | 
| + * - Objects follow conventional C++ scope behavior. | 
| + * Dispose() is no longer present; its equivalent is called in the destructor. | 
| + * - Get() is a convenience method to convert to a Local<T> | 
| + * - A copy constructor. | 
| + */ | 
| +template<class T> | 
| +class V8PersistentNG | 
| +{ | 
| + /** | 
| + * The underlying Persistent | 
| + */ | 
| + v8::Persistent<T> persistent; | 
| + /** | 
| + * Isolate pointer from which this Persistent was constructed. | 
| + * This is needed for the copy constructor using the old Persistent class. | 
| + */ | 
| + v8::Isolate* isolate; | 
| + | 
| +public: | 
| + V8PersistentNG() // = default; | 
| + {} | 
| + | 
| + template<class S> | 
| + V8PersistentNG(v8::Isolate* isolate, v8::Local<S> that) | 
| + : persistent(isolate, that), | 
| + isolate(isolate) | 
| + {} | 
| + | 
| + ~V8PersistentNG() | 
| + { | 
| + persistent.Dispose(); | 
| + } | 
| + | 
| + /** | 
| + * Copy constructor | 
| + */ | 
| + V8PersistentNG(const V8PersistentNG<T>& that) | 
| + : isolate(that.isolate) | 
| + { | 
| + persistent.Reset(that.isolate, that.persistent); | 
| + } | 
| + /** | 
| + * Move constructor | 
| + */ | 
| + V8PersistentNG(V8PersistentNG<T>&& that) | 
| + : isolate(that.isolate) | 
| + { | 
| + persistent.Reset(that.isolate, that.persistent); | 
| + } | 
| + /** | 
| + * Copy assignment | 
| + */ | 
| + V8PersistentNG& operator=(const V8PersistentNG<T>& that) | 
| + { | 
| + isolate = that.isolate; | 
| + persistent.Reset(that.isolate, that.persistent); | 
| + return *this; | 
| + } | 
| + /** | 
| + * Move assignment | 
| + */ | 
| + V8PersistentNG& operator=(V8PersistentNG<T>&& that) | 
| + { | 
| + isolate = that.isolate; | 
| + persistent.Reset(that.isolate, that.persistent); | 
| + return *this; | 
| + } | 
| + | 
| + /** | 
| + * Create a Local from this Persistent. | 
| + * | 
| + * The function signature matches that of the new v8. | 
| + * The `isolate` argument seems redundant, but that's out of our hands. | 
| + */ | 
| + v8::Local<T> Get(v8::Isolate* isolate) const | 
| + { | 
| + return v8::Local<T>::New(isolate, persistent); | 
| + } | 
| +}; | 
| + | 
| +#endif |