OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GIN_PUBLIC_ISOLATE_HOLDER_H_ | 5 #ifndef GIN_PUBLIC_ISOLATE_HOLDER_H_ |
6 #define GIN_PUBLIC_ISOLATE_HOLDER_H_ | 6 #define GIN_PUBLIC_ISOLATE_HOLDER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "gin/gin_export.h" | 10 #include "gin/gin_export.h" |
11 #include "v8/include/v8.h" | 11 #include "v8/include/v8.h" |
12 | 12 |
13 namespace gin { | 13 namespace gin { |
14 | 14 |
15 class PerIsolateData; | 15 class PerIsolateData; |
| 16 class RunMicrotasksObserver; |
16 | 17 |
17 // To embed Gin, first initialize gin using IsolateHolder::Initialize and then | 18 // To embed Gin, first initialize gin using IsolateHolder::Initialize and then |
18 // create an instance of IsolateHolder to hold the v8::Isolate in which you | 19 // create an instance of IsolateHolder to hold the v8::Isolate in which you |
19 // will execute JavaScript. You might wish to subclass IsolateHolder if you | 20 // will execute JavaScript. You might wish to subclass IsolateHolder if you |
20 // want to tie more state to the lifetime of the isolate. | 21 // want to tie more state to the lifetime of the isolate. |
21 class GIN_EXPORT IsolateHolder { | 22 class GIN_EXPORT IsolateHolder { |
22 public: | 23 public: |
23 // Controls whether or not V8 should only accept strict mode scripts. | 24 // Controls whether or not V8 should only accept strict mode scripts. |
24 enum ScriptMode { | 25 enum ScriptMode { |
25 kNonStrictMode, | 26 kNonStrictMode, |
26 kStrictMode | 27 kStrictMode |
27 }; | 28 }; |
28 | 29 |
29 IsolateHolder(); | 30 IsolateHolder(); |
30 ~IsolateHolder(); | 31 ~IsolateHolder(); |
31 | 32 |
32 // Should be invoked once before creating IsolateHolder instances to | 33 // Should be invoked once before creating IsolateHolder instances to |
33 // initialize V8 and Gin. | 34 // initialize V8 and Gin. |
34 static void Initialize(ScriptMode mode, | 35 static void Initialize(ScriptMode mode, |
35 v8::ArrayBuffer::Allocator* allocator); | 36 v8::ArrayBuffer::Allocator* allocator); |
36 | 37 |
37 v8::Isolate* isolate() { return isolate_; } | 38 v8::Isolate* isolate() { return isolate_; } |
38 | 39 |
| 40 // The implementations of Object.observe() and Promise enqueue v8 Microtasks |
| 41 // that should be executed just before control is returned to the message |
| 42 // loop. This method adds a MessageLoop TaskObserver which runs any pending |
| 43 // Microtasks each time a Task is completed. This method should be called |
| 44 // once, when a MessageLoop is created and it should be called on the |
| 45 // MessageLoop's thread. |
| 46 void AddRunMicrotasksObserver(); |
| 47 |
| 48 // This method should also only be called once, and on the MessageLoop's |
| 49 // thread. |
| 50 void RemoveRunMicrotasksObserver(); |
| 51 |
39 private: | 52 private: |
40 v8::Isolate* isolate_; | 53 v8::Isolate* isolate_; |
41 scoped_ptr<PerIsolateData> isolate_data_; | 54 scoped_ptr<PerIsolateData> isolate_data_; |
| 55 scoped_ptr<RunMicrotasksObserver> task_observer_; |
42 | 56 |
43 DISALLOW_COPY_AND_ASSIGN(IsolateHolder); | 57 DISALLOW_COPY_AND_ASSIGN(IsolateHolder); |
44 }; | 58 }; |
45 | 59 |
46 } // namespace gin | 60 } // namespace gin |
47 | 61 |
48 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_ | 62 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_ |
OLD | NEW |