| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 const JsContext context(shared_from_this()); | 224 const JsContext context(shared_from_this()); |
| 225 return JsValuePtr(new JsValue(shared_from_this(), v8::Boolean::New(val))); | 225 return JsValuePtr(new JsValue(shared_from_this(), v8::Boolean::New(val))); |
| 226 } | 226 } |
| 227 | 227 |
| 228 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewObject() | 228 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewObject() |
| 229 { | 229 { |
| 230 const JsContext context(shared_from_this()); | 230 const JsContext context(shared_from_this()); |
| 231 return JsValuePtr(new JsValue(shared_from_this(), v8::Object::New())); | 231 return JsValuePtr(new JsValue(shared_from_this(), v8::Object::New())); |
| 232 } | 232 } |
| 233 | 233 |
| 234 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewCallback( | 234 AdblockPlus::JsValue AdblockPlus::JsEngine::NewCallback( |
| 235 const v8::InvocationCallback& callback) | 235 const v8::InvocationCallback& callback) |
| 236 { | 236 { |
| 237 const JsContext context(shared_from_this()); | 237 const JsContext context(shared_from_this()); |
| 238 | 238 |
| 239 // Note: we are leaking this weak pointer, no obvious way to destroy it when | 239 // Note: we are leaking this weak pointer, no obvious way to destroy it when |
| 240 // it's no longer used | 240 // it's no longer used |
| 241 std::weak_ptr<JsEngine>* data = | 241 std::weak_ptr<JsEngine>* data = |
| 242 new std::weak_ptr<JsEngine>(shared_from_this()); | 242 new std::weak_ptr<JsEngine>(shared_from_this()); |
| 243 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(callback, | 243 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(callback, |
| 244 v8::External::New(data)); | 244 v8::External::New(data)); |
| 245 return JsValuePtr(new JsValue(shared_from_this(), templ->GetFunction())); | 245 return JsValue(shared_from_this(), templ->GetFunction()); |
| 246 } | 246 } |
| 247 | 247 |
| 248 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::FromArguments(const v8::Argument
s& arguments) | 248 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::FromArguments(const v8::Argument
s& arguments) |
| 249 { | 249 { |
| 250 const v8::Local<const v8::External> external = | 250 const v8::Local<const v8::External> external = |
| 251 v8::Local<const v8::External>::Cast(arguments.Data()); | 251 v8::Local<const v8::External>::Cast(arguments.Data()); |
| 252 std::weak_ptr<JsEngine>* data = | 252 std::weak_ptr<JsEngine>* data = |
| 253 static_cast<std::weak_ptr<JsEngine>*>(external->Value()); | 253 static_cast<std::weak_ptr<JsEngine>*>(external->Value()); |
| 254 JsEnginePtr result = data->lock(); | 254 JsEnginePtr result = data->lock(); |
| 255 if (!result) | 255 if (!result) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 327 |
| 328 | 328 |
| 329 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 329 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
| 330 const AdblockPlus::JsValue& value) | 330 const AdblockPlus::JsValue& value) |
| 331 { | 331 { |
| 332 auto global = GetGlobalObject(); | 332 auto global = GetGlobalObject(); |
| 333 if (global.IsUndefined() || global.IsNull()) | 333 if (global.IsUndefined() || global.IsNull()) |
| 334 throw std::runtime_error("Global object cannot be null"); | 334 throw std::runtime_error("Global object cannot be null"); |
| 335 global.SetProperty(name, value); | 335 global.SetProperty(name, value); |
| 336 } | 336 } |
| OLD | NEW |