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

Side by Side Diff: src/JsEngine.cpp

Issue 10011043: Move ABP JS code loading to FilterEngine and make it optional (Closed)
Patch Set: Created April 2, 2013, 10:32 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
« no previous file with comments | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <sstream> 2 #include <sstream>
3 3
4 #include "ConsoleJsObject.h" 4 #include "ConsoleJsObject.h"
5 5
6 extern const char* jsSources[];
7
8 namespace 6 namespace
9 { 7 {
10 v8::Handle<v8::Context> CreateContext( 8 v8::Handle<v8::Context> CreateContext(
11 AdblockPlus::ErrorCallback& errorCallback) 9 AdblockPlus::ErrorCallback& errorCallback)
12 { 10 {
13 const v8::HandleScope handleScope; 11 const v8::HandleScope handleScope;
14 const v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); 12 const v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
15 global->Set(v8::String::New("console"), 13 global->Set(v8::String::New("console"),
16 AdblockPlus::ConsoleJsObject::Create(errorCallback)); 14 AdblockPlus::ConsoleJsObject::Create(errorCallback));
17 return v8::Context::New(0, global); 15 return v8::Context::New(0, global);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception, 60 AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception,
63 const v8::Handle<v8::Message> message) 61 const v8::Handle<v8::Message> message)
64 : std::runtime_error(ExceptionToString(exception, message)) 62 : std::runtime_error(ExceptionToString(exception, message))
65 { 63 {
66 } 64 }
67 65
68 AdblockPlus::JsEngine::JsEngine(const FileReader* const fileReader, 66 AdblockPlus::JsEngine::JsEngine(const FileReader* const fileReader,
69 ErrorCallback* const errorCallback) 67 ErrorCallback* const errorCallback)
70 : fileReader(fileReader), context(CreateContext(*errorCallback)) 68 : fileReader(fileReader), context(CreateContext(*errorCallback))
71 { 69 {
72 for (int i = 0; jsSources[i] && jsSources[i + 1]; i += 2)
73 Evaluate(jsSources[i + 1], jsSources[i]);
74 } 70 }
75 71
76 void AdblockPlus::JsEngine::Evaluate(const char* source, const char* filename) 72 void AdblockPlus::JsEngine::Evaluate(const char* source, const char* filename)
77 { 73 {
78 const v8::HandleScope handleScope; 74 const v8::HandleScope handleScope;
79 const v8::Context::Scope contextScope(context); 75 const v8::Context::Scope contextScope(context);
80 const v8::TryCatch tryCatch; 76 const v8::TryCatch tryCatch;
81 const v8::Handle<v8::Script> script = CompileScript(source, filename); 77 const v8::Handle<v8::Script> script = CompileScript(source, filename);
82 CheckTryCatch(tryCatch); 78 CheckTryCatch(tryCatch);
83 script->Run(); 79 script->Run();
(...skipping 26 matching lines...) Expand all
110 const v8::Local<v8::Value> result = function->Call(function, 0, 0); 106 const v8::Local<v8::Value> result = function->Call(function, 0, 0);
111 CheckTryCatch(tryCatch); 107 CheckTryCatch(tryCatch);
112 const v8::String::AsciiValue ascii(result); 108 const v8::String::AsciiValue ascii(result);
113 return *ascii; 109 return *ascii;
114 } 110 }
115 111
116 void AdblockPlus::JsEngine::Gc() 112 void AdblockPlus::JsEngine::Gc()
117 { 113 {
118 while (!v8::V8::IdleNotification()); 114 while (!v8::V8::IdleNotification());
119 } 115 }
OLDNEW
« no previous file with comments | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld