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

Side by Side Diff: src/JsEngine.cpp

Issue 29499621: Issue 4983 - Get rid of Sleep() in the WebRequest test (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created July 27, 2017, 10:18 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
« no previous file with comments | « src/DefaultWebRequest.cpp ('k') | test/WebRequest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 v8::Platform* platform; 65 v8::Platform* platform;
66 public: 66 public:
67 static void Init() 67 static void Init()
68 { 68 {
69 // it's threadsafe since C++11 and it will be instantiated only once and 69 // it's threadsafe since C++11 and it will be instantiated only once and
70 // destroyed at the application exit 70 // destroyed at the application exit
71 static V8Initializer initializer; 71 static V8Initializer initializer;
72 } 72 }
73 }; 73 };
74
75 void DummyScheduler(const AdblockPlus::SchedulerTask& task)
76 {
77 std::thread(task).detach();
78 }
74 } 79 }
75 80
76 using namespace AdblockPlus; 81 using namespace AdblockPlus;
77 82
78 TimerPtr AdblockPlus::CreateDefaultTimer() 83 TimerPtr AdblockPlus::CreateDefaultTimer()
79 { 84 {
80 return TimerPtr(new DefaultTimer()); 85 return TimerPtr(new DefaultTimer());
81 } 86 }
82 87
83 FileSystemPtr AdblockPlus::CreateDefaultFileSystem() 88 FileSystemPtr AdblockPlus::CreateDefaultFileSystem()
84 { 89 {
85 return FileSystemPtr(new DefaultFileSystem(std::unique_ptr<DefaultFileSystemSy nc>(new DefaultFileSystemSync()))); 90 return FileSystemPtr(new DefaultFileSystem(std::unique_ptr<DefaultFileSystemSy nc>(new DefaultFileSystemSync())));
86 } 91 }
87 92
88 WebRequestPtr AdblockPlus::CreateDefaultWebRequest() 93 WebRequestPtr AdblockPlus::CreateDefaultWebRequest(const Scheduler& scheduler)
89 { 94 {
90 return WebRequestPtr(new DefaultWebRequest(std::unique_ptr<DefaultWebRequestSy nc>(new DefaultWebRequestSync()))); 95 return WebRequestPtr(new DefaultWebRequest(scheduler, std::unique_ptr<DefaultW ebRequestSync>(new DefaultWebRequestSync())));
91 } 96 }
92 97
93 LogSystemPtr AdblockPlus::CreateDefaultLogSystem() 98 LogSystemPtr AdblockPlus::CreateDefaultLogSystem()
94 { 99 {
95 return LogSystemPtr(new DefaultLogSystem()); 100 return LogSystemPtr(new DefaultLogSystem());
96 } 101 }
97 102
98 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate() 103 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate()
99 { 104 {
100 V8Initializer::Init(); 105 V8Initializer::Init();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 , webRequest(std::move(webRequest)) 161 , webRequest(std::move(webRequest))
157 , logSystem(std::move(logSystem)) 162 , logSystem(std::move(logSystem))
158 { 163 {
159 } 164 }
160 165
161 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, 166 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo,
162 TimerPtr timer, FileSystemPtr fileSystem, WebRequestPtr webRequest, LogSystemP tr logSystem) 167 TimerPtr timer, FileSystemPtr fileSystem, WebRequestPtr webRequest, LogSystemP tr logSystem)
163 { 168 {
164 JsEnginePtr result(new JsEngine(timer ? std::move(timer) : CreateDefaultTimer( ), 169 JsEnginePtr result(new JsEngine(timer ? std::move(timer) : CreateDefaultTimer( ),
165 fileSystem ? std::move(fileSystem) : CreateDefaultFileSystem(), 170 fileSystem ? std::move(fileSystem) : CreateDefaultFileSystem(),
166 webRequest ? std::move(webRequest) : CreateDefaultWebRequest(), 171 webRequest ? std::move(webRequest) : CreateDefaultWebRequest(::DummySchedule r),
167 logSystem ? std::move(logSystem) : CreateDefaultLogSystem())); 172 logSystem ? std::move(logSystem) : CreateDefaultLogSystem()));
168 173
169 const v8::Locker locker(result->GetIsolate()); 174 const v8::Locker locker(result->GetIsolate());
170 const v8::Isolate::Scope isolateScope(result->GetIsolate()); 175 const v8::Isolate::Scope isolateScope(result->GetIsolate());
171 const v8::HandleScope handleScope(result->GetIsolate()); 176 const v8::HandleScope handleScope(result->GetIsolate());
172 177
173 result->context.reset(new v8::Global<v8::Context>(result->GetIsolate(), 178 result->context.reset(new v8::Global<v8::Context>(result->GetIsolate(),
174 v8::Context::New(result->GetIsolate()))); 179 v8::Context::New(result->GetIsolate())));
175 auto global = result->GetGlobalObject(); 180 auto global = result->GetGlobalObject();
176 AdblockPlus::GlobalJsObject::Setup(*result, appInfo, global); 181 AdblockPlus::GlobalJsObject::Setup(*result, appInfo, global);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 { 341 {
337 return *logSystem; 342 return *logSystem;
338 } 343 }
339 344
340 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, 345 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
341 const AdblockPlus::JsValue& value) 346 const AdblockPlus::JsValue& value)
342 { 347 {
343 auto global = GetGlobalObject(); 348 auto global = GetGlobalObject();
344 global.SetProperty(name, value); 349 global.SetProperty(name, value);
345 } 350 }
OLDNEW
« no previous file with comments | « src/DefaultWebRequest.cpp ('k') | test/WebRequest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld