summaryrefslogtreecommitdiff
path: root/src/mongo/scripting/engine_v8.h
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2013-10-07 14:22:09 -0400
committerMathias Stearn <mathias@10gen.com>2013-10-07 17:16:09 -0400
commitaf5bab59517363df5c9bfe307525676073677756 (patch)
tree8c87368437e2e38cae26530db4cb0cb8c1465020 /src/mongo/scripting/engine_v8.h
parent9501c1bfce47079de54e0aba7b78bae341e3e916 (diff)
downloadmongo-af5bab59517363df5c9bfe307525676073677756.tar.gz
SERVER-10795 clean up V8Scope if exception thrown in constructor
Diffstat (limited to 'src/mongo/scripting/engine_v8.h')
-rw-r--r--src/mongo/scripting/engine_v8.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/mongo/scripting/engine_v8.h b/src/mongo/scripting/engine_v8.h
index 5b22c64df38..36ea1426044 100644
--- a/src/mongo/scripting/engine_v8.h
+++ b/src/mongo/scripting/engine_v8.h
@@ -432,7 +432,31 @@ namespace mongo {
v8::Persistent<v8::Function> _jsRegExpConstructor;
- v8::Isolate* _isolate;
+ /// Like v8::Isolate* but calls Dispose() in destructor.
+ class IsolateHolder {
+ MONGO_DISALLOW_COPYING(IsolateHolder);
+ public:
+ IsolateHolder() :_isolate(NULL) {}
+ ~IsolateHolder() {
+ if (_isolate) {
+ _isolate->Dispose();
+ _isolate = NULL;
+ }
+ }
+
+ void set(v8::Isolate* isolate) {
+ fassert(17184, !_isolate);
+ _isolate = isolate;
+ }
+
+ v8::Isolate* operator -> () const { return _isolate; };
+ operator v8::Isolate* () const { return _isolate; };
+ private:
+ v8::Isolate* _isolate;
+ };
+
+ IsolateHolder _isolate; // NOTE: this must be destructed before the ObjTrackers
+
V8CpuProfiler _cpuProfiler;
// See comments in strLitToV8