1 // Copyright 2017 The PDFium Authors 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 "fxjs/xfa/cjx_treelist.h" 8 9 #include <vector> 10 11 #include "fxjs/js_resources.h" 12 #include "fxjs/xfa/cfxjse_engine.h" 13 #include "fxjs/xfa/cfxjse_value.h" 14 #include "v8/include/v8-object.h" 15 #include "xfa/fxfa/parser/cxfa_document.h" 16 #include "xfa/fxfa/parser/cxfa_node.h" 17 #include "xfa/fxfa/parser/cxfa_treelist.h" 18 19 const CJX_MethodSpec CJX_TreeList::MethodSpecs[] = { 20 {"namedItem", namedItem_static}}; 21 CJX_TreeList(CXFA_TreeList * list)22CJX_TreeList::CJX_TreeList(CXFA_TreeList* list) : CJX_List(list) { 23 DefineMethods(MethodSpecs); 24 } 25 26 CJX_TreeList::~CJX_TreeList() = default; 27 DynamicTypeIs(TypeTag eType) const28bool CJX_TreeList::DynamicTypeIs(TypeTag eType) const { 29 return eType == static_type__ || ParentType__::DynamicTypeIs(eType); 30 } 31 GetXFATreeList()32CXFA_TreeList* CJX_TreeList::GetXFATreeList() { 33 return ToTreeList(GetXFAObject()); 34 } 35 namedItem(CFXJSE_Engine * runtime,const std::vector<v8::Local<v8::Value>> & params)36CJS_Result CJX_TreeList::namedItem( 37 CFXJSE_Engine* runtime, 38 const std::vector<v8::Local<v8::Value>>& params) { 39 if (params.size() != 1) 40 return CJS_Result::Failure(JSMessage::kParamError); 41 42 CXFA_Node* pNode = GetXFATreeList()->NamedItem( 43 runtime->ToWideString(params[0]).AsStringView()); 44 if (!pNode) 45 return CJS_Result::Success(); 46 47 return CJS_Result::Success( 48 GetDocument()->GetScriptContext()->GetOrCreateJSBindingFromMap(pNode)); 49 } 50