OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium 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 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #ifndef XFA_SRC_FXJSE_SCOPE_INLINE_H_ | |
8 #define XFA_SRC_FXJSE_SCOPE_INLINE_H_ | |
9 | |
10 #include "xfa/src/fxjse/context.h" | |
11 #include "xfa/src/fxjse/runtime.h" | |
12 | |
13 class CFXJSE_ScopeUtil_IsolateHandle { | |
14 protected: | |
15 v8::Isolate* m_isolate; | |
16 v8::Locker m_locker; | |
17 v8::Isolate::Scope m_iscope; | |
18 v8::HandleScope m_hscope; | |
19 | |
20 public: | |
21 explicit CFXJSE_ScopeUtil_IsolateHandle(v8::Isolate* pIsolate) | |
22 : m_isolate(pIsolate), | |
23 m_locker(pIsolate), | |
24 m_iscope(pIsolate), | |
25 m_hscope(pIsolate) {} | |
26 v8::Isolate* GetIsolate() { return m_isolate; } | |
27 | |
28 private: | |
29 CFXJSE_ScopeUtil_IsolateHandle(const CFXJSE_ScopeUtil_IsolateHandle&); | |
30 void operator=(const CFXJSE_ScopeUtil_IsolateHandle&); | |
31 void* operator new(size_t size); | |
32 void operator delete(void*, size_t); | |
33 }; | |
34 class CFXJSE_ScopeUtil_IsolateHandleRootContext { | |
35 CFXJSE_ScopeUtil_IsolateHandle m_parent; | |
36 v8::Context::Scope m_cscope; | |
37 | |
38 public: | |
39 explicit CFXJSE_ScopeUtil_IsolateHandleRootContext(v8::Isolate* pIsolate) | |
40 : m_parent(pIsolate), | |
41 m_cscope(v8::Local<v8::Context>::New( | |
42 pIsolate, | |
43 CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext)) {} | |
44 | |
45 private: | |
46 CFXJSE_ScopeUtil_IsolateHandleRootContext( | |
47 const CFXJSE_ScopeUtil_IsolateHandleRootContext&); | |
48 void operator=(const CFXJSE_ScopeUtil_IsolateHandleRootContext&); | |
49 void* operator new(size_t size); | |
50 void operator delete(void*, size_t); | |
51 }; | |
52 class CFXJSE_ScopeUtil_IsolateHandleContext { | |
53 CFXJSE_Context* m_context; | |
54 CFXJSE_ScopeUtil_IsolateHandle m_parent; | |
55 v8::Context::Scope m_cscope; | |
56 | |
57 public: | |
58 explicit CFXJSE_ScopeUtil_IsolateHandleContext(CFXJSE_Context* pContext) | |
59 : m_context(pContext), | |
60 m_parent(pContext->m_pIsolate), | |
61 m_cscope(v8::Local<v8::Context>::New(pContext->m_pIsolate, | |
62 pContext->m_hContext)) {} | |
63 v8::Isolate* GetIsolate() { return m_context->m_pIsolate; } | |
64 v8::Local<v8::Context> GetLocalContext() { | |
65 return v8::Local<v8::Context>::New(m_context->m_pIsolate, | |
66 m_context->m_hContext); | |
67 } | |
68 | |
69 private: | |
70 CFXJSE_ScopeUtil_IsolateHandleContext( | |
71 const CFXJSE_ScopeUtil_IsolateHandleContext&); | |
72 void operator=(const CFXJSE_ScopeUtil_IsolateHandleContext&); | |
73 void* operator new(size_t size); | |
74 void operator delete(void*, size_t); | |
75 }; | |
76 class CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext { | |
77 CFXJSE_Context* m_context; | |
78 CFXJSE_ScopeUtil_IsolateHandle m_parent; | |
79 v8::Context::Scope m_cscope; | |
80 | |
81 public: | |
82 explicit CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext( | |
83 v8::Isolate* pIsolate, | |
84 CFXJSE_Context* pContext) | |
85 : m_context(pContext), | |
86 m_parent(pIsolate), | |
87 m_cscope(v8::Local<v8::Context>::New( | |
88 pIsolate, | |
89 pContext ? pContext->m_hContext | |
90 : CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext)) {} | |
91 v8::Isolate* GetIsolate() { return m_parent.GetIsolate(); } | |
92 v8::Local<v8::Context> GetLocalContext() { | |
93 v8::Isolate* pIsolate = m_parent.GetIsolate(); | |
94 return v8::Local<v8::Context>::New( | |
95 pIsolate, m_context | |
96 ? m_context->m_hContext | |
97 : CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext); | |
98 } | |
99 | |
100 private: | |
101 CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext( | |
102 const CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext&); | |
103 void operator=(const CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext&); | |
104 void* operator new(size_t size); | |
105 void operator delete(void*, size_t); | |
106 }; | |
107 | |
108 #endif // XFA_SRC_FXJSE_SCOPE_INLINE_H_ | |
OLD | NEW |