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

Side by Side Diff: src/FileSystemJsObject.cpp

Issue 29361562: Issue 3594 - remove circular references JsEngine-JsValue-JsEngine (Closed)
Patch Set: address comments Created Nov. 25, 2016, 12: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
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-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
(...skipping 16 matching lines...) Expand all
27 #include "Utils.h" 27 #include "Utils.h"
28 28
29 using namespace AdblockPlus; 29 using namespace AdblockPlus;
30 30
31 namespace 31 namespace
32 { 32 {
33 class IoThread : public Thread 33 class IoThread : public Thread
34 { 34 {
35 public: 35 public:
36 IoThread(JsEnginePtr jsEngine, JsValuePtr callback) 36 IoThread(JsEnginePtr jsEngine, JsValuePtr callback)
37 : Thread(true), jsEngine(jsEngine), fileSystem(jsEngine->GetFileSystem()), 37 : Thread(true)
38 callback(callback) 38 , m_jsEngine(jsEngine)
39 , fileSystem(jsEngine->GetFileSystem())
40 , callback(callback)
39 { 41 {
40 } 42 }
41 43
42 protected: 44 protected:
43 JsEnginePtr jsEngine; 45 std::weak_ptr<JsEngine> m_jsEngine;
44 FileSystemPtr fileSystem; 46 FileSystemPtr fileSystem;
45 JsValuePtr callback; 47 JsValuePtr callback;
46 }; 48 };
47 49
48 class ReadThread : public IoThread 50 class ReadThread : public IoThread
49 { 51 {
50 public: 52 public:
51 ReadThread(JsEnginePtr jsEngine, JsValuePtr callback, 53 ReadThread(JsEnginePtr jsEngine, JsValuePtr callback,
52 const std::string& path) 54 const std::string& path)
53 : IoThread(jsEngine, callback), path(path) 55 : IoThread(jsEngine, callback), path(path)
(...skipping 11 matching lines...) Expand all
65 } 67 }
66 catch (std::exception& e) 68 catch (std::exception& e)
67 { 69 {
68 error = e.what(); 70 error = e.what();
69 } 71 }
70 catch (...) 72 catch (...)
71 { 73 {
72 error = "Unknown error while reading from " + path; 74 error = "Unknown error while reading from " + path;
73 } 75 }
74 76
75 const JsContext context(jsEngine); 77 JsContext context(m_jsEngine);
76 JsValuePtr result = jsEngine->NewObject(); 78 JsValuePtr result = context.GetJsEngine().NewObject();
77 result->SetProperty("content", content); 79 result->SetProperty("content", content);
78 result->SetProperty("error", error); 80 result->SetProperty("error", error);
79 JsValueList params; 81 JsValueList params;
80 params.push_back(result); 82 params.push_back(result);
81 callback->Call(params); 83 callback->Call(params);
82 } 84 }
83 85
84 private: 86 private:
85 std::string path; 87 std::string path;
86 }; 88 };
(...skipping 18 matching lines...) Expand all
105 } 107 }
106 catch (std::exception& e) 108 catch (std::exception& e)
107 { 109 {
108 error = e.what(); 110 error = e.what();
109 } 111 }
110 catch (...) 112 catch (...)
111 { 113 {
112 error = "Unknown error while writing to " + path; 114 error = "Unknown error while writing to " + path;
113 } 115 }
114 116
115 const JsContext context(jsEngine); 117 JsContext context(m_jsEngine);
116 JsValuePtr errorValue = jsEngine->NewValue(error); 118 JsValuePtr errorValue = context.GetJsEngine().NewValue(error);
117 JsValueList params; 119 JsValueList params;
118 params.push_back(errorValue); 120 params.push_back(errorValue);
119 callback->Call(params); 121 callback->Call(params);
120 } 122 }
121 123
122 private: 124 private:
123 std::string path; 125 std::string path;
124 std::string content; 126 std::string content;
125 }; 127 };
126 128
(...skipping 15 matching lines...) Expand all
142 } 144 }
143 catch (std::exception& e) 145 catch (std::exception& e)
144 { 146 {
145 error = e.what(); 147 error = e.what();
146 } 148 }
147 catch (...) 149 catch (...)
148 { 150 {
149 error = "Unknown error while moving " + fromPath + " to " + toPath; 151 error = "Unknown error while moving " + fromPath + " to " + toPath;
150 } 152 }
151 153
152 const JsContext context(jsEngine); 154 JsContext context(m_jsEngine);
153 JsValuePtr errorValue = jsEngine->NewValue(error); 155 JsValuePtr errorValue = context.GetJsEngine().NewValue(error);
154 JsValueList params; 156 JsValueList params;
155 params.push_back(errorValue); 157 params.push_back(errorValue);
156 callback->Call(params); 158 callback->Call(params);
157 } 159 }
158 160
159 private: 161 private:
160 std::string fromPath; 162 std::string fromPath;
161 std::string toPath; 163 std::string toPath;
162 }; 164 };
163 165
(...skipping 15 matching lines...) Expand all
179 } 181 }
180 catch (std::exception& e) 182 catch (std::exception& e)
181 { 183 {
182 error = e.what(); 184 error = e.what();
183 } 185 }
184 catch (...) 186 catch (...)
185 { 187 {
186 error = "Unknown error while removing " + path; 188 error = "Unknown error while removing " + path;
187 } 189 }
188 190
189 const JsContext context(jsEngine); 191 JsContext context(m_jsEngine);
190 JsValuePtr errorValue = jsEngine->NewValue(error); 192 JsValuePtr errorValue = context.GetJsEngine().NewValue(error);
191 JsValueList params; 193 JsValueList params;
192 params.push_back(errorValue); 194 params.push_back(errorValue);
193 callback->Call(params); 195 callback->Call(params);
194 } 196 }
195 197
196 private: 198 private:
197 std::string path; 199 std::string path;
198 }; 200 };
199 201
200 202
(...skipping 16 matching lines...) Expand all
217 } 219 }
218 catch (std::exception& e) 220 catch (std::exception& e)
219 { 221 {
220 error = e.what(); 222 error = e.what();
221 } 223 }
222 catch (...) 224 catch (...)
223 { 225 {
224 error = "Unknown error while calling stat on " + path; 226 error = "Unknown error while calling stat on " + path;
225 } 227 }
226 228
227 const JsContext context(jsEngine); 229 JsContext context(m_jsEngine);
228 JsValuePtr result = jsEngine->NewObject(); 230 JsValuePtr result = context.GetJsEngine().NewObject();
229 result->SetProperty("exists", statResult.exists); 231 result->SetProperty("exists", statResult.exists);
230 result->SetProperty("isFile", statResult.isFile); 232 result->SetProperty("isFile", statResult.isFile);
231 result->SetProperty("isDirectory", statResult.isDirectory); 233 result->SetProperty("isDirectory", statResult.isDirectory);
232 result->SetProperty("lastModified", statResult.lastModified); 234 result->SetProperty("lastModified", statResult.lastModified);
233 result->SetProperty("error", error); 235 result->SetProperty("error", error);
234 236
235 JsValueList params; 237 JsValueList params;
236 params.push_back(result); 238 params.push_back(result);
237 callback->Call(params); 239 callback->Call(params);
238 } 240 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj) 354 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj)
353 { 355 {
354 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback)); 356 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback));
355 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback)); 357 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback));
356 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback)); 358 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback));
357 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback)); 359 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback));
358 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback)); 360 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback));
359 obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback)); 361 obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback));
360 return obj; 362 return obj;
361 } 363 }
OLDNEW
« no previous file with comments | « include/AdblockPlus/JsValue.h ('k') | src/FilterEngine.cpp » ('j') | src/JsValue.cpp » ('J')

Powered by Google App Engine
This is Rietveld