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-2016 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 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 85 } |
86 | 86 |
87 JsEngine::TimerTask JsEngine::CreateTimerTask(const v8::Arguments& arguments) | 87 JsEngine::TimerTask JsEngine::CreateTimerTask(const v8::Arguments& arguments) |
88 { | 88 { |
89 if (arguments.Length() < 2) | 89 if (arguments.Length() < 2) |
90 throw std::runtime_error("setTimeout requires at least 2 parameters"); | 90 throw std::runtime_error("setTimeout requires at least 2 parameters"); |
91 | 91 |
92 if (!arguments[0]->IsFunction()) | 92 if (!arguments[0]->IsFunction()) |
93 throw std::runtime_error("First argument to setTimeout must be a function"); | 93 throw std::runtime_error("First argument to setTimeout must be a function"); |
94 | 94 |
95 auto ii_timerTaskInfo = timerTaskInfos.emplace(timerTaskInfos.end()); | 95 auto timerTaskInfoIterator = timerTaskInfos.emplace(timerTaskInfos.end()); |
96 ii_timerTaskInfo->delay = arguments[1]->IntegerValue(); | 96 timerTaskInfoIterator->delay = arguments[1]->IntegerValue(); |
97 | 97 |
98 for (int i = 0; i < arguments.Length(); i++) | 98 for (int i = 0; i < arguments.Length(); i++) |
99 ii_timerTaskInfo->arguments.emplace_back(new v8::Persistent<v8::Value>(GetIs
olate(), arguments[i])); | 99 timerTaskInfoIterator->arguments.emplace_back(new v8::Persistent<v8::Value>(
GetIsolate(), arguments[i])); |
100 TimerTask retValue = { shared_from_this(), ii_timerTaskInfo }; | 100 TimerTask retValue = { shared_from_this(), timerTaskInfoIterator }; |
101 return retValue; | 101 return retValue; |
102 } | 102 } |
103 | 103 |
104 void JsEngine::CallTimerTask(TimerTaskInfos::const_iterator ii_taskInfo) | 104 void JsEngine::CallTimerTask(TimerTaskInfos::const_iterator timerTaskInfoIterato
r) |
105 { | 105 { |
106 const JsContext context(shared_from_this()); | 106 const JsContext context(shared_from_this()); |
107 JsValue callback(shared_from_this(), v8::Local<v8::Value>::New(GetIsolate(), *
ii_taskInfo->arguments[0])); | 107 JsValue callback(shared_from_this(), v8::Local<v8::Value>::New(GetIsolate(), *
timerTaskInfoIterator->arguments[0])); |
108 JsValueList callbackArgs; | 108 JsValueList callbackArgs; |
109 for (int i = 2; i < ii_taskInfo->arguments.size(); i++) | 109 for (int i = 2; i < timerTaskInfoIterator->arguments.size(); i++) |
110 callbackArgs.emplace_back(new JsValue(shared_from_this(), | 110 callbackArgs.emplace_back(new JsValue(shared_from_this(), |
111 v8::Local<v8::Value>::New(GetIsolate(), *ii_taskInfo->arguments[i]))); | 111 v8::Local<v8::Value>::New(GetIsolate(), *timerTaskInfoIterator->arguments[i]
))); |
112 callback.Call(callbackArgs); | 112 callback.Call(callbackArgs); |
113 timerTaskInfos.erase(ii_taskInfo); | 113 timerTaskInfos.erase(timerTaskInfoIterator); |
114 } | 114 } |
115 | 115 |
116 AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate) | 116 AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate) |
117 : isolate(isolate) | 117 : isolate(isolate) |
118 { | 118 { |
119 } | 119 } |
120 | 120 |
121 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, cons
t ScopedV8IsolatePtr& isolate) | 121 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, cons
t ScopedV8IsolatePtr& isolate) |
122 { | 122 { |
123 JsEnginePtr result(new JsEngine(isolate)); | 123 JsEnginePtr result(new JsEngine(isolate)); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 310 |
311 | 311 |
312 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 312 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
313 AdblockPlus::JsValuePtr value) | 313 AdblockPlus::JsValuePtr value) |
314 { | 314 { |
315 auto global = GetGlobalObject(); | 315 auto global = GetGlobalObject(); |
316 if (!global) | 316 if (!global) |
317 throw std::runtime_error("Global object cannot be null"); | 317 throw std::runtime_error("Global object cannot be null"); |
318 global->SetProperty(name, value); | 318 global->SetProperty(name, value); |
319 } | 319 } |
LEFT | RIGHT |