[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 36e37408 | 2013-12-06 01:51:17 | [diff] [blame] | 5 | #ifndef GIN_PUBLIC_CONTEXT_HOLDER_H_ |
6 | #define GIN_PUBLIC_CONTEXT_HOLDER_H_ | ||||
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 7 | |
8 | #include <list> | ||||
mostynb | c862da8 | 2016-04-03 15:54:33 | [diff] [blame] | 9 | #include <memory> |
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 10 | |
avi | 90e658dd | 2015-12-21 07:16:19 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 12 | #include "gin/gin_export.h" |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 13 | #include "v8/include/v8.h" |
14 | |||||
15 | namespace gin { | ||||
16 | |||||
[email protected] | 36e37408 | 2013-12-06 01:51:17 | [diff] [blame] | 17 | // Gin embedder that store embedder data in v8::Contexts must do so in a |
18 | // single field with the index kPerContextDataStartIndex + GinEmbedder-enum. | ||||
19 | // The field at kDebugIdIndex is treated specially by V8 and is reserved for | ||||
20 | // a V8 debugger implementation (not used by gin). | ||||
21 | enum ContextEmbedderDataFields { | ||||
yurys | ea4636e | 2015-03-20 08:53:54 | [diff] [blame] | 22 | kDebugIdIndex = v8::Context::kDebugIdIndex, |
[email protected] | 36e37408 | 2013-12-06 01:51:17 | [diff] [blame] | 23 | kPerContextDataStartIndex, |
24 | }; | ||||
25 | |||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 26 | class PerContextData; |
27 | |||||
[email protected] | 1771610d | 2014-02-27 06:08:24 | [diff] [blame] | 28 | // ContextHolder is a generic class for holding a v8::Context. |
[email protected] | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 29 | class GIN_EXPORT ContextHolder { |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 30 | public: |
31 | explicit ContextHolder(v8::Isolate* isolate); | ||||
32 | ~ContextHolder(); | ||||
33 | |||||
34 | v8::Isolate* isolate() const { return isolate_; } | ||||
35 | |||||
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 36 | v8::Local<v8::Context> context() const { |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 37 | return v8::Local<v8::Context>::New(isolate_, context_); |
38 | } | ||||
39 | |||||
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 40 | void SetContext(v8::Local<v8::Context> context); |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 41 | |
42 | private: | ||||
43 | v8::Isolate* isolate_; | ||||
[email protected] | e13402e1 | 2013-12-17 07:56:59 | [diff] [blame] | 44 | v8::UniquePersistent<v8::Context> context_; |
mostynb | c862da8 | 2016-04-03 15:54:33 | [diff] [blame] | 45 | std::unique_ptr<PerContextData> data_; |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 46 | |
47 | DISALLOW_COPY_AND_ASSIGN(ContextHolder); | ||||
48 | }; | ||||
49 | |||||
50 | } // namespace gin | ||||
51 | |||||
[email protected] | 36e37408 | 2013-12-06 01:51:17 | [diff] [blame] | 52 | #endif // GIN_PUBLIC_CONTEXT_HOLDER_H_ |