summaryrefslogtreecommitdiff
path: root/src/mongo/scripting/engine_v8.cpp
diff options
context:
space:
mode:
authorBen Becker <ben.becker@10gen.com>2013-01-11 14:40:10 -0800
committerBen Becker <ben.becker@10gen.com>2013-01-11 15:15:44 -0800
commit5053efc1043a095a013c40af1cc382a60895d4b5 (patch)
tree520144c517e127f34960f41a506cb8081ed1eb39 /src/mongo/scripting/engine_v8.cpp
parent03b80fb81feb076a618b275825f1c662bba9237d (diff)
downloadmongo-5053efc1043a095a013c40af1cc382a60895d4b5.tar.gz
SERVER-8053: support for timeouts in V8Scope's invoke() and exec()
Diffstat (limited to 'src/mongo/scripting/engine_v8.cpp')
-rw-r--r--src/mongo/scripting/engine_v8.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/mongo/scripting/engine_v8.cpp b/src/mongo/scripting/engine_v8.cpp
index be321ba4893..ff7b04f50b7 100644
--- a/src/mongo/scripting/engine_v8.cpp
+++ b/src/mongo/scripting/engine_v8.cpp
@@ -298,7 +298,8 @@ namespace mongo {
V8ScriptEngine::V8ScriptEngine() :
_globalInterruptLock("GlobalV8InterruptLock"),
- _opToScopeMap() {
+ _opToScopeMap(),
+ _deadlineMonitor() {
}
V8ScriptEngine::~V8ScriptEngine() {
@@ -850,8 +851,6 @@ namespace mongo {
// TODO SERVER-8016: properly allocate handles on the stack
v8::Handle<v8::Value> args[24];
- // TODO SERVER-8053: implement timeoutMs
-
const int nargs = argsObject ? argsObject->nFields() : 0;
if (nargs) {
BSONObjIterator it(*argsObject);
@@ -877,8 +876,16 @@ namespace mongo {
return 1;
}
+ if (timeoutMs)
+ // start the deadline timer for this script
+ _engine->getDeadlineMonitor()->startDeadline(this, timeoutMs);
+
result = ((v8::Function*)(*funcValue))->Call(v8recv, nargs, nargs ? args : NULL);
+ if (timeoutMs)
+ // stop the deadline timer for this script
+ _engine->getDeadlineMonitor()->stopDeadline(this);
+
if (!nativePrologue()) {
_error = str::stream() << "javascript execution interrupted";
log() << _error << endl;
@@ -907,8 +914,6 @@ namespace mongo {
V8_SIMPLE_HEADER
v8::TryCatch try_catch;
- // TODO SERVER-8053: implement timeoutMs
-
v8::Handle<v8::Script> script =
v8::Script::Compile(v8::String::New(code.rawData(), code.size()),
v8::String::New(name.c_str()));
@@ -932,8 +937,16 @@ namespace mongo {
return false;
}
+ if (timeoutMs)
+ // start the deadline timer for this script
+ _engine->getDeadlineMonitor()->startDeadline(this, timeoutMs);
+
v8::Handle<v8::Value> result = script->Run();
+ if (timeoutMs)
+ // stopt the deadline timer for this script
+ _engine->getDeadlineMonitor()->stopDeadline(this);
+
bool resultSuccess = true;
if (!nativePrologue()) {
resultSuccess = false;