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

Side by Side Diff: src/JsEngine.cpp

Issue 29369520: Issue #4692 - Rewrite web request task to avoid engine self-reference
Patch Set: Created Dec. 24, 2016, 4:58 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
« no previous file with comments | « src/GlobalJsObject.cpp ('k') | src/JsValue.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-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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <AdblockPlus.h> 18 #include <AdblockPlus.h>
19 #include "GlobalJsObject.h" 19 #include "GlobalJsObject.h"
20 #include "JsContext.h" 20 #include "JsContext.h"
21 #include "JsEngineInternal.h" 21 #include "JsEngineInternal.h"
22 #include "JsEngineTransition.h" 22 #include "JsEngineTransition.h"
23 #include "JsError.h" 23 #include "JsError.h"
24 #include "Scheduler.h" 24 #include "Scheduler.h"
25 #include "Utils.h" 25 #include "Utils.h"
26 #include "WebRequestJsObject.h"
26 27
27 const AdblockPlus::ImmediateSingleUseThreadType AdblockPlus::ImmediateSingleUseT hread = {}; 28 const AdblockPlus::ImmediateSingleUseThreadType AdblockPlus::ImmediateSingleUseT hread = {};
28 29
29 class AdblockPlus::JsEngine::SchedulerImpl 30 class AdblockPlus::JsEngine::SchedulerImpl
30 : public SchedulerT<SingleUseWorker> 31 : public SchedulerT<SingleUseWorker>
31 { 32 {
32 public: 33 public:
33 SchedulerImpl() {} // = default; 34 SchedulerImpl() {} // = default;
34 }; 35 };
35 36
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 103
103 JsEngineInternal::JsEngineInternal(const AdblockPlus::ScopedV8IsolatePtr& isolat e) 104 JsEngineInternal::JsEngineInternal(const AdblockPlus::ScopedV8IsolatePtr& isolat e)
104 : AdblockPlus::JsEngine(isolate), 105 : AdblockPlus::JsEngine(isolate),
105 context(isolate->Get(),v8::Context::New(isolate->Get())) 106 context(isolate->Get(),v8::Context::New(isolate->Get()))
106 { 107 {
107 /* 108 /*
108 * Enter v8 scope for our context so that we can initialize its global object. 109 * Enter v8 scope for our context so that we can initialize its global object.
109 */ 110 */
110 const v8::Context::Scope contextScope(GetContextAsLocal()); 111 const v8::Context::Scope contextScope(GetContextAsLocal());
111 auto globalObject = GetGlobalObject(); 112 auto globalObject = GetGlobalObject();
113 // Timeout
112 auto propertyName = AdblockPlus::Utils::ToV8String(GetIsolate(), "setTimeout") ; 114 auto propertyName = AdblockPlus::Utils::ToV8String(GetIsolate(), "setTimeout") ;
113 globalObject->Set(propertyName, MakeCallback(::CallbackForSetTimeout)); 115 globalObject->Set(propertyName, MakeCallback(::CallbackForSetTimeout));
116 // Web request
117 auto auxiliaryObject = v8::Object::New();
118 propertyName = AdblockPlus::Utils::ToV8String(GetIsolate(), "GET");
119 auxiliaryObject->Set(propertyName, MakeCallback(::GETCallback));
120 propertyName = AdblockPlus::Utils::ToV8String(GetIsolate(), "_webRequest");
121 globalObject->Set(propertyName, auxiliaryObject);
114 // TODO: Move the rest of the global object initializations here 122 // TODO: Move the rest of the global object initializations here
115 } 123 }
116 124
117 /** 125 /**
118 * \par Design Notes 126 * \par Design Notes
119 * It is technically necessary to construct JsEngine instances *only* within a f actory. 127 * It is technically necessary to construct JsEngine instances *only* within a f actory.
120 * Initialization requires that certain transient v8 scopes be set up 128 * Initialization requires that certain transient v8 scopes be set up
121 * before initialization and torn down afterwards. 129 * before initialization and torn down afterwards.
122 * C++ has no syntax to use anything like a sentry object in the constructor its elf. 130 * C++ has no syntax to use anything like a sentry object in the constructor its elf.
123 * Thus we need to establish v8 scope within every C++ scope that constructs an object. 131 * Thus we need to establish v8 scope within every C++ scope that constructs an object.
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 384
377 JsEngineInternal* ToInternal(AdblockPlus::JsEnginePtr p) 385 JsEngineInternal* ToInternal(AdblockPlus::JsEnginePtr p)
378 { 386 {
379 return static_cast<JsEngineInternal*>(p.get()); 387 return static_cast<JsEngineInternal*>(p.get());
380 } 388 }
381 389
382 JsEngineInternal* ToInternal(AdblockPlus::JsEngine* p) 390 JsEngineInternal* ToInternal(AdblockPlus::JsEngine* p)
383 { 391 {
384 return static_cast<JsEngineInternal*>(p); 392 return static_cast<JsEngineInternal*>(p);
385 } 393 }
OLDNEW
« no previous file with comments | « src/GlobalJsObject.cpp ('k') | src/JsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld