1 // Copyright 2017 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 "fxjs/xfa/cjx_treelist.h" 8 9 #include <vector> 10 11 #include "fxjs/cfxjse_engine.h" 12 #include "fxjs/cfxjse_value.h" 13 #include "fxjs/js_resources.h" 14 #include "xfa/fxfa/parser/cxfa_document.h" 15 #include "xfa/fxfa/parser/cxfa_node.h" 16 #include "xfa/fxfa/parser/cxfa_treelist.h" 17 18 const CJX_MethodSpec CJX_TreeList::MethodSpecs[] = { 19 {"namedItem", namedItem_static}}; 20 CJX_TreeList(CXFA_TreeList * list)21CJX_TreeList::CJX_TreeList(CXFA_TreeList* list) : CJX_List(list) { 22 DefineMethods(MethodSpecs, FX_ArraySize(MethodSpecs)); 23 } 24 ~CJX_TreeList()25CJX_TreeList::~CJX_TreeList() {} 26 GetXFATreeList()27CXFA_TreeList* CJX_TreeList::GetXFATreeList() { 28 return static_cast<CXFA_TreeList*>(GetXFAObject()); 29 } 30 namedItem(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)31CJS_Return CJX_TreeList::namedItem( 32 CJS_V8* runtime, 33 const std::vector<v8::Local<v8::Value>>& params) { 34 if (params.size() != 1) 35 return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); 36 37 CXFA_Node* pNode = GetXFATreeList()->NamedItem( 38 runtime->ToWideString(params[0]).AsStringView()); 39 if (!pNode) 40 return CJS_Return(true); 41 42 CFXJSE_Value* value = 43 GetDocument()->GetScriptContext()->GetJSValueFromMap(pNode); 44 if (!value) 45 return CJS_Return(runtime->NewNull()); 46 47 return CJS_Return(value->DirectGetValue().Get(runtime->GetIsolate())); 48 } 49