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

Side by Side Diff: include/AdblockPlus/JsValue.h

Issue 29417624: Issue 5034 - Part 4: JsEngine::Evaluate() return a JsValue (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Rebased again Created April 20, 2017, 1:02 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
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | src/FilterEngine.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 22 matching lines...) Expand all
33 } 33 }
34 34
35 namespace AdblockPlus 35 namespace AdblockPlus
36 { 36 {
37 class JsValue; 37 class JsValue;
38 class JsEngine; 38 class JsEngine;
39 39
40 typedef std::shared_ptr<JsEngine> JsEnginePtr; 40 typedef std::shared_ptr<JsEngine> JsEnginePtr;
41 41
42 /** 42 /**
43 * Shared smart pointer to a `JsValue` instance.
44 */
45 typedef std::shared_ptr<JsValue> JsValuePtr;
46
47 /**
48 * List of JavaScript values. 43 * List of JavaScript values.
49 */ 44 */
50 typedef std::vector<AdblockPlus::JsValue> JsValueList; 45 typedef std::vector<AdblockPlus::JsValue> JsValueList;
51 46
52 /** 47 /**
53 * Wrapper for JavaScript values. 48 * Wrapper for JavaScript values.
54 * See `JsEngine` for creating `JsValue` objects. 49 * See `JsEngine` for creating `JsValue` objects.
55 */ 50 */
56 class JsValue 51 class JsValue
57 { 52 {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 * (see `IsArray()`). 110 * (see `IsArray()`).
116 * Technically, this is the name of the function that was used as a 111 * Technically, this is the name of the function that was used as a
117 * constructor. 112 * constructor.
118 * @return Class name of the value. 113 * @return Class name of the value.
119 */ 114 */
120 std::string GetClass() const; 115 std::string GetClass() const;
121 116
122 /** 117 /**
123 * Invokes the value as a function (see `IsFunction()`). 118 * Invokes the value as a function (see `IsFunction()`).
124 * @param params Optional list of parameters. 119 * @param params Optional list of parameters.
125 * @param thisPtr Optional `this` value.
126 * @return Value returned by the function. 120 * @return Value returned by the function.
127 */ 121 */
128 JsValue Call(const JsValueList& params = JsValueList(), 122 JsValue Call(const JsValueList& params = JsValueList()) const;
129 const AdblockPlus::JsValuePtr& thisPtr = AdblockPlus::JsValuePtr()) cons t; 123
124 /**
125 * Invokes the value as a method (see `IsFunction()`).
126 * @param params list of parameters.
127 * @param thisPtr `this` value.
128 * @return Value returned by the function.
129 */
130 JsValue Call(const JsValueList& params, const AdblockPlus::JsValue& thisValu e) const;
130 131
131 /** 132 /**
132 * Invokes the value as a function (see `IsFunction()`) with single 133 * Invokes the value as a function (see `IsFunction()`) with single
133 * parameter. 134 * parameter.
134 * @param arg A single required parameter. 135 * @param arg A single required parameter.
135 * @return Value returned by the function. 136 * @return Value returned by the function.
136 */ 137 */
137 JsValue Call(const JsValue& arg) const; 138 JsValue Call(const JsValue& arg) const;
138 139
139 v8::Local<v8::Value> UnwrapValue() const; 140 v8::Local<v8::Value> UnwrapValue() const;
140 141
141 protected: 142 protected:
142 JsEnginePtr jsEngine; 143 JsEnginePtr jsEngine;
143 private: 144 private:
144 JsValue(JsEnginePtr jsEngine, v8::Handle<v8::Value> value); 145 JsValue(JsEnginePtr jsEngine, v8::Handle<v8::Value> value);
145 void SetProperty(const std::string& name, v8::Handle<v8::Value> val); 146 void SetProperty(const std::string& name, v8::Handle<v8::Value> val);
146 // Parameter args is not const because a pointer to its internal arrays is 147 // Parameter args is not const because a pointer to its internal arrays is
147 // passed to v8::Function::Call but the latter does not expect a const point er. 148 // passed to v8::Function::Call but the latter does not expect a const point er.
148 JsValue Call(std::vector<v8::Handle<v8::Value>>& args, v8::Local<v8::Object> thisObj) const; 149 JsValue Call(std::vector<v8::Handle<v8::Value>>& args, v8::Local<v8::Object> thisObj) const;
149 150
150 std::unique_ptr<v8::Persistent<v8::Value>> value; 151 std::unique_ptr<v8::Persistent<v8::Value>> value;
151 }; 152 };
152 } 153 }
153 154
154 #endif 155 #endif
OLDNEW
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | src/FilterEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld