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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 106 } |
107 if (!m_isolate) { | 107 if (!m_isolate) { |
108 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); | 108 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); |
109 | 109 |
110 v8::Isolate::CreateParams params; | 110 v8::Isolate::CreateParams params; |
111 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); | 111 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); |
112 m_isolate = v8::Isolate::New(params); | 112 m_isolate = v8::Isolate::New(params); |
113 m_isolateManaged = true; | 113 m_isolateManaged = true; |
114 } | 114 } |
115 | 115 |
116 InitJSObjects(); | 116 DefineJSObjects(); |
117 | 117 |
118 CJS_Context* pContext = (CJS_Context*)NewContext(); | 118 CJS_Context* pContext = (CJS_Context*)NewContext(); |
119 JS_InitialRuntime(GetIsolate(), this, pContext, m_context); | 119 JS_InitialRuntime(GetIsolate(), this, pContext, m_context); |
120 ReleaseContext(pContext); | 120 ReleaseContext(pContext); |
121 } | 121 } |
122 | 122 |
123 CJS_Runtime::~CJS_Runtime() { | 123 CJS_Runtime::~CJS_Runtime() { |
124 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) | 124 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) |
125 delete m_ContextArray.GetAt(i); | 125 delete m_ContextArray.GetAt(i); |
126 | 126 |
127 m_ContextArray.RemoveAll(); | 127 m_ContextArray.RemoveAll(); |
128 JS_ReleaseRuntime(GetIsolate(), m_context); | 128 JS_ReleaseRuntime(GetIsolate(), m_context); |
129 RemoveEventsInLoop(m_pFieldEventPath); | 129 RemoveEventsInLoop(m_pFieldEventPath); |
130 | 130 |
131 m_pApp = NULL; | 131 m_pApp = NULL; |
132 m_pDocument = NULL; | 132 m_pDocument = NULL; |
133 m_pFieldEventPath = NULL; | 133 m_pFieldEventPath = NULL; |
134 m_context.Reset(); | 134 m_context.Reset(); |
135 | 135 |
136 if (m_isolateManaged) | 136 if (m_isolateManaged) |
137 m_isolate->Dispose(); | 137 m_isolate->Dispose(); |
138 } | 138 } |
139 | 139 |
140 FX_BOOL CJS_Runtime::InitJSObjects() { | 140 FX_BOOL CJS_Runtime::DefineJSObjects() { |
141 v8::Isolate::Scope isolate_scope(GetIsolate()); | 141 v8::Isolate::Scope isolate_scope(GetIsolate()); |
142 v8::HandleScope handle_scope(GetIsolate()); | 142 v8::HandleScope handle_scope(GetIsolate()); |
143 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); | 143 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); |
144 v8::Context::Scope context_scope(context); | 144 v8::Context::Scope context_scope(context); |
145 // 0 - 8 | 145 |
146 if (CJS_Border::Init(GetIsolate(), JS_STATIC) < 0) | 146 // The call order determines the "ObjDefID" assigned to each class. |
| 147 // ObjDefIDs 0 - 2 |
| 148 if (CJS_Border::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
147 return FALSE; | 149 return FALSE; |
148 if (CJS_Display::Init(GetIsolate(), JS_STATIC) < 0) | 150 if (CJS_Display::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
149 return FALSE; | 151 return FALSE; |
150 if (CJS_Font::Init(GetIsolate(), JS_STATIC) < 0) | 152 if (CJS_Font::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
151 return FALSE; | |
152 if (CJS_Highlight::Init(GetIsolate(), JS_STATIC) < 0) | |
153 return FALSE; | |
154 if (CJS_Position::Init(GetIsolate(), JS_STATIC) < 0) | |
155 return FALSE; | |
156 if (CJS_ScaleHow::Init(GetIsolate(), JS_STATIC) < 0) | |
157 return FALSE; | |
158 if (CJS_ScaleWhen::Init(GetIsolate(), JS_STATIC) < 0) | |
159 return FALSE; | |
160 if (CJS_Style::Init(GetIsolate(), JS_STATIC) < 0) | |
161 return FALSE; | |
162 if (CJS_Zoomtype::Init(GetIsolate(), JS_STATIC) < 0) | |
163 return FALSE; | 153 return FALSE; |
164 | 154 |
165 // 9 - 11 | 155 // ObjDefIDs 3 - 5 |
166 if (CJS_App::Init(GetIsolate(), JS_STATIC) < 0) | 156 if (CJS_Highlight::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
167 return FALSE; | 157 return FALSE; |
168 if (CJS_Color::Init(GetIsolate(), JS_STATIC) < 0) | 158 if (CJS_Position::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
169 return FALSE; | 159 return FALSE; |
170 if (CJS_Console::Init(GetIsolate(), JS_STATIC) < 0) | 160 if (CJS_ScaleHow::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
171 return FALSE; | 161 return FALSE; |
172 | 162 |
173 // 12 - 14 | 163 // ObjDefIDs 6 - 8 |
174 if (CJS_Document::Init(GetIsolate(), JS_DYNAMIC) < 0) | 164 if (CJS_ScaleWhen::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
175 return FALSE; | 165 return FALSE; |
176 if (CJS_Event::Init(GetIsolate(), JS_STATIC) < 0) | 166 if (CJS_Style::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
177 return FALSE; | 167 return FALSE; |
178 if (CJS_Field::Init(GetIsolate(), JS_DYNAMIC) < 0) | 168 if (CJS_Zoomtype::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
179 return FALSE; | 169 return FALSE; |
180 | 170 |
181 // 15 - 17 | 171 // ObjDefIDs 9 - 11 |
182 if (CJS_Global::Init(GetIsolate(), JS_STATIC) < 0) | 172 if (CJS_App::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
183 return FALSE; | 173 return FALSE; |
184 if (CJS_Icon::Init(GetIsolate(), JS_DYNAMIC) < 0) | 174 if (CJS_Color::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
185 return FALSE; | 175 return FALSE; |
186 if (CJS_Util::Init(GetIsolate(), JS_STATIC) < 0) | 176 if (CJS_Console::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
187 return FALSE; | 177 return FALSE; |
188 | 178 |
189 if (CJS_PublicMethods::Init(GetIsolate()) < 0) | 179 // ObjDefIDs 12 - 14 |
| 180 if (CJS_Document::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0) |
190 return FALSE; | 181 return FALSE; |
191 if (CJS_GlobalConsts::Init(GetIsolate()) < 0) | 182 if (CJS_Event::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
192 return FALSE; | 183 return FALSE; |
193 if (CJS_GlobalArrays::Init(GetIsolate()) < 0) | 184 if (CJS_Field::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0) |
194 return FALSE; | 185 return FALSE; |
195 | 186 |
196 if (CJS_TimerObj::Init(GetIsolate(), JS_DYNAMIC) < 0) | 187 // ObjDefIDs 15 - 17 |
| 188 if (CJS_Global::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
197 return FALSE; | 189 return FALSE; |
198 if (CJS_PrintParamsObj::Init(GetIsolate(), JS_DYNAMIC) < 0) | 190 if (CJS_Icon::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0) |
| 191 return FALSE; |
| 192 if (CJS_Util::DefineJSObjects(GetIsolate(), JS_STATIC) < 0) |
| 193 return FALSE; |
| 194 |
| 195 // ObjDefIDs 18 - 20 |
| 196 if (CJS_PublicMethods::DefineJSObjects(GetIsolate()) < 0) |
| 197 return FALSE; |
| 198 if (CJS_GlobalConsts::DefineJSObjects(GetIsolate()) < 0) |
| 199 return FALSE; |
| 200 if (CJS_GlobalArrays::DefineJSObjects(GetIsolate()) < 0) |
| 201 return FALSE; |
| 202 |
| 203 if (CJS_TimerObj::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0) |
| 204 return FALSE; |
| 205 if (CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0) |
199 return FALSE; | 206 return FALSE; |
200 | 207 |
201 return TRUE; | 208 return TRUE; |
202 } | 209 } |
203 | 210 |
204 IFXJS_Context* CJS_Runtime::NewContext() { | 211 IFXJS_Context* CJS_Runtime::NewContext() { |
205 CJS_Context* p = new CJS_Context(this); | 212 CJS_Context* p = new CJS_Context(this); |
206 m_ContextArray.Add(p); | 213 m_ContextArray.Add(p); |
207 return p; | 214 return p; |
208 } | 215 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 329 |
323 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { | 330 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { |
324 return v8::Local<v8::Context>::New(m_isolate, m_context); | 331 return v8::Local<v8::Context>::New(m_isolate, m_context); |
325 } | 332 } |
326 | 333 |
327 CFX_WideString ChangeObjName(const CFX_WideString& str) { | 334 CFX_WideString ChangeObjName(const CFX_WideString& str) { |
328 CFX_WideString sRet = str; | 335 CFX_WideString sRet = str; |
329 sRet.Replace(L"_", L"."); | 336 sRet.Replace(L"_", L"."); |
330 return sRet; | 337 return sRet; |
331 } | 338 } |
OLD | NEW |