OLD | NEW |
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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 std::string AdblockPlus::JsValue::GetClass() const | 218 std::string AdblockPlus::JsValue::GetClass() const |
219 { | 219 { |
220 if (!IsObject()) | 220 if (!IsObject()) |
221 throw new std::runtime_error("Cannot get constructor of a non-object"); | 221 throw new std::runtime_error("Cannot get constructor of a non-object"); |
222 | 222 |
223 const JsContext context(jsEngine); | 223 const JsContext context(jsEngine); |
224 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); | 224 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); |
225 return Utils::FromV8String(obj->GetConstructorName()); | 225 return Utils::FromV8String(obj->GetConstructorName()); |
226 } | 226 } |
227 | 227 |
228 JsValue JsValue::Call(const JsValueList& params, const JsValuePtr& thisPtr) cons
t | 228 JsValue JsValue::Call(const JsValueList& params) const |
229 { | 229 { |
230 const JsContext context(jsEngine); | 230 const JsContext context(jsEngine); |
231 v8::Local<v8::Object> thisObj = thisPtr ? | 231 std::vector<v8::Handle<v8::Value>> argv; |
232 v8::Local<v8::Object>::Cast(thisPtr->UnwrapValue()) : | 232 for (const auto& param : params) |
233 context.GetV8Context()->Global(); | 233 argv.push_back(param.UnwrapValue()); |
| 234 |
| 235 return Call(argv, context.GetV8Context()->Global()); |
| 236 } |
| 237 |
| 238 JsValue JsValue::Call(const JsValueList& params, const JsValue& thisValue) const |
| 239 { |
| 240 const JsContext context(jsEngine); |
| 241 v8::Local<v8::Object> thisObj = v8::Local<v8::Object>::Cast(thisValue.UnwrapVa
lue()); |
234 | 242 |
235 std::vector<v8::Handle<v8::Value>> argv; | 243 std::vector<v8::Handle<v8::Value>> argv; |
236 for (const auto& param : params) | 244 for (const auto& param : params) |
237 argv.push_back(param.UnwrapValue()); | 245 argv.push_back(param.UnwrapValue()); |
238 | 246 |
239 return Call(argv, thisObj); | 247 return Call(argv, thisObj); |
240 } | 248 } |
241 | 249 |
242 JsValue JsValue::Call(const JsValue& arg) const | 250 JsValue JsValue::Call(const JsValue& arg) const |
243 { | 251 { |
(...skipping 17 matching lines...) Expand all Loading... |
261 const v8::TryCatch tryCatch; | 269 const v8::TryCatch tryCatch; |
262 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(UnwrapValue()); | 270 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(UnwrapValue()); |
263 v8::Local<v8::Value> result = func->Call(thisObj, args.size(), | 271 v8::Local<v8::Value> result = func->Call(thisObj, args.size(), |
264 args.size() ? &args[0] : nullptr); | 272 args.size() ? &args[0] : nullptr); |
265 | 273 |
266 if (tryCatch.HasCaught()) | 274 if (tryCatch.HasCaught()) |
267 throw JsError(tryCatch.Exception(), tryCatch.Message()); | 275 throw JsError(tryCatch.Exception(), tryCatch.Message()); |
268 | 276 |
269 return JsValue(jsEngine, result); | 277 return JsValue(jsEngine, result); |
270 } | 278 } |
OLD | NEW |