Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/JsEngine.cpp

Issue 29813591: Issue 6526 - Use Maybe<> version of soon to be deprecated API in v8 6.7 (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created June 22, 2018, 8:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/JsValue.cpp » ('j') | src/JsValue.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (arguments.Length() < 2) 123 if (arguments.Length() < 2)
124 throw std::runtime_error("setTimeout requires at least 2 parameters"); 124 throw std::runtime_error("setTimeout requires at least 2 parameters");
125 125
126 if (!arguments[0]->IsFunction()) 126 if (!arguments[0]->IsFunction())
127 throw std::runtime_error("First argument to setTimeout must be a function"); 127 throw std::runtime_error("First argument to setTimeout must be a function");
128 128
129 auto jsValueArguments = jsEngine->ConvertArguments(arguments); 129 auto jsValueArguments = jsEngine->ConvertArguments(arguments);
130 auto timerParamsID = jsEngine->StoreJsValues(jsValueArguments); 130 auto timerParamsID = jsEngine->StoreJsValues(jsValueArguments);
131 131
132 std::weak_ptr<JsEngine> weakJsEngine = jsEngine; 132 std::weak_ptr<JsEngine> weakJsEngine = jsEngine;
133
134 int64_t millis = CHECKED_TO_VALUE(
135 arguments[1]->IntegerValue(arguments.GetIsolate()->GetCurrentContext()));
136
133 jsEngine->platform.WithTimer( 137 jsEngine->platform.WithTimer(
134 [arguments, weakJsEngine, timerParamsID](ITimer& timer) 138 [millis, weakJsEngine, timerParamsID](ITimer& timer)
135 { 139 {
136 timer.SetTimer( 140 timer.SetTimer(
137 std::chrono::milliseconds( 141 std::chrono::milliseconds(millis), [weakJsEngine, timerParamsID]
138 arguments[1]->IntegerValue()), [weakJsEngine, timerParamsID]
139 { 142 {
140 if (auto jsEngine = weakJsEngine.lock()) 143 if (auto jsEngine = weakJsEngine.lock())
141 jsEngine->CallTimerTask(timerParamsID); 144 jsEngine->CallTimerTask(timerParamsID);
142 }); 145 });
143 }); 146 });
144 } 147 }
145 148
146 void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID) 149 void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID)
147 { 150 {
148 auto timerParams = TakeJsValues(timerParamsID); 151 auto timerParams = TakeJsValues(timerParamsID);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 AdblockPlus::JsValue AdblockPlus::JsEngine::NewObject() 260 AdblockPlus::JsValue AdblockPlus::JsEngine::NewObject()
258 { 261 {
259 const JsContext context(*this); 262 const JsContext context(*this);
260 return JsValue(shared_from_this(), v8::Object::New(GetIsolate())); 263 return JsValue(shared_from_this(), v8::Object::New(GetIsolate()));
261 } 264 }
262 265
263 AdblockPlus::JsValue AdblockPlus::JsEngine::NewCallback( 266 AdblockPlus::JsValue AdblockPlus::JsEngine::NewCallback(
264 const v8::FunctionCallback& callback) 267 const v8::FunctionCallback& callback)
265 { 268 {
266 const JsContext context(*this); 269 const JsContext context(*this);
267 270 auto isolate = GetIsolate();
268 // Note: we are leaking this weak pointer, no obvious way to destroy it when 271 // Note: we are leaking this weak pointer, no obvious way to destroy it when
269 // it's no longer used 272 // it's no longer used
270 std::weak_ptr<JsEngine>* data = 273 std::weak_ptr<JsEngine>* data =
271 new std::weak_ptr<JsEngine>(shared_from_this()); 274 new std::weak_ptr<JsEngine>(shared_from_this());
272 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(GetIsolate() , callback, 275 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, cal lback,
273 v8::External::New(GetIsolate(), data)); 276 v8::External::New(isolate, data));
274 return JsValue(shared_from_this(), templ->GetFunction()); 277 return JsValue(shared_from_this(),
278 CHECKED_TO_LOCAL_NOTHROW(isolate, templ->GetFunction(isolate->GetCurrentCo ntext())));
275 } 279 }
276 280
277 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::FromArguments(const v8::Function CallbackInfo<v8::Value>& arguments) 281 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::FromArguments(const v8::Function CallbackInfo<v8::Value>& arguments)
278 { 282 {
279 const v8::Local<const v8::External> external = 283 const v8::Local<const v8::External> external =
280 v8::Local<const v8::External>::Cast(arguments.Data()); 284 v8::Local<const v8::External>::Cast(arguments.Data());
281 std::weak_ptr<JsEngine>* data = 285 std::weak_ptr<JsEngine>* data =
282 static_cast<std::weak_ptr<JsEngine>*>(external->Value()); 286 static_cast<std::weak_ptr<JsEngine>*>(external->Value());
283 JsEnginePtr result = data->lock(); 287 JsEnginePtr result = data->lock();
284 if (!result) 288 if (!result)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 list.push_back(JsValue(shared_from_this(), arguments[i])); 345 list.push_back(JsValue(shared_from_this(), arguments[i]));
342 return list; 346 return list;
343 } 347 }
344 348
345 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, 349 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
346 const AdblockPlus::JsValue& value) 350 const AdblockPlus::JsValue& value)
347 { 351 {
348 auto global = GetGlobalObject(); 352 auto global = GetGlobalObject();
349 global.SetProperty(name, value); 353 global.SetProperty(name, value);
350 } 354 }
OLDNEW
« no previous file with comments | « no previous file | src/JsValue.cpp » ('j') | src/JsValue.cpp » ('J')

Powered by Google App Engine
This is Rietveld