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

Side by Side Diff: shell/src/Main.cpp

Issue 10310030: Convert references to FileSystem & Co. into shared pointers (avoid use after free) (Closed)
Patch Set: Created April 18, 2013, 11:59 a.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 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <iostream> 2 #include <iostream>
3 #include <sstream> 3 #include <sstream>
4 4
5 #include "GcCommand.h" 5 #include "GcCommand.h"
6 #include "HelpCommand.h" 6 #include "HelpCommand.h"
7 #include "FiltersCommand.h" 7 #include "FiltersCommand.h"
8 #include "SubscriptionsCommand.h" 8 #include "SubscriptionsCommand.h"
9 #include "MatchesCommand.h" 9 #include "MatchesCommand.h"
10 10
11 namespace 11 namespace
12 { 12 {
13 class CerrErrorCallback : public AdblockPlus::ErrorCallback
14 {
15 public:
16 void operator()(const std::string& message)
17 {
18 std::cerr << "Error: " << message << std::endl;
19 }
20 };
21
22 void Add(CommandMap& commands, Command* command) 13 void Add(CommandMap& commands, Command* command)
23 { 14 {
24 commands[command->name] = command; 15 commands[command->name] = command;
25 } 16 }
26 17
27 bool ReadCommandLine(std::string& commandLine) 18 bool ReadCommandLine(std::string& commandLine)
28 { 19 {
29 std::cout << "> "; 20 std::cout << "> ";
30 const bool success = std::getline(std::cin, commandLine); 21 const bool success = std::getline(std::cin, commandLine);
31 if (!success) 22 if (!success)
32 std::cout << std::endl; 23 std::cout << std::endl;
33 return success; 24 return success;
34 } 25 }
35 26
36 void ParseCommandLine(const std::string& commandLine, std::string& name, 27 void ParseCommandLine(const std::string& commandLine, std::string& name,
37 std::string& arguments) 28 std::string& arguments)
38 { 29 {
39 std::istringstream lineStream(commandLine); 30 std::istringstream lineStream(commandLine);
40 lineStream >> name; 31 lineStream >> name;
41 std::getline(lineStream, arguments); 32 std::getline(lineStream, arguments);
42 } 33 }
43 } 34 }
44 35
45 int main() 36 int main()
46 { 37 {
47 try 38 try
48 { 39 {
49 AdblockPlus::DefaultFileSystem fileSystem;
50 AdblockPlus::DefaultWebRequest webRequest;
51 CerrErrorCallback errorCallback;
52 AdblockPlus::AppInfo appInfo; 40 AdblockPlus::AppInfo appInfo;
53 appInfo.version = "1.0"; 41 appInfo.version = "1.0";
54 appInfo.name = "Adblock Plus Shell"; 42 appInfo.name = "Adblock Plus Shell";
55 AdblockPlus::JsEngine jsEngine(appInfo, &fileSystem, &webRequest, 43 AdblockPlus::JsEngine jsEngine(appInfo);
56 &errorCallback);
57 AdblockPlus::FilterEngine filterEngine(jsEngine); 44 AdblockPlus::FilterEngine filterEngine(jsEngine);
58 45
59 CommandMap commands; 46 CommandMap commands;
60 Add(commands, new GcCommand(jsEngine)); 47 Add(commands, new GcCommand(jsEngine));
61 Add(commands, new HelpCommand(commands)); 48 Add(commands, new HelpCommand(commands));
62 Add(commands, new FiltersCommand(filterEngine)); 49 Add(commands, new FiltersCommand(filterEngine));
63 Add(commands, new SubscriptionsCommand(filterEngine)); 50 Add(commands, new SubscriptionsCommand(filterEngine));
64 Add(commands, new MatchesCommand(filterEngine)); 51 Add(commands, new MatchesCommand(filterEngine));
65 52
66 std::string commandLine; 53 std::string commandLine;
(...skipping 15 matching lines...) Expand all
82 std::cout << error.what() << std::endl; 69 std::cout << error.what() << std::endl;
83 } 70 }
84 } 71 }
85 } 72 }
86 catch (const std::exception& e) 73 catch (const std::exception& e)
87 { 74 {
88 std::cerr << "Exception: " << e.what() << std::endl; 75 std::cerr << "Exception: " << e.what() << std::endl;
89 } 76 }
90 return 0; 77 return 0;
91 } 78 }
OLDNEW
« no previous file with comments | « libadblockplus.gyp ('k') | src/ConsoleJsObject.cpp » ('j') | src/JsEngine.cpp » ('J')

Powered by Google App Engine
This is Rietveld