xref: /aosp_15_r20/external/pdfium/fxjs/xfa/cjx_container.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
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_container.h"
8 
9 #include <vector>
10 
11 #include "fxjs/xfa/cfxjse_class.h"
12 #include "fxjs/xfa/cfxjse_engine.h"
13 #include "fxjs/xfa/cfxjse_value.h"
14 #include "v8/include/cppgc/allocation.h"
15 #include "v8/include/v8-object.h"
16 #include "xfa/fxfa/parser/cxfa_arraynodelist.h"
17 #include "xfa/fxfa/parser/cxfa_document.h"
18 #include "xfa/fxfa/parser/cxfa_field.h"
19 
20 const CJX_MethodSpec CJX_Container::MethodSpecs[] = {
21     {"getDelta", getDelta_static},
22     {"getDeltas", getDeltas_static}};
23 
CJX_Container(CXFA_Node * node)24 CJX_Container::CJX_Container(CXFA_Node* node) : CJX_Node(node) {
25   DefineMethods(MethodSpecs);
26 }
27 
28 CJX_Container::~CJX_Container() = default;
29 
DynamicTypeIs(TypeTag eType) const30 bool CJX_Container::DynamicTypeIs(TypeTag eType) const {
31   return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
32 }
33 
getDelta(CFXJSE_Engine * runtime,const std::vector<v8::Local<v8::Value>> & params)34 CJS_Result CJX_Container::getDelta(
35     CFXJSE_Engine* runtime,
36     const std::vector<v8::Local<v8::Value>>& params) {
37   return CJS_Result::Success();
38 }
39 
getDeltas(CFXJSE_Engine * runtime,const std::vector<v8::Local<v8::Value>> & params)40 CJS_Result CJX_Container::getDeltas(
41     CFXJSE_Engine* runtime,
42     const std::vector<v8::Local<v8::Value>>& params) {
43   CXFA_Document* pDoc = GetDocument();
44   auto* pList = cppgc::MakeGarbageCollected<CXFA_ArrayNodeList>(
45       pDoc->GetHeap()->GetAllocationHandle(), pDoc);
46   pDoc->GetNodeOwner()->PersistList(pList);
47   return CJS_Result::Success(runtime->NewNormalXFAObject(pList));
48 }
49