Chromium Code Reviews| 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 // Whether to use V8 context snapshot for blink. | |
| 57 enum V8ContextMode { | |
|
haraken
2017/05/20 19:10:02
V8ContextShapshotMode
peria
2017/06/01 08:33:32
Done.
| |
| 58 kDefault, | |
|
haraken
2017/05/20 19:10:02
kDoNotUseSnapshot
peria
2017/05/30 08:25:43
Done.
| |
| 59 kUseSnapshot, | |
| 60 kTakeSnapshot, | |
| 61 }; | |
| 62 | |
| 56 explicit IsolateHolder( | 63 explicit IsolateHolder( |
| 57 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 64 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 58 IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 65 IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 59 AccessMode access_mode); | 66 AccessMode access_mode); |
| 60 IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 67 IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 61 AccessMode access_mode, | 68 AccessMode access_mode, |
| 62 AllowAtomicsWaitMode atomics_wait_mode); | 69 AllowAtomicsWaitMode atomics_wait_mode, |
| 70 intptr_t*, | |
|
haraken
2017/05/20 19:10:02
intptr_t* reference_table
peria
2017/05/30 08:25:44
Done.
| |
| 71 V8ContextMode); | |
| 63 ~IsolateHolder(); | 72 ~IsolateHolder(); |
| 64 | 73 |
| 65 // Should be invoked once before creating IsolateHolder instances to | 74 // Should be invoked once before creating IsolateHolder instances to |
| 66 // initialize V8 and Gin. In case V8_USE_EXTERNAL_STARTUP_DATA is | 75 // initialize V8 and Gin. In case V8_USE_EXTERNAL_STARTUP_DATA is |
| 67 // defined, V8's initial natives should be loaded (by calling | 76 // defined, V8's initial natives should be loaded (by calling |
| 68 // V8Initializer::LoadV8NativesFromFD or | 77 // V8Initializer::LoadV8NativesFromFD or |
| 69 // V8Initializer::LoadV8Natives) before calling this method. If the | 78 // V8Initializer::LoadV8Natives) before calling this method. If the |
| 70 // snapshot file is available, it should also be loaded (by calling | 79 // snapshot file is available, it should also be loaded (by calling |
| 71 // V8Initializer::LoadV8SnapshotFromFD or | 80 // V8Initializer::LoadV8SnapshotFromFD or |
| 72 // V8Initializer::LoadV8Snapshot) before calling this method. | 81 // V8Initializer::LoadV8Snapshot) before calling this method. |
| 73 static void Initialize(ScriptMode mode, | 82 static void Initialize(ScriptMode mode, |
| 74 V8ExtrasMode v8_extras_mode, | 83 V8ExtrasMode v8_extras_mode, |
| 75 v8::ArrayBuffer::Allocator* allocator); | 84 v8::ArrayBuffer::Allocator* allocator); |
| 76 | 85 |
| 77 v8::Isolate* isolate() { return isolate_; } | 86 v8::Isolate* isolate() { return isolate_; } |
| 87 v8::SnapshotCreator* snapshot_creator() { return snapshot_creator_.get(); } | |
| 78 | 88 |
| 79 // The implementations of Object.observe() and Promise enqueue v8 Microtasks | 89 // The implementations of Object.observe() and Promise enqueue v8 Microtasks |
| 80 // that should be executed just before control is returned to the message | 90 // that should be executed just before control is returned to the message |
| 81 // loop. This method adds a MessageLoop TaskObserver which runs any pending | 91 // loop. This method adds a MessageLoop TaskObserver which runs any pending |
| 82 // Microtasks each time a Task is completed. This method should be called | 92 // 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 | 93 // once, when a MessageLoop is created and it should be called on the |
| 84 // MessageLoop's thread. | 94 // MessageLoop's thread. |
| 85 void AddRunMicrotasksObserver(); | 95 void AddRunMicrotasksObserver(); |
| 86 | 96 |
| 87 // This method should also only be called once, and on the MessageLoop's | 97 // This method should also only be called once, and on the MessageLoop's |
| 88 // thread. | 98 // thread. |
| 89 void RemoveRunMicrotasksObserver(); | 99 void RemoveRunMicrotasksObserver(); |
| 90 | 100 |
| 91 // This method returns if v8::Locker is needed to access isolate. | 101 // This method returns if v8::Locker is needed to access isolate. |
| 92 AccessMode access_mode() const { return access_mode_; } | 102 AccessMode access_mode() const { return access_mode_; } |
| 93 | 103 |
| 94 void EnableIdleTasks(std::unique_ptr<V8IdleTaskRunner> idle_task_runner); | 104 void EnableIdleTasks(std::unique_ptr<V8IdleTaskRunner> idle_task_runner); |
| 95 | 105 |
| 96 // This method returns V8IsolateMemoryDumpProvider of this isolate, used for | 106 // This method returns V8IsolateMemoryDumpProvider of this isolate, used for |
| 97 // testing. | 107 // testing. |
| 98 V8IsolateMemoryDumpProvider* isolate_memory_dump_provider_for_testing() | 108 V8IsolateMemoryDumpProvider* isolate_memory_dump_provider_for_testing() |
| 99 const { | 109 const { |
| 100 return isolate_memory_dump_provider_.get(); | 110 return isolate_memory_dump_provider_.get(); |
| 101 } | 111 } |
| 102 | 112 |
| 113 V8ContextMode v8_context_mode() const { return v8_context_mode_; } | |
| 114 | |
| 103 private: | 115 private: |
| 104 v8::Isolate* isolate_; | 116 v8::Isolate* isolate_; |
| 117 std::unique_ptr<v8::SnapshotCreator> snapshot_creator_; | |
| 105 std::unique_ptr<PerIsolateData> isolate_data_; | 118 std::unique_ptr<PerIsolateData> isolate_data_; |
| 106 std::unique_ptr<RunMicrotasksObserver> task_observer_; | 119 std::unique_ptr<RunMicrotasksObserver> task_observer_; |
| 107 std::unique_ptr<V8IsolateMemoryDumpProvider> isolate_memory_dump_provider_; | 120 std::unique_ptr<V8IsolateMemoryDumpProvider> isolate_memory_dump_provider_; |
| 108 AccessMode access_mode_; | 121 AccessMode access_mode_; |
| 122 v8::StartupData startup_data_; | |
| 123 V8ContextMode v8_context_mode_; | |
|
haraken
2017/05/20 19:10:02
Can we probably simplify the code by moving these
peria
2017/05/30 08:25:44
Done.
| |
| 109 | 124 |
| 110 DISALLOW_COPY_AND_ASSIGN(IsolateHolder); | 125 DISALLOW_COPY_AND_ASSIGN(IsolateHolder); |
| 111 }; | 126 }; |
| 112 | 127 |
| 113 } // namespace gin | 128 } // namespace gin |
| 114 | 129 |
| 115 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_ | 130 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_ |
| OLD | NEW |