Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cjx_list.cpp
Go to the documentation of this file.
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_list.h"
8
9#include <vector>
10
11#include "fxjs/fxv8.h"
12#include "fxjs/js_resources.h"
13#include "fxjs/xfa/cfxjse_class.h"
14#include "fxjs/xfa/cfxjse_engine.h"
15#include "third_party/base/containers/span.h"
16#include "third_party/base/numerics/safe_conversions.h"
17#include "v8/include/v8-object.h"
18#include "v8/include/v8-primitive.h"
19#include "xfa/fxfa/parser/cxfa_document.h"
20#include "xfa/fxfa/parser/cxfa_list.h"
21#include "xfa/fxfa/parser/cxfa_node.h"
22
23const CJX_MethodSpec CJX_List::MethodSpecs[] = {{"append", append_static},
24 {"insert", insert_static},
25 {"item", item_static},
26 {"remove", remove_static}};
27
29 DefineMethods(MethodSpecs);
30}
31
32CJX_List::~CJX_List() = default;
33
34bool CJX_List::DynamicTypeIs(TypeTag eType) const {
35 return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
36}
37
38CXFA_List* CJX_List::GetXFAList() {
39 return ToList(GetXFAObject());
40}
41
42CJS_Result CJX_List::append(CFXJSE_Engine* runtime,
43 pdfium::span<v8::Local<v8::Value>> params) {
44 if (params.size() != 1)
46
47 auto* pNode = ToNode(runtime->ToXFAObject(params[0]));
48 if (!pNode)
50
51 if (!GetXFAList()->Append(pNode))
53
55}
56
57CJS_Result CJX_List::insert(CFXJSE_Engine* runtime,
58 pdfium::span<v8::Local<v8::Value>> params) {
59 if (params.size() != 2)
61
62 auto* pNewNode = ToNode(runtime->ToXFAObject(params[0]));
63 if (!pNewNode)
65
66 auto* pBeforeNode = ToNode(runtime->ToXFAObject(params[1]));
67 if (!GetXFAList()->Insert(pNewNode, pBeforeNode))
69
71}
72
73CJS_Result CJX_List::remove(CFXJSE_Engine* runtime,
74 pdfium::span<v8::Local<v8::Value>> params) {
75 if (params.size() != 1)
77
78 auto* pNode = ToNode(runtime->ToXFAObject(params[0]));
79 if (!pNode)
81
82 GetXFAList()->Remove(pNode);
84}
85
86CJS_Result CJX_List::item(CFXJSE_Engine* runtime,
87 pdfium::span<v8::Local<v8::Value>> params) {
88 if (params.size() != 1)
90
91 int32_t index = runtime->ToInt32(params[0]);
92 size_t cast_index = static_cast<size_t>(index);
93 if (index < 0 || cast_index >= GetXFAList()->GetLength())
95
97 runtime->NewNormalXFAObject(GetXFAList()->Item(cast_index)));
98}
99
100void CJX_List::length(v8::Isolate* pIsolate,
101 v8::Local<v8::Value>* pValue,
102 bool bSetting,
103 XFA_Attribute eAttribute) {
104 if (bSetting) {
106 return;
107 }
108 *pValue = fxv8::NewNumberHelper(
109 pIsolate, pdfium::base::checked_cast<int32_t>(GetXFAList()->GetLength()));
110}
friend class EventParamScope
static CJS_Result Success()
Definition cjs_result.h:27
static CJS_Result Failure(JSMessage id)
Definition cjs_result.h:34
CJX_List(CXFA_List *list)
Definition cjx_list.cpp:28
bool DynamicTypeIs(TypeTag eType) const override
Definition cjx_list.cpp:34
~CJX_List() override
void DefineMethods(pdfium::span< const CJX_MethodSpec > methods)
CXFA_Object * GetXFAObject() const
Definition cjx_object.h:113
void ThrowInvalidPropertyException(v8::Isolate *pIsolate) const
virtual bool DynamicTypeIs(TypeTag eType) const
virtual void Remove(CXFA_Node *pNode)=0
virtual bool Append(CXFA_Node *pNode)=0
virtual bool Insert(CXFA_Node *pNewNode, CXFA_Node *pBeforeNode)=0
XFA_Attribute
Definition fxfa_basic.h:67
JSMessage
@ kInvalidInputError