Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(924)

Side by Side Diff: fpdfsdk/src/javascript/JS_Runtime.cpp

Issue 1258093002: FX Bool considered harmful, part 3 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/javascript/JS_GlobalData.cpp ('k') | fpdfsdk/src/javascript/JS_Value.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 22 matching lines...) Expand all
33 33
34 IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environ ment* pApp) 34 IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environ ment* pApp)
35 { 35 {
36 if (!m_bInit) 36 if (!m_bInit)
37 { 37 {
38 unsigned int embedderDataSlot = 0; 38 unsigned int embedderDataSlot = 0;
39 if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { 39 if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
40 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8Embed derSlot; 40 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8Embed derSlot;
41 } 41 }
42 JS_Initial(embedderDataSlot); 42 JS_Initial(embedderDataSlot);
43 m_bInit = TRUE; 43 m_bInit = true;
44 } 44 }
45 return new CJS_Runtime(pApp); 45 return new CJS_Runtime(pApp);
46 } 46 }
47 void CJS_RuntimeFactory::AddRef() 47 void CJS_RuntimeFactory::AddRef()
48 { 48 {
49 //to do.Should be implemented as atom manipulation. 49 //to do.Should be implemented as atom manipulation.
50 m_nRef++; 50 m_nRef++;
51 } 51 }
52 void CJS_RuntimeFactory::Release() 52 void CJS_RuntimeFactory::Release()
53 { 53 {
54 if(m_bInit) 54 if(m_bInit)
55 { 55 {
56 //to do.Should be implemented as atom manipulation. 56 //to do.Should be implemented as atom manipulation.
57 if (--m_nRef == 0) 57 if (--m_nRef == 0)
58 { 58 {
59 JS_Release(); 59 JS_Release();
60 ReleaseGlobalData(); 60 ReleaseGlobalData();
61 m_bInit = FALSE; 61 m_bInit = false;
62 } 62 }
63 } 63 }
64 } 64 }
65 65
66 void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtim e* pRuntime) 66 void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtim e* pRuntime)
67 { 67 {
68 delete (CJS_Runtime*)pRuntime; 68 delete (CJS_Runtime*)pRuntime;
69 } 69 }
70 70
71 CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp) 71 CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp)
(...skipping 29 matching lines...) Expand all
101 101
102 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { 102 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) {
103 free(data); 103 free(data);
104 } 104 }
105 105
106 /* ------------------------------ CJS_Runtime ------------------------------ */ 106 /* ------------------------------ CJS_Runtime ------------------------------ */
107 107
108 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) : 108 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) :
109 m_pApp(pApp), 109 m_pApp(pApp),
110 m_pDocument(NULL), 110 m_pDocument(NULL),
111 » m_bBlocking(FALSE), 111 » m_bBlocking(false),
112 m_pFieldEventPath(NULL), 112 m_pFieldEventPath(NULL),
113 m_isolate(NULL) 113 m_isolate(NULL)
114 { 114 {
115 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { 115 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
116 m_isolate = reinterpret_cast<v8::Isolate*>(m_pApp->GetFormFillInfo()->m_ pJsPlatform->m_isolate); 116 m_isolate = reinterpret_cast<v8::Isolate*>(m_pApp->GetFormFillInfo()->m_ pJsPlatform->m_isolate);
117 } 117 }
118 if (!m_isolate) { 118 if (!m_isolate) {
119 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); 119 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator());
120 120
121 v8::Isolate::CreateParams params; 121 v8::Isolate::CreateParams params;
(...skipping 21 matching lines...) Expand all
143 143
144 m_pApp = NULL; 144 m_pApp = NULL;
145 m_pDocument = NULL; 145 m_pDocument = NULL;
146 m_pFieldEventPath = NULL; 146 m_pFieldEventPath = NULL;
147 m_context.Reset(); 147 m_context.Reset();
148 148
149 //m_isolate->Exit(); 149 //m_isolate->Exit();
150 m_isolate->Dispose(); 150 m_isolate->Dispose();
151 } 151 }
152 152
153 FX_BOOL CJS_Runtime::InitJSObjects() 153 bool CJS_Runtime::InitJSObjects()
154 { 154 {
155 v8::Isolate::Scope isolate_scope(GetIsolate()); 155 v8::Isolate::Scope isolate_scope(GetIsolate());
156 v8::HandleScope handle_scope(GetIsolate()); 156 v8::HandleScope handle_scope(GetIsolate());
157 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); 157 v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
158 v8::Context::Scope context_scope(context); 158 v8::Context::Scope context_scope(context);
159 //0 - 8 159 //0 - 8
160 if (CJS_Border::Init(*this, JS_STATIC) < 0) return FALSE; 160 if (CJS_Border::Init(*this, JS_STATIC) < 0) return false;
161 if (CJS_Display::Init(*this, JS_STATIC) < 0) return FALSE; 161 if (CJS_Display::Init(*this, JS_STATIC) < 0) return false;
162 if (CJS_Font::Init(*this, JS_STATIC) < 0) return FALSE; 162 if (CJS_Font::Init(*this, JS_STATIC) < 0) return false;
163 if (CJS_Highlight::Init(*this, JS_STATIC) < 0) return FALSE; 163 if (CJS_Highlight::Init(*this, JS_STATIC) < 0) return false;
164 if (CJS_Position::Init(*this, JS_STATIC) < 0) return FALSE; 164 if (CJS_Position::Init(*this, JS_STATIC) < 0) return false;
165 if (CJS_ScaleHow::Init(*this, JS_STATIC) < 0) return FALSE; 165 if (CJS_ScaleHow::Init(*this, JS_STATIC) < 0) return false;
166 if (CJS_ScaleWhen::Init(*this, JS_STATIC) < 0) return FALSE; 166 if (CJS_ScaleWhen::Init(*this, JS_STATIC) < 0) return false;
167 if (CJS_Style::Init(*this, JS_STATIC) < 0) return FALSE; 167 if (CJS_Style::Init(*this, JS_STATIC) < 0) return false;
168 if (CJS_Zoomtype::Init(*this, JS_STATIC) < 0) return FALSE; 168 if (CJS_Zoomtype::Init(*this, JS_STATIC) < 0) return false;
169 169
170 //9 - 11 170 //9 - 11
171 if (CJS_App::Init(*this, JS_STATIC) < 0) return FALSE; 171 if (CJS_App::Init(*this, JS_STATIC) < 0) return false;
172 if (CJS_Color::Init(*this, JS_STATIC) < 0) return FALSE; 172 if (CJS_Color::Init(*this, JS_STATIC) < 0) return false;
173 if (CJS_Console::Init(*this, JS_STATIC) < 0) return FALSE; 173 if (CJS_Console::Init(*this, JS_STATIC) < 0) return false;
174 174
175 //12 - 14 175 //12 - 14
176 if (CJS_Document::Init(*this, JS_DYNAMIC) < 0) return FALSE; 176 if (CJS_Document::Init(*this, JS_DYNAMIC) < 0) return false;
177 if (CJS_Event::Init(*this, JS_STATIC) < 0) return FALSE; 177 if (CJS_Event::Init(*this, JS_STATIC) < 0) return false;
178 if (CJS_Field::Init(*this, JS_DYNAMIC) < 0) return FALSE; 178 if (CJS_Field::Init(*this, JS_DYNAMIC) < 0) return false;
179 179
180 //15 - 17 180 //15 - 17
181 if (CJS_Global::Init(*this, JS_STATIC) < 0) return FALSE; 181 if (CJS_Global::Init(*this, JS_STATIC) < 0) return false;
182 if (CJS_Icon::Init(*this, JS_DYNAMIC) < 0) return FALSE; 182 if (CJS_Icon::Init(*this, JS_DYNAMIC) < 0) return false;
183 if (CJS_Util::Init(*this, JS_STATIC) < 0) return FALSE; 183 if (CJS_Util::Init(*this, JS_STATIC) < 0) return false;
184 184
185 if (CJS_PublicMethods::Init(*this) < 0) return FALSE; 185 if (CJS_PublicMethods::Init(*this) < 0) return false;
186 if (CJS_GlobalConsts::Init(*this) < 0) return FALSE; 186 if (CJS_GlobalConsts::Init(*this) < 0) return false;
187 if (CJS_GlobalArrays::Init(*this) < 0) return FALSE; 187 if (CJS_GlobalArrays::Init(*this) < 0) return false;
188 188
189 if (CJS_TimerObj::Init(*this, JS_DYNAMIC) < 0) return FALSE; 189 if (CJS_TimerObj::Init(*this, JS_DYNAMIC) < 0) return false;
190 if (CJS_PrintParamsObj::Init(*this, JS_DYNAMIC) <0) return FALSE; 190 if (CJS_PrintParamsObj::Init(*this, JS_DYNAMIC) <0) return false;
191 191
192 return TRUE; 192 return true;
193 } 193 }
194 194
195 IFXJS_Context* CJS_Runtime::NewContext() 195 IFXJS_Context* CJS_Runtime::NewContext()
196 { 196 {
197 CJS_Context * p = new CJS_Context(this); 197 CJS_Context * p = new CJS_Context(this);
198 m_ContextArray.Add(p); 198 m_ContextArray.Add(p);
199 return p; 199 return p;
200 } 200 }
201 201
202 void CJS_Runtime::ReleaseContext(IFXJS_Context * pContext) 202 void CJS_Runtime::ReleaseContext(IFXJS_Context * pContext)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 248 }
249 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"Document")); 249 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"Document"));
250 } 250 }
251 else 251 else
252 { 252 {
253 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"app")); 253 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"app"));
254 } 254 }
255 } 255 }
256 } 256 }
257 257
258 FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_ T eEventType) 258 bool CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_T e EventType)
259 { 259 {
260 if (m_pFieldEventPath == NULL) 260 if (m_pFieldEventPath == NULL)
261 { 261 {
262 m_pFieldEventPath = new CJS_FieldEvent; 262 m_pFieldEventPath = new CJS_FieldEvent;
263 m_pFieldEventPath->sTargetName = sTargetName; 263 m_pFieldEventPath->sTargetName = sTargetName;
264 m_pFieldEventPath->eEventType = eEventType; 264 m_pFieldEventPath->eEventType = eEventType;
265 m_pFieldEventPath->pNext = NULL; 265 m_pFieldEventPath->pNext = NULL;
266 266
267 return TRUE; 267 return true;
268 } 268 }
269 269
270 //to search 270 //to search
271 CJS_FieldEvent* p = m_pFieldEventPath; 271 CJS_FieldEvent* p = m_pFieldEventPath;
272 CJS_FieldEvent* pLast = m_pFieldEventPath; 272 CJS_FieldEvent* pLast = m_pFieldEventPath;
273 while (p) 273 while (p)
274 { 274 {
275 if (p->eEventType == eEventType && p->sTargetName == sTargetName) 275 if (p->eEventType == eEventType && p->sTargetName == sTargetName)
276 return FALSE; 276 return false;
277 277
278 pLast = p; 278 pLast = p;
279 p = p->pNext; 279 p = p->pNext;
280 } 280 }
281 281
282 //to add 282 //to add
283 CJS_FieldEvent* pNew = new CJS_FieldEvent; 283 CJS_FieldEvent* pNew = new CJS_FieldEvent;
284 pNew->sTargetName = sTargetName; 284 pNew->sTargetName = sTargetName;
285 pNew->eEventType = eEventType; 285 pNew->eEventType = eEventType;
286 pNew->pNext = NULL; 286 pNew->pNext = NULL;
287 287
288 pLast->pNext = pNew; 288 pLast->pNext = pNew;
289 289
290 return TRUE; 290 return true;
291 } 291 }
292 292
293 void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName, JS_EVENT_ T eEventType) 293 void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName, JS_EVENT_ T eEventType)
294 { 294 {
295 FX_BOOL bFind = FALSE; 295 bool bFind = false;
296 296
297 CJS_FieldEvent* p = m_pFieldEventPath; 297 CJS_FieldEvent* p = m_pFieldEventPath;
298 CJS_FieldEvent* pLast = NULL; 298 CJS_FieldEvent* pLast = NULL;
299 while (p) 299 while (p)
300 { 300 {
301 if (p->eEventType == eEventType && p->sTargetName == sTargetName) 301 if (p->eEventType == eEventType && p->sTargetName == sTargetName)
302 { 302 {
303 bFind = TRUE; 303 bFind = true;
304 break; 304 break;
305 } 305 }
306 306
307 pLast = p; 307 pLast = p;
308 p = p->pNext; 308 p = p->pNext;
309 } 309 }
310 310
311 if (bFind) 311 if (bFind)
312 { 312 {
313 RemoveEventsInLoop(p); 313 RemoveEventsInLoop(p);
(...skipping 23 matching lines...) Expand all
337 { 337 {
338 return v8::Local<v8::Context>::New(m_isolate, m_context); 338 return v8::Local<v8::Context>::New(m_isolate, m_context);
339 } 339 }
340 340
341 CFX_WideString ChangeObjName(const CFX_WideString& str) 341 CFX_WideString ChangeObjName(const CFX_WideString& str)
342 { 342 {
343 CFX_WideString sRet = str; 343 CFX_WideString sRet = str;
344 sRet.Replace(L"_", L"."); 344 sRet.Replace(L"_", L".");
345 return sRet; 345 return sRet;
346 } 346 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_GlobalData.cpp ('k') | fpdfsdk/src/javascript/JS_Value.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698