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

Side by Side Diff: src/JsValue.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/JsEngine.cpp ('k') | src/Value.h » ('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
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 const JsContext context(jsEngine); 89 const JsContext context(jsEngine);
90 return UnwrapValue()->IsArray(); 90 return UnwrapValue()->IsArray();
91 } 91 }
92 92
93 bool AdblockPlus::JsValue::IsFunction() const 93 bool AdblockPlus::JsValue::IsFunction() const
94 { 94 {
95 const JsContext context(jsEngine); 95 const JsContext context(jsEngine);
96 return UnwrapValue()->IsFunction(); 96 return UnwrapValue()->IsFunction();
97 } 97 }
98 98
99 std::tuple<bool, std::string> ConvertString(v8::Local<v8::Value> v8value)
100 {
101 if (!(v8value->IsString() || v8value->IsStringObject()))
102 {
103 return std::make_tuple(false, std::string());
104 }
105 return std::make_tuple(true, AdblockPlus::Utils::FromV8String(v8value));
106 }
107
99 std::string AdblockPlus::JsValue::AsString() const 108 std::string AdblockPlus::JsValue::AsString() const
100 { 109 {
101 const JsContext context(jsEngine); 110 const JsContext context(jsEngine);
102 return Utils::FromV8String(UnwrapValue()); 111 return Utils::FromV8String(UnwrapValue());
103 } 112 }
104 113
105 int64_t AdblockPlus::JsValue::AsInt() const 114 int64_t AdblockPlus::JsValue::AsInt() const
106 { 115 {
107 const JsContext context(jsEngine); 116 const JsContext context(jsEngine);
108 return UnwrapValue()->IntegerValue(); 117 return UnwrapValue()->IntegerValue();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 void AdblockPlus::JsValue::SetProperty(const std::string& name, v8::Handle<v8::V alue> val) 169 void AdblockPlus::JsValue::SetProperty(const std::string& name, v8::Handle<v8::V alue> val)
161 { 170 {
162 if (!IsObject()) 171 if (!IsObject())
163 throw new std::runtime_error("Attempting to set property on a non-object"); 172 throw new std::runtime_error("Attempting to set property on a non-object");
164 173
165 v8::Local<v8::String> property = Utils::ToV8String(jsEngine->GetIsolate(), nam e); 174 v8::Local<v8::String> property = Utils::ToV8String(jsEngine->GetIsolate(), nam e);
166 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); 175 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue());
167 obj->Set(property, val); 176 obj->Set(property, val);
168 } 177 }
169 178
179 void SetPropertyOnV8Object(v8::Isolate* isolate, v8::Local<v8::Object>& target, const std::string& propertyName, const v8::Handle<v8::Value>& propertyValue)
180 {
181 auto v8PropertyName = AdblockPlus::Utils::ToV8String(isolate, propertyName);
182 target->Set(v8PropertyName, propertyValue);
183 }
184
170 v8::Local<v8::Value> AdblockPlus::JsValue::UnwrapValue() const 185 v8::Local<v8::Value> AdblockPlus::JsValue::UnwrapValue() const
171 { 186 {
172 return v8::Local<v8::Value>::New(jsEngine->GetIsolate(), *value); 187 return v8::Local<v8::Value>::New(jsEngine->GetIsolate(), *value);
173 } 188 }
174 189
175 void AdblockPlus::JsValue::SetProperty(const std::string& name, const std::strin g& val) 190 void AdblockPlus::JsValue::SetProperty(const std::string& name, const std::strin g& val)
176 { 191 {
177 const JsContext context(jsEngine); 192 const JsContext context(jsEngine);
178 SetProperty(name, Utils::ToV8String(jsEngine->GetIsolate(), val)); 193 SetProperty(name, Utils::ToV8String(jsEngine->GetIsolate(), val));
179 } 194 }
180 195
196 void SetPropertyOnV8Object(v8::Isolate* isolate, v8::Local<v8::Object>& target, const std::string& propertyName, const std::string& propertyValue)
197 {
198 SetPropertyOnV8Object(isolate, target, propertyName, AdblockPlus::Utils::ToV8S tring(isolate, propertyValue));
199 }
200
181 void AdblockPlus::JsValue::SetProperty(const std::string& name, int64_t val) 201 void AdblockPlus::JsValue::SetProperty(const std::string& name, int64_t val)
182 { 202 {
183 const JsContext context(jsEngine); 203 const JsContext context(jsEngine);
184 SetProperty(name, v8::Number::New(jsEngine->GetIsolate(), val)); 204 SetProperty(name, v8::Number::New(jsEngine->GetIsolate(), val));
185 } 205 }
186 206
207 void SetPropertyOnV8Object(v8::Isolate* isolate, v8::Local<v8::Object>& target, const std::string& propertyName, int64_t propertyValue)
208 {
209 SetPropertyOnV8Object(isolate, target, propertyName, v8::Number::New(isolate, propertyValue));
210 }
211
187 void AdblockPlus::JsValue::SetProperty(const std::string& name, const JsValuePtr & val) 212 void AdblockPlus::JsValue::SetProperty(const std::string& name, const JsValuePtr & val)
188 { 213 {
189 const JsContext context(jsEngine); 214 const JsContext context(jsEngine);
190 SetProperty(name, val->UnwrapValue()); 215 SetProperty(name, val->UnwrapValue());
191 } 216 }
192 217
193 void AdblockPlus::JsValue::SetProperty(const std::string& name, bool val) 218 void AdblockPlus::JsValue::SetProperty(const std::string& name, bool val)
194 { 219 {
195 const JsContext context(jsEngine); 220 const JsContext context(jsEngine);
196 SetProperty(name, v8::Boolean::New(val)); 221 SetProperty(name, v8::Boolean::New(val));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 return JsValuePtr(new JsValue(jsEngine, result)); 260 return JsValuePtr(new JsValue(jsEngine, result));
236 } 261 }
237 262
238 AdblockPlus::JsValuePtr AdblockPlus::JsValue::Call(const JsValue& arg) const 263 AdblockPlus::JsValuePtr AdblockPlus::JsValue::Call(const JsValue& arg) const
239 { 264 {
240 const JsContext context(jsEngine); 265 const JsContext context(jsEngine);
241 JsValueList params; 266 JsValueList params;
242 params.push_back(JsValuePtr(new JsValue(arg.jsEngine, arg.UnwrapValue()))); 267 params.push_back(JsValuePtr(new JsValue(arg.jsEngine, arg.UnwrapValue())));
243 return Call(params); 268 return Call(params);
244 } 269 }
OLDNEW
« no previous file with comments | « src/JsEngine.cpp ('k') | src/Value.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld