OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 catch (std::exception& e) | 66 catch (std::exception& e) |
67 { | 67 { |
68 error = e.what(); | 68 error = e.what(); |
69 } | 69 } |
70 catch (...) | 70 catch (...) |
71 { | 71 { |
72 error = "Unknown error while reading from " + path; | 72 error = "Unknown error while reading from " + path; |
73 } | 73 } |
74 | 74 |
75 const JsContext context(jsEngine); | 75 const JsContext context{*jsEngine}; |
76 JsValuePtr result = jsEngine->NewObject(); | 76 JsValuePtr result = jsEngine->NewObject(); |
77 result->SetProperty("content", content); | 77 result->SetProperty("content", content); |
78 result->SetProperty("error", error); | 78 result->SetProperty("error", error); |
79 JsValueList params; | 79 JsValueList params; |
80 params.push_back(result); | 80 params.push_back(result); |
81 callback->Call(params); | 81 callback->Call(params); |
82 delete this; | 82 delete this; |
83 } | 83 } |
84 | 84 |
85 private: | 85 private: |
(...skipping 20 matching lines...) Expand all Loading... |
106 } | 106 } |
107 catch (std::exception& e) | 107 catch (std::exception& e) |
108 { | 108 { |
109 error = e.what(); | 109 error = e.what(); |
110 } | 110 } |
111 catch (...) | 111 catch (...) |
112 { | 112 { |
113 error = "Unknown error while writing to " + path; | 113 error = "Unknown error while writing to " + path; |
114 } | 114 } |
115 | 115 |
116 const JsContext context(jsEngine); | 116 const JsContext context{*jsEngine}; |
117 JsValuePtr errorValue = jsEngine->NewValue(error); | 117 JsValuePtr errorValue = jsEngine->NewValue(error); |
118 JsValueList params; | 118 JsValueList params; |
119 params.push_back(errorValue); | 119 params.push_back(errorValue); |
120 callback->Call(params); | 120 callback->Call(params); |
121 delete this; | 121 delete this; |
122 } | 122 } |
123 | 123 |
124 private: | 124 private: |
125 std::string path; | 125 std::string path; |
126 std::string content; | 126 std::string content; |
(...skipping 17 matching lines...) Expand all Loading... |
144 } | 144 } |
145 catch (std::exception& e) | 145 catch (std::exception& e) |
146 { | 146 { |
147 error = e.what(); | 147 error = e.what(); |
148 } | 148 } |
149 catch (...) | 149 catch (...) |
150 { | 150 { |
151 error = "Unknown error while moving " + fromPath + " to " + toPath; | 151 error = "Unknown error while moving " + fromPath + " to " + toPath; |
152 } | 152 } |
153 | 153 |
154 const JsContext context(jsEngine); | 154 const JsContext context{*jsEngine}; |
155 JsValuePtr errorValue = jsEngine->NewValue(error); | 155 JsValuePtr errorValue = jsEngine->NewValue(error); |
156 JsValueList params; | 156 JsValueList params; |
157 params.push_back(errorValue); | 157 params.push_back(errorValue); |
158 callback->Call(params); | 158 callback->Call(params); |
159 delete this; | 159 delete this; |
160 } | 160 } |
161 | 161 |
162 private: | 162 private: |
163 std::string fromPath; | 163 std::string fromPath; |
164 std::string toPath; | 164 std::string toPath; |
(...skipping 17 matching lines...) Expand all Loading... |
182 } | 182 } |
183 catch (std::exception& e) | 183 catch (std::exception& e) |
184 { | 184 { |
185 error = e.what(); | 185 error = e.what(); |
186 } | 186 } |
187 catch (...) | 187 catch (...) |
188 { | 188 { |
189 error = "Unknown error while removing " + path; | 189 error = "Unknown error while removing " + path; |
190 } | 190 } |
191 | 191 |
192 const JsContext context(jsEngine); | 192 const JsContext context{*jsEngine}; |
193 JsValuePtr errorValue = jsEngine->NewValue(error); | 193 JsValuePtr errorValue = jsEngine->NewValue(error); |
194 JsValueList params; | 194 JsValueList params; |
195 params.push_back(errorValue); | 195 params.push_back(errorValue); |
196 callback->Call(params); | 196 callback->Call(params); |
197 delete this; | 197 delete this; |
198 } | 198 } |
199 | 199 |
200 private: | 200 private: |
201 std::string path; | 201 std::string path; |
202 }; | 202 }; |
(...skipping 18 matching lines...) Expand all Loading... |
221 } | 221 } |
222 catch (std::exception& e) | 222 catch (std::exception& e) |
223 { | 223 { |
224 error = e.what(); | 224 error = e.what(); |
225 } | 225 } |
226 catch (...) | 226 catch (...) |
227 { | 227 { |
228 error = "Unknown error while calling stat on " + path; | 228 error = "Unknown error while calling stat on " + path; |
229 } | 229 } |
230 | 230 |
231 const JsContext context(jsEngine); | 231 const JsContext context{*jsEngine}; |
232 JsValuePtr result = jsEngine->NewObject(); | 232 JsValuePtr result = jsEngine->NewObject(); |
233 result->SetProperty("exists", statResult.exists); | 233 result->SetProperty("exists", statResult.exists); |
234 result->SetProperty("isFile", statResult.isFile); | 234 result->SetProperty("isFile", statResult.isFile); |
235 result->SetProperty("isDirectory", statResult.isDirectory); | 235 result->SetProperty("isDirectory", statResult.isDirectory); |
236 result->SetProperty("lastModified", statResult.lastModified); | 236 result->SetProperty("lastModified", statResult.lastModified); |
237 result->SetProperty("error", error); | 237 result->SetProperty("error", error); |
238 | 238 |
239 JsValueList params; | 239 JsValueList params; |
240 params.push_back(result); | 240 params.push_back(result); |
241 callback->Call(params); | 241 callback->Call(params); |
242 delete this; | 242 delete this; |
243 } | 243 } |
244 | 244 |
245 private: | 245 private: |
246 std::string path; | 246 std::string path; |
247 }; | 247 }; |
248 | 248 |
249 v8::Handle<v8::Value> ReadCallback(const v8::Arguments& arguments) | 249 void ReadCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
250 { | 250 { |
251 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
uments); | 251 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(inf
o); |
252 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 252 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(info); |
253 | 253 |
| 254 auto isolate = info.GetIsolate(); |
254 if (converted.size() != 2) | 255 if (converted.size() != 2) |
255 return v8::ThrowException(v8::String::New( | 256 { |
| 257 isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate, |
256 "_fileSystem.read requires 2 parameters")); | 258 "_fileSystem.read requires 2 parameters")); |
| 259 return; |
| 260 } |
257 if (!converted[1]->IsFunction()) | 261 if (!converted[1]->IsFunction()) |
258 return v8::ThrowException(v8::String::New( | 262 { |
| 263 isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate, |
259 "Second argument to _fileSystem.read must be a function")); | 264 "Second argument to _fileSystem.read must be a function")); |
| 265 return; |
| 266 } |
260 ReadThread* const readThread = new ReadThread(jsEngine, converted[1], | 267 ReadThread* const readThread = new ReadThread(jsEngine, converted[1], |
261 converted[0]->AsString()); | 268 converted[0]->AsString()); |
262 readThread->Start(); | 269 readThread->Start(); |
263 return v8::Undefined(); | |
264 } | 270 } |
265 | 271 |
266 v8::Handle<v8::Value> WriteCallback(const v8::Arguments& arguments) | 272 void WriteCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
267 { | 273 { |
268 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
uments); | 274 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(inf
o); |
269 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 275 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(info); |
270 | 276 |
| 277 auto isolate = info.GetIsolate(); |
271 if (converted.size() != 3) | 278 if (converted.size() != 3) |
272 return v8::ThrowException(v8::String::New( | 279 { |
| 280 isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate, |
273 "_fileSystem.write requires 3 parameters")); | 281 "_fileSystem.write requires 3 parameters")); |
| 282 return; |
| 283 } |
274 if (!converted[2]->IsFunction()) | 284 if (!converted[2]->IsFunction()) |
275 return v8::ThrowException(v8::String::New( | 285 { |
| 286 isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate, |
276 "Third argument to _fileSystem.write must be a function")); | 287 "Third argument to _fileSystem.write must be a function")); |
| 288 return; |
| 289 } |
277 WriteThread* const writeThread = new WriteThread(jsEngine, converted[2], | 290 WriteThread* const writeThread = new WriteThread(jsEngine, converted[2], |
278 converted[0]->AsString(), converted[1]->AsString()); | 291 converted[0]->AsString(), converted[1]->AsString()); |
279 writeThread->Start(); | 292 writeThread->Start(); |
280 return v8::Undefined(); | |
281 } | 293 } |
282 | 294 |
283 v8::Handle<v8::Value> MoveCallback(const v8::Arguments& arguments) | 295 void MoveCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
284 { | 296 { |
285 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
uments); | 297 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(inf
o); |
286 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 298 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(info); |
287 | 299 |
| 300 auto isolate = info.GetIsolate(); |
288 if (converted.size() != 3) | 301 if (converted.size() != 3) |
289 return v8::ThrowException(v8::String::New( | 302 { |
| 303 isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate, |
290 "_fileSystem.move requires 3 parameters")); | 304 "_fileSystem.move requires 3 parameters")); |
| 305 return; |
| 306 } |
| 307 |
291 if (!converted[2]->IsFunction()) | 308 if (!converted[2]->IsFunction()) |
292 return v8::ThrowException(v8::String::New( | 309 { |
| 310 isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate, |
293 "Third argument to _fileSystem.move must be a function")); | 311 "Third argument to _fileSystem.move must be a function")); |
| 312 return; |
| 313 } |
294 MoveThread* const moveThread = new MoveThread(jsEngine, converted[2], | 314 MoveThread* const moveThread = new MoveThread(jsEngine, converted[2], |
295 converted[0]->AsString(), converted[1]->AsString()); | 315 converted[0]->AsString(), converted[1]->AsString()); |
296 moveThread->Start(); | 316 moveThread->Start(); |
297 return v8::Undefined(); | |
298 } | 317 } |
299 | 318 |
300 v8::Handle<v8::Value> RemoveCallback(const v8::Arguments& arguments) | 319 void RemoveCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
301 { | 320 { |
302 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
uments); | 321 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(inf
o); |
303 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 322 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(info); |
304 | 323 |
| 324 auto isolate = info.GetIsolate(); |
305 if (converted.size() != 2) | 325 if (converted.size() != 2) |
306 return v8::ThrowException(v8::String::New( | 326 { |
| 327 isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate, |
307 "_fileSystem.remove requires 2 parameters")); | 328 "_fileSystem.remove requires 2 parameters")); |
| 329 return; |
| 330 } |
| 331 |
308 if (!converted[1]->IsFunction()) | 332 if (!converted[1]->IsFunction()) |
309 return v8::ThrowException(v8::String::New( | 333 { |
| 334 isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate, |
310 "Second argument to _fileSystem.remove must be a function")); | 335 "Second argument to _fileSystem.remove must be a function")); |
| 336 return; |
| 337 } |
311 RemoveThread* const removeThread = new RemoveThread(jsEngine, converted[1], | 338 RemoveThread* const removeThread = new RemoveThread(jsEngine, converted[1], |
312 converted[0]->AsString()); | 339 converted[0]->AsString()); |
313 removeThread->Start(); | 340 removeThread->Start(); |
314 return v8::Undefined(); | |
315 } | 341 } |
316 | 342 |
317 v8::Handle<v8::Value> StatCallback(const v8::Arguments& arguments) | 343 void StatCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
318 { | 344 { |
319 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
uments); | 345 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(inf
o); |
320 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 346 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(info); |
321 | 347 |
| 348 auto isolate = info.GetIsolate(); |
322 if (converted.size() != 2) | 349 if (converted.size() != 2) |
323 return v8::ThrowException(v8::String::New( | 350 { |
| 351 isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate, |
324 "_fileSystem.stat requires 2 parameters")); | 352 "_fileSystem.stat requires 2 parameters")); |
| 353 return; |
| 354 } |
| 355 |
325 if (!converted[1]->IsFunction()) | 356 if (!converted[1]->IsFunction()) |
326 return v8::ThrowException(v8::String::New( | 357 { |
| 358 isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate, |
327 "Second argument to _fileSystem.stat must be a function")); | 359 "Second argument to _fileSystem.stat must be a function")); |
| 360 return; |
| 361 } |
| 362 |
328 StatThread* const statThread = new StatThread(jsEngine, converted[1], | 363 StatThread* const statThread = new StatThread(jsEngine, converted[1], |
329 converted[0]->AsString()); | 364 converted[0]->AsString()); |
330 statThread->Start(); | 365 statThread->Start(); |
331 return v8::Undefined(); | |
332 } | 366 } |
333 | 367 |
334 v8::Handle<v8::Value> ResolveCallback(const v8::Arguments& arguments) | 368 void ResolveCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
335 { | 369 { |
336 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
uments); | 370 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(inf
o); |
337 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 371 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(info); |
338 | 372 |
| 373 auto isolate = info.GetIsolate(); |
339 if (converted.size() != 1) | 374 if (converted.size() != 1) |
340 return v8::ThrowException(v8::String::New( | 375 { |
| 376 isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate, |
341 "_fileSystem.resolve requires 1 parameter")); | 377 "_fileSystem.resolve requires 1 parameter")); |
| 378 return; |
| 379 } |
342 | 380 |
343 std::string resolved = jsEngine->GetFileSystem()->Resolve(converted[0]->AsSt
ring()); | 381 std::string resolved = jsEngine->GetFileSystem()->Resolve(converted[0]->AsSt
ring()); |
344 | 382 |
345 return Utils::ToV8String(arguments.GetIsolate(), resolved); | 383 info.GetReturnValue().Set(Utils::ToV8String(isolate, resolved)); |
346 } | 384 } |
347 | 385 |
348 } | 386 } |
349 | 387 |
350 | 388 |
351 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj) | 389 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj) |
352 { | 390 { |
353 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback)); | 391 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback)); |
354 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback)); | 392 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback)); |
355 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback)); | 393 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback)); |
356 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback)); | 394 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback)); |
357 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback)); | 395 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback)); |
358 obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback)); | 396 obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback)); |
359 return obj; | 397 return obj; |
360 } | 398 } |
OLD | NEW |