Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fxjse / src / scope_inline.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #ifndef FXJSE_SCOPE_INLINE_H_\r
8 #define FXJSE_SCOPE_INLINE_H_\r
9 #include "runtime.h"\r
10 #include "context.h"\r
11 class CFXJSE_ScopeUtil_IsolateHandle\r
12 {\r
13 protected:\r
14     v8::Isolate*                m_isolate;\r
15     v8::Locker                  m_locker;\r
16     v8::Isolate::Scope  m_iscope;\r
17     v8::HandleScope             m_hscope;\r
18 public:\r
19     explicit CFXJSE_ScopeUtil_IsolateHandle(v8::Isolate* pIsolate) : m_isolate(pIsolate), m_locker(pIsolate), m_iscope(pIsolate), m_hscope(pIsolate) {}\r
20     v8::Isolate*                        GetIsolate()\r
21     {\r
22         return m_isolate;\r
23     }\r
24 private:\r
25     CFXJSE_ScopeUtil_IsolateHandle(const CFXJSE_ScopeUtil_IsolateHandle&);\r
26     void operator=(const CFXJSE_ScopeUtil_IsolateHandle&);\r
27     void* operator new(size_t size);\r
28     void operator delete(void*, size_t);\r
29 };\r
30 class CFXJSE_ScopeUtil_IsolateHandleRootContext\r
31 {\r
32     CFXJSE_ScopeUtil_IsolateHandle m_parent;\r
33     v8::Context::Scope  m_cscope;\r
34 public:\r
35     explicit CFXJSE_ScopeUtil_IsolateHandleRootContext(v8::Isolate* pIsolate) : m_parent(pIsolate), m_cscope(v8::Local<v8::Context>::New(pIsolate,      CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext)) {}\r
36 private:\r
37     CFXJSE_ScopeUtil_IsolateHandleRootContext(const CFXJSE_ScopeUtil_IsolateHandleRootContext&);\r
38     void operator=(const CFXJSE_ScopeUtil_IsolateHandleRootContext&);\r
39     void* operator new(size_t size);\r
40     void operator delete(void*, size_t);\r
41 };\r
42 class CFXJSE_ScopeUtil_IsolateHandleContext\r
43 {\r
44     CFXJSE_Context*                                     m_context;\r
45     CFXJSE_ScopeUtil_IsolateHandle      m_parent;\r
46     v8::Context::Scope                          m_cscope;\r
47 public:\r
48     explicit CFXJSE_ScopeUtil_IsolateHandleContext(CFXJSE_Context* pContext) : m_context(pContext), m_parent(pContext->m_pIsolate), m_cscope(v8::Local<v8::Context>::New(pContext->m_pIsolate, pContext->m_hContext)) {}\r
49     v8::Isolate*                        GetIsolate()\r
50     {\r
51         return m_context->m_pIsolate;\r
52     }\r
53     v8::Local<v8::Context>      GetLocalContext()\r
54     {\r
55         return v8::Local<v8::Context>::New(m_context->m_pIsolate, m_context->m_hContext);\r
56     }\r
57 private:\r
58     CFXJSE_ScopeUtil_IsolateHandleContext(const CFXJSE_ScopeUtil_IsolateHandleContext&);\r
59     void operator=(const CFXJSE_ScopeUtil_IsolateHandleContext&);\r
60     void* operator new(size_t size);\r
61     void operator delete(void*, size_t);\r
62 };\r
63 class CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext\r
64 {\r
65     CFXJSE_Context*                                     m_context;\r
66     CFXJSE_ScopeUtil_IsolateHandle      m_parent;\r
67     v8::Context::Scope                          m_cscope;\r
68 public:\r
69     explicit CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext(v8::Isolate* pIsolate, CFXJSE_Context* pContext)\r
70         : m_context(pContext), m_parent(pIsolate), m_cscope(v8::Local<v8::Context>::New(pIsolate, pContext ? pContext->m_hContext : CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext)) {}\r
71     v8::Isolate*                        GetIsolate()\r
72     {\r
73         return m_parent.GetIsolate();\r
74     }\r
75     v8::Local<v8::Context>      GetLocalContext()\r
76     {\r
77         v8::Isolate* pIsolate = m_parent.GetIsolate();\r
78         return v8::Local<v8::Context>::New(pIsolate, m_context ? m_context->m_hContext : CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext);\r
79     }\r
80 private:\r
81     CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext(const CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext&);\r
82     void operator=(const CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext&);\r
83     void* operator new(size_t size);\r
84     void operator delete(void*, size_t);\r
85 };\r
86 #endif\r