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

Side by Side Diff: src/JsEngine.cpp

Issue 10297026: Remove JsEngine::Load() (Closed)
Patch Set: Created April 18, 2013, 1:34 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/JsEngine.h ('k') | test/JsEngine.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 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <sstream> 2 #include <sstream>
3 3
4 #include "GlobalJsObject.h" 4 #include "GlobalJsObject.h"
5 #include "Utils.h" 5 #include "Utils.h"
6 6
7 namespace 7 namespace
8 { 8 {
9 v8::Handle<v8::Script> CompileScript(const std::string& source, const std::str ing& filename) 9 v8::Handle<v8::Script> CompileScript(const std::string& source, const std::str ing& filename)
10 { 10 {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 { 62 {
63 const Context context(*this); 63 const Context context(*this);
64 const v8::TryCatch tryCatch; 64 const v8::TryCatch tryCatch;
65 const v8::Handle<v8::Script> script = CompileScript(source, filename); 65 const v8::Handle<v8::Script> script = CompileScript(source, filename);
66 CheckTryCatch(tryCatch); 66 CheckTryCatch(tryCatch);
67 v8::Local<v8::Value> result = script->Run(); 67 v8::Local<v8::Value> result = script->Run();
68 CheckTryCatch(tryCatch); 68 CheckTryCatch(tryCatch);
69 return JsValuePtr(new JsValue(*this, result)); 69 return JsValuePtr(new JsValue(*this, result));
70 } 70 }
71 71
72 void AdblockPlus::JsEngine::Load(const std::string& scriptPath)
73 {
74 const std::tr1::shared_ptr<std::istream> file = GetFileSystem()->Read(scriptPa th);
75 if (!file || !*file)
76 throw std::runtime_error("Unable to load script " + scriptPath);
77 Evaluate(Utils::Slurp(*file));
78 }
79
80 void AdblockPlus::JsEngine::Gc() 72 void AdblockPlus::JsEngine::Gc()
81 { 73 {
82 while (!v8::V8::IdleNotification()); 74 while (!v8::V8::IdleNotification());
83 } 75 }
84 76
85 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val) 77 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val)
86 { 78 {
87 const Context context(*this); 79 const Context context(*this);
88 return JsValuePtr(new JsValue(*this, v8::String::New(val.c_str(), val.length() ))); 80 return JsValuePtr(new JsValue(*this, v8::String::New(val.c_str(), val.length() )));
89 } 81 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 void AdblockPlus::JsEngine::SetErrorCallback(AdblockPlus::ErrorCallbackPtr val) 158 void AdblockPlus::JsEngine::SetErrorCallback(AdblockPlus::ErrorCallbackPtr val)
167 { 159 {
168 errorCallback = val; 160 errorCallback = val;
169 } 161 }
170 162
171 AdblockPlus::JsEngine::Context::Context(const JsEngine& jsEngine) 163 AdblockPlus::JsEngine::Context::Context(const JsEngine& jsEngine)
172 : locker(jsEngine.isolate), handleScope(), 164 : locker(jsEngine.isolate), handleScope(),
173 contextScope(jsEngine.context) 165 contextScope(jsEngine.context)
174 { 166 {
175 } 167 }
OLDNEW
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | test/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld