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

Delta Between Two Patch Sets: src/JsValue.cpp

Issue 29361562: Issue 3594 - remove circular references JsEngine-JsValue-JsEngine (Closed)
Left Patch Set: address comments Created Nov. 25, 2016, 12:02 p.m.
Right Patch Set: temporary workaround for race condition Created Dec. 1, 2016, 10:26 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/JsContext.cpp ('k') | src/Notification.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 <vector> 18 #include <vector>
19 #include <AdblockPlus.h> 19 #include <AdblockPlus.h>
20 20
21 #include "JsContext.h" 21 #include "JsContext.h"
22 #include "JsError.h" 22 #include "JsError.h"
23 #include "Utils.h" 23 #include "Utils.h"
24 24
25 AdblockPlus::JsValue::JsValue(const std::weak_ptr<AdblockPlus::JsEngine>& jsEngi ne, 25 AdblockPlus::JsValue::JsValue(const std::weak_ptr<AdblockPlus::JsEngine>& jsEngi ne,
26 v8::Handle<v8::Value> value) 26 v8::Handle<v8::Value> value)
27 : jsEngine(jsEngine) 27 : jsEngine(jsEngine)
28 , value(new v8::Persistent<v8::Value>(Utils::lockJsEngine(jsEngine)->GetIsolat e(), value)) 28 , value(new v8::Persistent<v8::Value>(Utils::lockJsEngine(jsEngine)->GetIsolat e(), value))
Eric 2016/11/28 14:21:13 This use of 'lockJsEngine' has a race condition. T
sergei 2016/11/29 10:45:18 lockJsEngine returns an object not a reference or
29 { 29 {
30 } 30 }
31 31
32 AdblockPlus::JsValue::JsValue(AdblockPlus::JsValue&& src) 32 AdblockPlus::JsValue::JsValue(AdblockPlus::JsValue&& src)
33 : jsEngine(move(src.jsEngine)), 33 : jsEngine(std::move(src.jsEngine)),
34 value(std::move(src.value)) 34 value(std::move(src.value))
Eric 2016/11/28 14:21:13 For consistency, this should either be (1) `std::m
sergei 2016/11/29 10:45:19 I have added std:: rather for aesthetic view than
35 { 35 {
36 } 36 }
37 37
38 AdblockPlus::JsValue::~JsValue() 38 AdblockPlus::JsValue::~JsValue()
39 { 39 {
40 try 40 try
41 { 41 {
42 JsContext context(jsEngine); 42 JsContext context(jsEngine);
sergei 2016/12/01 22:24:37 Although I have not seen a crash on practice there
43 if (value) 43 if (value)
44 { 44 {
45 value->Dispose(); 45 value->Dispose();
46 value.reset(); 46 value.reset();
47 } 47 }
48 } 48 }
49 catch (const JsEngine::JsEngineNotAvailableException&) 49 catch (const JsEngine::JsEngineNotAvailableException&)
50 { 50 {
51 } 51 }
52 } 52 }
Eric 2016/11/28 14:21:14 It's excessive to instantiate a `JsContext` object
sergei 2016/11/29 10:45:18 JsContext is not only to ensure that JsEngine is s
53 53
54 bool AdblockPlus::JsValue::IsUndefined() const 54 bool AdblockPlus::JsValue::IsUndefined() const
55 { 55 {
56 JsContext context(jsEngine); 56 JsContext context(jsEngine);
57 return UnwrapValue(context.GetJsEngine())->IsUndefined(); 57 return UnwrapValue(context.GetJsEngine())->IsUndefined();
58 } 58 }
59 59
60 bool AdblockPlus::JsValue::IsNull() const 60 bool AdblockPlus::JsValue::IsNull() const
61 { 61 {
62 JsContext context(jsEngine); 62 JsContext context(jsEngine);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 return JsValuePtr(new JsValue(jsEngine, result)); 244 return JsValuePtr(new JsValue(jsEngine, result));
245 } 245 }
246 246
247 AdblockPlus::JsValuePtr AdblockPlus::JsValue::Call(const JsValue& arg) const 247 AdblockPlus::JsValuePtr AdblockPlus::JsValue::Call(const JsValue& arg) const
248 { 248 {
249 JsContext context(jsEngine); 249 JsContext context(jsEngine);
250 JsValueList params; 250 JsValueList params;
251 params.push_back(JsValuePtr(new JsValue(arg.jsEngine, arg.UnwrapValue(context. GetJsEngine())))); 251 params.push_back(JsValuePtr(new JsValue(arg.jsEngine, arg.UnwrapValue(context. GetJsEngine()))));
252 return Call(params); 252 return Call(params);
253 } 253 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld