| 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/IJavaScript.h" | 7 #include "../../include/javascript/IJavaScript.h" |
| 8 #include "../../include/javascript/JS_Context.h" | 8 #include "../../include/javascript/JS_Context.h" |
| 9 #include "../../include/javascript/JS_Define.h" | 9 #include "../../include/javascript/JS_Define.h" |
| 10 #include "../../include/javascript/JS_EventHandler.h" | 10 #include "../../include/javascript/JS_EventHandler.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 BEGIN_JS_STATIC_PROP(CJS_Global) | 90 BEGIN_JS_STATIC_PROP(CJS_Global) |
| 91 END_JS_STATIC_PROP() | 91 END_JS_STATIC_PROP() |
| 92 | 92 |
| 93 BEGIN_JS_STATIC_METHOD(CJS_Global) | 93 BEGIN_JS_STATIC_METHOD(CJS_Global) |
| 94 JS_STATIC_METHOD_ENTRY(setPersistent) | 94 JS_STATIC_METHOD_ENTRY(setPersistent) |
| 95 END_JS_STATIC_METHOD() | 95 END_JS_STATIC_METHOD() |
| 96 | 96 |
| 97 IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, global_alternate, global); | 97 IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, global_alternate, global); |
| 98 | 98 |
| 99 FX_BOOL»CJS_Global::InitInstance(IFXJS_Context* cc) | 99 bool» CJS_Global::InitInstance(IFXJS_Context* cc) |
| 100 { | 100 { |
| 101 CJS_Context* pContext = (CJS_Context*)cc; | 101 CJS_Context* pContext = (CJS_Context*)cc; |
| 102 ASSERT(pContext != NULL); | 102 ASSERT(pContext != NULL); |
| 103 | 103 |
| 104 global_alternate* pGlobal = (global_alternate*)GetEmbedObject(); | 104 global_alternate* pGlobal = (global_alternate*)GetEmbedObject(); |
| 105 ASSERT(pGlobal != NULL); | 105 ASSERT(pGlobal != NULL); |
| 106 | 106 |
| 107 pGlobal->Initial(pContext->GetReaderApp()); | 107 pGlobal->Initial(pContext->GetReaderApp()); |
| 108 | 108 |
| 109 » return TRUE; | 109 » return true; |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 global_alternate::global_alternate(CJS_Object* pJSObject) | 112 global_alternate::global_alternate(CJS_Object* pJSObject) |
| 113 : CJS_EmbedObj(pJSObject), | 113 : CJS_EmbedObj(pJSObject), |
| 114 m_pApp(NULL) | 114 m_pApp(NULL) |
| 115 { | 115 { |
| 116 } | 116 } |
| 117 | 117 |
| 118 global_alternate::~global_alternate(void) | 118 global_alternate::~global_alternate(void) |
| 119 { | 119 { |
| 120 DestroyGlobalPersisitentVariables(); | 120 DestroyGlobalPersisitentVariables(); |
| 121 m_pApp->GetRuntimeFactory()->ReleaseGlobalData(); | 121 m_pApp->GetRuntimeFactory()->ReleaseGlobalData(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void global_alternate::Initial(CPDFDoc_Environment* pApp) | 124 void global_alternate::Initial(CPDFDoc_Environment* pApp) |
| 125 { | 125 { |
| 126 m_pApp = pApp; | 126 m_pApp = pApp; |
| 127 m_pGlobalData = pApp->GetRuntimeFactory()->NewGlobalData(pApp); | 127 m_pGlobalData = pApp->GetRuntimeFactory()->NewGlobalData(pApp); |
| 128 UpdateGlobalPersistentVariables(); | 128 UpdateGlobalPersistentVariables(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 FX_BOOL»global_alternate::QueryProperty(const FX_WCHAR* propname) | 131 bool» global_alternate::QueryProperty(const FX_WCHAR* propname) |
| 132 { | 132 { |
| 133 return CFX_WideString(propname) != L"setPersistent"; | 133 return CFX_WideString(propname) != L"setPersistent"; |
| 134 } | 134 } |
| 135 | 135 |
| 136 FX_BOOL»global_alternate::DelProperty(IFXJS_Context* cc, const FX_WCHAR* propnam
e, CFX_WideString& sError) | 136 bool» global_alternate::DelProperty(IFXJS_Context* cc, const FX_WCHAR* propnam
e, CFX_WideString& sError) |
| 137 { | 137 { |
| 138 js_global_data* pData = NULL; | 138 js_global_data* pData = NULL; |
| 139 CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname); | 139 CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname); |
| 140 | 140 |
| 141 if (m_mapGlobal.Lookup(sPropName, (void*&)pData)) | 141 if (m_mapGlobal.Lookup(sPropName, (void*&)pData)) |
| 142 { | 142 { |
| 143 » » pData->bDeleted = TRUE; | 143 » » pData->bDeleted = true; |
| 144 » » return TRUE; | 144 » » return true; |
| 145 } | 145 } |
| 146 | 146 |
| 147 » return FALSE; | 147 » return false; |
| 148 } | 148 } |
| 149 | 149 |
| 150 FX_BOOL global_alternate::DoProperty(IFXJS_Context* cc, const FX_WCHAR* propname
, CJS_PropValue& vp, CFX_WideString& sError) | 150 bool global_alternate::DoProperty(IFXJS_Context* cc, const FX_WCHAR* propname, C
JS_PropValue& vp, CFX_WideString& sError) |
| 151 { | 151 { |
| 152 if (vp.IsSetting()) | 152 if (vp.IsSetting()) |
| 153 { | 153 { |
| 154 CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname)
; | 154 CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname)
; |
| 155 switch (vp.GetType()) | 155 switch (vp.GetType()) |
| 156 { | 156 { |
| 157 case VT_number: | 157 case VT_number: |
| 158 { | 158 { |
| 159 double dData; | 159 double dData; |
| 160 vp >> dData; | 160 vp >> dData; |
| 161 » » » » return SetGlobalVariables(sPropName, JS_GLOBALDA
TA_TYPE_NUMBER, dData, false, "", v8::Local<v8::Object>(), FALSE); | 161 » » » » return SetGlobalVariables(sPropName, JS_GLOBALDA
TA_TYPE_NUMBER, dData, false, "", v8::Local<v8::Object>(), false); |
| 162 } | 162 } |
| 163 case VT_boolean: | 163 case VT_boolean: |
| 164 { | 164 { |
| 165 bool bData; | 165 bool bData; |
| 166 vp >> bData; | 166 vp >> bData; |
| 167 » » » » return SetGlobalVariables(sPropName, JS_GLOBALDA
TA_TYPE_BOOLEAN, 0, bData, "", v8::Local<v8::Object>(), FALSE); | 167 » » » » return SetGlobalVariables(sPropName, JS_GLOBALDA
TA_TYPE_BOOLEAN, 0, bData, "", v8::Local<v8::Object>(), false); |
| 168 } | 168 } |
| 169 case VT_string: | 169 case VT_string: |
| 170 { | 170 { |
| 171 CFX_ByteString sData; | 171 CFX_ByteString sData; |
| 172 vp >> sData; | 172 vp >> sData; |
| 173 » » » » return SetGlobalVariables(sPropName, JS_GLOBALDA
TA_TYPE_STRING, 0, false, sData, v8::Local<v8::Object>(), FALSE); | 173 » » » » return SetGlobalVariables(sPropName, JS_GLOBALDA
TA_TYPE_STRING, 0, false, sData, v8::Local<v8::Object>(), false); |
| 174 } | 174 } |
| 175 case VT_object: | 175 case VT_object: |
| 176 { | 176 { |
| 177 JSObject pData; | 177 JSObject pData; |
| 178 vp >> pData; | 178 vp >> pData; |
| 179 » » » » return SetGlobalVariables(sPropName, JS_GLOBALDA
TA_TYPE_OBJECT, 0, false, "", pData, FALSE); | 179 » » » » return SetGlobalVariables(sPropName, JS_GLOBALDA
TA_TYPE_OBJECT, 0, false, "", pData, false); |
| 180 } | 180 } |
| 181 case VT_null: | 181 case VT_null: |
| 182 { | 182 { |
| 183 » » » » return SetGlobalVariables(sPropName, JS_GLOBALDA
TA_TYPE_NULL, 0, false, "", v8::Local<v8::Object>(), FALSE); | 183 » » » » return SetGlobalVariables(sPropName, JS_GLOBALDA
TA_TYPE_NULL, 0, false, "", v8::Local<v8::Object>(), false); |
| 184 } | 184 } |
| 185 case VT_undefined: | 185 case VT_undefined: |
| 186 { | 186 { |
| 187 DelProperty(cc, propname, sError); | 187 DelProperty(cc, propname, sError); |
| 188 » » » » return TRUE; | 188 » » » » return true; |
| 189 } | 189 } |
| 190 default: | 190 default: |
| 191 » » » return FALSE; | 191 » » » return false; |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 else | 194 else |
| 195 { | 195 { |
| 196 js_global_data* pData = NULL; | 196 js_global_data* pData = NULL; |
| 197 CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname)
; | 197 CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname)
; |
| 198 | 198 |
| 199 if (m_mapGlobal.Lookup(sPropName, (void*&)pData)) | 199 if (m_mapGlobal.Lookup(sPropName, (void*&)pData)) |
| 200 { | 200 { |
| 201 if (pData) | 201 if (pData) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 216 case JS_GLOBALDATA_TYPE_OBJECT: | 216 case JS_GLOBALDATA_TYPE_OBJECT: |
| 217 { | 217 { |
| 218 v8::Local<v8::Object> ob
j = v8::Local<v8::Object>::New(vp.GetIsolate(),pData->pData); | 218 v8::Local<v8::Object> ob
j = v8::Local<v8::Object>::New(vp.GetIsolate(),pData->pData); |
| 219 vp << obj; | 219 vp << obj; |
| 220 break; | 220 break; |
| 221 } | 221 } |
| 222 case JS_GLOBALDATA_TYPE_NULL: | 222 case JS_GLOBALDATA_TYPE_NULL: |
| 223 vp.SetNull(); | 223 vp.SetNull(); |
| 224 break; | 224 break; |
| 225 default: | 225 default: |
| 226 » » » » » » return FALSE; | 226 » » » » » » return false; |
| 227 } | 227 } |
| 228 » » » » » return TRUE; | 228 » » » » » return true; |
| 229 } | 229 } |
| 230 else | 230 else |
| 231 { | 231 { |
| 232 » » » » » return TRUE; | 232 » » » » » return true; |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 else | 235 else |
| 236 { | 236 { |
| 237 vp.SetNull(); | 237 vp.SetNull(); |
| 238 » » » » return TRUE; | 238 » » » » return true; |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 else | 241 else |
| 242 { | 242 { |
| 243 vp.SetNull(); | 243 vp.SetNull(); |
| 244 » » » return TRUE; | 244 » » » return true; |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 | 247 |
| 248 » return FALSE; | 248 » return false; |
| 249 } | 249 } |
| 250 | 250 |
| 251 FX_BOOL global_alternate::setPersistent(IFXJS_Context* cc, const CJS_Parameters&
params, CJS_Value& vRet, CFX_WideString& sError) | 251 bool global_alternate::setPersistent(IFXJS_Context* cc, const CJS_Parameters& pa
rams, CJS_Value& vRet, CFX_WideString& sError) |
| 252 { | 252 { |
| 253 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 253 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 254 if (params.size() != 2) | 254 if (params.size() != 2) |
| 255 { | 255 { |
| 256 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 256 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 257 » » return FALSE; | 257 » » return false; |
| 258 } | 258 } |
| 259 | 259 |
| 260 CFX_ByteString sName = params[0].ToCFXByteString(); | 260 CFX_ByteString sName = params[0].ToCFXByteString(); |
| 261 | 261 |
| 262 js_global_data* pData = NULL; | 262 js_global_data* pData = NULL; |
| 263 if (m_mapGlobal.Lookup(sName, (void*&)pData)) | 263 if (m_mapGlobal.Lookup(sName, (void*&)pData)) |
| 264 { | 264 { |
| 265 if (pData && !pData->bDeleted) | 265 if (pData && !pData->bDeleted) |
| 266 { | 266 { |
| 267 pData->bPersistent = params[1].ToBool(); | 267 pData->bPersistent = params[1].ToBool(); |
| 268 » » » return TRUE; | 268 » » » return true; |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 | 271 |
| 272 sError = JSGetStringFromID(pContext, IDS_STRING_JSNOGLOBAL); | 272 sError = JSGetStringFromID(pContext, IDS_STRING_JSNOGLOBAL); |
| 273 » return FALSE; | 273 » return false; |
| 274 } | 274 } |
| 275 | 275 |
| 276 void global_alternate::UpdateGlobalPersistentVariables() | 276 void global_alternate::UpdateGlobalPersistentVariables() |
| 277 { | 277 { |
| 278 ASSERT(m_pGlobalData != NULL); | 278 ASSERT(m_pGlobalData != NULL); |
| 279 | 279 |
| 280 for (int i=0,sz=m_pGlobalData->GetSize(); i<sz; i++) | 280 for (int i=0,sz=m_pGlobalData->GetSize(); i<sz; i++) |
| 281 { | 281 { |
| 282 CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i); | 282 CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i); |
| 283 ASSERT(pData != NULL); | 283 ASSERT(pData != NULL); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 CFX_ByteString name; | 486 CFX_ByteString name; |
| 487 js_global_data* pData = NULL; | 487 js_global_data* pData = NULL; |
| 488 m_mapGlobal.GetNextAssoc(pos, name, (void*&)pData); | 488 m_mapGlobal.GetNextAssoc(pos, name, (void*&)pData); |
| 489 delete pData; | 489 delete pData; |
| 490 } | 490 } |
| 491 | 491 |
| 492 m_mapGlobal.RemoveAll(); | 492 m_mapGlobal.RemoveAll(); |
| 493 } | 493 } |
| 494 | 494 |
| 495 | 495 |
| 496 FX_BOOL global_alternate::SetGlobalVariables(const FX_CHAR* propname, int nType, | 496 bool global_alternate::SetGlobalVariables(const FX_CHAR* propname, int nType, |
| 497 double dData, bool bData, const CFX_ByteString&
sData, JSObject pData, bool bDefaultPersistent) | 497 double dData, bool bData, const CFX_ByteString&
sData, JSObject pData, bool bDefaultPersistent) |
| 498 { | 498 { |
| 499 » if (propname == NULL) return FALSE; | 499 » if (propname == NULL) return false; |
| 500 | 500 |
| 501 js_global_data* pTemp = NULL; | 501 js_global_data* pTemp = NULL; |
| 502 m_mapGlobal.Lookup(propname, (void*&)pTemp); | 502 m_mapGlobal.Lookup(propname, (void*&)pTemp); |
| 503 | 503 |
| 504 if (pTemp) | 504 if (pTemp) |
| 505 { | 505 { |
| 506 if (pTemp->bDeleted || pTemp->nType != nType) | 506 if (pTemp->bDeleted || pTemp->nType != nType) |
| 507 { | 507 { |
| 508 pTemp->dData = 0; | 508 pTemp->dData = 0; |
| 509 pTemp->bData = 0; | 509 pTemp->bData = 0; |
| 510 pTemp->sData = ""; | 510 pTemp->sData = ""; |
| 511 pTemp->nType = nType; | 511 pTemp->nType = nType; |
| 512 } | 512 } |
| 513 | 513 |
| 514 » » pTemp->bDeleted = FALSE; | 514 » » pTemp->bDeleted = false; |
| 515 | 515 |
| 516 switch (nType) | 516 switch (nType) |
| 517 { | 517 { |
| 518 case JS_GLOBALDATA_TYPE_NUMBER: | 518 case JS_GLOBALDATA_TYPE_NUMBER: |
| 519 { | 519 { |
| 520 pTemp->dData = dData; | 520 pTemp->dData = dData; |
| 521 } | 521 } |
| 522 break; | 522 break; |
| 523 case JS_GLOBALDATA_TYPE_BOOLEAN: | 523 case JS_GLOBALDATA_TYPE_BOOLEAN: |
| 524 { | 524 { |
| 525 pTemp->bData = bData; | 525 pTemp->bData = bData; |
| 526 } | 526 } |
| 527 break; | 527 break; |
| 528 case JS_GLOBALDATA_TYPE_STRING: | 528 case JS_GLOBALDATA_TYPE_STRING: |
| 529 { | 529 { |
| 530 pTemp->sData = sData; | 530 pTemp->sData = sData; |
| 531 } | 531 } |
| 532 break; | 532 break; |
| 533 case JS_GLOBALDATA_TYPE_OBJECT: | 533 case JS_GLOBALDATA_TYPE_OBJECT: |
| 534 { | 534 { |
| 535 pTemp->pData.Reset(JS_GetRuntime(pData), pData); | 535 pTemp->pData.Reset(JS_GetRuntime(pData), pData); |
| 536 } | 536 } |
| 537 break; | 537 break; |
| 538 case JS_GLOBALDATA_TYPE_NULL: | 538 case JS_GLOBALDATA_TYPE_NULL: |
| 539 break; | 539 break; |
| 540 default: | 540 default: |
| 541 » » » return FALSE; | 541 » » » return false; |
| 542 } | 542 } |
| 543 | 543 |
| 544 » » return TRUE; | 544 » » return true; |
| 545 } | 545 } |
| 546 | 546 |
| 547 js_global_data* pNewData = NULL; | 547 js_global_data* pNewData = NULL; |
| 548 | 548 |
| 549 switch (nType) | 549 switch (nType) |
| 550 { | 550 { |
| 551 case JS_GLOBALDATA_TYPE_NUMBER: | 551 case JS_GLOBALDATA_TYPE_NUMBER: |
| 552 { | 552 { |
| 553 pNewData = new js_global_data; | 553 pNewData = new js_global_data; |
| 554 pNewData->nType = JS_GLOBALDATA_TYPE_NUMBER; | 554 pNewData->nType = JS_GLOBALDATA_TYPE_NUMBER; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 581 } | 581 } |
| 582 break; | 582 break; |
| 583 case JS_GLOBALDATA_TYPE_NULL: | 583 case JS_GLOBALDATA_TYPE_NULL: |
| 584 { | 584 { |
| 585 pNewData = new js_global_data; | 585 pNewData = new js_global_data; |
| 586 pNewData->nType = JS_GLOBALDATA_TYPE_NULL; | 586 pNewData->nType = JS_GLOBALDATA_TYPE_NULL; |
| 587 pNewData->bPersistent = bDefaultPersistent; | 587 pNewData->bPersistent = bDefaultPersistent; |
| 588 } | 588 } |
| 589 break; | 589 break; |
| 590 default: | 590 default: |
| 591 » » return FALSE; | 591 » » return false; |
| 592 } | 592 } |
| 593 | 593 |
| 594 m_mapGlobal.SetAt(propname, (void*)pNewData); | 594 m_mapGlobal.SetAt(propname, (void*)pNewData); |
| 595 | 595 |
| 596 » return TRUE; | 596 » return true; |
| 597 } | 597 } |
| 598 | 598 |
| 599 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p) | 599 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p) |
| 600 { | 600 { |
| 601 const unsigned int nHash = JS_CalcHash(JS_GetTypeof(p)); | 601 const unsigned int nHash = JS_CalcHash(JS_GetTypeof(p)); |
| 602 | 602 |
| 603 if (nHash == JSCONST_nUndefHash) | 603 if (nHash == JSCONST_nUndefHash) |
| 604 return VT_undefined; | 604 return VT_undefined; |
| 605 if (nHash == JSCONST_nNullHash) | 605 if (nHash == JSCONST_nNullHash) |
| 606 return VT_null; | 606 return VT_null; |
| 607 if (nHash == JSCONST_nStringHash) | 607 if (nHash == JSCONST_nStringHash) |
| 608 return VT_string; | 608 return VT_string; |
| 609 if (nHash == JSCONST_nNumberHash) | 609 if (nHash == JSCONST_nNumberHash) |
| 610 return VT_number; | 610 return VT_number; |
| 611 if (nHash == JSCONST_nBoolHash) | 611 if (nHash == JSCONST_nBoolHash) |
| 612 return VT_boolean; | 612 return VT_boolean; |
| 613 if (nHash == JSCONST_nDateHash) | 613 if (nHash == JSCONST_nDateHash) |
| 614 return VT_date; | 614 return VT_date; |
| 615 if (nHash == JSCONST_nObjectHash) | 615 if (nHash == JSCONST_nObjectHash) |
| 616 return VT_object; | 616 return VT_object; |
| 617 if (nHash == JSCONST_nFXobjHash) | 617 if (nHash == JSCONST_nFXobjHash) |
| 618 return VT_fxobject; | 618 return VT_fxobject; |
| 619 | 619 |
| 620 return VT_unknown; | 620 return VT_unknown; |
| 621 } | 621 } |
| 622 | 622 |
| OLD | NEW |