OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 |
| 7 #include "xfa/fxfa/parser/xfa_object.h" |
| 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" |
| 10 #include "xfa/fxfa/parser/xfa_document.h" |
| 11 #include "xfa/fxfa/parser/xfa_script_imp.h" |
| 12 |
| 13 CXFA_NodeList::CXFA_NodeList(CXFA_Document* pDocument) |
| 14 : CXFA_Object(pDocument, |
| 15 XFA_ObjectType::NodeList, |
| 16 XFA_Element::NodeList, |
| 17 CFX_WideStringC(L"nodeList")) { |
| 18 m_pDocument->GetScriptContext()->AddToCacheList( |
| 19 std::unique_ptr<CXFA_NodeList>(this)); |
| 20 } |
| 21 |
| 22 CXFA_NodeList::~CXFA_NodeList() {} |
| 23 |
| 24 CXFA_Node* CXFA_NodeList::NamedItem(const CFX_WideStringC& wsName) { |
| 25 uint32_t dwHashCode = FX_HashCode_GetW(wsName, false); |
| 26 int32_t iCount = GetLength(); |
| 27 for (int32_t i = 0; i < iCount; i++) { |
| 28 CXFA_Node* ret = Item(i); |
| 29 if (dwHashCode == ret->GetNameHash()) |
| 30 return ret; |
| 31 } |
| 32 return nullptr; |
| 33 } |
| 34 |
| 35 void CXFA_NodeList::Script_ListClass_Append(CFXJSE_Arguments* pArguments) { |
| 36 int32_t argc = pArguments->GetLength(); |
| 37 if (argc == 1) { |
| 38 CXFA_Node* pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 39 if (pNode) { |
| 40 Append(pNode); |
| 41 } else { |
| 42 ThrowException(XFA_IDS_ARGUMENT_MISMATCH); |
| 43 } |
| 44 } else { |
| 45 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"append"); |
| 46 } |
| 47 } |
| 48 |
| 49 void CXFA_NodeList::Script_ListClass_Insert(CFXJSE_Arguments* pArguments) { |
| 50 int32_t argc = pArguments->GetLength(); |
| 51 if (argc == 2) { |
| 52 CXFA_Node* pNewNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 53 CXFA_Node* pBeforeNode = static_cast<CXFA_Node*>(pArguments->GetObject(1)); |
| 54 if (pNewNode) { |
| 55 Insert(pNewNode, pBeforeNode); |
| 56 } else { |
| 57 ThrowException(XFA_IDS_ARGUMENT_MISMATCH); |
| 58 } |
| 59 } else { |
| 60 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"insert"); |
| 61 } |
| 62 } |
| 63 |
| 64 void CXFA_NodeList::Script_ListClass_Remove(CFXJSE_Arguments* pArguments) { |
| 65 int32_t argc = pArguments->GetLength(); |
| 66 if (argc == 1) { |
| 67 CXFA_Node* pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 68 if (pNode) { |
| 69 Remove(pNode); |
| 70 } else { |
| 71 ThrowException(XFA_IDS_ARGUMENT_MISMATCH); |
| 72 } |
| 73 } else { |
| 74 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remove"); |
| 75 } |
| 76 } |
| 77 |
| 78 void CXFA_NodeList::Script_ListClass_Item(CFXJSE_Arguments* pArguments) { |
| 79 int32_t argc = pArguments->GetLength(); |
| 80 if (argc == 1) { |
| 81 int32_t iIndex = pArguments->GetInt32(0); |
| 82 if ((iIndex >= 0) && (iIndex + 1 <= GetLength())) { |
| 83 pArguments->GetReturnValue()->Assign( |
| 84 m_pDocument->GetScriptContext()->GetJSValueFromMap(Item(iIndex))); |
| 85 } else { |
| 86 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); |
| 87 } |
| 88 } else { |
| 89 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"item"); |
| 90 } |
| 91 } |
| 92 |
| 93 void CXFA_NodeList::Script_TreelistClass_NamedItem( |
| 94 CFXJSE_Arguments* pArguments) { |
| 95 int32_t argc = pArguments->GetLength(); |
| 96 if (argc == 1) { |
| 97 CFX_ByteString szName = pArguments->GetUTF8String(0); |
| 98 CXFA_Node* pNode = |
| 99 NamedItem(CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC()); |
| 100 if (!pNode) { |
| 101 return; |
| 102 } |
| 103 pArguments->GetReturnValue()->Assign( |
| 104 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); |
| 105 } else { |
| 106 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"namedItem"); |
| 107 } |
| 108 } |
| 109 |
| 110 void CXFA_NodeList::Script_ListClass_Length(CFXJSE_Value* pValue, |
| 111 FX_BOOL bSetting, |
| 112 XFA_ATTRIBUTE eAttribute) { |
| 113 if (!bSetting) { |
| 114 pValue->SetInteger(GetLength()); |
| 115 } else { |
| 116 ThrowException(XFA_IDS_INVAlID_PROP_SET); |
| 117 } |
| 118 } |
OLD | NEW |