| 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/JS_GlobalData.h" | 7 #include "fpdfsdk/javascript/JS_GlobalData.h" |
| 8 | 8 |
| 9 #include "core/fdrm/crypto/include/fx_crypt.h" | 9 #include "core/fdrm/crypto/include/fx_crypt.h" |
| 10 #include "fpdfsdk/include/javascript/IJavaScript.h" | 10 #include "fpdfsdk/include/javascript/IJavaScript.h" |
| 11 #include "third_party/base/stl_util.h" |
| 11 | 12 |
| 12 #define JS_MAXGLOBALDATA (1024 * 4 - 8) | 13 #define JS_MAXGLOBALDATA (1024 * 4 - 8) |
| 13 | 14 |
| 14 /* --------------------- CJS_GlobalVariableArray --------------------- */ | 15 /* --------------------- CJS_GlobalVariableArray --------------------- */ |
| 15 | 16 |
| 16 CJS_GlobalVariableArray::CJS_GlobalVariableArray() {} | 17 CJS_GlobalVariableArray::CJS_GlobalVariableArray() {} |
| 17 | 18 |
| 18 CJS_GlobalVariableArray::~CJS_GlobalVariableArray() { | 19 CJS_GlobalVariableArray::~CJS_GlobalVariableArray() { |
| 19 Empty(); | 20 Empty(); |
| 20 } | 21 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 0x19, 0xa8, 0xe8, 0x01, 0xf6, 0xa8, 0xb6, 0x4d, 0x82, 0x04, 0x45, 0x6d, | 91 0x19, 0xa8, 0xe8, 0x01, 0xf6, 0xa8, 0xb6, 0x4d, 0x82, 0x04, 0x45, 0x6d, |
| 91 0xb4, 0xcf, 0xd7, 0x77, 0x67, 0xf9, 0x75, 0x9f, 0xf0, 0xe0, 0x1e, 0x51, | 92 0xb4, 0xcf, 0xd7, 0x77, 0x67, 0xf9, 0x75, 0x9f, 0xf0, 0xe0, 0x1e, 0x51, |
| 92 0xee, 0x46, 0xfd, 0x0b, 0xc9, 0x93, 0x25, 0x55, 0x4a, 0xee, 0xe0, 0x16, | 93 0xee, 0x46, 0xfd, 0x0b, 0xc9, 0x93, 0x25, 0x55, 0x4a, 0xee, 0xe0, 0x16, |
| 93 0xd0, 0xdf, 0x8c, 0xfa, 0x2a, 0xa9, 0x49, 0xfd, 0x97, 0x1c, 0x0e, 0x22, | 94 0xd0, 0xdf, 0x8c, 0xfa, 0x2a, 0xa9, 0x49, 0xfd, 0x97, 0x1c, 0x0e, 0x22, |
| 94 0x13, 0x28, 0x7c, 0xaf, 0xc4, 0xfc, 0x9c, 0x12, 0x65, 0x8c, 0x4e, 0x5b, | 95 0x13, 0x28, 0x7c, 0xaf, 0xc4, 0xfc, 0x9c, 0x12, 0x65, 0x8c, 0x4e, 0x5b, |
| 95 0x04, 0x75, 0x89, 0xc9, 0xb1, 0xed, 0x50, 0xca, 0x96, 0x6f, 0x1a, 0x7a, | 96 0x04, 0x75, 0x89, 0xc9, 0xb1, 0xed, 0x50, 0xca, 0x96, 0x6f, 0x1a, 0x7a, |
| 96 0xfe, 0x58, 0x5d, 0xec, 0x19, 0x4a, 0xf6, 0x35, 0x6a, 0x97, 0x14, 0x00, | 97 0xfe, 0x58, 0x5d, 0xec, 0x19, 0x4a, 0xf6, 0x35, 0x6a, 0x97, 0x14, 0x00, |
| 97 0x0e, 0xd0, 0x6b, 0xbb, 0xd5, 0x75, 0x55, 0x8b, 0x6e, 0x6b, 0x19, 0xa0, | 98 0x0e, 0xd0, 0x6b, 0xbb, 0xd5, 0x75, 0x55, 0x8b, 0x6e, 0x6b, 0x19, 0xa0, |
| 98 0xf8, 0x77, 0xd5, 0xa3}; | 99 0xf8, 0x77, 0xd5, 0xa3}; |
| 99 | 100 |
| 101 // Returns true if non-empty, setting sPropName |
| 102 static bool TrimPropName(const char* propname, CFX_ByteString* sPropName) { |
| 103 ASSERT(propname); |
| 104 *sPropName = propname; |
| 105 sPropName->TrimLeft(); |
| 106 sPropName->TrimRight(); |
| 107 return sPropName->GetLength() != 0; |
| 108 } |
| 109 |
| 100 CJS_GlobalData* CJS_GlobalData::g_Instance = nullptr; | 110 CJS_GlobalData* CJS_GlobalData::g_Instance = nullptr; |
| 101 | 111 |
| 102 // static | 112 // static |
| 103 CJS_GlobalData* CJS_GlobalData::GetRetainedInstance(CPDFDoc_Environment* pApp) { | 113 CJS_GlobalData* CJS_GlobalData::GetRetainedInstance(CPDFDoc_Environment* pApp) { |
| 104 if (!g_Instance) { | 114 if (!g_Instance) { |
| 105 g_Instance = new CJS_GlobalData(); | 115 g_Instance = new CJS_GlobalData(); |
| 106 } | 116 } |
| 107 ++g_Instance->m_RefCount; | 117 ++g_Instance->m_RefCount; |
| 108 return g_Instance; | 118 return g_Instance; |
| 109 } | 119 } |
| 110 | 120 |
| 111 void CJS_GlobalData::Release() { | 121 void CJS_GlobalData::Release() { |
| 112 if (!--m_RefCount) { | 122 if (!--m_RefCount) { |
| 113 delete g_Instance; | 123 delete g_Instance; |
| 114 g_Instance = nullptr; | 124 g_Instance = nullptr; |
| 115 } | 125 } |
| 116 } | 126 } |
| 117 | 127 |
| 118 CJS_GlobalData::CJS_GlobalData() : m_RefCount(0) { | 128 CJS_GlobalData::CJS_GlobalData() |
| 119 m_sFilePath += SDK_JS_GLOBALDATA_FILENAME; | 129 : m_RefCount(0), m_sFilePath(SDK_JS_GLOBALDATA_FILENAME) { |
| 120 LoadGlobalPersistentVariables(); | 130 LoadGlobalPersistentVariables(); |
| 121 } | 131 } |
| 122 | 132 |
| 123 CJS_GlobalData::~CJS_GlobalData() { | 133 CJS_GlobalData::~CJS_GlobalData() { |
| 124 SaveGlobalPersisitentVariables(); | 134 SaveGlobalPersisitentVariables(); |
| 125 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) | |
| 126 delete m_arrayGlobalData.GetAt(i); | |
| 127 | |
| 128 m_arrayGlobalData.RemoveAll(); | |
| 129 } | 135 } |
| 130 | 136 |
| 131 int CJS_GlobalData::FindGlobalVariable(const FX_CHAR* propname) { | 137 CJS_GlobalData::iterator CJS_GlobalData::FindGlobalVariable( |
| 132 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) { | 138 const FX_CHAR* propname) { |
| 133 CJS_GlobalData_Element* pTemp = m_arrayGlobalData.GetAt(i); | 139 for (auto it = m_arrayGlobalData.begin(); it != m_arrayGlobalData.end(); |
| 134 if (pTemp->data.sKey[0] == *propname && pTemp->data.sKey == propname) | 140 ++it) { |
| 135 return i; | 141 if ((*it)->data.sKey == propname) |
| 142 return it; |
| 136 } | 143 } |
| 137 return -1; | 144 return m_arrayGlobalData.end(); |
| 145 } |
| 146 |
| 147 CJS_GlobalData::const_iterator CJS_GlobalData::FindGlobalVariable( |
| 148 const FX_CHAR* propname) const { |
| 149 for (auto it = m_arrayGlobalData.begin(); it != m_arrayGlobalData.end(); |
| 150 ++it) { |
| 151 if ((*it)->data.sKey == propname) |
| 152 return it; |
| 153 } |
| 154 return m_arrayGlobalData.end(); |
| 138 } | 155 } |
| 139 | 156 |
| 140 CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable( | 157 CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable( |
| 141 const FX_CHAR* propname) { | 158 const FX_CHAR* propname) { |
| 142 ASSERT(propname); | 159 auto iter = FindGlobalVariable(propname); |
| 143 | 160 return iter != m_arrayGlobalData.end() ? iter->get() : nullptr; |
| 144 int nFind = FindGlobalVariable(propname); | |
| 145 return nFind >= 0 ? m_arrayGlobalData.GetAt(nFind) : nullptr; | |
| 146 } | 161 } |
| 147 | 162 |
| 148 void CJS_GlobalData::SetGlobalVariableNumber(const FX_CHAR* propname, | 163 void CJS_GlobalData::SetGlobalVariableNumber(const FX_CHAR* propname, |
| 149 double dData) { | 164 double dData) { |
| 150 ASSERT(propname); | 165 CFX_ByteString sPropName; |
| 151 CFX_ByteString sPropName = propname; | 166 if (!TrimPropName(propname, &sPropName)) |
| 152 sPropName.TrimLeft(); | |
| 153 sPropName.TrimRight(); | |
| 154 if (sPropName.GetLength() == 0) | |
| 155 return; | 167 return; |
| 156 | 168 |
| 157 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { | 169 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { |
| 158 pData->data.nType = JS_GLOBALDATA_TYPE_NUMBER; | 170 pData->data.nType = JS_GLOBALDATA_TYPE_NUMBER; |
| 159 pData->data.dData = dData; | 171 pData->data.dData = dData; |
| 160 } else { | 172 return; |
| 161 CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element; | |
| 162 pNewData->data.sKey = sPropName; | |
| 163 pNewData->data.nType = JS_GLOBALDATA_TYPE_NUMBER; | |
| 164 pNewData->data.dData = dData; | |
| 165 m_arrayGlobalData.Add(pNewData); | |
| 166 } | 173 } |
| 174 std::unique_ptr<CJS_GlobalData_Element> pNewData(new CJS_GlobalData_Element); |
| 175 pNewData->data.sKey = sPropName; |
| 176 pNewData->data.nType = JS_GLOBALDATA_TYPE_NUMBER; |
| 177 pNewData->data.dData = dData; |
| 178 m_arrayGlobalData.push_back(std::move(pNewData)); |
| 167 } | 179 } |
| 168 | 180 |
| 169 void CJS_GlobalData::SetGlobalVariableBoolean(const FX_CHAR* propname, | 181 void CJS_GlobalData::SetGlobalVariableBoolean(const FX_CHAR* propname, |
| 170 bool bData) { | 182 bool bData) { |
| 171 ASSERT(propname); | 183 CFX_ByteString sPropName; |
| 172 CFX_ByteString sPropName = propname; | 184 if (!TrimPropName(propname, &sPropName)) |
| 173 | |
| 174 sPropName.TrimLeft(); | |
| 175 sPropName.TrimRight(); | |
| 176 | |
| 177 if (sPropName.GetLength() == 0) | |
| 178 return; | 185 return; |
| 179 | 186 |
| 180 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { | 187 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { |
| 181 pData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN; | 188 pData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN; |
| 182 pData->data.bData = bData; | 189 pData->data.bData = bData; |
| 183 } else { | 190 return; |
| 184 CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element; | |
| 185 pNewData->data.sKey = sPropName; | |
| 186 pNewData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN; | |
| 187 pNewData->data.bData = bData; | |
| 188 | |
| 189 m_arrayGlobalData.Add(pNewData); | |
| 190 } | 191 } |
| 192 std::unique_ptr<CJS_GlobalData_Element> pNewData(new CJS_GlobalData_Element); |
| 193 pNewData->data.sKey = sPropName; |
| 194 pNewData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN; |
| 195 pNewData->data.bData = bData; |
| 196 m_arrayGlobalData.push_back(std::move(pNewData)); |
| 191 } | 197 } |
| 192 | 198 |
| 193 void CJS_GlobalData::SetGlobalVariableString(const FX_CHAR* propname, | 199 void CJS_GlobalData::SetGlobalVariableString(const FX_CHAR* propname, |
| 194 const CFX_ByteString& sData) { | 200 const CFX_ByteString& sData) { |
| 195 ASSERT(propname); | 201 CFX_ByteString sPropName; |
| 196 CFX_ByteString sPropName = propname; | 202 if (!TrimPropName(propname, &sPropName)) |
| 197 | |
| 198 sPropName.TrimLeft(); | |
| 199 sPropName.TrimRight(); | |
| 200 | |
| 201 if (sPropName.GetLength() == 0) | |
| 202 return; | 203 return; |
| 203 | 204 |
| 204 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { | 205 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { |
| 205 pData->data.nType = JS_GLOBALDATA_TYPE_STRING; | 206 pData->data.nType = JS_GLOBALDATA_TYPE_STRING; |
| 206 pData->data.sData = sData; | 207 pData->data.sData = sData; |
| 207 } else { | 208 return; |
| 208 CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element; | |
| 209 pNewData->data.sKey = sPropName; | |
| 210 pNewData->data.nType = JS_GLOBALDATA_TYPE_STRING; | |
| 211 pNewData->data.sData = sData; | |
| 212 | |
| 213 m_arrayGlobalData.Add(pNewData); | |
| 214 } | 209 } |
| 210 std::unique_ptr<CJS_GlobalData_Element> pNewData(new CJS_GlobalData_Element); |
| 211 pNewData->data.sKey = sPropName; |
| 212 pNewData->data.nType = JS_GLOBALDATA_TYPE_STRING; |
| 213 pNewData->data.sData = sData; |
| 214 m_arrayGlobalData.push_back(std::move(pNewData)); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void CJS_GlobalData::SetGlobalVariableObject( | 217 void CJS_GlobalData::SetGlobalVariableObject( |
| 218 const FX_CHAR* propname, | 218 const FX_CHAR* propname, |
| 219 const CJS_GlobalVariableArray& array) { | 219 const CJS_GlobalVariableArray& array) { |
| 220 ASSERT(propname); | 220 CFX_ByteString sPropName; |
| 221 CFX_ByteString sPropName = propname; | 221 if (!TrimPropName(propname, &sPropName)) |
| 222 | |
| 223 sPropName.TrimLeft(); | |
| 224 sPropName.TrimRight(); | |
| 225 | |
| 226 if (sPropName.GetLength() == 0) | |
| 227 return; | 222 return; |
| 228 | 223 |
| 229 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { | 224 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { |
| 230 pData->data.nType = JS_GLOBALDATA_TYPE_OBJECT; | 225 pData->data.nType = JS_GLOBALDATA_TYPE_OBJECT; |
| 231 pData->data.objData.Copy(array); | 226 pData->data.objData.Copy(array); |
| 232 } else { | 227 return; |
| 233 CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element; | |
| 234 pNewData->data.sKey = sPropName; | |
| 235 pNewData->data.nType = JS_GLOBALDATA_TYPE_OBJECT; | |
| 236 pNewData->data.objData.Copy(array); | |
| 237 | |
| 238 m_arrayGlobalData.Add(pNewData); | |
| 239 } | 228 } |
| 229 std::unique_ptr<CJS_GlobalData_Element> pNewData(new CJS_GlobalData_Element); |
| 230 pNewData->data.sKey = sPropName; |
| 231 pNewData->data.nType = JS_GLOBALDATA_TYPE_OBJECT; |
| 232 pNewData->data.objData.Copy(array); |
| 233 m_arrayGlobalData.push_back(std::move(pNewData)); |
| 240 } | 234 } |
| 241 | 235 |
| 242 void CJS_GlobalData::SetGlobalVariableNull(const FX_CHAR* propname) { | 236 void CJS_GlobalData::SetGlobalVariableNull(const FX_CHAR* propname) { |
| 243 ASSERT(propname); | 237 CFX_ByteString sPropName; |
| 244 CFX_ByteString sPropName = propname; | 238 if (!TrimPropName(propname, &sPropName)) |
| 245 | |
| 246 sPropName.TrimLeft(); | |
| 247 sPropName.TrimRight(); | |
| 248 | |
| 249 if (sPropName.GetLength() == 0) | |
| 250 return; | 239 return; |
| 251 | 240 |
| 252 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { | 241 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { |
| 253 pData->data.nType = JS_GLOBALDATA_TYPE_NULL; | 242 pData->data.nType = JS_GLOBALDATA_TYPE_NULL; |
| 254 } else { | 243 return; |
| 255 CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element; | |
| 256 pNewData->data.sKey = sPropName; | |
| 257 pNewData->data.nType = JS_GLOBALDATA_TYPE_NULL; | |
| 258 | |
| 259 m_arrayGlobalData.Add(pNewData); | |
| 260 } | 244 } |
| 245 std::unique_ptr<CJS_GlobalData_Element> pNewData(new CJS_GlobalData_Element); |
| 246 pNewData->data.sKey = sPropName; |
| 247 pNewData->data.nType = JS_GLOBALDATA_TYPE_NULL; |
| 248 m_arrayGlobalData.push_back(std::move(pNewData)); |
| 261 } | 249 } |
| 262 | 250 |
| 263 FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent(const FX_CHAR* propname, | 251 FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent(const FX_CHAR* propname, |
| 264 FX_BOOL bPersistent) { | 252 FX_BOOL bPersistent) { |
| 265 ASSERT(propname); | 253 CFX_ByteString sPropName; |
| 266 CFX_ByteString sPropName = propname; | 254 if (!TrimPropName(propname, &sPropName)) |
| 267 | |
| 268 sPropName.TrimLeft(); | |
| 269 sPropName.TrimRight(); | |
| 270 | |
| 271 if (sPropName.GetLength() == 0) | |
| 272 return FALSE; | 255 return FALSE; |
| 273 | 256 |
| 274 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { | 257 CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName); |
| 275 pData->bPersistent = bPersistent; | 258 if (!pData) |
| 276 return TRUE; | 259 return FALSE; |
| 277 } | |
| 278 | 260 |
| 279 return FALSE; | 261 pData->bPersistent = bPersistent; |
| 262 return TRUE; |
| 280 } | 263 } |
| 281 | 264 |
| 282 FX_BOOL CJS_GlobalData::DeleteGlobalVariable(const FX_CHAR* propname) { | 265 FX_BOOL CJS_GlobalData::DeleteGlobalVariable(const FX_CHAR* propname) { |
| 283 ASSERT(propname); | 266 CFX_ByteString sPropName; |
| 284 CFX_ByteString sPropName = propname; | 267 if (!TrimPropName(propname, &sPropName)) |
| 285 | |
| 286 sPropName.TrimLeft(); | |
| 287 sPropName.TrimRight(); | |
| 288 | |
| 289 if (sPropName.GetLength() == 0) | |
| 290 return FALSE; | 268 return FALSE; |
| 291 | 269 |
| 292 int nFind = FindGlobalVariable(sPropName); | 270 auto iter = FindGlobalVariable(sPropName); |
| 271 if (iter == m_arrayGlobalData.end()) |
| 272 return FALSE; |
| 293 | 273 |
| 294 if (nFind >= 0) { | 274 m_arrayGlobalData.erase(iter); |
| 295 delete m_arrayGlobalData.GetAt(nFind); | 275 return TRUE; |
| 296 m_arrayGlobalData.RemoveAt(nFind); | |
| 297 return TRUE; | |
| 298 } | |
| 299 | |
| 300 return FALSE; | |
| 301 } | 276 } |
| 302 | 277 |
| 303 int32_t CJS_GlobalData::GetSize() const { | 278 int32_t CJS_GlobalData::GetSize() const { |
| 304 return m_arrayGlobalData.GetSize(); | 279 return pdfium::CollectionSize<int32_t>(m_arrayGlobalData); |
| 305 } | 280 } |
| 306 | 281 |
| 307 CJS_GlobalData_Element* CJS_GlobalData::GetAt(int index) const { | 282 CJS_GlobalData_Element* CJS_GlobalData::GetAt(int index) const { |
| 308 return m_arrayGlobalData.GetAt(index); | 283 if (index < 0 || index >= GetSize()) |
| 284 return nullptr; |
| 285 return m_arrayGlobalData[index].get(); |
| 309 } | 286 } |
| 310 | 287 |
| 311 void CJS_GlobalData::LoadGlobalPersistentVariables() { | 288 void CJS_GlobalData::LoadGlobalPersistentVariables() { |
| 312 uint8_t* pBuffer = NULL; | 289 uint8_t* pBuffer = NULL; |
| 313 int32_t nLength = 0; | 290 int32_t nLength = 0; |
| 314 | 291 |
| 315 LoadFileBuffer(m_sFilePath.c_str(), pBuffer, nLength); | 292 LoadFileBuffer(m_sFilePath.c_str(), pBuffer, nLength); |
| 316 CRYPT_ArcFourCryptBlock(pBuffer, nLength, JS_RC4KEY, sizeof(JS_RC4KEY)); | 293 CRYPT_ArcFourCryptBlock(pBuffer, nLength, JS_RC4KEY, sizeof(JS_RC4KEY)); |
| 317 | 294 |
| 318 if (pBuffer) { | 295 if (pBuffer) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 } | 370 } |
| 394 } | 371 } |
| 395 } | 372 } |
| 396 FX_Free(pBuffer); | 373 FX_Free(pBuffer); |
| 397 } | 374 } |
| 398 } | 375 } |
| 399 | 376 |
| 400 void CJS_GlobalData::SaveGlobalPersisitentVariables() { | 377 void CJS_GlobalData::SaveGlobalPersisitentVariables() { |
| 401 uint32_t nCount = 0; | 378 uint32_t nCount = 0; |
| 402 CFX_BinaryBuf sData; | 379 CFX_BinaryBuf sData; |
| 403 | 380 for (const auto& pElement : m_arrayGlobalData) { |
| 404 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) { | |
| 405 CJS_GlobalData_Element* pElement = m_arrayGlobalData.GetAt(i); | |
| 406 if (pElement->bPersistent) { | 381 if (pElement->bPersistent) { |
| 407 CFX_BinaryBuf sElement; | 382 CFX_BinaryBuf sElement; |
| 408 MakeByteString(pElement->data.sKey, &pElement->data, sElement); | 383 MakeByteString(pElement->data.sKey, &pElement->data, sElement); |
| 409 | |
| 410 if (sData.GetSize() + sElement.GetSize() > JS_MAXGLOBALDATA) | 384 if (sData.GetSize() + sElement.GetSize() > JS_MAXGLOBALDATA) |
| 411 break; | 385 break; |
| 412 | 386 |
| 413 sData.AppendBlock(sElement.GetBuffer(), sElement.GetSize()); | 387 sData.AppendBlock(sElement.GetBuffer(), sElement.GetSize()); |
| 414 nCount++; | 388 nCount++; |
| 415 } | 389 } |
| 416 } | 390 } |
| 417 | 391 |
| 418 CFX_BinaryBuf sFile; | 392 CFX_BinaryBuf sFile; |
| 419 | |
| 420 uint16_t wType = (uint16_t)(('X' << 8) | 'F'); | 393 uint16_t wType = (uint16_t)(('X' << 8) | 'F'); |
| 421 sFile.AppendBlock(&wType, sizeof(uint16_t)); | 394 sFile.AppendBlock(&wType, sizeof(uint16_t)); |
| 422 uint16_t wVersion = 2; | 395 uint16_t wVersion = 2; |
| 423 sFile.AppendBlock(&wVersion, sizeof(uint16_t)); | 396 sFile.AppendBlock(&wVersion, sizeof(uint16_t)); |
| 424 sFile.AppendBlock(&nCount, sizeof(uint32_t)); | 397 sFile.AppendBlock(&nCount, sizeof(uint32_t)); |
| 425 uint32_t dwSize = sData.GetSize(); | 398 uint32_t dwSize = sData.GetSize(); |
| 426 sFile.AppendBlock(&dwSize, sizeof(uint32_t)); | 399 sFile.AppendBlock(&dwSize, sizeof(uint32_t)); |
| 427 | 400 |
| 428 sFile.AppendBlock(sData.GetBuffer(), sData.GetSize()); | 401 sFile.AppendBlock(sData.GetBuffer(), sData.GetSize()); |
| 429 | 402 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 case JS_GLOBALDATA_TYPE_NULL: { | 454 case JS_GLOBALDATA_TYPE_NULL: { |
| 482 uint32_t dwNameLen = (uint32_t)name.GetLength(); | 455 uint32_t dwNameLen = (uint32_t)name.GetLength(); |
| 483 sData.AppendBlock(&dwNameLen, sizeof(uint32_t)); | 456 sData.AppendBlock(&dwNameLen, sizeof(uint32_t)); |
| 484 sData.AppendString(name); | 457 sData.AppendString(name); |
| 485 sData.AppendBlock(&wType, sizeof(uint32_t)); | 458 sData.AppendBlock(&wType, sizeof(uint32_t)); |
| 486 } break; | 459 } break; |
| 487 default: | 460 default: |
| 488 break; | 461 break; |
| 489 } | 462 } |
| 490 } | 463 } |
| OLD | NEW |