7#include "fxjs/xfa/cjx_tree.h"
9#include "core/fxcrt/numerics/safe_conversions.h"
10#include "core/fxcrt/span.h"
12#include "fxjs/js_resources.h"
13#include "fxjs/xfa/cfxjse_class.h"
14#include "fxjs/xfa/cfxjse_engine.h"
15#include "v8/include/cppgc/allocation.h"
16#include "v8/include/v8-object.h"
17#include "v8/include/v8-primitive.h"
18#include "xfa/fxfa/parser/cxfa_arraynodelist.h"
19#include "xfa/fxfa/parser/cxfa_attachnodelist.h"
20#include "xfa/fxfa/parser/cxfa_document.h"
21#include "xfa/fxfa/parser/cxfa_node.h"
22#include "xfa/fxfa/parser/cxfa_object.h"
25 {
"resolveNode", resolveNode_static},
26 {
"resolveNodes", resolveNodes_static}};
29 DefineMethods(MethodSpecs);
39 pdfium::span<v8::Local<v8::Value>> params) {
40 if (params.size() != 1)
43 WideString wsExpression = runtime->ToWideString(params[0]);
49 runtime->ResolveObjects(
50 ToNode(pRefNode), wsExpression.AsStringView(),
51 Mask<XFA_ResolveFlag>{
52 XFA_ResolveFlag::kChildren, XFA_ResolveFlag::kAttributes,
53 XFA_ResolveFlag::kProperties, XFA_ResolveFlag::kParent,
54 XFA_ResolveFlag::kSiblings});
55 if (!maybeResult.has_value())
60 maybeResult.value().objects.front().Get())
);
63 if (!maybeResult.value().script_attribute.callback ||
64 maybeResult.value().script_attribute.eValueType !=
69 v8::Local<v8::Value> pValue;
70 CJX_Object* jsObject = maybeResult.value().objects.front()->JSObject();
71 (*maybeResult.value().script_attribute.callback)(
72 runtime->GetIsolate(), jsObject, &pValue,
false,
73 maybeResult.value().script_attribute.attribute);
74 return CJS_Result::Success(pValue);
78 pdfium::span<v8::Local<v8::Value>> params) {
79 if (params.size() != 1)
87 XFA_ResolveFlag::kChildren, XFA_ResolveFlag::kAttributes,
88 XFA_ResolveFlag::kProperties, XFA_ResolveFlag::kParent,
89 XFA_ResolveFlag::kSiblings};
90 return CJS_Result::Success(ResolveNodeList(runtime->GetIsolate(),
91 runtime->ToWideString(params[0]),
92 kFlags, ToNode(refNode)));
96 v8::Local<v8::Value>* pValue,
104 XFA_ResolveFlag::kALL};
106 *pValue = ResolveNodeList(pIsolate, wsExpression, kFlags,
nullptr);
110 v8::Local<v8::Value>* pValue,
118 XFA_ResolveFlag::kALL};
121 *pValue = ResolveNodeList(pIsolate, wsExpression, kFlags,
nullptr);
125 v8::Local<v8::Value>* pValue,
129 FXJSE_ThrowMessage(pIsolate,
"Unable to set ");
134 auto* pNodeList = cppgc::MakeGarbageCollected<CXFA_AttachNodeList>(
135 pDoc->GetHeap()->GetAllocationHandle(), pDoc, GetXFANode());
139 *pValue = pNodeList->JSObject()->NewBoundV8Object(
144 v8::Local<v8::Value>* pValue,
153 *pValue = pParent ? GetDocument()
155 ->GetOrCreateJSBindingFromMap(pParent)
157 : fxv8::NewNullHelper(pIsolate).As<v8::Value>();
161 v8::Local<v8::Value>* pValue,
170 size_t iIndex = pNode ? pNode->GetIndexByName() : 0;
172 fxv8::NewNumberHelper(pIsolate,
pdfium::checked_cast<int32_t>(iIndex));
175void CJX_Tree::classIndex(
v8::Isolate* pIsolate,
176 v8::Local<v8::Value>* pValue,
185 size_t iIndex = pNode ? pNode->GetIndexByClassName() : 0;
187 fxv8::NewNumberHelper(pIsolate,
pdfium::checked_cast<int32_t>(iIndex));
190void CJX_Tree::somExpression(
v8::Isolate* pIsolate,
191 v8::Local<v8::Value>* pValue,
200 *pValue = fxv8::NewStringHelper(pIsolate, bsSOMExpression.AsStringView());
203v8::Local<v8::Value>
CJX_Tree::ResolveNodeList(
v8::Isolate* pIsolate,
211 auto* pNodeList = cppgc::MakeGarbageCollected<CXFA_ArrayNodeList>(
212 pDoc->GetHeap()->GetAllocationHandle(), pDoc);
217 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringView(),
220 if (maybeResult.has_value()) {
221 if (maybeResult.value().type ==
223 for (
auto& pObject : maybeResult.value().objects) {
224 if (pObject->IsNode())
225 pNodeList->Append(pObject->AsNode());
228 if (maybeResult.value().script_attribute.callback &&
229 maybeResult.value().script_attribute.eValueType ==
231 for (
auto& pObject : maybeResult.value().objects) {
232 v8::Local<v8::Value> innerValue;
233 CJX_Object* jsObject = pObject->JSObject();
234 (*maybeResult.value().script_attribute.callback)(
235 pIsolate, jsObject, &innerValue,
false,
236 maybeResult.value().script_attribute.attribute);
238 CFXJSE_Engine::ToObject(pScriptContext->GetIsolate(), innerValue);
240 pNodeList->Append(obj->AsNode());
245 return pNodeList->JSObject()->NewBoundV8Object(
fxcrt::ByteString ByteString
CXFA_Object * GetThisObject() const
CFXJSE_Class * GetJseNormalClass() const
friend class EventParamScope
static CJS_Result Success()
static CJS_Result Failure(JSMessage id)
CXFA_Object * GetXFAObject() const
void ThrowInvalidPropertyException(v8::Isolate *pIsolate) const
CXFA_Document * GetDocument() const
virtual bool DynamicTypeIs(TypeTag eType) const
CXFA_Node * GetXFANode() const
WideString GetAttributeByEnum(XFA_Attribute attr) const
CJX_Object(CXFA_Object *obj)
CJX_Tree(CXFA_Object *obj)
bool DynamicTypeIs(TypeTag eType) const override
CFXJSE_Engine * GetScriptContext() const
CXFA_NodeOwner * GetNodeOwner()
void PersistList(CXFA_List *list)
XFA_Element GetElementType() const
static WideString FromASCII(ByteStringView str)
fxcrt::WideString WideString