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

Side by Side Diff: src/ConsoleJsObject.cpp

Issue 29500602: Issue 5450 - introduce the Platform class (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: rebase Created July 31, 2017, 12:53 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
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <AdblockPlus/JsValue.h> 18 #include <AdblockPlus/JsValue.h>
19 #include <AdblockPlus/LogSystem.h> 19 #include <AdblockPlus/LogSystem.h>
20 #include <sstream> 20 #include <sstream>
21 21
22 #include "ConsoleJsObject.h" 22 #include "ConsoleJsObject.h"
23 #include "JsContext.h" 23 #include "JsContext.h"
24 #include "Utils.h" 24 #include "Utils.h"
25 #include <AdblockPlus/Platform.h>
25 26
26 namespace 27 namespace
27 { 28 {
28 void DoLog(AdblockPlus::LogSystem::LogLevel logLevel, 29 void DoLog(AdblockPlus::LogSystem::LogLevel logLevel,
29 const v8::FunctionCallbackInfo<v8::Value>& arguments) 30 const v8::FunctionCallbackInfo<v8::Value>& arguments)
30 { 31 {
31 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 32 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
32 const AdblockPlus::JsContext context(*jsEngine); 33 const AdblockPlus::JsContext context(*jsEngine);
33 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 34 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
34 35
35 std::stringstream message; 36 std::stringstream message;
36 for (size_t i = 0; i < converted.size(); i++) 37 for (size_t i = 0; i < converted.size(); i++)
37 { 38 {
38 if (i > 0) 39 if (i > 0)
39 message << " "; 40 message << " ";
40 message << converted[i].AsString(); 41 message << converted[i].AsString();
41 } 42 }
42 43
43 std::stringstream source; 44 std::stringstream source;
44 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);
45 source << AdblockPlus::Utils::FromV8String(frame->GetScriptName()); 46 source << AdblockPlus::Utils::FromV8String(frame->GetScriptName());
46 source << ":" << frame->GetLineNumber(); 47 source << ":" << frame->GetLineNumber();
47 48
48 AdblockPlus::LogSystem& callback = jsEngine->GetLogSystem(); 49 AdblockPlus::LogSystem& callback = jsEngine->GetPlatform().GetLogSystem();
49 callback(logLevel, message.str(), source.str()); 50 callback(logLevel, message.str(), source.str());
50 } 51 }
51 52
52 void LogCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) 53 void LogCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
53 { 54 {
54 return DoLog(AdblockPlus::LogSystem::LOG_LEVEL_LOG, arguments); 55 return DoLog(AdblockPlus::LogSystem::LOG_LEVEL_LOG, arguments);
55 } 56 }
56 57
57 void DebugCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) 58 void DebugCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
58 { 59 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (name.size()) 91 if (name.size())
91 traceback << name; 92 traceback << name;
92 else 93 else
93 traceback << "/* anonymous */"; 94 traceback << "/* anonymous */";
94 traceback << "() at "; 95 traceback << "() at ";
95 traceback << AdblockPlus::Utils::FromV8String(frame->GetScriptName()); 96 traceback << AdblockPlus::Utils::FromV8String(frame->GetScriptName());
96 traceback << ":" << frame->GetLineNumber(); 97 traceback << ":" << frame->GetLineNumber();
97 traceback << std::endl; 98 traceback << std::endl;
98 } 99 }
99 100
100 AdblockPlus::LogSystem& callback = jsEngine->GetLogSystem(); 101 AdblockPlus::LogSystem& callback = jsEngine->GetPlatform().GetLogSystem();
101 callback(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, traceback.str(), ""); 102 callback(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, traceback.str(), "");
102 } 103 }
103 } 104 }
104 105
105 AdblockPlus::JsValue& AdblockPlus::ConsoleJsObject::Setup( 106 AdblockPlus::JsValue& AdblockPlus::ConsoleJsObject::Setup(
106 AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValue& obj) 107 AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValue& obj)
107 { 108 {
108 obj.SetProperty("log", jsEngine.NewCallback(::LogCallback)); 109 obj.SetProperty("log", jsEngine.NewCallback(::LogCallback));
109 obj.SetProperty("debug", jsEngine.NewCallback(::DebugCallback)); 110 obj.SetProperty("debug", jsEngine.NewCallback(::DebugCallback));
110 obj.SetProperty("info", jsEngine.NewCallback(::InfoCallback)); 111 obj.SetProperty("info", jsEngine.NewCallback(::InfoCallback));
111 obj.SetProperty("warn", jsEngine.NewCallback(::WarnCallback)); 112 obj.SetProperty("warn", jsEngine.NewCallback(::WarnCallback));
112 obj.SetProperty("error", jsEngine.NewCallback(::ErrorCallback)); 113 obj.SetProperty("error", jsEngine.NewCallback(::ErrorCallback));
113 obj.SetProperty("trace", jsEngine.NewCallback(::TraceCallback)); 114 obj.SetProperty("trace", jsEngine.NewCallback(::TraceCallback));
114 return obj; 115 return obj;
115 } 116 }
OLDNEW

Powered by Google App Engine
This is Rietveld