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
cfxjse_engine.h
Go to the documentation of this file.
1// Copyright 2014 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#ifndef FXJS_XFA_CFXJSE_ENGINE_H_
8#define FXJS_XFA_CFXJSE_ENGINE_H_
9
10#include <map>
11#include <memory>
12#include <type_traits>
13#include <vector>
14
15#include "core/fxcrt/mask.h"
16#include "core/fxcrt/unowned_ptr.h"
17#include "fxjs/cfx_v8.h"
18#include "fxjs/xfa/cfxjse_context.h"
19#include "v8/include/cppgc/persistent.h"
20#include "v8/include/v8-forward.h"
21#include "v8/include/v8-persistent-handle.h"
22#include "xfa/fxfa/cxfa_eventparam.h"
23#include "xfa/fxfa/parser/cxfa_document.h"
24#include "xfa/fxfa/parser/cxfa_script.h"
25#include "xfa/fxfa/parser/xfa_basic_data.h"
26
27class CFXJSE_Class;
28class CFXJSE_FormCalcContext;
32class CFXJSE_Value;
33class CJS_Runtime;
34
36 kChildren = 1 << 0,
37 kTagName = 1 << 1,
38 kAttributes = 1 << 2,
39 kProperties = 1 << 3,
40 kSiblings = 1 << 5,
41 kParent = 1 << 6,
42 kAnyChild = 1 << 7,
43 kALL = 1 << 8,
44 kCreateNode = 1 << 10,
45 kBind = 1 << 11,
46 kBindNew = 1 << 12,
47};
48
49class CFXJSE_Engine final : public CFX_V8 {
50 public:
52 CPPGC_STACK_ALLOCATED(); // Allow raw/unowned pointers.
53
54 public:
55 enum class Type {
56 kNodes = 0,
62 };
63
68
71
72 // Vector of Member would be correct for stack-based vectors, if
73 // STL worked with cppgc.
75 };
76
77 static CXFA_Object* ToObject(const v8::FunctionCallbackInfo<v8::Value>& info);
78 static CXFA_Object* ToObject(v8::Isolate* pIsolate,
79 v8::Local<v8::Value> value);
80 static CXFA_Object* ToObject(v8::Isolate* pIsolate, CFXJSE_Value* pValue);
81 static CXFA_Object* ToObject(CFXJSE_HostObject* pHostObj);
83 v8::Isolate* pIsolate,
84 v8::Local<v8::Object> pObject,
85 ByteStringView szPropName);
86 static void GlobalPropertySetter(v8::Isolate* pIsolate,
87 v8::Local<v8::Object> pObject,
88 ByteStringView szPropName,
89 v8::Local<v8::Value> pValue);
91 v8::Isolate* pIsolate,
92 v8::Local<v8::Object> pObject,
93 ByteStringView szPropName);
94 static void NormalPropertySetter(v8::Isolate* pIsolate,
95 v8::Local<v8::Object> pObject,
96 ByteStringView szPropName,
97 v8::Local<v8::Value> pValue);
99 const v8::FunctionCallbackInfo<v8::Value>& info,
100 const WideString& functionName);
101 static FXJSE_ClassPropType NormalPropTypeGetter(v8::Isolate* pIsolate,
102 v8::Local<v8::Object> pObject,
103 ByteStringView szPropName,
104 bool bQueryIn);
105 static FXJSE_ClassPropType GlobalPropTypeGetter(v8::Isolate* pIsolate,
106 v8::Local<v8::Object> pObject,
107 ByteStringView szPropName,
108 bool bQueryIn);
109
110 CFXJSE_Engine(CXFA_Document* pDocument, CJS_Runtime* fxjs_runtime);
111 ~CFXJSE_Engine() override;
112
114 CPPGC_STACK_ALLOCATED();
115
116 public:
118 CXFA_Node* pTarget,
119 CXFA_EventParam* pEventParam);
121
122 private:
123 UnownedPtr<CFXJSE_Engine> m_pEngine;
124 UnownedPtr<CXFA_Node> m_pPrevTarget;
125 UnownedPtr<CXFA_EventParam> m_pPrevEventParam;
126 };
127 friend class EventParamScope;
128
129 CXFA_Node* GetEventTarget() const { return m_pTarget; }
130 CXFA_EventParam* GetEventParam() const { return m_eventParam; }
131
132 CFXJSE_Context::ExecutionResult RunScript(CXFA_Script::Type eScriptType,
133 WideStringView wsScript,
134 CXFA_Object* pThisObject);
135
137 WideStringView wsExpression,
138 Mask<XFA_ResolveFlag> dwStyles);
139
141 CXFA_Object* refObject,
142 WideStringView wsExpression,
143 Mask<XFA_ResolveFlag> dwStyles,
144 CXFA_Node* bindNode);
145
147
148 CXFA_Object* GetThisObject() const { return m_pThisObject; }
149 CFXJSE_Class* GetJseNormalClass() const { return m_pJsClass; }
150 CXFA_Document* GetDocument() const { return m_pDocument.Get(); }
151
153 void AddNodesOfRunScript(CXFA_Node* pNode);
154
155 void SetRunAtType(XFA_AttributeValue eRunAt) { m_eRunAtType = eRunAt; }
156 bool IsRunAtClient() { return m_eRunAtType != XFA_AttributeValue::Server; }
157
158 CXFA_Script::Type GetType();
159
160 void AddObjectToUpArray(CXFA_Node* pNode);
162
163 CXFA_Object* ToXFAObject(v8::Local<v8::Value> obj);
165
166 bool IsResolvingNodes() const { return m_bResolvingNodes; }
167
168 CFXJSE_Context* GetJseContextForTest() const { return GetJseContext(); }
169
170 private:
171 CFXJSE_Context* GetJseContext() const { return m_JsContext.get(); }
172 CFXJSE_Context* CreateVariablesContext(CXFA_Script* pScriptNode,
173 CXFA_Node* pSubform);
174 void RemoveBuiltInObjs(CFXJSE_Context* pContext);
175 bool QueryNodeByFlag(CXFA_Node* refNode,
176 WideStringView propname,
177 v8::Local<v8::Value>* pValue,
178 Mask<XFA_ResolveFlag> dwFlag);
179 bool UpdateNodeByFlag(CXFA_Node* refNode,
180 WideStringView propname,
181 v8::Local<v8::Value> pValue,
182 Mask<XFA_ResolveFlag> dwFlag);
183 bool IsStrictScopeInJavaScript();
184 CXFA_Object* GetVariablesThis(CXFA_Object* pObject);
185 CXFA_Object* GetVariablesScript(CXFA_Object* pObject);
186 CFXJSE_Context* VariablesContextForScriptNode(CXFA_Script* pScriptNode);
187 bool QueryVariableValue(CXFA_Script* pScriptNode,
188 ByteStringView szPropName,
189 v8::Local<v8::Value>* pValue);
190 bool UpdateVariableValue(CXFA_Script* pScriptNode,
191 ByteStringView szPropName,
192 v8::Local<v8::Value> pValue);
193 void RunVariablesScript(CXFA_Script* pScriptNode);
194
195 UnownedPtr<CJS_Runtime> const m_pSubordinateRuntime;
196 cppgc::WeakPersistent<CXFA_Document> const m_pDocument;
197 std::unique_ptr<CFXJSE_Context> m_JsContext;
198 UnownedPtr<CFXJSE_Class> m_pJsClass;
199 CXFA_Script::Type m_eScriptType = CXFA_Script::Type::Unknown;
200 // |m_mapObjectToValue| is what ensures the v8 object bound to a
201 // CJX_Object remains valid for the lifetime of the engine.
206 cppgc::Persistent<CXFA_Node> m_pTarget;
207 UnownedPtr<CXFA_EventParam> m_eventParam;
210 std::unique_ptr<CFXJSE_NodeHelper> const m_NodeHelper;
211 std::unique_ptr<CFXJSE_ResolveProcessor> const m_ResolveProcessor;
212 std::unique_ptr<CFXJSE_FormCalcContext> m_FormCalcContext;
213 cppgc::Persistent<CXFA_Object> m_pThisObject;
214 XFA_AttributeValue m_eRunAtType = XFA_AttributeValue::Client;
215 bool m_bResolvingNodes = false;
216};
217
218#endif // FXJS_XFA_CFXJSE_ENGINE_H_
const FXJSE_CLASS_DESCRIPTOR kNormalClassDescriptor
const FXJSE_CLASS_DESCRIPTOR kGlobalClassDescriptor
const FXJSE_CLASS_DESCRIPTOR kVariablesClassDescriptor
XFA_ResolveFlag
EventParamScope(CFXJSE_Engine *pEngine, CXFA_Node *pTarget, CXFA_EventParam *pEventParam)
ResolveResult & operator=(const ResolveResult &that)
XFA_SCRIPTATTRIBUTEINFO script_attribute
ResolveResult(const ResolveResult &that)
void SetRunAtType(XFA_AttributeValue eRunAt)
static CJS_Result NormalMethodCall(const v8::FunctionCallbackInfo< v8::Value > &info, const WideString &functionName)
bool IsResolvingNodes() const
CXFA_Object * ToXFAObject(v8::Local< v8::Value > obj)
CXFA_Node * GetEventTarget() const
static v8::Local< v8::Value > NormalPropertyGetter(v8::Isolate *pIsolate, v8::Local< v8::Object > pObject, ByteStringView szPropName)
static void GlobalPropertySetter(v8::Isolate *pIsolate, v8::Local< v8::Object > pObject, ByteStringView szPropName, v8::Local< v8::Value > pValue)
CFXJSE_Engine(CXFA_Document *pDocument, CJS_Runtime *fxjs_runtime)
static FXJSE_ClassPropType GlobalPropTypeGetter(v8::Isolate *pIsolate, v8::Local< v8::Object > pObject, ByteStringView szPropName, bool bQueryIn)
CXFA_EventParam * GetEventParam() const
static CXFA_Object * ToObject(const v8::FunctionCallbackInfo< v8::Value > &info)
CXFA_Object * GetThisObject() const
CXFA_Script::Type GetType()
CFXJSE_Class * GetJseNormalClass() const
void AddNodesOfRunScript(CXFA_Node *pNode)
void SetNodesOfRunScript(std::vector< cppgc::Persistent< CXFA_Node > > *pArray)
static v8::Local< v8::Value > GlobalPropertyGetter(v8::Isolate *pIsolate, v8::Local< v8::Object > pObject, ByteStringView szPropName)
friend class EventParamScope
static FXJSE_ClassPropType NormalPropTypeGetter(v8::Isolate *pIsolate, v8::Local< v8::Object > pObject, ByteStringView szPropName, bool bQueryIn)
static CXFA_Object * ToObject(v8::Isolate *pIsolate, CFXJSE_Value *pValue)
absl::optional< ResolveResult > ResolveObjectsWithBindNode(CXFA_Object *refObject, WideStringView wsExpression, Mask< XFA_ResolveFlag > dwStyles, CXFA_Node *bindNode)
CFXJSE_Context * GetJseContextForTest() const
v8::Local< v8::Object > NewNormalXFAObject(CXFA_Object *obj)
CFXJSE_Context::ExecutionResult RunScript(CXFA_Script::Type eScriptType, WideStringView wsScript, CXFA_Object *pThisObject)
static void NormalPropertySetter(v8::Isolate *pIsolate, v8::Local< v8::Object > pObject, ByteStringView szPropName, v8::Local< v8::Value > pValue)
CXFA_Node * LastObjectFromUpArray()
~CFXJSE_Engine() override
absl::optional< ResolveResult > ResolveObjects(CXFA_Object *refObject, WideStringView wsExpression, Mask< XFA_ResolveFlag > dwStyles)
static CXFA_Object * ToObject(v8::Isolate *pIsolate, v8::Local< v8::Value > value)
static CXFA_Object * ToObject(CFXJSE_HostObject *pHostObj)
CXFA_Document * GetDocument() const
void AddObjectToUpArray(CXFA_Node *pNode)
v8::Local< v8::Object > GetOrCreateJSBindingFromMap(CXFA_Object *pObject)
virtual CJX_Object * AsCJXObject()
Definition fxjse.cpp:38
CFXJSE_Engine::ResolveResult m_Result
CFXJSE_ScopeUtil_IsolateHandleContext(CFXJSE_Context *pContext)
static CJS_Result Failure(const WideString &str)
Definition cjs_result.h:31
bool HasMethod(const WideString &func) const
CXFA_Object * GetXFAObject() const
Definition cjx_object.h:113
CXFA_FFNotify * GetNotify() const
CFXJSE_Engine * GetScriptContext() const
CXFA_Object * GetXFAObject(XFA_HashCode wsNodeNameHash)
CXFA_Node * GetRoot() const
IJS_Runtime * GetIJSRuntime() const
CXFA_FFDoc * GetFFDoc() const
XFA_Element GetElementType() const
Definition cxfa_object.h:91
bool IsThisProxy() const
Definition cxfa_object.h:74
CXFA_Node * AsNode()
CJX_Object * JSObject()
Definition cxfa_object.h:81
CXFA_Document * GetDocument() const
Definition cxfa_object.h:48
bool IsNode() const
Definition cxfa_object.h:55
static CXFA_Script * FromNode(CXFA_Node *pNode)
CXFA_Script * GetScriptNode() const
CXFA_Node * GetThisNode() const
static CXFA_Variables * FromNode(CXFA_Node *pNode)
static WideString FromUTF8(ByteStringView str)
bool EqualsASCII(ByteStringView that) const
Definition widestring.h:216
CXFA_ThisProxy * ToThisProxy(CXFA_Object *pObj)
CXFA_Node * ToNode(CXFA_Object *pObj)
XFA_Attribute
Definition fxfa_basic.h:67
XFA_HashCode
Definition fxfa_basic.h:12
@ XFA_HASHCODE_Layout
Definition fxfa_basic.h:25
XFA_Element
Definition fxfa_basic.h:75
XFA_AttributeValue
Definition fxfa_basic.h:60
FXJSE_ClassPropType
Definition fxjse.h:31
Definition fxv8.h:22
bool IsUndefined(v8::Local< v8::Value > value)
Definition fxv8.cpp:19
const char kClassTag[]
Definition fxjse.cpp:18
XFA_ATTRIBUTE_CALLBACK callback