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

Unified Diff: src/JsEngine.cpp

Issue 9616008: Handle compile time exceptions (Closed)
Patch Set: Created March 6, 2013, 3:17 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/JsEngine.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/JsEngine.cpp
===================================================================
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -15,6 +15,12 @@
return v8::Context::New(0, global);
}
+ void CheckTryCatch(const v8::TryCatch& tryCatch)
+ {
+ if (tryCatch.HasCaught())
+ throw AdblockPlus::JsError(tryCatch.Exception());
+ }
+
std::string Slurp(std::istream& stream)
{
std::stringstream content;
@@ -39,11 +45,11 @@
const v8::HandleScope handleScope;
const v8::Context::Scope contextScope(context);
const v8::Handle<v8::String> v8Source = v8::String::New(source.c_str());
+ const v8::TryCatch tryCatch;
const v8::Handle<v8::Script> script = v8::Script::Compile(v8Source);
- const v8::TryCatch tryCatch;
+ CheckTryCatch(tryCatch);
const v8::Handle<const v8::Value> result = script->Run();
- if (result.IsEmpty())
- throw JsError(tryCatch.Exception());
+ CheckTryCatch(tryCatch);
}
void AdblockPlus::JsEngine::Load(const std::string& scriptPath)
@@ -63,8 +69,7 @@
global->Get(v8::String::New(functionName.c_str())));
const v8::TryCatch tryCatch;
const v8::Local<v8::Value> result = function->Call(function, 0, 0);
- if (result.IsEmpty())
- throw JsError(tryCatch.Exception());
+ CheckTryCatch(tryCatch);
const v8::String::AsciiValue ascii(result);
return *ascii;
}
« no previous file with comments | « no previous file | test/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld