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

Side by Side Diff: src/JsEngine.cpp

Issue 29810573: Issue 6526 - Remove deprecated Utf8Value() usage (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created June 19, 2018, 5:11 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 | « src/FileSystemJsObject.cpp ('k') | src/JsError.h » ('j') | no next file with comments »
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 21 matching lines...) Expand all
32 const v8::Local<v8::String> v8Source = ToV8String(isolate, source); 32 const v8::Local<v8::String> v8Source = ToV8String(isolate, source);
33 if (filename.length()) 33 if (filename.length())
34 { 34 {
35 const v8::Local<v8::String> v8Filename = ToV8String(isolate, filename); 35 const v8::Local<v8::String> v8Filename = ToV8String(isolate, filename);
36 return v8::Script::Compile(v8Source, v8Filename); 36 return v8::Script::Compile(v8Source, v8Filename);
37 } 37 }
38 else 38 else
39 return v8::Script::Compile(v8Source); 39 return v8::Script::Compile(v8Source);
40 } 40 }
41 41
42 void CheckTryCatch(const v8::TryCatch& tryCatch) 42 void CheckTryCatch(v8::Isolate* isolate, const v8::TryCatch& tryCatch)
43 { 43 {
44 if (tryCatch.HasCaught()) 44 if (tryCatch.HasCaught())
45 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message()); 45 throw AdblockPlus::JsError(isolate,
46 tryCatch.Exception(), tryCatch.Message());
46 } 47 }
47 48
48 class V8Initializer 49 class V8Initializer
49 { 50 {
50 V8Initializer() 51 V8Initializer()
51 : platform{nullptr} 52 : platform{nullptr}
52 { 53 {
53 std::string cmd = "--use_strict"; 54 std::string cmd = "--use_strict";
54 v8::V8::SetFlagsFromString(cmd.c_str(), cmd.length()); 55 v8::V8::SetFlagsFromString(cmd.c_str(), cmd.length());
55 platform = v8::platform::CreateDefaultPlatform(); 56 platform = v8::platform::CreateDefaultPlatform();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 return JsValue(shared_from_this(), context.GetV8Context()->Global()); 187 return JsValue(shared_from_this(), context.GetV8Context()->Global());
187 } 188 }
188 189
189 AdblockPlus::JsValue AdblockPlus::JsEngine::Evaluate(const std::string& source, 190 AdblockPlus::JsValue AdblockPlus::JsEngine::Evaluate(const std::string& source,
190 const std::string& filename) 191 const std::string& filename)
191 { 192 {
192 const JsContext context(*this); 193 const JsContext context(*this);
193 const v8::TryCatch tryCatch(GetIsolate()); 194 const v8::TryCatch tryCatch(GetIsolate());
194 const v8::Local<v8::Script> script = CompileScript(GetIsolate(), source, 195 const v8::Local<v8::Script> script = CompileScript(GetIsolate(), source,
195 filename); 196 filename);
196 CheckTryCatch(tryCatch); 197 CheckTryCatch(GetIsolate(), tryCatch);
197 v8::Local<v8::Value> result = script->Run(); 198 v8::Local<v8::Value> result = script->Run();
198 CheckTryCatch(tryCatch); 199 CheckTryCatch(GetIsolate(), tryCatch);
199 return JsValue(shared_from_this(), result); 200 return JsValue(shared_from_this(), result);
200 } 201 }
201 202
202 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, 203 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName,
203 const AdblockPlus::JsEngine::EventCallback& callback) 204 const AdblockPlus::JsEngine::EventCallback& callback)
204 { 205 {
205 if (!callback) 206 if (!callback)
206 { 207 {
207 RemoveEventCallback(eventName); 208 RemoveEventCallback(eventName);
208 return; 209 return;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 list.push_back(JsValue(shared_from_this(), arguments[i])); 341 list.push_back(JsValue(shared_from_this(), arguments[i]));
341 return list; 342 return list;
342 } 343 }
343 344
344 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, 345 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
345 const AdblockPlus::JsValue& value) 346 const AdblockPlus::JsValue& value)
346 { 347 {
347 auto global = GetGlobalObject(); 348 auto global = GetGlobalObject();
348 global.SetProperty(name, value); 349 global.SetProperty(name, value);
349 } 350 }
OLDNEW
« no previous file with comments | « src/FileSystemJsObject.cpp ('k') | src/JsError.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld