Chromium Code Reviews| Index: fpdfsdk/src/javascript/Document.cpp |
| diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp |
| index f4a1090c3d5985ab79ecde74e5e0235300bce96b..920bc83f87a0eb76baea1c9b56ff52139ff46b64 100644 |
| --- a/fpdfsdk/src/javascript/Document.cpp |
| +++ b/fpdfsdk/src/javascript/Document.cpp |
| @@ -149,23 +149,13 @@ void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { |
| Document::Document(CJS_Object* pJSObject) |
| : CJS_EmbedObj(pJSObject), |
| m_isolate(NULL), |
| - m_pIconTree(NULL), |
| m_pDocument(NULL), |
| m_cwBaseURL(L""), |
| m_bDelay(FALSE) {} |
| Document::~Document() { |
| - if (m_pIconTree) { |
| - m_pIconTree->DeleteIconTree(); |
| - delete m_pIconTree; |
| - m_pIconTree = NULL; |
| - } |
| for (int i = 0; i < m_DelayData.GetSize(); i++) { |
| - if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { |
| - delete pData; |
| - pData = NULL; |
| - m_DelayData.SetAt(i, NULL); |
| - } |
| + delete m_DelayData.GetAt(i); |
|
Lei Zhang
2016/01/05 22:35:31
Looks like another good candidate to convert to us
Tom Sepez
2016/01/05 23:10:09
Acknowledged.
|
| } |
| m_DelayData.RemoveAll(); |
| @@ -1255,51 +1245,6 @@ bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { |
| rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); |
| } |
| -void IconTree::InsertIconElement(IconElement* pNewIcon) { |
| - if (!pNewIcon) |
| - return; |
| - |
| - if (m_pHead || m_pEnd) { |
| - m_pEnd->NextIcon = pNewIcon; |
| - m_pEnd = pNewIcon; |
| - } else { |
| - m_pHead = pNewIcon; |
| - m_pEnd = pNewIcon; |
| - } |
| - m_iLength++; |
| -} |
| - |
| -void IconTree::DeleteIconTree() { |
| - if (!m_pHead || !m_pEnd) |
| - return; |
| - |
| - IconElement* pTemp = NULL; |
| - while (m_pEnd != m_pHead) { |
| - pTemp = m_pHead; |
| - m_pHead = m_pHead->NextIcon; |
| - delete pTemp; |
| - } |
| - |
| - delete m_pEnd; |
| - m_pHead = NULL; |
| - m_pEnd = NULL; |
| -} |
| - |
| -int IconTree::GetLength() { |
| - return m_iLength; |
| -} |
| - |
| -IconElement* IconTree::operator[](int iIndex) { |
| - if (iIndex >= 0 && iIndex <= m_iLength) { |
| - IconElement* pTemp = m_pHead; |
| - for (int i = 0; i < iIndex; i++) { |
| - pTemp = pTemp->NextIcon; |
| - } |
| - return pTemp; |
| - } |
| - return NULL; |
| -} |
| - |
| FX_BOOL Document::addIcon(IJS_Context* cc, |
| const std::vector<CJS_Value>& params, |
| CJS_Value& vRet, |
| @@ -1328,15 +1273,8 @@ FX_BOOL Document::addIcon(IJS_Context* cc, |
| return FALSE; |
| } |
| - Icon* pIcon = (Icon*)pEmbedObj; |
| - if (!m_pIconTree) |
| - m_pIconTree = new IconTree(); |
| - |
| - IconElement* pNewIcon = new IconElement(); |
| - pNewIcon->IconName = swIconName; |
| - pNewIcon->NextIcon = NULL; |
| - pNewIcon->IconStream = pIcon; |
| - m_pIconTree->InsertIconElement(pNewIcon); |
| + m_IconList.push_back(std::unique_ptr<IconElement>( |
|
Lei Zhang
2016/01/05 22:35:31
Do you know if there's a std::unique_ptr equivalen
Tom Sepez
2016/01/05 23:10:09
C++14 will introduce make_unique(xxx), but its not
|
| + new IconElement(swIconName, (Icon*)pEmbedObj))); |
| return TRUE; |
| } |
| @@ -1349,18 +1287,11 @@ FX_BOOL Document::icons(IJS_Context* cc, |
| return FALSE; |
| } |
| - if (!m_pIconTree) { |
| - vp.SetNull(); |
| - return TRUE; |
| - } |
| - |
| CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| CJS_Array Icons(pRuntime); |
| - IconElement* pIconElement = NULL; |
| - int iIconTreeLength = m_pIconTree->GetLength(); |
| - for (int i = 0; i < iIconTreeLength; i++) { |
| - pIconElement = (*m_pIconTree)[i]; |
| + int i = 0; |
|
Lei Zhang
2016/01/05 22:35:30
Shall we implement append() / push_back() for CJS_
|
| + for (const auto& pIconElement : m_IconList) { |
| v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
| pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); |
| if (pObj.IsEmpty()) |
| @@ -1376,7 +1307,7 @@ FX_BOOL Document::icons(IJS_Context* cc, |
| pIcon->SetStream(pIconElement->IconStream->GetStream()); |
| pIcon->SetIconName(pIconElement->IconName); |
| - Icons.SetElement(i, CJS_Value(pRuntime, pJS_Icon)); |
| + Icons.SetElement(i++, CJS_Value(pRuntime, pJS_Icon)); |
| } |
| vp << Icons; |
| @@ -1393,16 +1324,12 @@ FX_BOOL Document::getIcon(IJS_Context* cc, |
| return FALSE; |
| } |
| - if (!m_pIconTree) |
| - return FALSE; |
| CFX_WideString swIconName = params[0].ToCFXWideString(); |
| - int iIconCounts = m_pIconTree->GetLength(); |
| - |
| CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| - for (int i = 0; i < iIconCounts; i++) { |
| - if ((*m_pIconTree)[i]->IconName == swIconName) { |
| - Icon* pRetIcon = (*m_pIconTree)[i]->IconStream; |
| + for (const auto& pIconElement : m_IconList) { |
| + if (pIconElement->IconName == swIconName) { |
| + Icon* pRetIcon = pIconElement->IconStream; |
| v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
| pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); |