Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / test / base / v8_unit_test.h
index 7d64b84..4b056d3 100644 (file)
@@ -68,13 +68,35 @@ class V8UnitTest : public testing::Test {
   static void ChromeSend(const v8::FunctionCallbackInfo<v8::Value>& args);
 
  private:
+  // A helper class to ensure that the lifetimes of the Isolate and the
+  // HandleScope are correctly nested.
+  class IsolateScope {
+   public:
+    IsolateScope() : isolate_(v8::Isolate::New()) { isolate_->Enter(); }
+
+    ~IsolateScope() {
+      isolate_->Exit();
+      isolate_->Dispose();
+    }
+
+    v8::Isolate* isolate() const { return isolate_; }
+
+   private:
+    v8::Isolate* isolate_;
+
+    DISALLOW_COPY_AND_ASSIGN(IsolateScope);
+  };
+
+  // A handy shortcut.
+  v8::Isolate* isolate() const { return isolate_scope_.isolate(); }
+
   // Executes all added javascript libraries. Returns true if no errors.
   bool ExecuteJavascriptLibraries();
 
   // Initializes paths and libraries.
   void InitPathsAndLibraries();
 
-  v8::Isolate* isolate_;
+  IsolateScope isolate_scope_;
 
   // Handle scope that is used throughout the life of this class.
   v8::HandleScope handle_scope_;