LEFT | RIGHT |
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-2015 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 * |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 return JsValuePtr(new JsValue(shared_from_this(), v8::Object::New())); | 149 return JsValuePtr(new JsValue(shared_from_this(), v8::Object::New())); |
150 } | 150 } |
151 | 151 |
152 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewCallback( | 152 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewCallback( |
153 v8::InvocationCallback callback) | 153 v8::InvocationCallback callback) |
154 { | 154 { |
155 const JsContext context(shared_from_this()); | 155 const JsContext context(shared_from_this()); |
156 | 156 |
157 // Note: we are leaking this weak pointer, no obvious way to destroy it when | 157 // Note: we are leaking this weak pointer, no obvious way to destroy it when |
158 // it's no longer used | 158 // it's no longer used |
159 std::tr1::weak_ptr<JsEngine>* data = | 159 std::weak_ptr<JsEngine>* data = |
160 new std::tr1::weak_ptr<JsEngine>(shared_from_this()); | 160 new std::weak_ptr<JsEngine>(shared_from_this()); |
161 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(callback, | 161 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(callback, |
162 v8::External::New(data)); | 162 v8::External::New(data)); |
163 return JsValuePtr(new JsValue(shared_from_this(), templ->GetFunction())); | 163 return JsValuePtr(new JsValue(shared_from_this(), templ->GetFunction())); |
164 } | 164 } |
165 | 165 |
166 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::FromArguments(const v8::Argument
s& arguments) | 166 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::FromArguments(const v8::Argument
s& arguments) |
167 { | 167 { |
168 const v8::Local<const v8::External> external = | 168 const v8::Local<const v8::External> external = |
169 v8::Local<const v8::External>::Cast(arguments.Data()); | 169 v8::Local<const v8::External>::Cast(arguments.Data()); |
170 std::tr1::weak_ptr<JsEngine>* data = | 170 std::weak_ptr<JsEngine>* data = |
171 static_cast<std::tr1::weak_ptr<JsEngine>*>(external->Value()); | 171 static_cast<std::weak_ptr<JsEngine>*>(external->Value()); |
172 JsEnginePtr result = data->lock(); | 172 JsEnginePtr result = data->lock(); |
173 if (!result) | 173 if (!result) |
174 throw std::runtime_error("Oops, our JsEngine is gone, how did that happen?")
; | 174 throw std::runtime_error("Oops, our JsEngine is gone, how did that happen?")
; |
175 return result; | 175 return result; |
176 } | 176 } |
177 | 177 |
178 AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Argum
ents& arguments) | 178 AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Argum
ents& arguments) |
179 { | 179 { |
180 const JsContext context(shared_from_this()); | 180 const JsContext context(shared_from_this()); |
181 JsValueList list; | 181 JsValueList list; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 231 |
232 | 232 |
233 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 233 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
234 AdblockPlus::JsValuePtr value) | 234 AdblockPlus::JsValuePtr value) |
235 { | 235 { |
236 if (!globalJsObject) | 236 if (!globalJsObject) |
237 throw std::runtime_error("Global object cannot be null"); | 237 throw std::runtime_error("Global object cannot be null"); |
238 | 238 |
239 globalJsObject->SetProperty(name, value); | 239 globalJsObject->SetProperty(name, value); |
240 } | 240 } |
LEFT | RIGHT |