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 "fpdfsdk/javascript/global.h" | 7 #include "fpdfsdk/javascript/global.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, JSGlobalAlternate, global); | 87 IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, JSGlobalAlternate, global); |
88 | 88 |
89 void CJS_Global::InitInstance(IJS_Runtime* pIRuntime) { | 89 void CJS_Global::InitInstance(IJS_Runtime* pIRuntime) { |
90 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); | 90 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); |
91 JSGlobalAlternate* pGlobal = | 91 JSGlobalAlternate* pGlobal = |
92 static_cast<JSGlobalAlternate*>(GetEmbedObject()); | 92 static_cast<JSGlobalAlternate*>(GetEmbedObject()); |
93 pGlobal->Initial(pRuntime->GetReaderApp()); | 93 pGlobal->Initial(pRuntime->GetReaderApp()); |
94 } | 94 } |
95 | 95 |
96 JSGlobalAlternate::JSGlobalAlternate(CJS_Object* pJSObject) | 96 JSGlobalAlternate::JSGlobalAlternate(CJS_Object* pJSObject) |
97 : CJS_EmbedObj(pJSObject), m_pApp(NULL) {} | 97 : CJS_EmbedObj(pJSObject), m_pApp(nullptr) {} |
98 | 98 |
99 JSGlobalAlternate::~JSGlobalAlternate() { | 99 JSGlobalAlternate::~JSGlobalAlternate() { |
100 DestroyGlobalPersisitentVariables(); | 100 DestroyGlobalPersisitentVariables(); |
101 m_pGlobalData->Release(); | 101 m_pGlobalData->Release(); |
102 } | 102 } |
103 | 103 |
104 void JSGlobalAlternate::Initial(CPDFDoc_Environment* pApp) { | 104 void JSGlobalAlternate::Initial(CPDFDoc_Environment* pApp) { |
105 m_pApp = pApp; | 105 m_pApp = pApp; |
106 m_pGlobalData = CJS_GlobalData::GetRetainedInstance(pApp); | 106 m_pGlobalData = CJS_GlobalData::GetRetainedInstance(pApp); |
107 UpdateGlobalPersistentVariables(); | 107 UpdateGlobalPersistentVariables(); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 } | 225 } |
226 | 226 |
227 void JSGlobalAlternate::UpdateGlobalPersistentVariables() { | 227 void JSGlobalAlternate::UpdateGlobalPersistentVariables() { |
228 for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) { | 228 for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) { |
229 CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i); | 229 CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i); |
230 switch (pData->data.nType) { | 230 switch (pData->data.nType) { |
231 case JS_GLOBALDATA_TYPE_NUMBER: | 231 case JS_GLOBALDATA_TYPE_NUMBER: |
232 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, | 232 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, |
233 pData->data.dData, false, "", | 233 pData->data.dData, false, "", |
234 v8::Local<v8::Object>(), pData->bPersistent == 1); | 234 v8::Local<v8::Object>(), pData->bPersistent == 1); |
235 FXJS_PutObjectNumber(NULL, m_pJSObject->ToV8Object(), | 235 FXJS_PutObjectNumber(nullptr, m_pJSObject->ToV8Object(), |
236 pData->data.sKey.UTF8Decode(), pData->data.dData); | 236 pData->data.sKey.UTF8Decode(), pData->data.dData); |
237 break; | 237 break; |
238 case JS_GLOBALDATA_TYPE_BOOLEAN: | 238 case JS_GLOBALDATA_TYPE_BOOLEAN: |
239 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, | 239 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, |
240 (bool)(pData->data.bData == 1), "", | 240 (bool)(pData->data.bData == 1), "", |
241 v8::Local<v8::Object>(), pData->bPersistent == 1); | 241 v8::Local<v8::Object>(), pData->bPersistent == 1); |
242 FXJS_PutObjectBoolean(NULL, m_pJSObject->ToV8Object(), | 242 FXJS_PutObjectBoolean(nullptr, m_pJSObject->ToV8Object(), |
243 pData->data.sKey.UTF8Decode(), | 243 pData->data.sKey.UTF8Decode(), |
244 (bool)(pData->data.bData == 1)); | 244 (bool)(pData->data.bData == 1)); |
245 break; | 245 break; |
246 case JS_GLOBALDATA_TYPE_STRING: | 246 case JS_GLOBALDATA_TYPE_STRING: |
247 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, | 247 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, |
248 false, pData->data.sData, v8::Local<v8::Object>(), | 248 false, pData->data.sData, v8::Local<v8::Object>(), |
249 pData->bPersistent == 1); | 249 pData->bPersistent == 1); |
250 FXJS_PutObjectString(NULL, m_pJSObject->ToV8Object(), | 250 FXJS_PutObjectString(nullptr, m_pJSObject->ToV8Object(), |
251 pData->data.sKey.UTF8Decode(), | 251 pData->data.sKey.UTF8Decode(), |
252 pData->data.sData.UTF8Decode()); | 252 pData->data.sData.UTF8Decode()); |
253 break; | 253 break; |
254 case JS_GLOBALDATA_TYPE_OBJECT: { | 254 case JS_GLOBALDATA_TYPE_OBJECT: { |
255 v8::Isolate* pRuntime = m_pJSObject->ToV8Object()->GetIsolate(); | 255 v8::Isolate* pRuntime = m_pJSObject->ToV8Object()->GetIsolate(); |
256 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(pRuntime, NULL, -1); | 256 v8::Local<v8::Object> pObj = |
| 257 FXJS_NewFxDynamicObj(pRuntime, nullptr, -1); |
257 | 258 |
258 PutObjectProperty(pObj, &pData->data); | 259 PutObjectProperty(pObj, &pData->data); |
259 | 260 |
260 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0, | 261 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0, |
261 false, "", pObj, pData->bPersistent == 1); | 262 false, "", pObj, pData->bPersistent == 1); |
262 FXJS_PutObjectObject(NULL, m_pJSObject->ToV8Object(), | 263 FXJS_PutObjectObject(nullptr, m_pJSObject->ToV8Object(), |
263 pData->data.sKey.UTF8Decode(), pObj); | 264 pData->data.sKey.UTF8Decode(), pObj); |
264 } break; | 265 } break; |
265 case JS_GLOBALDATA_TYPE_NULL: | 266 case JS_GLOBALDATA_TYPE_NULL: |
266 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, | 267 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, |
267 "", v8::Local<v8::Object>(), | 268 "", v8::Local<v8::Object>(), |
268 pData->bPersistent == 1); | 269 pData->bPersistent == 1); |
269 FXJS_PutObjectNull(NULL, m_pJSObject->ToV8Object(), | 270 FXJS_PutObjectNull(nullptr, m_pJSObject->ToV8Object(), |
270 pData->data.sKey.UTF8Decode()); | 271 pData->data.sKey.UTF8Decode()); |
271 break; | 272 break; |
272 } | 273 } |
273 } | 274 } |
274 } | 275 } |
275 | 276 |
276 void JSGlobalAlternate::CommitGlobalPersisitentVariables(IJS_Context* cc) { | 277 void JSGlobalAlternate::CommitGlobalPersisitentVariables(IJS_Context* cc) { |
277 for (auto it = m_mapGlobal.begin(); it != m_mapGlobal.end(); ++it) { | 278 for (auto it = m_mapGlobal.begin(); it != m_mapGlobal.end(); ++it) { |
278 CFX_ByteString name = it->first; | 279 CFX_ByteString name = it->first; |
279 JSGlobalData* pData = it->second; | 280 JSGlobalData* pData = it->second; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 } | 367 } |
367 } | 368 } |
368 } | 369 } |
369 | 370 |
370 void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj, | 371 void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj, |
371 CJS_KeyValue* pData) { | 372 CJS_KeyValue* pData) { |
372 for (int i = 0, sz = pData->objData.Count(); i < sz; i++) { | 373 for (int i = 0, sz = pData->objData.Count(); i < sz; i++) { |
373 CJS_KeyValue* pObjData = pData->objData.GetAt(i); | 374 CJS_KeyValue* pObjData = pData->objData.GetAt(i); |
374 switch (pObjData->nType) { | 375 switch (pObjData->nType) { |
375 case JS_GLOBALDATA_TYPE_NUMBER: | 376 case JS_GLOBALDATA_TYPE_NUMBER: |
376 FXJS_PutObjectNumber(NULL, pObj, pObjData->sKey.UTF8Decode(), | 377 FXJS_PutObjectNumber(nullptr, pObj, pObjData->sKey.UTF8Decode(), |
377 pObjData->dData); | 378 pObjData->dData); |
378 break; | 379 break; |
379 case JS_GLOBALDATA_TYPE_BOOLEAN: | 380 case JS_GLOBALDATA_TYPE_BOOLEAN: |
380 FXJS_PutObjectBoolean(NULL, pObj, pObjData->sKey.UTF8Decode(), | 381 FXJS_PutObjectBoolean(nullptr, pObj, pObjData->sKey.UTF8Decode(), |
381 pObjData->bData == 1); | 382 pObjData->bData == 1); |
382 break; | 383 break; |
383 case JS_GLOBALDATA_TYPE_STRING: | 384 case JS_GLOBALDATA_TYPE_STRING: |
384 FXJS_PutObjectString(NULL, pObj, pObjData->sKey.UTF8Decode(), | 385 FXJS_PutObjectString(nullptr, pObj, pObjData->sKey.UTF8Decode(), |
385 pObjData->sData.UTF8Decode()); | 386 pObjData->sData.UTF8Decode()); |
386 break; | 387 break; |
387 case JS_GLOBALDATA_TYPE_OBJECT: { | 388 case JS_GLOBALDATA_TYPE_OBJECT: { |
388 v8::Isolate* pRuntime = m_pJSObject->ToV8Object()->GetIsolate(); | 389 v8::Isolate* pRuntime = m_pJSObject->ToV8Object()->GetIsolate(); |
389 v8::Local<v8::Object> pNewObj = | 390 v8::Local<v8::Object> pNewObj = |
390 FXJS_NewFxDynamicObj(pRuntime, NULL, -1); | 391 FXJS_NewFxDynamicObj(pRuntime, nullptr, -1); |
391 PutObjectProperty(pNewObj, pObjData); | 392 PutObjectProperty(pNewObj, pObjData); |
392 FXJS_PutObjectObject(NULL, pObj, pObjData->sKey.UTF8Decode(), pNewObj); | 393 FXJS_PutObjectObject(nullptr, pObj, pObjData->sKey.UTF8Decode(), |
| 394 pNewObj); |
393 } break; | 395 } break; |
394 case JS_GLOBALDATA_TYPE_NULL: | 396 case JS_GLOBALDATA_TYPE_NULL: |
395 FXJS_PutObjectNull(NULL, pObj, pObjData->sKey.UTF8Decode()); | 397 FXJS_PutObjectNull(nullptr, pObj, pObjData->sKey.UTF8Decode()); |
396 break; | 398 break; |
397 } | 399 } |
398 } | 400 } |
399 } | 401 } |
400 | 402 |
401 void JSGlobalAlternate::DestroyGlobalPersisitentVariables() { | 403 void JSGlobalAlternate::DestroyGlobalPersisitentVariables() { |
402 for (const auto& pair : m_mapGlobal) { | 404 for (const auto& pair : m_mapGlobal) { |
403 delete pair.second; | 405 delete pair.second; |
404 } | 406 } |
405 m_mapGlobal.clear(); | 407 m_mapGlobal.clear(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 pTemp->pData.Reset(pData->GetIsolate(), pData); | 442 pTemp->pData.Reset(pData->GetIsolate(), pData); |
441 } break; | 443 } break; |
442 case JS_GLOBALDATA_TYPE_NULL: | 444 case JS_GLOBALDATA_TYPE_NULL: |
443 break; | 445 break; |
444 default: | 446 default: |
445 return FALSE; | 447 return FALSE; |
446 } | 448 } |
447 return TRUE; | 449 return TRUE; |
448 } | 450 } |
449 | 451 |
450 JSGlobalData* pNewData = NULL; | 452 JSGlobalData* pNewData = nullptr; |
451 | 453 |
452 switch (nType) { | 454 switch (nType) { |
453 case JS_GLOBALDATA_TYPE_NUMBER: { | 455 case JS_GLOBALDATA_TYPE_NUMBER: { |
454 pNewData = new JSGlobalData; | 456 pNewData = new JSGlobalData; |
455 pNewData->nType = JS_GLOBALDATA_TYPE_NUMBER; | 457 pNewData->nType = JS_GLOBALDATA_TYPE_NUMBER; |
456 pNewData->dData = dData; | 458 pNewData->dData = dData; |
457 pNewData->bPersistent = bDefaultPersistent; | 459 pNewData->bPersistent = bDefaultPersistent; |
458 } break; | 460 } break; |
459 case JS_GLOBALDATA_TYPE_BOOLEAN: { | 461 case JS_GLOBALDATA_TYPE_BOOLEAN: { |
460 pNewData = new JSGlobalData; | 462 pNewData = new JSGlobalData; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 return CJS_Value::VT_boolean; | 504 return CJS_Value::VT_boolean; |
503 if (nHash == JSCONST_nDateHash) | 505 if (nHash == JSCONST_nDateHash) |
504 return CJS_Value::VT_date; | 506 return CJS_Value::VT_date; |
505 if (nHash == JSCONST_nObjectHash) | 507 if (nHash == JSCONST_nObjectHash) |
506 return CJS_Value::VT_object; | 508 return CJS_Value::VT_object; |
507 if (nHash == JSCONST_nFXobjHash) | 509 if (nHash == JSCONST_nFXobjHash) |
508 return CJS_Value::VT_fxobject; | 510 return CJS_Value::VT_fxobject; |
509 | 511 |
510 return CJS_Value::VT_unknown; | 512 return CJS_Value::VT_unknown; |
511 } | 513 } |
OLD | NEW |