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

Side by Side Diff: src/ConsoleJsObject.cpp

Issue 29543810: Issue 5118 - Lock the platform interfaces before use (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Last details Created Sept. 13, 2017, 8:17 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 | « include/AdblockPlus/Platform.h ('k') | src/FileSystemJsObject.cpp » ('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 28 matching lines...) Expand all
39 if (i > 0) 39 if (i > 0)
40 message << " "; 40 message << " ";
41 message << converted[i].AsString(); 41 message << converted[i].AsString();
42 } 42 }
43 43
44 std::stringstream source; 44 std::stringstream source;
45 v8::Local<v8::StackFrame> frame = v8::StackTrace::CurrentStackTrace(argument s.GetIsolate(), 1)->GetFrame(0); 45 v8::Local<v8::StackFrame> frame = v8::StackTrace::CurrentStackTrace(argument s.GetIsolate(), 1)->GetFrame(0);
46 source << AdblockPlus::Utils::FromV8String(frame->GetScriptName()); 46 source << AdblockPlus::Utils::FromV8String(frame->GetScriptName());
47 source << ":" << frame->GetLineNumber(); 47 source << ":" << frame->GetLineNumber();
48 48
49 AdblockPlus::LogSystem& callback = jsEngine->GetPlatform().GetLogSystem(); 49 jsEngine->GetPlatform().WithLogSystem(
50 callback(logLevel, message.str(), source.str()); 50 [logLevel, &message, &source](AdblockPlus::LogSystem& callback)
51 {
52 callback(logLevel, message.str(), source.str());
53 });
51 } 54 }
52 55
53 void LogCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) 56 void LogCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
54 { 57 {
55 return DoLog(AdblockPlus::LogSystem::LOG_LEVEL_LOG, arguments); 58 return DoLog(AdblockPlus::LogSystem::LOG_LEVEL_LOG, arguments);
56 } 59 }
57 60
58 void DebugCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) 61 void DebugCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
59 { 62 {
60 DoLog(AdblockPlus::LogSystem::LOG_LEVEL_LOG, arguments); 63 DoLog(AdblockPlus::LogSystem::LOG_LEVEL_LOG, arguments);
(...skipping 30 matching lines...) Expand all
91 if (name.size()) 94 if (name.size())
92 traceback << name; 95 traceback << name;
93 else 96 else
94 traceback << "/* anonymous */"; 97 traceback << "/* anonymous */";
95 traceback << "() at "; 98 traceback << "() at ";
96 traceback << AdblockPlus::Utils::FromV8String(frame->GetScriptName()); 99 traceback << AdblockPlus::Utils::FromV8String(frame->GetScriptName());
97 traceback << ":" << frame->GetLineNumber(); 100 traceback << ":" << frame->GetLineNumber();
98 traceback << std::endl; 101 traceback << std::endl;
99 } 102 }
100 103
101 AdblockPlus::LogSystem& callback = jsEngine->GetPlatform().GetLogSystem(); 104 jsEngine->GetPlatform().WithLogSystem(
102 callback(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, traceback.str(), ""); 105 [&traceback](AdblockPlus::LogSystem& callback)
106 {
107 callback(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, traceback.str(), "");
108 });
103 } 109 }
104 } 110 }
105 111
106 AdblockPlus::JsValue& AdblockPlus::ConsoleJsObject::Setup( 112 AdblockPlus::JsValue& AdblockPlus::ConsoleJsObject::Setup(
107 AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValue& obj) 113 AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValue& obj)
108 { 114 {
109 obj.SetProperty("log", jsEngine.NewCallback(::LogCallback)); 115 obj.SetProperty("log", jsEngine.NewCallback(::LogCallback));
110 obj.SetProperty("debug", jsEngine.NewCallback(::DebugCallback)); 116 obj.SetProperty("debug", jsEngine.NewCallback(::DebugCallback));
111 obj.SetProperty("info", jsEngine.NewCallback(::InfoCallback)); 117 obj.SetProperty("info", jsEngine.NewCallback(::InfoCallback));
112 obj.SetProperty("warn", jsEngine.NewCallback(::WarnCallback)); 118 obj.SetProperty("warn", jsEngine.NewCallback(::WarnCallback));
113 obj.SetProperty("error", jsEngine.NewCallback(::ErrorCallback)); 119 obj.SetProperty("error", jsEngine.NewCallback(::ErrorCallback));
114 obj.SetProperty("trace", jsEngine.NewCallback(::TraceCallback)); 120 obj.SetProperty("trace", jsEngine.NewCallback(::TraceCallback));
115 return obj; 121 return obj;
116 } 122 }
OLDNEW
« no previous file with comments | « include/AdblockPlus/Platform.h ('k') | src/FileSystemJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld