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

Unified Diff: include/AdblockPlus/JsEngine.h

Issue 29364548: Issue 4188 - Update libadblockplus-android to use the latest libadblockplus (Closed)
Patch Set: Created Nov. 25, 2016, 12:36 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/AdblockPlus/FilterEngine.h ('k') | include/AdblockPlus/JsValue.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/JsEngine.h
===================================================================
--- a/include/AdblockPlus/JsEngine.h
+++ b/include/AdblockPlus/JsEngine.h
@@ -1,11 +1,11 @@
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
- * Copyright (C) 2006-2015 Eyeo GmbH
+ * 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
@@ -24,18 +24,16 @@
#include <stdint.h>
#include <string>
#include <AdblockPlus/AppInfo.h>
#include <AdblockPlus/LogSystem.h>
#include <AdblockPlus/FileSystem.h>
#include <AdblockPlus/JsValue.h>
#include <AdblockPlus/WebRequest.h>
-#include "V8ValueHolder.h"
-
namespace v8
{
class Arguments;
class Isolate;
class Value;
class Context;
template<class T> class Handle;
typedef Handle<Value>(*InvocationCallback)(const Arguments &args);
@@ -46,16 +44,41 @@ namespace AdblockPlus
class JsEngine;
/**
* Shared smart pointer to a `JsEngine` instance.
*/
typedef std::shared_ptr<JsEngine> JsEnginePtr;
/**
+ * Scope based isolate manager. Creates a new isolate instance on
+ * constructing and disposes it on destructing.
+ */
+ class ScopedV8Isolate
+ {
+ public:
+ ScopedV8Isolate();
+ ~ScopedV8Isolate();
+ v8::Isolate* Get()
+ {
+ return isolate;
+ }
+ private:
+ ScopedV8Isolate(const ScopedV8Isolate&);
+ ScopedV8Isolate& operator=(const ScopedV8Isolate&);
+
+ v8::Isolate* isolate;
+ };
+
+ /**
+ * Shared smart pointer to ScopedV8Isolate instance;
+ */
+ typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr;
+
+ /**
* JavaScript engine used by `FilterEngine`, wraps v8.
*/
class JsEngine : public std::enable_shared_from_this<JsEngine>
{
friend class JsValue;
friend class JsContext;
public:
@@ -67,19 +90,21 @@ namespace AdblockPlus
/**
* Maps events to callback functions.
*/
typedef std::map<std::string, EventCallback> EventMap;
/**
* Creates a new JavaScript engine instance.
* @param appInfo Information about the app.
+ * @param isolate v8::Isolate wrapper. This parameter should be considered
+ * as a temporary hack for tests, it will go away. Issue #3593.
* @return New `JsEngine` instance.
*/
- static JsEnginePtr New(const AppInfo& appInfo = AppInfo());
+ static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), const ScopedV8IsolatePtr& isolate = ScopedV8IsolatePtr(new ScopedV8Isolate()));
/**
* Registers the callback function for an event.
* @param eventName Event name. Note that this can be any string - it's a
* general purpose event handling mechanism.
* @param callback Event callback function.
*/
void SetEventCallback(const std::string& eventName, EventCallback callback);
@@ -212,22 +237,33 @@ namespace AdblockPlus
/**
* Sets a global property that can be accessed by all the scripts.
* @param name Name of the property to set.
* @param value Value of the property to set.
*/
void SetGlobalProperty(const std::string& name, AdblockPlus::JsValuePtr value);
+ /**
+ * Returns a pointer to associated v8::Isolate.
+ */
+ v8::Isolate* GetIsolate()
+ {
+ return isolate->Get();
+ }
+
private:
- JsEngine();
+ explicit JsEngine(const ScopedV8IsolatePtr& isolate);
+
+ /// Isolate must be disposed only after disposing of all objects which are
+ /// using it.
+ ScopedV8IsolatePtr isolate;
FileSystemPtr fileSystem;
WebRequestPtr webRequest;
LogSystemPtr logSystem;
- v8::Isolate* isolate;
- V8ValueHolder<v8::Context> context;
+ std::unique_ptr<v8::Persistent<v8::Context>> context;
EventMap eventCallbacks;
JsValuePtr globalJsObject;
};
}
#endif
« no previous file with comments | « include/AdblockPlus/FilterEngine.h ('k') | include/AdblockPlus/JsValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld