summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cscript_eventpseudomodel.cpp8
-rw-r--r--xfa/fxfa/parser/cscript_hostpseudomodel.cpp8
-rw-r--r--xfa/fxfa/parser/cscript_layoutpseudomodel.cpp2
-rw-r--r--xfa/fxfa/parser/cscript_signaturepseudomodel.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_document.cpp10
-rw-r--r--xfa/fxfa/parser/cxfa_document.h8
-rw-r--r--xfa/fxfa/parser/cxfa_layoutpagemgr.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp16
-rw-r--r--xfa/fxfa/parser/cxfa_nodehelper.cpp11
-rw-r--r--xfa/fxfa/parser/cxfa_nodehelper.h4
-rw-r--r--xfa/fxfa/parser/cxfa_nodelist.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_resolveprocessor.cpp6
-rw-r--r--xfa/fxfa/parser/cxfa_resolveprocessor.h6
-rw-r--r--xfa/fxfa/parser/cxfa_scriptcontext.cpp779
-rw-r--r--xfa/fxfa/parser/cxfa_scriptcontext.h126
-rw-r--r--xfa/fxfa/parser/cxfa_valuearray.cpp4
-rw-r--r--xfa/fxfa/parser/xfa_document_datamerger_imp.cpp2
17 files changed, 45 insertions, 951 deletions
diff --git a/xfa/fxfa/parser/cscript_eventpseudomodel.cpp b/xfa/fxfa/parser/cscript_eventpseudomodel.cpp
index ecf2a98915..1f20f291e6 100644
--- a/xfa/fxfa/parser/cscript_eventpseudomodel.cpp
+++ b/xfa/fxfa/parser/cscript_eventpseudomodel.cpp
@@ -7,12 +7,12 @@
#include "xfa/fxfa/parser/cscript_eventpseudomodel.h"
#include "fxjs/cfxjse_arguments.h"
+#include "fxjs/cfxjse_engine.h"
#include "xfa/fxfa/cxfa_eventparam.h"
#include "xfa/fxfa/cxfa_ffnotify.h"
#include "xfa/fxfa/cxfa_ffwidgethandler.h"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_localemgr.h"
-#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
#include "xfa/fxfa/parser/xfa_utils.h"
namespace {
@@ -54,7 +54,7 @@ CScript_EventPseudoModel::~CScript_EventPseudoModel() {}
void CScript_EventPseudoModel::Property(CFXJSE_Value* pValue,
XFA_Event dwFlag,
bool bSetting) {
- CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
+ CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext)
return;
@@ -198,7 +198,7 @@ void CScript_EventPseudoModel::Target(CFXJSE_Value* pValue,
Property(pValue, XFA_Event::Target, bSetting);
}
void CScript_EventPseudoModel::Emit(CFXJSE_Arguments* pArguments) {
- CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
+ CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext) {
return;
}
@@ -217,7 +217,7 @@ void CScript_EventPseudoModel::Emit(CFXJSE_Arguments* pArguments) {
pWidgetHandler->ProcessEvent(pEventParam->m_pTarget, pEventParam);
}
void CScript_EventPseudoModel::Reset(CFXJSE_Arguments* pArguments) {
- CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
+ CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext) {
return;
}
diff --git a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp
index f1eaff8c93..c074e0ed2e 100644
--- a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp
+++ b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp
@@ -9,12 +9,12 @@
#include <memory>
#include "fxjs/cfxjse_arguments.h"
+#include "fxjs/cfxjse_engine.h"
#include "xfa/fxfa/cxfa_ffnotify.h"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
#include "xfa/fxfa/parser/cxfa_localemgr.h"
#include "xfa/fxfa/parser/cxfa_node.h"
-#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
#include "xfa/fxfa/parser/xfa_resolvenode_rs.h"
#include "xfa/fxfa/parser/xfa_utils.h"
@@ -244,7 +244,7 @@ void CScript_HostPseudoModel::OpenList(CFXJSE_Arguments* pArguments) {
if (pValue->IsObject()) {
pNode = ToNode(pValue.get(), nullptr);
} else if (pValue->IsString()) {
- CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
+ CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext)
return;
@@ -364,7 +364,7 @@ void CScript_HostPseudoModel::ResetData(CFXJSE_Arguments* pArguments) {
int32_t iExpLength = wsExpression.GetLength();
while (iStart < iExpLength) {
iStart = XFA_FilterName(wsExpression.AsStringView(), iStart, wsName);
- CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
+ CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext)
return;
@@ -425,7 +425,7 @@ void CScript_HostPseudoModel::SetFocus(CFXJSE_Arguments* pArguments) {
if (pValue->IsObject()) {
pNode = ToNode(pValue.get(), nullptr);
} else if (pValue->IsString()) {
- CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
+ CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext)
return;
diff --git a/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp
index e35a3b8aa0..3195b8448d 100644
--- a/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp
+++ b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp
@@ -9,6 +9,7 @@
#include <set>
#include "fxjs/cfxjse_arguments.h"
+#include "fxjs/cfxjse_engine.h"
#include "third_party/base/stl_util.h"
#include "xfa/fxfa/cxfa_ffnotify.h"
#include "xfa/fxfa/parser/cxfa_arraynodelist.h"
@@ -20,7 +21,6 @@
#include "xfa/fxfa/parser/cxfa_localemgr.h"
#include "xfa/fxfa/parser/cxfa_measurement.h"
#include "xfa/fxfa/parser/cxfa_node.h"
-#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
#include "xfa/fxfa/parser/cxfa_traversestrategy_contentlayoutitem.h"
#include "xfa/fxfa/parser/xfa_utils.h"
diff --git a/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp b/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp
index a1136b1ddf..ff98953590 100644
--- a/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp
+++ b/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp
@@ -7,10 +7,10 @@
#include "xfa/fxfa/parser/cscript_signaturepseudomodel.h"
#include "fxjs/cfxjse_arguments.h"
+#include "fxjs/cfxjse_engine.h"
#include "xfa/fxfa/cxfa_ffnotify.h"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_localemgr.h"
-#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
#include "xfa/fxfa/parser/xfa_utils.h"
CScript_SignaturePseudoModel::CScript_SignaturePseudoModel(
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp
index cd60f47bed..3ab1a988b5 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -7,6 +7,7 @@
#include "xfa/fxfa/parser/cxfa_document.h"
#include "core/fxcrt/fx_extension.h"
+#include "fxjs/cfxjse_engine.h"
#include "xfa/fxfa/cxfa_ffnotify.h"
#include "xfa/fxfa/parser/cscript_datawindow.h"
#include "xfa/fxfa/parser/cscript_eventpseudomodel.h"
@@ -18,7 +19,6 @@
#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
#include "xfa/fxfa/parser/cxfa_localemgr.h"
#include "xfa/fxfa/parser/cxfa_node.h"
-#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
#include "xfa/fxfa/parser/cxfa_traversestrategy_xfanode.h"
#include "xfa/fxfa/parser/xfa_resolvenode_rs.h"
#include "xfa/fxfa/parser/xfa_utils.h"
@@ -284,15 +284,15 @@ CXFA_LocaleMgr* CXFA_Document::GetLocalMgr() {
return m_pLocalMgr.get();
}
-CXFA_ScriptContext* CXFA_Document::InitScriptContext(v8::Isolate* pIsolate) {
- CXFA_ScriptContext* result = GetScriptContext();
+CFXJSE_Engine* CXFA_Document::InitScriptContext(v8::Isolate* pIsolate) {
+ CFXJSE_Engine* result = GetScriptContext();
result->Initialize(pIsolate);
return result;
}
-CXFA_ScriptContext* CXFA_Document::GetScriptContext() {
+CFXJSE_Engine* CXFA_Document::GetScriptContext() {
if (!m_pScriptContext)
- m_pScriptContext = pdfium::MakeUnique<CXFA_ScriptContext>(this);
+ m_pScriptContext = pdfium::MakeUnique<CFXJSE_Engine>(this);
return m_pScriptContext.get();
}
diff --git a/xfa/fxfa/parser/cxfa_document.h b/xfa/fxfa/parser/cxfa_document.h
index 69154b21e8..7b71f7bf56 100644
--- a/xfa/fxfa/parser/cxfa_document.h
+++ b/xfa/fxfa/parser/cxfa_document.h
@@ -55,14 +55,14 @@ class CXFA_LayoutProcessor;
class CXFA_DocumentParser;
class CXFA_ContainerLayoutItem;
class CXFA_FFNotify;
-class CXFA_ScriptContext;
+class CFXJSE_Engine;
class CXFA_Document {
public:
explicit CXFA_Document(CXFA_DocumentParser* pParser);
~CXFA_Document();
- CXFA_ScriptContext* InitScriptContext(v8::Isolate* pIsolate);
+ CFXJSE_Engine* InitScriptContext(v8::Isolate* pIsolate);
CXFA_Node* GetRoot() const { return m_pRootNode; }
@@ -74,7 +74,7 @@ class CXFA_Document {
CXFA_Node* GetNotBindNode(const std::vector<CXFA_Object*>& arrayNodes);
CXFA_LayoutProcessor* GetLayoutProcessor();
CXFA_LayoutProcessor* GetDocLayout();
- CXFA_ScriptContext* GetScriptContext();
+ CFXJSE_Engine* GetScriptContext();
void SetRoot(CXFA_Node* pNewRoot);
@@ -111,7 +111,7 @@ class CXFA_Document {
private:
CXFA_DocumentParser* m_pParser;
CXFA_Node* m_pRootNode;
- std::unique_ptr<CXFA_ScriptContext> m_pScriptContext;
+ std::unique_ptr<CFXJSE_Engine> m_pScriptContext;
std::unique_ptr<CXFA_LayoutProcessor> m_pLayoutProcessor;
std::unique_ptr<CXFA_LocaleMgr> m_pLocalMgr;
std::unique_ptr<CScript_DataWindow> m_pScriptDataWindow;
diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
index a9e5449e3f..759d19de79 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
@@ -6,6 +6,7 @@
#include "xfa/fxfa/parser/cxfa_layoutpagemgr.h"
+#include "fxjs/cfxjse_engine.h"
#include "third_party/base/stl_util.h"
#include "xfa/fxfa/cxfa_ffnotify.h"
#include "xfa/fxfa/parser/cxfa_containerlayoutitem.h"
@@ -17,7 +18,6 @@
#include "xfa/fxfa/parser/cxfa_measurement.h"
#include "xfa/fxfa/parser/cxfa_node.h"
#include "xfa/fxfa/parser/cxfa_object.h"
-#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
#include "xfa/fxfa/parser/cxfa_traversestrategy_contentareacontainerlayoutitem.h"
#include "xfa/fxfa/parser/cxfa_traversestrategy_layoutitem.h"
#include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h"
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 0a95b5f0ee..f9333187a2 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -19,6 +19,7 @@
#include "core/fxcrt/xml/cfx_xmlelement.h"
#include "core/fxcrt/xml/cfx_xmlnode.h"
#include "core/fxcrt/xml/cfx_xmltext.h"
+#include "fxjs/cfxjse_engine.h"
#include "fxjs/cfxjse_value.h"
#include "third_party/base/logging.h"
#include "third_party/base/ptr_util.h"
@@ -32,7 +33,6 @@
#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
#include "xfa/fxfa/parser/cxfa_measurement.h"
#include "xfa/fxfa/parser/cxfa_occur.h"
-#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
#include "xfa/fxfa/parser/cxfa_simple_parser.h"
#include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h"
#include "xfa/fxfa/parser/xfa_basic_data.h"
@@ -970,7 +970,7 @@ void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
}
WideString wsExpression =
WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringView());
- CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
+ CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext)
return;
CXFA_Node* refNode = this;
@@ -1029,7 +1029,7 @@ void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
WideString wsExpression,
uint32_t dwFlag,
CXFA_Node* refNode) {
- CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
+ CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext)
return;
XFA_RESOLVENODE_RS resoveNodeRS;
@@ -1073,7 +1073,7 @@ void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
bool bSetting,
XFA_ATTRIBUTE eAttribute) {
- CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
+ CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext)
return;
if (bSetting) {
@@ -4259,7 +4259,7 @@ bool CXFA_Node::TryContent(WideString& wsContent,
}
if (pNode) {
if (bScriptModify) {
- CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
+ CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
if (pScriptContext) {
m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
}
@@ -4622,7 +4622,7 @@ CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
}
int32_t CXFA_Node::GetNodeSameNameIndex() const {
- CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
+ CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext) {
return -1;
}
@@ -4630,7 +4630,7 @@ int32_t CXFA_Node::GetNodeSameNameIndex() const {
}
int32_t CXFA_Node::GetNodeSameClassIndex() const {
- CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
+ CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext) {
return -1;
}
@@ -4638,7 +4638,7 @@ int32_t CXFA_Node::GetNodeSameClassIndex() const {
}
void CXFA_Node::GetSOMExpression(WideString& wsSOMExpression) {
- CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
+ CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext) {
return;
}
diff --git a/xfa/fxfa/parser/cxfa_nodehelper.cpp b/xfa/fxfa/parser/cxfa_nodehelper.cpp
index bc91c66f77..289149998e 100644
--- a/xfa/fxfa/parser/cxfa_nodehelper.cpp
+++ b/xfa/fxfa/parser/cxfa_nodehelper.cpp
@@ -7,10 +7,10 @@
#include "xfa/fxfa/parser/cxfa_nodehelper.h"
#include "core/fxcrt/fx_extension.h"
+#include "fxjs/cfxjse_engine.h"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_localemgr.h"
#include "xfa/fxfa/parser/cxfa_node.h"
-#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
#include "xfa/fxfa/parser/xfa_resolvenode_rs.h"
#include "xfa/fxfa/parser/xfa_utils.h"
@@ -313,11 +313,10 @@ bool CXFA_NodeHelper::CreateNode_ForCondition(WideString& wsCondition) {
return false;
}
-bool CXFA_NodeHelper::ResolveNodes_CreateNode(
- WideString wsName,
- WideString wsCondition,
- bool bLastNode,
- CXFA_ScriptContext* pScriptContext) {
+bool CXFA_NodeHelper::ResolveNodes_CreateNode(WideString wsName,
+ WideString wsCondition,
+ bool bLastNode,
+ CFXJSE_Engine* pScriptContext) {
if (!m_pCreateParent) {
return false;
}
diff --git a/xfa/fxfa/parser/cxfa_nodehelper.h b/xfa/fxfa/parser/cxfa_nodehelper.h
index 4c7d7ae10c..6c63a7b4ae 100644
--- a/xfa/fxfa/parser/cxfa_nodehelper.h
+++ b/xfa/fxfa/parser/cxfa_nodehelper.h
@@ -11,7 +11,7 @@
#include "xfa/fxfa/parser/xfa_resolvenode_rs.h"
-class CXFA_ScriptContext;
+class CFXJSE_Engine;
enum XFA_LOGIC_TYPE {
XFA_LOGIC_NoTransparent,
@@ -56,7 +56,7 @@ class CXFA_NodeHelper {
bool ResolveNodes_CreateNode(WideString wsName,
WideString wsCondition,
bool bLastNode,
- CXFA_ScriptContext* pScriptContext);
+ CFXJSE_Engine* pScriptContext);
bool CreateNode_ForCondition(WideString& wsCondition);
void SetCreateNodeType(CXFA_Node* refNode);
bool NodeIsProperty(CXFA_Node* refNode);
diff --git a/xfa/fxfa/parser/cxfa_nodelist.cpp b/xfa/fxfa/parser/cxfa_nodelist.cpp
index cea1f127a6..cbee420870 100644
--- a/xfa/fxfa/parser/cxfa_nodelist.cpp
+++ b/xfa/fxfa/parser/cxfa_nodelist.cpp
@@ -9,9 +9,9 @@
#include <memory>
#include "core/fxcrt/fx_extension.h"
+#include "fxjs/cfxjse_engine.h"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_node.h"
-#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
CXFA_NodeList::CXFA_NodeList(CXFA_Document* pDocument)
: CXFA_Object(pDocument,
diff --git a/xfa/fxfa/parser/cxfa_resolveprocessor.cpp b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp
index 4d0ec516b2..a72ad7b3f6 100644
--- a/xfa/fxfa/parser/cxfa_resolveprocessor.cpp
+++ b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp
@@ -11,6 +11,7 @@
#include <vector>
#include "core/fxcrt/fx_extension.h"
+#include "fxjs/cfxjse_engine.h"
#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
#include "xfa/fxfa/parser/cxfa_document.h"
@@ -18,7 +19,6 @@
#include "xfa/fxfa/parser/cxfa_node.h"
#include "xfa/fxfa/parser/cxfa_nodehelper.h"
#include "xfa/fxfa/parser/cxfa_object.h"
-#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
#include "xfa/fxfa/parser/xfa_resolvenode_rs.h"
#include "xfa/fxfa/parser/xfa_utils.h"
@@ -669,7 +669,7 @@ void CXFA_ResolveProcessor::DoPredicateFilter(int32_t iCurIndex,
return;
}
- CXFA_ScriptContext* pContext = rnd.m_pSC;
+ CFXJSE_Engine* pContext = rnd.m_pSC;
wsExpression = wsCondition.Mid(2, wsCondition.GetLength() - 3);
for (int32_t i = iFoundCount - 1; i >= 0; i--) {
auto pRetValue = pdfium::MakeUnique<CFXJSE_Value>(rnd.m_pSC->GetRuntime());
@@ -781,7 +781,7 @@ void CXFA_ResolveProcessor::SetIndexDataBind(WideString& wsNextCondition,
}
}
-CXFA_ResolveNodesData::CXFA_ResolveNodesData(CXFA_ScriptContext* pSC)
+CXFA_ResolveNodesData::CXFA_ResolveNodesData(CFXJSE_Engine* pSC)
: m_pSC(pSC),
m_CurObject(nullptr),
m_wsName(),
diff --git a/xfa/fxfa/parser/cxfa_resolveprocessor.h b/xfa/fxfa/parser/cxfa_resolveprocessor.h
index b48ee36476..c12dfdc80d 100644
--- a/xfa/fxfa/parser/cxfa_resolveprocessor.h
+++ b/xfa/fxfa/parser/cxfa_resolveprocessor.h
@@ -13,14 +13,14 @@
#include "xfa/fxfa/parser/xfa_resolvenode_rs.h"
class CXFA_NodeHelper;
-class CXFA_ScriptContext;
+class CFXJSE_Engine;
class CXFA_ResolveNodesData {
public:
- explicit CXFA_ResolveNodesData(CXFA_ScriptContext* pSC = nullptr);
+ explicit CXFA_ResolveNodesData(CFXJSE_Engine* pSC = nullptr);
~CXFA_ResolveNodesData();
- CXFA_ScriptContext* m_pSC;
+ CFXJSE_Engine* m_pSC;
CXFA_Object* m_CurObject;
WideString m_wsName;
XFA_HashCode m_uHashName;
diff --git a/xfa/fxfa/parser/cxfa_scriptcontext.cpp b/xfa/fxfa/parser/cxfa_scriptcontext.cpp
deleted file mode 100644
index 4e78f46f17..0000000000
--- a/xfa/fxfa/parser/cxfa_scriptcontext.cpp
+++ /dev/null
@@ -1,779 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
-
-#include <utility>
-
-#include "core/fxcrt/autorestorer.h"
-#include "core/fxcrt/cfx_widetextbuf.h"
-#include "core/fxcrt/fx_extension.h"
-#include "fxjs/cfxjse_arguments.h"
-#include "fxjs/cfxjse_class.h"
-#include "fxjs/cfxjse_value.h"
-#include "third_party/base/ptr_util.h"
-#include "third_party/base/stl_util.h"
-#include "xfa/fxfa/cxfa_eventparam.h"
-#include "xfa/fxfa/cxfa_ffnotify.h"
-#include "xfa/fxfa/parser/cxfa_document.h"
-#include "xfa/fxfa/parser/cxfa_localemgr.h"
-#include "xfa/fxfa/parser/cxfa_node.h"
-#include "xfa/fxfa/parser/cxfa_nodehelper.h"
-#include "xfa/fxfa/parser/cxfa_nodelist.h"
-#include "xfa/fxfa/parser/cxfa_object.h"
-#include "xfa/fxfa/parser/cxfa_resolveprocessor.h"
-#include "xfa/fxfa/parser/cxfa_thisproxy.h"
-#include "xfa/fxfa/parser/xfa_basic_data.h"
-#include "xfa/fxfa/parser/xfa_resolvenode_rs.h"
-#include "xfa/fxfa/parser/xfa_utils.h"
-
-namespace {
-
-const FXJSE_CLASS_DESCRIPTOR GlobalClassDescriptor = {
- "Root", // name
- nullptr, // constructor
- nullptr, // properties
- nullptr, // methods
- 0, // property count
- 0, // method count
- CXFA_ScriptContext::GlobalPropTypeGetter,
- CXFA_ScriptContext::GlobalPropertyGetter,
- CXFA_ScriptContext::GlobalPropertySetter,
- nullptr, // property deleter
- CXFA_ScriptContext::NormalMethodCall,
-};
-
-const FXJSE_CLASS_DESCRIPTOR NormalClassDescriptor = {
- "XFAObject", // name
- nullptr, // constructor
- nullptr, // properties
- nullptr, // methods
- 0, // property count
- 0, // method count
- CXFA_ScriptContext::NormalPropTypeGetter,
- CXFA_ScriptContext::NormalPropertyGetter,
- CXFA_ScriptContext::NormalPropertySetter,
- nullptr, // property deleter
- CXFA_ScriptContext::NormalMethodCall,
-};
-
-const FXJSE_CLASS_DESCRIPTOR VariablesClassDescriptor = {
- "XFAScriptObject", // name
- nullptr, // constructor
- nullptr, // properties
- nullptr, // methods
- 0, // property count
- 0, // method count
- CXFA_ScriptContext::NormalPropTypeGetter,
- CXFA_ScriptContext::GlobalPropertyGetter,
- CXFA_ScriptContext::GlobalPropertySetter,
- nullptr, // property deleter
- CXFA_ScriptContext::NormalMethodCall,
-};
-
-const char kFormCalcRuntime[] = "pfm_rt";
-
-CXFA_ThisProxy* ToThisProxy(CFXJSE_Value* pValue, CFXJSE_Class* pClass) {
- return static_cast<CXFA_ThisProxy*>(pValue->ToHostObject(pClass));
-}
-
-const XFA_METHODINFO* GetMethodByName(XFA_Element eElement,
- const WideStringView& wsMethodName) {
- if (wsMethodName.IsEmpty())
- return nullptr;
-
- int32_t iElementIndex = static_cast<int32_t>(eElement);
- while (iElementIndex >= 0 && iElementIndex < g_iScriptIndexCount) {
- const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex;
- int32_t icount = scriptIndex->wMethodCount;
- if (icount == 0) {
- iElementIndex = scriptIndex->wParentIndex;
- continue;
- }
- uint32_t uHash = FX_HashCode_GetW(wsMethodName, false);
- int32_t iStart = scriptIndex->wMethodStart;
- // TODO(dsinclair): Switch to std::lower_bound.
- int32_t iEnd = iStart + icount - 1;
- do {
- int32_t iMid = (iStart + iEnd) / 2;
- const XFA_METHODINFO* pInfo = g_SomMethodData + iMid;
- if (uHash == pInfo->uHash)
- return pInfo;
- if (uHash < pInfo->uHash)
- iEnd = iMid - 1;
- else
- iStart = iMid + 1;
- } while (iStart <= iEnd);
- iElementIndex = scriptIndex->wParentIndex;
- }
- return nullptr;
-}
-
-} // namespace
-
-// static.
-CXFA_Object* CXFA_ScriptContext::ToObject(CFXJSE_Value* pValue,
- CFXJSE_Class* pClass) {
- CFXJSE_HostObject* pHostObj = pValue->ToHostObject(pClass);
- if (!pHostObj || pHostObj->type() != CFXJSE_HostObject::kXFA)
- return nullptr;
- return static_cast<CXFA_Object*>(pHostObj);
-}
-
-CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument)
- : m_pDocument(pDocument),
- m_pIsolate(nullptr),
- m_pJsClass(nullptr),
- m_eScriptType(XFA_SCRIPTLANGTYPE_Unkown),
- m_pScriptNodeArray(nullptr),
- m_pThisObject(nullptr),
- m_dwBuiltInInFlags(0),
- m_eRunAtType(XFA_ATTRIBUTEENUM_Client) {}
-
-CXFA_ScriptContext::~CXFA_ScriptContext() {
- for (const auto& pair : m_mapVariableToContext)
- delete ToThisProxy(pair.second->GetGlobalObject().get(), nullptr);
-}
-
-void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) {
- m_pIsolate = pIsolate;
- DefineJsContext();
- DefineJsClass();
- m_ResolveProcessor = pdfium::MakeUnique<CXFA_ResolveProcessor>();
-}
-
-bool CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType,
- const WideStringView& wsScript,
- CFXJSE_Value* hRetValue,
- CXFA_Object* pThisObject) {
- ByteString btScript;
- AutoRestorer<XFA_SCRIPTLANGTYPE> typeRestorer(&m_eScriptType);
- m_eScriptType = eScriptType;
- if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) {
- if (!m_FM2JSContext) {
- m_FM2JSContext = pdfium::MakeUnique<CXFA_FM2JSContext>(
- m_pIsolate, m_JsContext.get(), m_pDocument.Get());
- }
- CFX_WideTextBuf wsJavaScript;
- if (!CXFA_FM2JSContext::Translate(wsScript, &wsJavaScript)) {
- hRetValue->SetUndefined();
- return false;
- }
- btScript = FX_UTF8Encode(wsJavaScript.AsStringView());
- } else {
- btScript = FX_UTF8Encode(wsScript);
- }
- AutoRestorer<CXFA_Object*> nodeRestorer(&m_pThisObject);
- m_pThisObject = pThisObject;
- CFXJSE_Value* pValue = pThisObject ? GetJSValueFromMap(pThisObject) : nullptr;
- return m_JsContext->ExecuteScript(btScript.c_str(), hRetValue, pValue);
-}
-
-void CXFA_ScriptContext::GlobalPropertySetter(CFXJSE_Value* pObject,
- const ByteStringView& szPropName,
- CFXJSE_Value* pValue) {
- CXFA_Object* lpOrginalNode = ToObject(pObject, nullptr);
- CXFA_Document* pDoc = lpOrginalNode->GetDocument();
- CXFA_ScriptContext* lpScriptContext = pDoc->GetScriptContext();
- CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode);
- WideString wsPropName = WideString::FromUTF8(szPropName);
- uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings |
- XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties |
- XFA_RESOLVENODE_Attributes;
- CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject());
- if (lpOrginalNode->IsVariablesThis())
- pRefNode = ToNode(lpCurNode);
- if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringView(),
- pValue, dwFlag, true)) {
- return;
- }
- if (lpOrginalNode->IsVariablesThis()) {
- if (pValue && pValue->IsUndefined()) {
- pObject->SetObjectOwnProperty(szPropName, pValue);
- return;
- }
- }
- CXFA_FFNotify* pNotify = pDoc->GetNotify();
- if (!pNotify) {
- return;
- }
- pNotify->GetDocEnvironment()->SetGlobalProperty(pNotify->GetHDOC(),
- szPropName, pValue);
-}
-bool CXFA_ScriptContext::QueryNodeByFlag(CXFA_Node* refNode,
- const WideStringView& propname,
- CFXJSE_Value* pValue,
- uint32_t dwFlag,
- bool bSetting) {
- if (!refNode)
- return false;
- XFA_RESOLVENODE_RS resolveRs;
- if (ResolveObjects(refNode, propname, resolveRs, dwFlag) <= 0)
- return false;
- if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
- pValue->Assign(GetJSValueFromMap(resolveRs.objects.front()));
- return true;
- }
- if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Attribute) {
- const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = resolveRs.pScriptAttribute;
- if (lpAttributeInfo) {
- (resolveRs.objects.front()->*(lpAttributeInfo->lpfnCallback))(
- pValue, bSetting, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
- }
- }
- return true;
-}
-void CXFA_ScriptContext::GlobalPropertyGetter(CFXJSE_Value* pObject,
- const ByteStringView& szPropName,
- CFXJSE_Value* pValue) {
- CXFA_Object* pOriginalObject = ToObject(pObject, nullptr);
- CXFA_Document* pDoc = pOriginalObject->GetDocument();
- CXFA_ScriptContext* lpScriptContext = pDoc->GetScriptContext();
- CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOriginalObject);
- WideString wsPropName = WideString::FromUTF8(szPropName);
- if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) {
- if (szPropName == kFormCalcRuntime) {
- lpScriptContext->m_FM2JSContext->GlobalPropertyGetter(pValue);
- return;
- }
- XFA_HashCode uHashCode = static_cast<XFA_HashCode>(
- FX_HashCode_GetW(wsPropName.AsStringView(), false));
- if (uHashCode != XFA_HASHCODE_Layout) {
- CXFA_Object* pObj =
- lpScriptContext->GetDocument()->GetXFAObject(uHashCode);
- if (pObj) {
- pValue->Assign(lpScriptContext->GetJSValueFromMap(pObj));
- return;
- }
- }
- }
- uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties |
- XFA_RESOLVENODE_Attributes;
- CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject());
- if (pOriginalObject->IsVariablesThis()) {
- pRefNode = ToNode(lpCurNode);
- }
- if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringView(),
- pValue, dwFlag, false)) {
- return;
- }
- dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings;
- if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringView(),
- pValue, dwFlag, false)) {
- return;
- }
- CXFA_Object* pScriptObject =
- lpScriptContext->GetVariablesThis(pOriginalObject, true);
- if (pScriptObject &&
- lpScriptContext->QueryVariableValue(pScriptObject->AsNode(), szPropName,
- pValue, true)) {
- return;
- }
- CXFA_FFNotify* pNotify = pDoc->GetNotify();
- if (!pNotify) {
- return;
- }
- pNotify->GetDocEnvironment()->GetGlobalProperty(pNotify->GetHDOC(),
- szPropName, pValue);
-}
-void CXFA_ScriptContext::NormalPropertyGetter(CFXJSE_Value* pOriginalValue,
- const ByteStringView& szPropName,
- CFXJSE_Value* pReturnValue) {
- CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr);
- if (!pOriginalObject) {
- pReturnValue->SetUndefined();
- return;
- }
- WideString wsPropName = WideString::FromUTF8(szPropName);
- CXFA_ScriptContext* lpScriptContext =
- pOriginalObject->GetDocument()->GetScriptContext();
- CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject);
- if (wsPropName == L"xfa") {
- CFXJSE_Value* pValue = lpScriptContext->GetJSValueFromMap(
- lpScriptContext->GetDocument()->GetRoot());
- pReturnValue->Assign(pValue);
- return;
- }
- uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties |
- XFA_RESOLVENODE_Attributes;
- bool bRet = lpScriptContext->QueryNodeByFlag(
- ToNode(pObject), wsPropName.AsStringView(), pReturnValue, dwFlag, false);
- if (bRet) {
- return;
- }
- if (pObject == lpScriptContext->GetThisObject() ||
- (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Javascript &&
- !lpScriptContext->IsStrictScopeInJavaScript())) {
- dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings;
- bRet = lpScriptContext->QueryNodeByFlag(ToNode(pObject),
- wsPropName.AsStringView(),
- pReturnValue, dwFlag, false);
- }
- if (bRet) {
- return;
- }
- CXFA_Object* pScriptObject =
- lpScriptContext->GetVariablesThis(pOriginalObject, true);
- if (pScriptObject) {
- bRet = lpScriptContext->QueryVariableValue(ToNode(pScriptObject),
- szPropName, pReturnValue, true);
- }
- if (!bRet) {
- pReturnValue->SetUndefined();
- }
-}
-void CXFA_ScriptContext::NormalPropertySetter(CFXJSE_Value* pOriginalValue,
- const ByteStringView& szPropName,
- CFXJSE_Value* pReturnValue) {
- CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr);
- if (!pOriginalObject)
- return;
-
- CXFA_ScriptContext* lpScriptContext =
- pOriginalObject->GetDocument()->GetScriptContext();
- CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject);
- WideString wsPropName = WideString::FromUTF8(szPropName);
- const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName(
- pObject->GetElementType(), wsPropName.AsStringView());
- if (lpAttributeInfo) {
- (pObject->*(lpAttributeInfo->lpfnCallback))(
- pReturnValue, true, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
- } else {
- if (pObject->IsNode()) {
- if (wsPropName[0] == '#') {
- wsPropName = wsPropName.Right(wsPropName.GetLength() - 1);
- }
- CXFA_Node* pNode = ToNode(pObject);
- CXFA_Node* pPropOrChild = nullptr;
- XFA_Element eType = XFA_GetElementTypeForName(wsPropName.AsStringView());
- if (eType != XFA_Element::Unknown)
- pPropOrChild = pNode->GetProperty(0, eType);
- else
- pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringView());
-
- if (pPropOrChild) {
- WideString wsDefaultName(L"{default}");
- const XFA_SCRIPTATTRIBUTEINFO* lpAttrInfo =
- XFA_GetScriptAttributeByName(pPropOrChild->GetElementType(),
- wsDefaultName.AsStringView());
- if (lpAttrInfo) {
- (pPropOrChild->*(lpAttrInfo->lpfnCallback))(
- pReturnValue, true, (XFA_ATTRIBUTE)lpAttrInfo->eAttribute);
- return;
- }
- }
- }
- CXFA_Object* pScriptObject =
- lpScriptContext->GetVariablesThis(pOriginalObject, true);
- if (pScriptObject) {
- lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName,
- pReturnValue, false);
- }
- }
-}
-int32_t CXFA_ScriptContext::NormalPropTypeGetter(
- CFXJSE_Value* pOriginalValue,
- const ByteStringView& szPropName,
- bool bQueryIn) {
- CXFA_Object* pObject = ToObject(pOriginalValue, nullptr);
- if (!pObject)
- return FXJSE_ClassPropType_None;
-
- CXFA_ScriptContext* lpScriptContext =
- pObject->GetDocument()->GetScriptContext();
- pObject = lpScriptContext->GetVariablesThis(pObject);
- XFA_Element eType = pObject->GetElementType();
- WideString wsPropName = WideString::FromUTF8(szPropName);
- if (GetMethodByName(eType, wsPropName.AsStringView())) {
- return FXJSE_ClassPropType_Method;
- }
- if (bQueryIn &&
- !XFA_GetScriptAttributeByName(eType, wsPropName.AsStringView())) {
- return FXJSE_ClassPropType_None;
- }
- return FXJSE_ClassPropType_Property;
-}
-int32_t CXFA_ScriptContext::GlobalPropTypeGetter(
- CFXJSE_Value* pOriginalValue,
- const ByteStringView& szPropName,
- bool bQueryIn) {
- CXFA_Object* pObject = ToObject(pOriginalValue, nullptr);
- if (!pObject)
- return FXJSE_ClassPropType_None;
-
- CXFA_ScriptContext* lpScriptContext =
- pObject->GetDocument()->GetScriptContext();
- pObject = lpScriptContext->GetVariablesThis(pObject);
- XFA_Element eType = pObject->GetElementType();
- WideString wsPropName = WideString::FromUTF8(szPropName);
- if (GetMethodByName(eType, wsPropName.AsStringView())) {
- return FXJSE_ClassPropType_Method;
- }
- return FXJSE_ClassPropType_Property;
-}
-void CXFA_ScriptContext::NormalMethodCall(CFXJSE_Value* pThis,
- const ByteStringView& szFuncName,
- CFXJSE_Arguments& args) {
- CXFA_Object* pObject = ToObject(pThis, nullptr);
- if (!pObject)
- return;
-
- CXFA_ScriptContext* lpScriptContext =
- pObject->GetDocument()->GetScriptContext();
- pObject = lpScriptContext->GetVariablesThis(pObject);
- WideString wsFunName = WideString::FromUTF8(szFuncName);
- const XFA_METHODINFO* lpMethodInfo =
- GetMethodByName(pObject->GetElementType(), wsFunName.AsStringView());
- if (!lpMethodInfo)
- return;
-
- (pObject->*(lpMethodInfo->lpfnCallback))(&args);
-}
-bool CXFA_ScriptContext::IsStrictScopeInJavaScript() {
- return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping);
-}
-XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() {
- return m_eScriptType;
-}
-void CXFA_ScriptContext::DefineJsContext() {
- m_JsContext = CFXJSE_Context::Create(m_pIsolate, &GlobalClassDescriptor,
- m_pDocument->GetRoot());
- RemoveBuiltInObjs(m_JsContext.get());
- m_JsContext->EnableCompatibleMode();
-}
-
-CFXJSE_Context* CXFA_ScriptContext::CreateVariablesContext(
- CXFA_Node* pScriptNode,
- CXFA_Node* pSubform) {
- if (!pScriptNode || !pSubform)
- return nullptr;
-
- auto pNewContext =
- CFXJSE_Context::Create(m_pIsolate, &VariablesClassDescriptor,
- new CXFA_ThisProxy(pSubform, pScriptNode));
- RemoveBuiltInObjs(pNewContext.get());
- pNewContext->EnableCompatibleMode();
- CFXJSE_Context* pResult = pNewContext.get();
- m_mapVariableToContext[pScriptNode] = std::move(pNewContext);
- return pResult;
-}
-
-CXFA_Object* CXFA_ScriptContext::GetVariablesThis(CXFA_Object* pObject,
- bool bScriptNode) {
- if (!pObject->IsVariablesThis())
- return pObject;
-
- CXFA_ThisProxy* pProxy = static_cast<CXFA_ThisProxy*>(pObject);
- return bScriptNode ? pProxy->GetScriptNode() : pProxy->GetThisNode();
-}
-
-bool CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) {
- if (!pScriptNode)
- return false;
-
- if (pScriptNode->GetElementType() != XFA_Element::Script)
- return true;
-
- CXFA_Node* pParent = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent);
- if (!pParent || pParent->GetElementType() != XFA_Element::Variables)
- return false;
-
- auto it = m_mapVariableToContext.find(pScriptNode);
- if (it != m_mapVariableToContext.end() && it->second)
- return true;
-
- CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild);
- if (!pTextNode)
- return false;
-
- WideStringView wsScript;
- if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript))
- return false;
-
- ByteString btScript = FX_UTF8Encode(wsScript);
- auto hRetValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate);
- CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent);
- CFXJSE_Context* pVariablesContext =
- CreateVariablesContext(pScriptNode, pThisObject);
- AutoRestorer<CXFA_Object*> nodeRestorer(&m_pThisObject);
- m_pThisObject = pThisObject;
- return pVariablesContext->ExecuteScript(btScript.c_str(), hRetValue.get());
-}
-
-bool CXFA_ScriptContext::QueryVariableValue(CXFA_Node* pScriptNode,
- const ByteStringView& szPropName,
- CFXJSE_Value* pValue,
- bool bGetter) {
- if (!pScriptNode || pScriptNode->GetElementType() != XFA_Element::Script)
- return false;
-
- CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent);
- if (!variablesNode ||
- variablesNode->GetElementType() != XFA_Element::Variables)
- return false;
-
- auto it = m_mapVariableToContext.find(pScriptNode);
- if (it == m_mapVariableToContext.end() || !it->second)
- return false;
-
- CFXJSE_Context* pVariableContext = it->second.get();
- std::unique_ptr<CFXJSE_Value> pObject = pVariableContext->GetGlobalObject();
- auto hVariableValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate);
- if (!bGetter) {
- pObject->SetObjectOwnProperty(szPropName, pValue);
- return true;
- }
- if (pObject->HasObjectOwnProperty(szPropName, false)) {
- pObject->GetObjectProperty(szPropName, hVariableValue.get());
- if (hVariableValue->IsFunction())
- pValue->SetFunctionBind(hVariableValue.get(), pObject.get());
- else if (bGetter)
- pValue->Assign(hVariableValue.get());
- else
- hVariableValue.get()->Assign(pValue);
- return true;
- }
- return false;
-}
-
-void CXFA_ScriptContext::DefineJsClass() {
- m_pJsClass =
- CFXJSE_Class::Create(m_JsContext.get(), &NormalClassDescriptor, false);
-}
-
-void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const {
- static const ByteStringView OBJ_NAME[2] = {"Number", "Date"};
- std::unique_ptr<CFXJSE_Value> pObject = pContext->GetGlobalObject();
- auto hProp = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate);
- for (int i = 0; i < 2; ++i) {
- if (pObject->GetObjectProperty(OBJ_NAME[i], hProp.get()))
- pObject->DeleteObjectProperty(OBJ_NAME[i]);
- }
-}
-CFXJSE_Class* CXFA_ScriptContext::GetJseNormalClass() {
- return m_pJsClass;
-}
-
-int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refObject,
- const WideStringView& wsExpression,
- XFA_RESOLVENODE_RS& resolveNodeRS,
- uint32_t dwStyles,
- CXFA_Node* bindNode) {
- if (wsExpression.IsEmpty())
- return 0;
-
- if (m_eScriptType != XFA_SCRIPTLANGTYPE_Formcalc ||
- (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) {
- m_upObjectArray.clear();
- }
- if (refObject && refObject->IsNode() &&
- (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) {
- m_upObjectArray.push_back(refObject->AsNode());
- }
-
- bool bNextCreate = false;
- if (dwStyles & XFA_RESOLVENODE_CreateNode) {
- m_ResolveProcessor->GetNodeHelper()->SetCreateNodeType(bindNode);
- }
- m_ResolveProcessor->GetNodeHelper()->m_pCreateParent = nullptr;
- m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart = -1;
-
- CXFA_ResolveNodesData rndFind;
- int32_t nStart = 0;
- int32_t nLevel = 0;
- int32_t nRet = -1;
- rndFind.m_pSC = this;
- std::vector<CXFA_Object*> findObjects;
- findObjects.push_back(refObject ? refObject : m_pDocument->GetRoot());
- int32_t nNodes = 0;
- while (true) {
- nNodes = pdfium::CollectionSize<int32_t>(findObjects);
- int32_t i = 0;
- rndFind.m_dwStyles = dwStyles;
- m_ResolveProcessor->SetCurStart(nStart);
- nStart = m_ResolveProcessor->GetFilter(wsExpression, nStart, rndFind);
- if (nStart < 1) {
- if ((dwStyles & XFA_RESOLVENODE_CreateNode) && !bNextCreate) {
- CXFA_Node* pDataNode = nullptr;
- nStart = m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart;
- if (nStart != -1) {
- pDataNode = m_pDocument->GetNotBindNode(findObjects);
- if (pDataNode) {
- findObjects.clear();
- findObjects.push_back(pDataNode);
- break;
- }
- } else {
- pDataNode = findObjects.front()->AsNode();
- findObjects.clear();
- findObjects.push_back(pDataNode);
- break;
- }
- dwStyles |= XFA_RESOLVENODE_Bind;
- findObjects.clear();
- findObjects.push_back(
- m_ResolveProcessor->GetNodeHelper()->m_pAllStartParent);
- continue;
- } else {
- break;
- }
- }
- if (bNextCreate) {
- bool bCreate =
- m_ResolveProcessor->GetNodeHelper()->ResolveNodes_CreateNode(
- rndFind.m_wsName, rndFind.m_wsCondition,
- nStart ==
- pdfium::base::checked_cast<int32_t>(wsExpression.GetLength()),
- this);
- if (bCreate) {
- continue;
- } else {
- break;
- }
- }
- std::vector<CXFA_Object*> retObjects;
- while (i < nNodes) {
- bool bDataBind = false;
- if (((dwStyles & XFA_RESOLVENODE_Bind) ||
- (dwStyles & XFA_RESOLVENODE_CreateNode)) &&
- nNodes > 1) {
- CXFA_ResolveNodesData rndBind;
- m_ResolveProcessor->GetFilter(wsExpression, nStart, rndBind);
- m_ResolveProcessor->SetIndexDataBind(rndBind.m_wsCondition, i, nNodes);
- bDataBind = true;
- }
- rndFind.m_CurObject = findObjects[i++];
- rndFind.m_nLevel = nLevel;
- rndFind.m_dwFlag = XFA_RESOVENODE_RSTYPE_Nodes;
- nRet = m_ResolveProcessor->Resolve(rndFind);
- if (nRet < 1) {
- continue;
- }
- if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute &&
- rndFind.m_pScriptAttribute &&
- nStart <
- pdfium::base::checked_cast<int32_t>(wsExpression.GetLength())) {
- auto pValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate);
- (rndFind.m_Objects.front()
- ->*(rndFind.m_pScriptAttribute->lpfnCallback))(
- pValue.get(), false,
- (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute);
- rndFind.m_Objects.front() = ToObject(pValue.get(), nullptr);
- }
- if (!m_upObjectArray.empty())
- m_upObjectArray.pop_back();
- retObjects.insert(retObjects.end(), rndFind.m_Objects.begin(),
- rndFind.m_Objects.end());
- rndFind.m_Objects.clear();
- if (bDataBind)
- break;
- }
- findObjects.clear();
- nNodes = pdfium::CollectionSize<int32_t>(retObjects);
- if (nNodes < 1) {
- if (dwStyles & XFA_RESOLVENODE_CreateNode) {
- bNextCreate = true;
- if (!m_ResolveProcessor->GetNodeHelper()->m_pCreateParent) {
- m_ResolveProcessor->GetNodeHelper()->m_pCreateParent =
- ToNode(rndFind.m_CurObject);
- m_ResolveProcessor->GetNodeHelper()->m_iCreateCount = 1;
- }
- bool bCreate =
- m_ResolveProcessor->GetNodeHelper()->ResolveNodes_CreateNode(
- rndFind.m_wsName, rndFind.m_wsCondition,
- nStart == pdfium::base::checked_cast<int32_t>(
- wsExpression.GetLength()),
- this);
- if (bCreate) {
- continue;
- } else {
- break;
- }
- } else {
- break;
- }
- }
- findObjects =
- std::vector<CXFA_Object*>(retObjects.begin(), retObjects.end());
- rndFind.m_Objects.clear();
- if (nLevel == 0) {
- dwStyles &= ~(XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings);
- }
- nLevel++;
- }
- if (!bNextCreate) {
- resolveNodeRS.dwFlags = rndFind.m_dwFlag;
- if (nNodes > 0) {
- resolveNodeRS.objects.insert(resolveNodeRS.objects.end(),
- findObjects.begin(), findObjects.end());
- }
- if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute) {
- resolveNodeRS.pScriptAttribute = rndFind.m_pScriptAttribute;
- return 1;
- }
- }
- if (dwStyles & (XFA_RESOLVENODE_CreateNode | XFA_RESOLVENODE_Bind |
- XFA_RESOLVENODE_BindNew)) {
- m_ResolveProcessor->SetResultCreateNode(resolveNodeRS,
- rndFind.m_wsCondition);
- if (!bNextCreate && (dwStyles & XFA_RESOLVENODE_CreateNode)) {
- resolveNodeRS.dwFlags = XFA_RESOVENODE_RSTYPE_ExistNodes;
- }
- return pdfium::CollectionSize<int32_t>(resolveNodeRS.objects);
- }
- return nNodes;
-}
-
-void CXFA_ScriptContext::AddToCacheList(std::unique_ptr<CXFA_NodeList> pList) {
- m_CacheList.push_back(std::move(pList));
-}
-
-CFXJSE_Value* CXFA_ScriptContext::GetJSValueFromMap(CXFA_Object* pObject) {
- if (!pObject)
- return nullptr;
- if (pObject->IsNode())
- RunVariablesScript(pObject->AsNode());
-
- auto iter = m_mapObjectToValue.find(pObject);
- if (iter != m_mapObjectToValue.end())
- return iter->second.get();
-
- auto jsValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate);
- jsValue->SetObject(pObject, m_pJsClass);
- CFXJSE_Value* pValue = jsValue.get();
- m_mapObjectToValue.insert(std::make_pair(pObject, std::move(jsValue)));
- return pValue;
-}
-int32_t CXFA_ScriptContext::GetIndexByName(CXFA_Node* refNode) {
- CXFA_NodeHelper* lpNodeHelper = m_ResolveProcessor->GetNodeHelper();
- return lpNodeHelper->GetIndex(refNode, XFA_LOGIC_Transparent,
- lpNodeHelper->NodeIsProperty(refNode), false);
-}
-int32_t CXFA_ScriptContext::GetIndexByClassName(CXFA_Node* refNode) {
- CXFA_NodeHelper* lpNodeHelper = m_ResolveProcessor->GetNodeHelper();
- return lpNodeHelper->GetIndex(refNode, XFA_LOGIC_Transparent,
- lpNodeHelper->NodeIsProperty(refNode), true);
-}
-void CXFA_ScriptContext::GetSomExpression(CXFA_Node* refNode,
- WideString& wsExpression) {
- CXFA_NodeHelper* lpNodeHelper = m_ResolveProcessor->GetNodeHelper();
- lpNodeHelper->GetNameExpression(refNode, wsExpression, true,
- XFA_LOGIC_Transparent);
-}
-void CXFA_ScriptContext::SetNodesOfRunScript(std::vector<CXFA_Node*>* pArray) {
- m_pScriptNodeArray = pArray;
-}
-
-void CXFA_ScriptContext::AddNodesOfRunScript(
- const std::vector<CXFA_Node*>& nodes) {
- if (m_pScriptNodeArray && !nodes.empty())
- *m_pScriptNodeArray = nodes;
-}
-
-void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) {
- if (m_pScriptNodeArray && !pdfium::ContainsValue(*m_pScriptNodeArray, pNode))
- m_pScriptNodeArray->push_back(pNode);
-}
diff --git a/xfa/fxfa/parser/cxfa_scriptcontext.h b/xfa/fxfa/parser/cxfa_scriptcontext.h
deleted file mode 100644
index 75d30278bd..0000000000
--- a/xfa/fxfa/parser/cxfa_scriptcontext.h
+++ /dev/null
@@ -1,126 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FXFA_PARSER_CXFA_SCRIPTCONTEXT_H_
-#define XFA_FXFA_PARSER_CXFA_SCRIPTCONTEXT_H_
-
-#include <map>
-#include <memory>
-#include <vector>
-
-#include "fxjs/cfxjse_arguments.h"
-#include "xfa/fxfa/cxfa_eventparam.h"
-#include "xfa/fxfa/fm2js/cxfa_fm2jscontext.h"
-#include "xfa/fxfa/parser/cxfa_document.h"
-#include "xfa/fxfa/parser/xfa_resolvenode_rs.h"
-
-#define XFA_RESOLVENODE_TagName 0x0002
-
-class CXFA_ResolveProcessor;
-
-class CXFA_ScriptContext {
- public:
- explicit CXFA_ScriptContext(CXFA_Document* pDocument);
- ~CXFA_ScriptContext();
-
- void Initialize(v8::Isolate* pIsolate);
- void SetEventParam(CXFA_EventParam param) { m_eventParam = param; }
- CXFA_EventParam* GetEventParam() { return &m_eventParam; }
- bool RunScript(XFA_SCRIPTLANGTYPE eScriptType,
- const WideStringView& wsScript,
- CFXJSE_Value* pRetValue,
- CXFA_Object* pThisObject);
-
- int32_t ResolveObjects(CXFA_Object* refObject,
- const WideStringView& wsExpression,
- XFA_RESOLVENODE_RS& resolveNodeRS,
- uint32_t dwStyles = XFA_RESOLVENODE_Children,
- CXFA_Node* bindNode = nullptr);
- CFXJSE_Value* GetJSValueFromMap(CXFA_Object* pObject);
- void AddToCacheList(std::unique_ptr<CXFA_NodeList> pList);
- CXFA_Object* GetThisObject() const { return m_pThisObject; }
- v8::Isolate* GetRuntime() const { return m_pIsolate; }
-
- int32_t GetIndexByName(CXFA_Node* refNode);
- int32_t GetIndexByClassName(CXFA_Node* refNode);
- void GetSomExpression(CXFA_Node* refNode, WideString& wsExpression);
-
- void SetNodesOfRunScript(std::vector<CXFA_Node*>* pArray);
- void AddNodesOfRunScript(const std::vector<CXFA_Node*>& nodes);
- void AddNodesOfRunScript(CXFA_Node* pNode);
- CFXJSE_Class* GetJseNormalClass();
-
- void SetRunAtType(XFA_ATTRIBUTEENUM eRunAt) { m_eRunAtType = eRunAt; }
- bool IsRunAtClient() { return m_eRunAtType != XFA_ATTRIBUTEENUM_Server; }
- bool QueryNodeByFlag(CXFA_Node* refNode,
- const WideStringView& propname,
- CFXJSE_Value* pValue,
- uint32_t dwFlag,
- bool bSetting);
- bool QueryVariableValue(CXFA_Node* pScriptNode,
- const ByteStringView& szPropName,
- CFXJSE_Value* pValue,
- bool bGetter);
- bool QueryBuiltinValue(const ByteStringView& szPropName,
- CFXJSE_Value* pValue);
- static void GlobalPropertyGetter(CFXJSE_Value* pObject,
- const ByteStringView& szPropName,
- CFXJSE_Value* pValue);
- static void GlobalPropertySetter(CFXJSE_Value* pObject,
- const ByteStringView& szPropName,
- CFXJSE_Value* pValue);
- static void NormalPropertyGetter(CFXJSE_Value* pObject,
- const ByteStringView& szPropName,
- CFXJSE_Value* pValue);
- static void NormalPropertySetter(CFXJSE_Value* pObject,
- const ByteStringView& szPropName,
- CFXJSE_Value* pValue);
- static void NormalMethodCall(CFXJSE_Value* hThis,
- const ByteStringView& szFuncName,
- CFXJSE_Arguments& args);
- static int32_t NormalPropTypeGetter(CFXJSE_Value* pObject,
- const ByteStringView& szPropName,
- bool bQueryIn);
- static int32_t GlobalPropTypeGetter(CFXJSE_Value* pObject,
- const ByteStringView& szPropName,
- bool bQueryIn);
- bool RunVariablesScript(CXFA_Node* pScriptNode);
- CXFA_Object* GetVariablesThis(CXFA_Object* pObject, bool bScriptNode = false);
- bool IsStrictScopeInJavaScript();
- XFA_SCRIPTLANGTYPE GetType();
- std::vector<CXFA_Node*>* GetUpObjectArray() { return &m_upObjectArray; }
- CXFA_Document* GetDocument() const { return m_pDocument.Get(); }
-
- static CXFA_Object* ToObject(CFXJSE_Value* pValue, CFXJSE_Class* pClass);
-
- private:
- void DefineJsContext();
- CFXJSE_Context* CreateVariablesContext(CXFA_Node* pScriptNode,
- CXFA_Node* pSubform);
- void DefineJsClass();
- void RemoveBuiltInObjs(CFXJSE_Context* pContext) const;
-
- UnownedPtr<CXFA_Document> const m_pDocument;
- std::unique_ptr<CFXJSE_Context> m_JsContext;
- v8::Isolate* m_pIsolate;
- CFXJSE_Class* m_pJsClass;
- XFA_SCRIPTLANGTYPE m_eScriptType;
- std::map<CXFA_Object*, std::unique_ptr<CFXJSE_Value>> m_mapObjectToValue;
- std::map<CXFA_Object*, std::unique_ptr<CFXJSE_Context>>
- m_mapVariableToContext;
- CXFA_EventParam m_eventParam;
- std::vector<CXFA_Node*> m_upObjectArray;
- // CacheList holds the NodeList items so we can clean them up when we're done.
- std::vector<std::unique_ptr<CXFA_NodeList>> m_CacheList;
- std::vector<CXFA_Node*>* m_pScriptNodeArray;
- std::unique_ptr<CXFA_ResolveProcessor> m_ResolveProcessor;
- std::unique_ptr<CXFA_FM2JSContext> m_FM2JSContext;
- CXFA_Object* m_pThisObject;
- uint32_t m_dwBuiltInInFlags;
- XFA_ATTRIBUTEENUM m_eRunAtType;
-};
-
-#endif // XFA_FXFA_PARSER_CXFA_SCRIPTCONTEXT_H_
diff --git a/xfa/fxfa/parser/cxfa_valuearray.cpp b/xfa/fxfa/parser/cxfa_valuearray.cpp
index eded624c36..83ffe6b275 100644
--- a/xfa/fxfa/parser/cxfa_valuearray.cpp
+++ b/xfa/fxfa/parser/cxfa_valuearray.cpp
@@ -8,7 +8,7 @@
#include <algorithm>
-#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
+#include "fxjs/cfxjse_engine.h"
CXFA_ValueArray::CXFA_ValueArray(v8::Isolate* pIsolate)
: m_pIsolate(pIsolate) {}
@@ -19,7 +19,7 @@ std::vector<CXFA_Object*> CXFA_ValueArray::GetAttributeObject() {
std::vector<CXFA_Object*> result(m_Values.size());
std::transform(m_Values.begin(), m_Values.end(), result.begin(),
[](const std::unique_ptr<CFXJSE_Value>& value) {
- return CXFA_ScriptContext::ToObject(value.get(), nullptr);
+ return CFXJSE_Engine::ToObject(value.get(), nullptr);
});
return result;
}
diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
index 373412ebf9..12a1ba77c4 100644
--- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
+++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
@@ -12,6 +12,7 @@
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/xml/cfx_xmlelement.h"
#include "core/fxcrt/xml/cfx_xmlnode.h"
+#include "fxjs/cfxjse_engine.h"
#include "third_party/base/logging.h"
#include "third_party/base/stl_util.h"
#include "xfa/fxfa/parser/cxfa_document.h"
@@ -19,7 +20,6 @@
#include "xfa/fxfa/parser/cxfa_localemgr.h"
#include "xfa/fxfa/parser/cxfa_node.h"
#include "xfa/fxfa/parser/cxfa_occur.h"
-#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
#include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h"
#include "xfa/fxfa/parser/cxfa_traversestrategy_xfanode.h"
#include "xfa/fxfa/parser/xfa_resolvenode_rs.h"