Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / gin / public / isolate_holder.h
index ee696f6..29cc208 100644 (file)
 namespace gin {
 
 class PerIsolateData;
+class RunMicrotasksObserver;
 
-// To embed Gin, first create an instance of IsolateHolder to hold the
-// v8::Isolate in which you will execute JavaScript. You might wish to subclass
-// IsolateHolder if you want to tie more state to the lifetime of the isolate.
-//
-// You can use gin in two modes: either gin manages V8, or the gin-embedder
-// manages gin. If gin manages V8, use the IsolateHolder constructor that does
-// not take an v8::Isolate parameter, otherwise, the gin-embedder needs to
-// create v8::Isolates and pass them to IsolateHolder.
-//
-// It is not possible to mix the two.
+// To embed Gin, first initialize gin using IsolateHolder::Initialize and then
+// create an instance of IsolateHolder to hold the v8::Isolate in which you
+// will execute JavaScript. You might wish to subclass IsolateHolder if you
+// want to tie more state to the lifetime of the isolate.
 class GIN_EXPORT IsolateHolder {
  public:
   // Controls whether or not V8 should only accept strict mode scripts.
@@ -32,19 +27,32 @@ class GIN_EXPORT IsolateHolder {
     kStrictMode
   };
 
-  explicit IsolateHolder(ScriptMode mode);
-  IsolateHolder(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator);
-
+  IsolateHolder();
   ~IsolateHolder();
 
+  // Should be invoked once before creating IsolateHolder instances to
+  // initialize V8 and Gin.
+  static void Initialize(ScriptMode mode,
+                         v8::ArrayBuffer::Allocator* allocator);
+
   v8::Isolate* isolate() { return isolate_; }
 
- private:
-  void Init(v8::ArrayBuffer::Allocator* allocator);
+  // The implementations of Object.observe() and Promise enqueue v8 Microtasks
+  // that should be executed just before control is returned to the message
+  // loop. This method adds a MessageLoop TaskObserver which runs any pending
+  // Microtasks each time a Task is completed. This method should be called
+  // once, when a MessageLoop is created and it should be called on the
+  // MessageLoop's thread.
+  void AddRunMicrotasksObserver();
 
-  bool isolate_owner_;
+  // This method should also only be called once, and on the MessageLoop's
+  // thread.
+  void RemoveRunMicrotasksObserver();
+
+ private:
   v8::Isolate* isolate_;
   scoped_ptr<PerIsolateData> isolate_data_;
+  scoped_ptr<RunMicrotasksObserver> task_observer_;
 
   DISALLOW_COPY_AND_ASSIGN(IsolateHolder);
 };