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

Delta Between Two Patch Sets: src/FileSystemJsObject.cpp

Issue 29361562: Issue 3594 - remove circular references JsEngine-JsValue-JsEngine (Closed)
Left Patch Set: Created Nov. 3, 2016, 11:26 a.m.
Right Patch Set: temporary workaround for race condition Created Dec. 1, 2016, 10:26 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <AdblockPlus/FileSystem.h> 18 #include <AdblockPlus/FileSystem.h>
19 #include <stdexcept> 19 #include <stdexcept>
20 #include <sstream> 20 #include <sstream>
21 #include <vector> 21 #include <vector>
22 #include <thread>
23 22
24 #include <AdblockPlus/JsValue.h> 23 #include <AdblockPlus/JsValue.h>
25 #include "FileSystemJsObject.h" 24 #include "FileSystemJsObject.h"
26 #include "JsContext.h" 25 #include "JsContext.h"
27 #include "Thread.h" 26 #include "Thread.h"
28 #include "Utils.h" 27 #include "Utils.h"
29 28
30 using namespace AdblockPlus; 29 using namespace AdblockPlus;
31 30
32 namespace 31 namespace
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 catch (std::exception& e) 68 catch (std::exception& e)
70 { 69 {
71 error = e.what(); 70 error = e.what();
72 } 71 }
73 catch (...) 72 catch (...)
74 { 73 {
75 error = "Unknown error while reading from " + path; 74 error = "Unknown error while reading from " + path;
76 } 75 }
77 76
78 JsContext context(m_jsEngine); 77 JsContext context(m_jsEngine);
79 JsValuePtr result = context.jsEngine().NewObject(); 78 JsValuePtr result = context.GetJsEngine().NewObject();
80 result->SetProperty("content", content); 79 result->SetProperty("content", content);
81 result->SetProperty("error", error); 80 result->SetProperty("error", error);
82 JsValueList params; 81 JsValueList params;
83 params.push_back(result); 82 params.push_back(result);
84 callback->Call(params); 83 callback->Call(params);
85 } 84 }
86 85
87 private: 86 private:
88 std::string path; 87 std::string path;
89 }; 88 };
(...skipping 19 matching lines...) Expand all
109 catch (std::exception& e) 108 catch (std::exception& e)
110 { 109 {
111 error = e.what(); 110 error = e.what();
112 } 111 }
113 catch (...) 112 catch (...)
114 { 113 {
115 error = "Unknown error while writing to " + path; 114 error = "Unknown error while writing to " + path;
116 } 115 }
117 116
118 JsContext context(m_jsEngine); 117 JsContext context(m_jsEngine);
119 JsValuePtr errorValue = context.jsEngine().NewValue(error); 118 JsValuePtr errorValue = context.GetJsEngine().NewValue(error);
120 JsValueList params; 119 JsValueList params;
121 params.push_back(errorValue); 120 params.push_back(errorValue);
122 callback->Call(params); 121 callback->Call(params);
123 } 122 }
124 123
125 private: 124 private:
126 std::string path; 125 std::string path;
127 std::string content; 126 std::string content;
128 }; 127 };
129 128
(...skipping 16 matching lines...) Expand all
146 catch (std::exception& e) 145 catch (std::exception& e)
147 { 146 {
148 error = e.what(); 147 error = e.what();
149 } 148 }
150 catch (...) 149 catch (...)
151 { 150 {
152 error = "Unknown error while moving " + fromPath + " to " + toPath; 151 error = "Unknown error while moving " + fromPath + " to " + toPath;
153 } 152 }
154 153
155 JsContext context(m_jsEngine); 154 JsContext context(m_jsEngine);
156 JsValuePtr errorValue = context.jsEngine().NewValue(error); 155 JsValuePtr errorValue = context.GetJsEngine().NewValue(error);
157 JsValueList params; 156 JsValueList params;
158 params.push_back(errorValue); 157 params.push_back(errorValue);
159 callback->Call(params); 158 callback->Call(params);
160 } 159 }
161 160
162 private: 161 private:
163 std::string fromPath; 162 std::string fromPath;
164 std::string toPath; 163 std::string toPath;
165 }; 164 };
166 165
(...skipping 16 matching lines...) Expand all
183 catch (std::exception& e) 182 catch (std::exception& e)
184 { 183 {
185 error = e.what(); 184 error = e.what();
186 } 185 }
187 catch (...) 186 catch (...)
188 { 187 {
189 error = "Unknown error while removing " + path; 188 error = "Unknown error while removing " + path;
190 } 189 }
191 190
192 JsContext context(m_jsEngine); 191 JsContext context(m_jsEngine);
193 JsValuePtr errorValue = context.jsEngine().NewValue(error); 192 JsValuePtr errorValue = context.GetJsEngine().NewValue(error);
194 JsValueList params; 193 JsValueList params;
195 params.push_back(errorValue); 194 params.push_back(errorValue);
196 callback->Call(params); 195 callback->Call(params);
197 } 196 }
198 197
199 private: 198 private:
200 std::string path; 199 std::string path;
201 }; 200 };
202 201
203 202
(...skipping 17 matching lines...) Expand all
221 catch (std::exception& e) 220 catch (std::exception& e)
222 { 221 {
223 error = e.what(); 222 error = e.what();
224 } 223 }
225 catch (...) 224 catch (...)
226 { 225 {
227 error = "Unknown error while calling stat on " + path; 226 error = "Unknown error while calling stat on " + path;
228 } 227 }
229 228
230 JsContext context(m_jsEngine); 229 JsContext context(m_jsEngine);
231 JsValuePtr result = context.jsEngine().NewObject(); 230 JsValuePtr result = context.GetJsEngine().NewObject();
232 result->SetProperty("exists", statResult.exists); 231 result->SetProperty("exists", statResult.exists);
233 result->SetProperty("isFile", statResult.isFile); 232 result->SetProperty("isFile", statResult.isFile);
234 result->SetProperty("isDirectory", statResult.isDirectory); 233 result->SetProperty("isDirectory", statResult.isDirectory);
235 result->SetProperty("lastModified", statResult.lastModified); 234 result->SetProperty("lastModified", statResult.lastModified);
236 result->SetProperty("error", error); 235 result->SetProperty("error", error);
237 236
238 JsValueList params; 237 JsValueList params;
239 params.push_back(result); 238 params.push_back(result);
240 callback->Call(params); 239 callback->Call(params);
241 } 240 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj) 354 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj)
356 { 355 {
357 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback)); 356 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback));
358 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback)); 357 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback));
359 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback)); 358 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback));
360 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback)); 359 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback));
361 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback)); 360 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback));
362 obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback)); 361 obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback));
363 return obj; 362 return obj;
364 } 363 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld