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

Powered by Google App Engine
This is Rietveld