OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../include/javascript/JavaScript.h" | 7 #include "../../include/javascript/JavaScript.h" |
8 #include "../../include/javascript/IJavaScript.h" | 8 #include "../../include/javascript/IJavaScript.h" |
9 #include "../../include/javascript/JS_EventHandler.h" | 9 #include "../../include/javascript/JS_EventHandler.h" |
10 #include "../../include/javascript/JS_Runtime.h" | 10 #include "../../include/javascript/JS_Runtime.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 free(data); | 91 free(data); |
92 } | 92 } |
93 | 93 |
94 /* ------------------------------ CJS_Runtime ------------------------------ */ | 94 /* ------------------------------ CJS_Runtime ------------------------------ */ |
95 | 95 |
96 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) | 96 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) |
97 : m_pApp(pApp), | 97 : m_pApp(pApp), |
98 m_pDocument(NULL), | 98 m_pDocument(NULL), |
99 m_bBlocking(FALSE), | 99 m_bBlocking(FALSE), |
100 m_pFieldEventPath(NULL), | 100 m_pFieldEventPath(NULL), |
101 m_isolate(NULL) { | 101 m_isolate(NULL), |
| 102 m_isolateManaged(false) { |
102 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { | 103 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { |
103 m_isolate = reinterpret_cast<v8::Isolate*>( | 104 m_isolate = reinterpret_cast<v8::Isolate*>( |
104 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); | 105 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); |
105 } | 106 } |
106 if (!m_isolate) { | 107 if (!m_isolate) { |
107 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); | 108 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); |
108 | 109 |
109 v8::Isolate::CreateParams params; | 110 v8::Isolate::CreateParams params; |
110 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); | 111 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); |
111 m_isolate = v8::Isolate::New(params); | 112 m_isolate = v8::Isolate::New(params); |
| 113 m_isolateManaged = true; |
112 } | 114 } |
113 | 115 |
114 InitJSObjects(); | 116 InitJSObjects(); |
115 | 117 |
116 CJS_Context* pContext = (CJS_Context*)NewContext(); | 118 CJS_Context* pContext = (CJS_Context*)NewContext(); |
117 JS_InitialRuntime(*this, this, pContext, m_context); | 119 JS_InitialRuntime(*this, this, pContext, m_context); |
118 ReleaseContext(pContext); | 120 ReleaseContext(pContext); |
119 } | 121 } |
120 | 122 |
121 CJS_Runtime::~CJS_Runtime() { | 123 CJS_Runtime::~CJS_Runtime() { |
122 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) | 124 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) |
123 delete m_ContextArray.GetAt(i); | 125 delete m_ContextArray.GetAt(i); |
124 | 126 |
125 m_ContextArray.RemoveAll(); | 127 m_ContextArray.RemoveAll(); |
126 | 128 |
127 JS_ReleaseRuntime(*this, m_context); | 129 JS_ReleaseRuntime(*this, m_context); |
128 | 130 |
129 RemoveEventsInLoop(m_pFieldEventPath); | 131 RemoveEventsInLoop(m_pFieldEventPath); |
130 | 132 |
131 m_pApp = NULL; | 133 m_pApp = NULL; |
132 m_pDocument = NULL; | 134 m_pDocument = NULL; |
133 m_pFieldEventPath = NULL; | 135 m_pFieldEventPath = NULL; |
134 m_context.Reset(); | 136 m_context.Reset(); |
135 | 137 |
136 // m_isolate->Exit(); | 138 if (m_isolateManaged) |
137 m_isolate->Dispose(); | 139 m_isolate->Dispose(); |
138 } | 140 } |
139 | 141 |
140 FX_BOOL CJS_Runtime::InitJSObjects() { | 142 FX_BOOL CJS_Runtime::InitJSObjects() { |
141 v8::Isolate::Scope isolate_scope(GetIsolate()); | 143 v8::Isolate::Scope isolate_scope(GetIsolate()); |
142 v8::HandleScope handle_scope(GetIsolate()); | 144 v8::HandleScope handle_scope(GetIsolate()); |
143 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); | 145 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); |
144 v8::Context::Scope context_scope(context); | 146 v8::Context::Scope context_scope(context); |
145 // 0 - 8 | 147 // 0 - 8 |
146 if (CJS_Border::Init(*this, JS_STATIC) < 0) | 148 if (CJS_Border::Init(*this, JS_STATIC) < 0) |
147 return FALSE; | 149 return FALSE; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 | 327 |
326 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { | 328 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { |
327 return v8::Local<v8::Context>::New(m_isolate, m_context); | 329 return v8::Local<v8::Context>::New(m_isolate, m_context); |
328 } | 330 } |
329 | 331 |
330 CFX_WideString ChangeObjName(const CFX_WideString& str) { | 332 CFX_WideString ChangeObjName(const CFX_WideString& str) { |
331 CFX_WideString sRet = str; | 333 CFX_WideString sRet = str; |
332 sRet.Replace(L"_", L"."); | 334 sRet.Replace(L"_", L"."); |
333 return sRet; | 335 return sRet; |
334 } | 336 } |
OLD | NEW |