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

Delta Between Two Patch Sets: src/JsValue.cpp

Issue 29812649: Issue 6526 - *ToV8String() return MaybeLocal<> and check Call() return value (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Left Patch Set: Introduce CHECKED_TO_LOCAL_NOTHROW and use it. Created June 22, 2018, 3:49 p.m.
Right Patch Set: Wrap macro arguments in brackets. Created Aug. 6, 2018, 1:25 p.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/JsEngine.cpp ('k') | src/Utils.h » ('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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 177 }
178 178
179 179
180 AdblockPlus::JsValue AdblockPlus::JsValue::GetProperty(const std::string& name) const 180 AdblockPlus::JsValue AdblockPlus::JsValue::GetProperty(const std::string& name) const
181 { 181 {
182 if (!IsObject()) 182 if (!IsObject())
183 throw std::runtime_error("Attempting to get property of a non-object"); 183 throw std::runtime_error("Attempting to get property of a non-object");
184 184
185 const JsContext context(*jsEngine); 185 const JsContext context(*jsEngine);
186 auto isolate = jsEngine->GetIsolate(); 186 auto isolate = jsEngine->GetIsolate();
187 v8::Local<v8::String> property = CHECKED_TO_LOCAL_NOTHROW( 187 v8::Local<v8::String> property = CHECKED_TO_LOCAL(
188 isolate, Utils::ToV8String(isolate, name)); 188 isolate, Utils::ToV8String(isolate, name));
189 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); 189 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue());
190 return JsValue(jsEngine, CHECKED_TO_LOCAL_NOTHROW( 190 return JsValue(jsEngine, CHECKED_TO_LOCAL(
191 isolate, obj->Get(isolate->GetCurrentContext(), property))); 191 isolate, obj->Get(isolate->GetCurrentContext(), property)));
192 } 192 }
193 193
194 void AdblockPlus::JsValue::SetProperty(const std::string& name, v8::Local<v8::Va lue> val) 194 void AdblockPlus::JsValue::SetProperty(const std::string& name, v8::Local<v8::Va lue> val)
195 { 195 {
196 if (!IsObject()) 196 if (!IsObject())
197 throw std::runtime_error("Attempting to set property on a non-object"); 197 throw std::runtime_error("Attempting to set property on a non-object");
198 auto isolate = jsEngine->GetIsolate(); 198 auto isolate = jsEngine->GetIsolate();
199 199
200 v8::Local<v8::String> property = CHECKED_TO_LOCAL_NOTHROW( 200 v8::Local<v8::String> property = CHECKED_TO_LOCAL(
201 isolate, Utils::ToV8String(isolate, name)); 201 isolate, Utils::ToV8String(isolate, name));
202 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); 202 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue());
203 obj->Set(property, val); 203 obj->Set(property, val);
204 } 204 }
205 205
206 v8::Local<v8::Value> AdblockPlus::JsValue::UnwrapValue() const 206 v8::Local<v8::Value> AdblockPlus::JsValue::UnwrapValue() const
207 { 207 {
208 return v8::Local<v8::Value>::New(jsEngine->GetIsolate(), *value); 208 return v8::Local<v8::Value>::New(jsEngine->GetIsolate(), *value);
209 } 209 }
210 210
211 void AdblockPlus::JsValue::SetProperty(const std::string& name, const std::strin g& val) 211 void AdblockPlus::JsValue::SetProperty(const std::string& name, const std::strin g& val)
212 { 212 {
213 const JsContext context(*jsEngine); 213 const JsContext context(*jsEngine);
214 auto isolate = jsEngine->GetIsolate(); 214 auto isolate = jsEngine->GetIsolate();
215 215
216 SetProperty(name, CHECKED_TO_LOCAL_NOTHROW( 216 SetProperty(name, CHECKED_TO_LOCAL(
217 isolate, Utils::ToV8String(jsEngine->GetIsolate(), val))); 217 isolate, Utils::ToV8String(jsEngine->GetIsolate(), val)));
218 } 218 }
219 219
220 void AdblockPlus::JsValue::SetStringBufferProperty(const std::string& name, cons t StringBuffer& val) 220 void AdblockPlus::JsValue::SetStringBufferProperty(const std::string& name, cons t StringBuffer& val)
221 { 221 {
222 const JsContext context(*jsEngine); 222 const JsContext context(*jsEngine);
223 auto isolate = jsEngine->GetIsolate(); 223 auto isolate = jsEngine->GetIsolate();
224 224
225 SetProperty(name, CHECKED_TO_LOCAL_NOTHROW( 225 SetProperty(name, CHECKED_TO_LOCAL(
226 isolate, Utils::StringBufferToV8String(isolate, val))); 226 isolate, Utils::StringBufferToV8String(isolate, val)));
227 } 227 }
228 228
229 void AdblockPlus::JsValue::SetProperty(const std::string& name, int64_t val) 229 void AdblockPlus::JsValue::SetProperty(const std::string& name, int64_t val)
230 { 230 {
231 const JsContext context(*jsEngine); 231 const JsContext context(*jsEngine);
232 SetProperty(name, v8::Number::New(jsEngine->GetIsolate(), val)); 232 SetProperty(name, v8::Number::New(jsEngine->GetIsolate(), val));
233 } 233 }
234 234
235 void AdblockPlus::JsValue::SetProperty(const std::string& name, const JsValue& v al) 235 void AdblockPlus::JsValue::SetProperty(const std::string& name, const JsValue& v al)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 if (!IsFunction()) 291 if (!IsFunction())
292 throw std::runtime_error("Attempting to call a non-function"); 292 throw std::runtime_error("Attempting to call a non-function");
293 if (!thisObj->IsObject()) 293 if (!thisObj->IsObject())
294 throw std::runtime_error("`this` pointer has to be an object"); 294 throw std::runtime_error("`this` pointer has to be an object");
295 295
296 const JsContext context(*jsEngine); 296 const JsContext context(*jsEngine);
297 auto isolate = jsEngine->GetIsolate(); 297 auto isolate = jsEngine->GetIsolate();
298 298
299 const v8::TryCatch tryCatch(isolate); 299 const v8::TryCatch tryCatch(isolate);
300 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(UnwrapValue()); 300 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(UnwrapValue());
301 auto result = CHECKED_TO_LOCAL( 301 auto result = CHECKED_TO_LOCAL_WITH_TRY_CATCH(
302 isolate, func->Call(isolate->GetCurrentContext(), 302 isolate, func->Call(isolate->GetCurrentContext(),
303 thisObj, args.size(), args.size() ? &args[0] : nullptr), tryCatch); 303 thisObj, args.size(), args.size() ? &args[0] : nullptr), tryCatch);
304 304
305 return JsValue(jsEngine, result); 305 return JsValue(jsEngine, result);
306 } 306 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld