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

Side by Side Diff: src/FileSystemJsObject.cpp

Issue 29367507: Issue #3595 - Add an actual scheduler; use joined threads for file system
Patch Set: Created Dec. 14, 2016, 5:38 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 251
252 v8::Isolate* isolate = arguments.GetIsolate(); 252 v8::Isolate* isolate = arguments.GetIsolate();
253 if (converted.size() != 2) 253 if (converted.size() != 2)
254 return v8::ThrowException(Utils::ToV8String(isolate, 254 return v8::ThrowException(Utils::ToV8String(isolate,
255 "_fileSystem.read requires 2 parameters")); 255 "_fileSystem.read requires 2 parameters"));
256 if (!converted[1]->IsFunction()) 256 if (!converted[1]->IsFunction())
257 return v8::ThrowException(Utils::ToV8String(isolate, 257 return v8::ThrowException(Utils::ToV8String(isolate,
258 "Second argument to _fileSystem.read must be a function")); 258 "Second argument to _fileSystem.read must be a function"));
259 const auto readTask = std::make_shared<ReadTask>(jsEngine, converted[1], 259 const auto readTask = std::make_shared<ReadTask>(jsEngine, converted[1],
260 converted[0]->AsString()); 260 converted[0]->AsString());
261 AdblockPlus::Scheduler::StartImmediatelyInSingleUseThread(AdblockPlus::MakeH eapFunction(readTask)); 261 jsEngine->Schedule(AdblockPlus::MakeHeapFunction(readTask), AdblockPlus::Imm ediateSingleUseThread);
262 return v8::Undefined(); 262 return v8::Undefined();
263 } 263 }
264 264
265 v8::Handle<v8::Value> WriteCallback(const v8::Arguments& arguments) 265 v8::Handle<v8::Value> WriteCallback(const v8::Arguments& arguments)
266 { 266 {
267 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 267 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
268 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 268 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
269 269
270 v8::Isolate* isolate = arguments.GetIsolate(); 270 v8::Isolate* isolate = arguments.GetIsolate();
271 if (converted.size() != 3) 271 if (converted.size() != 3)
272 return v8::ThrowException(Utils::ToV8String(isolate, 272 return v8::ThrowException(Utils::ToV8String(isolate,
273 "_fileSystem.write requires 3 parameters")); 273 "_fileSystem.write requires 3 parameters"));
274 if (!converted[2]->IsFunction()) 274 if (!converted[2]->IsFunction())
275 return v8::ThrowException(Utils::ToV8String(isolate, 275 return v8::ThrowException(Utils::ToV8String(isolate,
276 "Third argument to _fileSystem.write must be a function")); 276 "Third argument to _fileSystem.write must be a function"));
277 const auto writeTask = std::make_shared<WriteTask>(jsEngine, converted[2], 277 const auto writeTask = std::make_shared<WriteTask>(jsEngine, converted[2],
278 converted[0]->AsString(), converted[1]->AsString()); 278 converted[0]->AsString(), converted[1]->AsString());
279 AdblockPlus::Scheduler::StartImmediatelyInSingleUseThread(AdblockPlus::MakeH eapFunction(writeTask)); 279 jsEngine->Schedule(AdblockPlus::MakeHeapFunction(writeTask), AdblockPlus::Im mediateSingleUseThread);
280 return v8::Undefined(); 280 return v8::Undefined();
281 } 281 }
282 282
283 v8::Handle<v8::Value> MoveCallback(const v8::Arguments& arguments) 283 v8::Handle<v8::Value> MoveCallback(const v8::Arguments& arguments)
284 { 284 {
285 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 285 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
286 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 286 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
287 287
288 v8::Isolate* isolate = arguments.GetIsolate(); 288 v8::Isolate* isolate = arguments.GetIsolate();
289 if (converted.size() != 3) 289 if (converted.size() != 3)
290 return v8::ThrowException(Utils::ToV8String(isolate, 290 return v8::ThrowException(Utils::ToV8String(isolate,
291 "_fileSystem.move requires 3 parameters")); 291 "_fileSystem.move requires 3 parameters"));
292 if (!converted[2]->IsFunction()) 292 if (!converted[2]->IsFunction())
293 return v8::ThrowException(Utils::ToV8String(isolate, 293 return v8::ThrowException(Utils::ToV8String(isolate,
294 "Third argument to _fileSystem.move must be a function")); 294 "Third argument to _fileSystem.move must be a function"));
295 const auto moveTask = std::make_shared<MoveTask>(jsEngine, converted[2], 295 const auto moveTask = std::make_shared<MoveTask>(jsEngine, converted[2],
296 converted[0]->AsString(), converted[1]->AsString()); 296 converted[0]->AsString(), converted[1]->AsString());
297 AdblockPlus::Scheduler::StartImmediatelyInSingleUseThread(AdblockPlus::MakeH eapFunction(moveTask)); 297 jsEngine->Schedule(AdblockPlus::MakeHeapFunction(moveTask), AdblockPlus::Imm ediateSingleUseThread);
298 return v8::Undefined(); 298 return v8::Undefined();
299 } 299 }
300 300
301 v8::Handle<v8::Value> RemoveCallback(const v8::Arguments& arguments) 301 v8::Handle<v8::Value> RemoveCallback(const v8::Arguments& arguments)
302 { 302 {
303 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 303 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
304 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 304 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
305 305
306 v8::Isolate* isolate = arguments.GetIsolate(); 306 v8::Isolate* isolate = arguments.GetIsolate();
307 if (converted.size() != 2) 307 if (converted.size() != 2)
308 return v8::ThrowException(Utils::ToV8String(isolate, 308 return v8::ThrowException(Utils::ToV8String(isolate,
309 "_fileSystem.remove requires 2 parameters")); 309 "_fileSystem.remove requires 2 parameters"));
310 if (!converted[1]->IsFunction()) 310 if (!converted[1]->IsFunction())
311 return v8::ThrowException(Utils::ToV8String(isolate, 311 return v8::ThrowException(Utils::ToV8String(isolate,
312 "Second argument to _fileSystem.remove must be a function")); 312 "Second argument to _fileSystem.remove must be a function"));
313 const auto removeTask = std::make_shared<RemoveTask>(jsEngine, converted[1], 313 const auto removeTask = std::make_shared<RemoveTask>(jsEngine, converted[1],
314 converted[0]->AsString()); 314 converted[0]->AsString());
315 AdblockPlus::Scheduler::StartImmediatelyInSingleUseThread(AdblockPlus::MakeH eapFunction(removeTask)); 315 jsEngine->Schedule(AdblockPlus::MakeHeapFunction(removeTask), AdblockPlus::I mmediateSingleUseThread);
316 return v8::Undefined(); 316 return v8::Undefined();
317 } 317 }
318 318
319 v8::Handle<v8::Value> StatCallback(const v8::Arguments& arguments) 319 v8::Handle<v8::Value> StatCallback(const v8::Arguments& arguments)
320 { 320 {
321 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 321 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
322 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 322 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
323 323
324 v8::Isolate* isolate = arguments.GetIsolate(); 324 v8::Isolate* isolate = arguments.GetIsolate();
325 if (converted.size() != 2) 325 if (converted.size() != 2)
326 return v8::ThrowException(Utils::ToV8String(isolate, 326 return v8::ThrowException(Utils::ToV8String(isolate,
327 "_fileSystem.stat requires 2 parameters")); 327 "_fileSystem.stat requires 2 parameters"));
328 if (!converted[1]->IsFunction()) 328 if (!converted[1]->IsFunction())
329 return v8::ThrowException(Utils::ToV8String(isolate, 329 return v8::ThrowException(Utils::ToV8String(isolate,
330 "Second argument to _fileSystem.stat must be a function")); 330 "Second argument to _fileSystem.stat must be a function"));
331 const auto statTask = std::make_shared<StatTask>(jsEngine, converted[1], 331 const auto statTask = std::make_shared<StatTask>(jsEngine, converted[1],
332 converted[0]->AsString()); 332 converted[0]->AsString());
333 AdblockPlus::Scheduler::StartImmediatelyInSingleUseThread(AdblockPlus::MakeH eapFunction(statTask)); 333 jsEngine->Schedule(AdblockPlus::MakeHeapFunction(statTask), AdblockPlus::Imm ediateSingleUseThread);
334 return v8::Undefined(); 334 return v8::Undefined();
335 } 335 }
336 336
337 v8::Handle<v8::Value> ResolveCallback(const v8::Arguments& arguments) 337 v8::Handle<v8::Value> ResolveCallback(const v8::Arguments& arguments)
338 { 338 {
339 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 339 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
340 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 340 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
341 341
342 v8::Isolate* isolate = arguments.GetIsolate(); 342 v8::Isolate* isolate = arguments.GetIsolate();
343 if (converted.size() != 1) 343 if (converted.size() != 1)
(...skipping 11 matching lines...) Expand all
355 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj) 355 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj)
356 { 356 {
357 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback)); 357 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback));
358 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback)); 358 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback));
359 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback)); 359 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback));
360 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback)); 360 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback));
361 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback)); 361 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback));
362 obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback)); 362 obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback));
363 return obj; 363 return obj;
364 } 364 }
OLDNEW

Powered by Google App Engine
This is Rietveld