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