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 <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 kDisallowAtomicsWait, | 46 kDisallowAtomicsWait, |
47 kAllowAtomicsWait | 47 kAllowAtomicsWait |
48 }; | 48 }; |
49 | 49 |
50 // Indicates whether V8 works with stable or experimental v8 extras. | 50 // Indicates whether V8 works with stable or experimental v8 extras. |
51 enum V8ExtrasMode { | 51 enum V8ExtrasMode { |
52 kStableV8Extras, | 52 kStableV8Extras, |
53 kStableAndExperimentalV8Extras, | 53 kStableAndExperimentalV8Extras, |
54 }; | 54 }; |
55 | 55 |
56 enum V8ContextMode { | |
57 kDefault, | |
58 kTakeSnapshot, | |
59 kUseSnapshot, | |
60 }; | |
61 | |
56 explicit IsolateHolder( | 62 explicit IsolateHolder( |
57 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 63 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
58 IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 64 IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
59 AccessMode access_mode); | 65 AccessMode access_mode); |
60 IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 66 IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
61 AccessMode access_mode, | 67 AccessMode access_mode, |
62 AllowAtomicsWaitMode atomics_wait_mode); | 68 AllowAtomicsWaitMode atomics_wait_mode, |
69 intptr_t*, | |
Yuki
2017/05/12 15:20:09
nit: Write the argument name that is not trivial.
peria
2017/05/30 08:25:41
Done.
| |
70 V8ContextMode); | |
63 ~IsolateHolder(); | 71 ~IsolateHolder(); |
64 | 72 |
65 // Should be invoked once before creating IsolateHolder instances to | 73 // Should be invoked once before creating IsolateHolder instances to |
66 // initialize V8 and Gin. In case V8_USE_EXTERNAL_STARTUP_DATA is | 74 // initialize V8 and Gin. In case V8_USE_EXTERNAL_STARTUP_DATA is |
67 // defined, V8's initial natives should be loaded (by calling | 75 // defined, V8's initial natives should be loaded (by calling |
68 // V8Initializer::LoadV8NativesFromFD or | 76 // V8Initializer::LoadV8NativesFromFD or |
69 // V8Initializer::LoadV8Natives) before calling this method. If the | 77 // V8Initializer::LoadV8Natives) before calling this method. If the |
70 // snapshot file is available, it should also be loaded (by calling | 78 // snapshot file is available, it should also be loaded (by calling |
71 // V8Initializer::LoadV8SnapshotFromFD or | 79 // V8Initializer::LoadV8SnapshotFromFD or |
72 // V8Initializer::LoadV8Snapshot) before calling this method. | 80 // V8Initializer::LoadV8Snapshot) before calling this method. |
73 static void Initialize(ScriptMode mode, | 81 static void Initialize(ScriptMode mode, |
74 V8ExtrasMode v8_extras_mode, | 82 V8ExtrasMode v8_extras_mode, |
75 v8::ArrayBuffer::Allocator* allocator); | 83 v8::ArrayBuffer::Allocator* allocator); |
76 | 84 |
77 v8::Isolate* isolate() { return isolate_; } | 85 v8::Isolate* isolate() { return isolate_; } |
86 v8::SnapshotCreator* snapshot_creator() { return snapshot_creator_.get(); } | |
78 | 87 |
79 // The implementations of Object.observe() and Promise enqueue v8 Microtasks | 88 // The implementations of Object.observe() and Promise enqueue v8 Microtasks |
80 // that should be executed just before control is returned to the message | 89 // that should be executed just before control is returned to the message |
81 // loop. This method adds a MessageLoop TaskObserver which runs any pending | 90 // loop. This method adds a MessageLoop TaskObserver which runs any pending |
82 // Microtasks each time a Task is completed. This method should be called | 91 // Microtasks each time a Task is completed. This method should be called |
83 // once, when a MessageLoop is created and it should be called on the | 92 // once, when a MessageLoop is created and it should be called on the |
84 // MessageLoop's thread. | 93 // MessageLoop's thread. |
85 void AddRunMicrotasksObserver(); | 94 void AddRunMicrotasksObserver(); |
86 | 95 |
87 // This method should also only be called once, and on the MessageLoop's | 96 // This method should also only be called once, and on the MessageLoop's |
88 // thread. | 97 // thread. |
89 void RemoveRunMicrotasksObserver(); | 98 void RemoveRunMicrotasksObserver(); |
90 | 99 |
91 // This method returns if v8::Locker is needed to access isolate. | 100 // This method returns if v8::Locker is needed to access isolate. |
92 AccessMode access_mode() const { return access_mode_; } | 101 AccessMode access_mode() const { return access_mode_; } |
93 | 102 |
94 void EnableIdleTasks(std::unique_ptr<V8IdleTaskRunner> idle_task_runner); | 103 void EnableIdleTasks(std::unique_ptr<V8IdleTaskRunner> idle_task_runner); |
95 | 104 |
96 // This method returns V8IsolateMemoryDumpProvider of this isolate, used for | 105 // This method returns V8IsolateMemoryDumpProvider of this isolate, used for |
97 // testing. | 106 // testing. |
98 V8IsolateMemoryDumpProvider* isolate_memory_dump_provider_for_testing() | 107 V8IsolateMemoryDumpProvider* isolate_memory_dump_provider_for_testing() |
99 const { | 108 const { |
100 return isolate_memory_dump_provider_.get(); | 109 return isolate_memory_dump_provider_.get(); |
101 } | 110 } |
102 | 111 |
112 V8ContextMode v8_context_mode() const { return v8_context_mode_; } | |
113 | |
103 private: | 114 private: |
104 v8::Isolate* isolate_; | 115 v8::Isolate* isolate_; |
116 std::unique_ptr<v8::SnapshotCreator> snapshot_creator_; | |
105 std::unique_ptr<PerIsolateData> isolate_data_; | 117 std::unique_ptr<PerIsolateData> isolate_data_; |
106 std::unique_ptr<RunMicrotasksObserver> task_observer_; | 118 std::unique_ptr<RunMicrotasksObserver> task_observer_; |
107 std::unique_ptr<V8IsolateMemoryDumpProvider> isolate_memory_dump_provider_; | 119 std::unique_ptr<V8IsolateMemoryDumpProvider> isolate_memory_dump_provider_; |
108 AccessMode access_mode_; | 120 AccessMode access_mode_; |
121 v8::StartupData startup_data_; | |
122 V8ContextMode v8_context_mode_; | |
109 | 123 |
110 DISALLOW_COPY_AND_ASSIGN(IsolateHolder); | 124 DISALLOW_COPY_AND_ASSIGN(IsolateHolder); |
111 }; | 125 }; |
112 | 126 |
113 } // namespace gin | 127 } // namespace gin |
114 | 128 |
115 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_ | 129 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_ |
OLD | NEW |