| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxfa/parser/xfa_script_imp.h" | 7 #include "xfa/fxfa/parser/xfa_script_imp.h" |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
| 10 #include "fxjse/include/cfxjse_arguments.h" | 10 #include "fxjse/include/cfxjse_arguments.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 // static. | 76 // static. |
| 77 CXFA_Object* CXFA_ScriptContext::ToObject(CFXJSE_Value* pValue, | 77 CXFA_Object* CXFA_ScriptContext::ToObject(CFXJSE_Value* pValue, |
| 78 CFXJSE_Class* pClass) { | 78 CFXJSE_Class* pClass) { |
| 79 return static_cast<CXFA_Object*>(pValue->ToHostObject(pClass)); | 79 return static_cast<CXFA_Object*>(pValue->ToHostObject(pClass)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) | 82 CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) |
| 83 : m_pDocument(pDocument), | 83 : m_pDocument(pDocument), |
| 84 m_pJsContext(nullptr), | |
| 85 m_pIsolate(nullptr), | 84 m_pIsolate(nullptr), |
| 86 m_pJsClass(nullptr), | 85 m_pJsClass(nullptr), |
| 87 m_eScriptType(XFA_SCRIPTLANGTYPE_Unkown), | 86 m_eScriptType(XFA_SCRIPTLANGTYPE_Unkown), |
| 88 m_pScriptNodeArray(nullptr), | 87 m_pScriptNodeArray(nullptr), |
| 89 m_pResolveProcessor(nullptr), | |
| 90 m_hFM2JSContext(nullptr), | |
| 91 m_pThisObject(nullptr), | 88 m_pThisObject(nullptr), |
| 92 m_dwBuiltInInFlags(0), | 89 m_dwBuiltInInFlags(0), |
| 93 m_eRunAtType(XFA_ATTRIBUTEENUM_Client) { | 90 m_eRunAtType(XFA_ATTRIBUTEENUM_Client) {} |
| 94 } | |
| 95 | 91 |
| 96 CXFA_ScriptContext::~CXFA_ScriptContext() { | 92 CXFA_ScriptContext::~CXFA_ScriptContext() { |
| 97 FX_POSITION ps = m_mapXFAToValue.GetStartPosition(); | 93 FX_POSITION ps = m_mapVariableToContext.GetStartPosition(); |
| 98 while (ps) { | 94 while (ps) { |
| 99 CXFA_Object* pXFAObj; | 95 CXFA_Object* pScriptNode; |
| 100 CFXJSE_Value* pValue; | 96 CFXJSE_Context* pVariableContext = nullptr; |
| 101 m_mapXFAToValue.GetNextAssoc(ps, pXFAObj, pValue); | 97 m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext); |
| 102 delete pValue; | 98 |
| 99 delete ToThisProxy(pVariableContext->GetGlobalObject().get(), nullptr); |
| 100 delete pVariableContext; |
| 103 } | 101 } |
| 104 m_mapXFAToValue.RemoveAll(); | 102 m_mapVariableToContext.RemoveAll(); |
| 105 ReleaseVariablesMap(); | |
| 106 | 103 |
| 107 delete m_hFM2JSContext; | |
| 108 delete m_pJsContext; | |
| 109 | |
| 110 delete m_pResolveProcessor; | |
| 111 m_upObjectArray.RemoveAll(); | 104 m_upObjectArray.RemoveAll(); |
| 112 for (int32_t i = 0; i < m_CacheListArray.GetSize(); i++) | |
| 113 delete m_CacheListArray[i]; | |
| 114 } | 105 } |
| 115 void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { | 106 void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { |
| 116 m_pIsolate = pIsolate; | 107 m_pIsolate = pIsolate; |
| 117 DefineJsContext(); | 108 DefineJsContext(); |
| 118 DefineJsClass(); | 109 DefineJsClass(); |
| 119 m_pResolveProcessor = new CXFA_ResolveProcessor; | 110 m_ResolveProcessor.reset(new CXFA_ResolveProcessor); |
| 120 } | 111 } |
| 121 FX_BOOL CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, | 112 FX_BOOL CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, |
| 122 const CFX_WideStringC& wsScript, | 113 const CFX_WideStringC& wsScript, |
| 123 CFXJSE_Value* hRetValue, | 114 CFXJSE_Value* hRetValue, |
| 124 CXFA_Object* pThisObject) { | 115 CXFA_Object* pThisObject) { |
| 125 CFX_ByteString btScript; | 116 CFX_ByteString btScript; |
| 126 XFA_SCRIPTLANGTYPE eSaveType = m_eScriptType; | 117 XFA_SCRIPTLANGTYPE eSaveType = m_eScriptType; |
| 127 m_eScriptType = eScriptType; | 118 m_eScriptType = eScriptType; |
| 128 if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) { | 119 if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) { |
| 129 if (!m_hFM2JSContext) { | 120 if (!m_FM2JSContext) { |
| 130 m_hFM2JSContext = | 121 m_FM2JSContext.reset( |
| 131 new CXFA_FM2JSContext(m_pIsolate, m_pJsContext, m_pDocument); | 122 new CXFA_FM2JSContext(m_pIsolate, m_JsContext.get(), m_pDocument)); |
| 132 } | 123 } |
| 133 CFX_WideTextBuf wsJavaScript; | 124 CFX_WideTextBuf wsJavaScript; |
| 134 CFX_WideString wsErrorInfo; | 125 CFX_WideString wsErrorInfo; |
| 135 int32_t iFlags = | 126 int32_t iFlags = |
| 136 CXFA_FM2JSContext::Translate(wsScript, wsJavaScript, wsErrorInfo); | 127 CXFA_FM2JSContext::Translate(wsScript, wsJavaScript, wsErrorInfo); |
| 137 if (iFlags) { | 128 if (iFlags) { |
| 138 hRetValue->SetUndefined(); | 129 hRetValue->SetUndefined(); |
| 139 return FALSE; | 130 return FALSE; |
| 140 } | 131 } |
| 141 btScript = | 132 btScript = |
| 142 FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); | 133 FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); |
| 143 } else { | 134 } else { |
| 144 btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); | 135 btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); |
| 145 } | 136 } |
| 146 CXFA_Object* pOriginalObject = m_pThisObject; | 137 CXFA_Object* pOriginalObject = m_pThisObject; |
| 147 m_pThisObject = pThisObject; | 138 m_pThisObject = pThisObject; |
| 148 CFXJSE_Value* pValue = pThisObject ? GetJSValueFromMap(pThisObject) : NULL; | 139 CFXJSE_Value* pValue = pThisObject ? GetJSValueFromMap(pThisObject) : nullptr; |
| 149 FX_BOOL bRet = | 140 FX_BOOL bRet = |
| 150 m_pJsContext->ExecuteScript(btScript.c_str(), hRetValue, pValue); | 141 m_JsContext->ExecuteScript(btScript.c_str(), hRetValue, pValue); |
| 151 m_pThisObject = pOriginalObject; | 142 m_pThisObject = pOriginalObject; |
| 152 m_eScriptType = eSaveType; | 143 m_eScriptType = eSaveType; |
| 153 return bRet; | 144 return bRet; |
| 154 } | 145 } |
| 155 void CXFA_ScriptContext::GlobalPropertySetter(CFXJSE_Value* pObject, | 146 void CXFA_ScriptContext::GlobalPropertySetter(CFXJSE_Value* pObject, |
| 156 const CFX_ByteStringC& szPropName, | 147 const CFX_ByteStringC& szPropName, |
| 157 CFXJSE_Value* pValue) { | 148 CFXJSE_Value* pValue) { |
| 158 CXFA_Object* lpOrginalNode = ToObject(pObject, nullptr); | 149 CXFA_Object* lpOrginalNode = ToObject(pObject, nullptr); |
| 159 CXFA_Document* pDoc = lpOrginalNode->GetDocument(); | 150 CXFA_Document* pDoc = lpOrginalNode->GetDocument(); |
| 160 CXFA_ScriptContext* lpScriptContext = pDoc->GetScriptContext(); | 151 CXFA_ScriptContext* lpScriptContext = pDoc->GetScriptContext(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 void CXFA_ScriptContext::GlobalPropertyGetter(CFXJSE_Value* pObject, | 201 void CXFA_ScriptContext::GlobalPropertyGetter(CFXJSE_Value* pObject, |
| 211 const CFX_ByteStringC& szPropName, | 202 const CFX_ByteStringC& szPropName, |
| 212 CFXJSE_Value* pValue) { | 203 CFXJSE_Value* pValue) { |
| 213 CXFA_Object* pOriginalObject = ToObject(pObject, nullptr); | 204 CXFA_Object* pOriginalObject = ToObject(pObject, nullptr); |
| 214 CXFA_Document* pDoc = pOriginalObject->GetDocument(); | 205 CXFA_Document* pDoc = pOriginalObject->GetDocument(); |
| 215 CXFA_ScriptContext* lpScriptContext = pDoc->GetScriptContext(); | 206 CXFA_ScriptContext* lpScriptContext = pDoc->GetScriptContext(); |
| 216 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOriginalObject); | 207 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOriginalObject); |
| 217 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 208 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 218 if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { | 209 if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { |
| 219 if (szPropName == kFormCalcRuntime) { | 210 if (szPropName == kFormCalcRuntime) { |
| 220 lpScriptContext->m_hFM2JSContext->GlobalPropertyGetter(pValue); | 211 lpScriptContext->m_FM2JSContext->GlobalPropertyGetter(pValue); |
| 221 return; | 212 return; |
| 222 } | 213 } |
| 223 XFA_HashCode uHashCode = static_cast<XFA_HashCode>( | 214 XFA_HashCode uHashCode = static_cast<XFA_HashCode>( |
| 224 FX_HashCode_GetW(wsPropName.AsStringC(), false)); | 215 FX_HashCode_GetW(wsPropName.AsStringC(), false)); |
| 225 if (uHashCode != XFA_HASHCODE_Layout) { | 216 if (uHashCode != XFA_HASHCODE_Layout) { |
| 226 CXFA_Object* pObj = | 217 CXFA_Object* pObj = |
| 227 lpScriptContext->GetDocument()->GetXFAObject(uHashCode); | 218 lpScriptContext->GetDocument()->GetXFAObject(uHashCode); |
| 228 if (pObj) { | 219 if (pObj) { |
| 229 pValue->Assign(lpScriptContext->GetJSValueFromMap(pObj)); | 220 pValue->Assign(lpScriptContext->GetJSValueFromMap(pObj)); |
| 230 return; | 221 return; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 pObject->GetClassID(), wsPropName.AsStringC()); | 311 pObject->GetClassID(), wsPropName.AsStringC()); |
| 321 if (lpAttributeInfo) { | 312 if (lpAttributeInfo) { |
| 322 (pObject->*(lpAttributeInfo->lpfnCallback))( | 313 (pObject->*(lpAttributeInfo->lpfnCallback))( |
| 323 pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); | 314 pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
| 324 } else { | 315 } else { |
| 325 if (pObject->IsNode()) { | 316 if (pObject->IsNode()) { |
| 326 if (wsPropName.GetAt(0) == '#') { | 317 if (wsPropName.GetAt(0) == '#') { |
| 327 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); | 318 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); |
| 328 } | 319 } |
| 329 CXFA_Node* pNode = ToNode(pObject); | 320 CXFA_Node* pNode = ToNode(pObject); |
| 330 CXFA_Node* pPropOrChild = NULL; | 321 CXFA_Node* pPropOrChild = nullptr; |
| 331 const XFA_ELEMENTINFO* lpElementInfo = | 322 const XFA_ELEMENTINFO* lpElementInfo = |
| 332 XFA_GetElementByName(wsPropName.AsStringC()); | 323 XFA_GetElementByName(wsPropName.AsStringC()); |
| 333 if (lpElementInfo) { | 324 if (lpElementInfo) { |
| 334 pPropOrChild = pNode->GetProperty(0, lpElementInfo->eName); | 325 pPropOrChild = pNode->GetProperty(0, lpElementInfo->eName); |
| 335 } else { | 326 } else { |
| 336 pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); | 327 pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); |
| 337 } | 328 } |
| 338 if (pPropOrChild) { | 329 if (pPropOrChild) { |
| 339 CFX_WideString wsDefaultName(L"{default}"); | 330 CFX_WideString wsDefaultName(L"{default}"); |
| 340 const XFA_SCRIPTATTRIBUTEINFO* lpAttrInfo = | 331 const XFA_SCRIPTATTRIBUTEINFO* lpAttrInfo = |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 404 |
| 414 (pObject->*(lpMethodInfo->lpfnCallback))(&args); | 405 (pObject->*(lpMethodInfo->lpfnCallback))(&args); |
| 415 } | 406 } |
| 416 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { | 407 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { |
| 417 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); | 408 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); |
| 418 } | 409 } |
| 419 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { | 410 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { |
| 420 return m_eScriptType; | 411 return m_eScriptType; |
| 421 } | 412 } |
| 422 void CXFA_ScriptContext::DefineJsContext() { | 413 void CXFA_ScriptContext::DefineJsContext() { |
| 423 m_pJsContext = CFXJSE_Context::Create(m_pIsolate, &GlobalClassDescriptor, | 414 m_JsContext.reset(CFXJSE_Context::Create(m_pIsolate, &GlobalClassDescriptor, |
| 424 m_pDocument->GetRoot()); | 415 m_pDocument->GetRoot())); |
| 425 RemoveBuiltInObjs(m_pJsContext); | 416 RemoveBuiltInObjs(m_JsContext.get()); |
| 426 m_pJsContext->EnableCompatibleMode(); | 417 m_JsContext->EnableCompatibleMode(); |
| 427 } | 418 } |
| 428 CFXJSE_Context* CXFA_ScriptContext::CreateVariablesContext( | 419 CFXJSE_Context* CXFA_ScriptContext::CreateVariablesContext( |
| 429 CXFA_Node* pScriptNode, | 420 CXFA_Node* pScriptNode, |
| 430 CXFA_Node* pSubform) { | 421 CXFA_Node* pSubform) { |
| 431 if (!pScriptNode || !pSubform) | 422 if (!pScriptNode || !pSubform) |
| 432 return nullptr; | 423 return nullptr; |
| 433 | 424 |
| 434 CFXJSE_Context* pVariablesContext = | 425 CFXJSE_Context* pVariablesContext = |
| 435 CFXJSE_Context::Create(m_pIsolate, &VariablesClassDescriptor, | 426 CFXJSE_Context::Create(m_pIsolate, &VariablesClassDescriptor, |
| 436 new CXFA_ThisProxy(pSubform, pScriptNode)); | 427 new CXFA_ThisProxy(pSubform, pScriptNode)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 pValue->SetFunctionBind(hVariableValue.get(), pObject.get()); | 504 pValue->SetFunctionBind(hVariableValue.get(), pObject.get()); |
| 514 else if (bGetter) | 505 else if (bGetter) |
| 515 pValue->Assign(hVariableValue.get()); | 506 pValue->Assign(hVariableValue.get()); |
| 516 else | 507 else |
| 517 hVariableValue.get()->Assign(pValue); | 508 hVariableValue.get()->Assign(pValue); |
| 518 bRes = TRUE; | 509 bRes = TRUE; |
| 519 } | 510 } |
| 520 return bRes; | 511 return bRes; |
| 521 } | 512 } |
| 522 | 513 |
| 523 void CXFA_ScriptContext::ReleaseVariablesMap() { | |
| 524 FX_POSITION ps = m_mapVariableToContext.GetStartPosition(); | |
| 525 while (ps) { | |
| 526 CXFA_Object* pScriptNode; | |
| 527 CFXJSE_Context* pVariableContext = nullptr; | |
| 528 m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext); | |
| 529 | |
| 530 delete ToThisProxy(pVariableContext->GetGlobalObject().get(), nullptr); | |
| 531 delete pVariableContext; | |
| 532 } | |
| 533 m_mapVariableToContext.RemoveAll(); | |
| 534 } | |
| 535 | |
| 536 void CXFA_ScriptContext::DefineJsClass() { | 514 void CXFA_ScriptContext::DefineJsClass() { |
| 537 m_pJsClass = CFXJSE_Class::Create(m_pJsContext, &NormalClassDescriptor); | 515 m_pJsClass = CFXJSE_Class::Create(m_JsContext.get(), &NormalClassDescriptor); |
| 538 } | 516 } |
| 539 | 517 |
| 540 void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { | 518 void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { |
| 541 static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; | 519 static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; |
| 542 std::unique_ptr<CFXJSE_Value> pObject = pContext->GetGlobalObject(); | 520 std::unique_ptr<CFXJSE_Value> pObject = pContext->GetGlobalObject(); |
| 543 std::unique_ptr<CFXJSE_Value> hProp(new CFXJSE_Value(m_pIsolate)); | 521 std::unique_ptr<CFXJSE_Value> hProp(new CFXJSE_Value(m_pIsolate)); |
| 544 for (int i = 0; i < 2; ++i) { | 522 for (int i = 0; i < 2; ++i) { |
| 545 if (pObject->GetObjectProperty(OBJ_NAME[i], hProp.get())) | 523 if (pObject->GetObjectProperty(OBJ_NAME[i], hProp.get())) |
| 546 pObject->DeleteObjectProperty(OBJ_NAME[i]); | 524 pObject->DeleteObjectProperty(OBJ_NAME[i]); |
| 547 } | 525 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 560 if (m_eScriptType != XFA_SCRIPTLANGTYPE_Formcalc || | 538 if (m_eScriptType != XFA_SCRIPTLANGTYPE_Formcalc || |
| 561 (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { | 539 (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { |
| 562 m_upObjectArray.RemoveAll(); | 540 m_upObjectArray.RemoveAll(); |
| 563 } | 541 } |
| 564 if (refNode && refNode->IsNode() && | 542 if (refNode && refNode->IsNode() && |
| 565 (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { | 543 (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { |
| 566 m_upObjectArray.Add(refNode->AsNode()); | 544 m_upObjectArray.Add(refNode->AsNode()); |
| 567 } | 545 } |
| 568 FX_BOOL bNextCreate = FALSE; | 546 FX_BOOL bNextCreate = FALSE; |
| 569 if (dwStyles & XFA_RESOLVENODE_CreateNode) { | 547 if (dwStyles & XFA_RESOLVENODE_CreateNode) { |
| 570 m_pResolveProcessor->GetNodeHelper()->XFA_SetCreateNodeType(bindNode); | 548 m_ResolveProcessor->GetNodeHelper()->XFA_SetCreateNodeType(bindNode); |
| 571 } | 549 } |
| 572 m_pResolveProcessor->GetNodeHelper()->m_pCreateParent = NULL; | 550 m_ResolveProcessor->GetNodeHelper()->m_pCreateParent = nullptr; |
| 573 m_pResolveProcessor->GetNodeHelper()->m_iCurAllStart = -1; | 551 m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart = -1; |
| 574 CXFA_ResolveNodesData rndFind; | 552 CXFA_ResolveNodesData rndFind; |
| 575 int32_t nStart = 0; | 553 int32_t nStart = 0; |
| 576 int32_t nLevel = 0; | 554 int32_t nLevel = 0; |
| 577 int32_t nRet = -1; | 555 int32_t nRet = -1; |
| 578 rndFind.m_pSC = this; | 556 rndFind.m_pSC = this; |
| 579 CXFA_ObjArray findNodes; | 557 CXFA_ObjArray findNodes; |
| 580 findNodes.Add(refNode ? refNode : m_pDocument->GetRoot()); | 558 findNodes.Add(refNode ? refNode : m_pDocument->GetRoot()); |
| 581 int32_t nNodes = 0; | 559 int32_t nNodes = 0; |
| 582 while (TRUE) { | 560 while (TRUE) { |
| 583 nNodes = findNodes.GetSize(); | 561 nNodes = findNodes.GetSize(); |
| 584 int32_t i = 0; | 562 int32_t i = 0; |
| 585 rndFind.m_dwStyles = dwStyles; | 563 rndFind.m_dwStyles = dwStyles; |
| 586 m_pResolveProcessor->m_iCurStart = nStart; | 564 m_ResolveProcessor->m_iCurStart = nStart; |
| 587 nStart = m_pResolveProcessor->XFA_ResolveNodes_GetFilter(wsExpression, | 565 nStart = m_ResolveProcessor->XFA_ResolveNodes_GetFilter(wsExpression, |
| 588 nStart, rndFind); | 566 nStart, rndFind); |
| 589 if (nStart < 1) { | 567 if (nStart < 1) { |
| 590 if ((dwStyles & XFA_RESOLVENODE_CreateNode) && !bNextCreate) { | 568 if ((dwStyles & XFA_RESOLVENODE_CreateNode) && !bNextCreate) { |
| 591 CXFA_Node* pDataNode = NULL; | 569 CXFA_Node* pDataNode = nullptr; |
| 592 nStart = m_pResolveProcessor->GetNodeHelper()->m_iCurAllStart; | 570 nStart = m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart; |
| 593 if (nStart != -1) { | 571 if (nStart != -1) { |
| 594 pDataNode = m_pDocument->GetNotBindNode(findNodes); | 572 pDataNode = m_pDocument->GetNotBindNode(findNodes); |
| 595 if (pDataNode) { | 573 if (pDataNode) { |
| 596 findNodes.RemoveAll(); | 574 findNodes.RemoveAll(); |
| 597 findNodes.Add(pDataNode); | 575 findNodes.Add(pDataNode); |
| 598 break; | 576 break; |
| 599 } | 577 } |
| 600 } else { | 578 } else { |
| 601 pDataNode = findNodes[0]->AsNode(); | 579 pDataNode = findNodes[0]->AsNode(); |
| 602 findNodes.RemoveAll(); | 580 findNodes.RemoveAll(); |
| 603 findNodes.Add(pDataNode); | 581 findNodes.Add(pDataNode); |
| 604 break; | 582 break; |
| 605 } | 583 } |
| 606 dwStyles |= XFA_RESOLVENODE_Bind; | 584 dwStyles |= XFA_RESOLVENODE_Bind; |
| 607 findNodes.RemoveAll(); | 585 findNodes.RemoveAll(); |
| 608 findNodes.Add(m_pResolveProcessor->GetNodeHelper()->m_pAllStartParent); | 586 findNodes.Add(m_ResolveProcessor->GetNodeHelper()->m_pAllStartParent); |
| 609 continue; | 587 continue; |
| 610 } else { | 588 } else { |
| 611 break; | 589 break; |
| 612 } | 590 } |
| 613 } | 591 } |
| 614 if (bNextCreate) { | 592 if (bNextCreate) { |
| 615 FX_BOOL bCreate = | 593 FX_BOOL bCreate = |
| 616 m_pResolveProcessor->GetNodeHelper()->XFA_ResolveNodes_CreateNode( | 594 m_ResolveProcessor->GetNodeHelper()->XFA_ResolveNodes_CreateNode( |
| 617 rndFind.m_wsName, rndFind.m_wsCondition, | 595 rndFind.m_wsName, rndFind.m_wsCondition, |
| 618 nStart == wsExpression.GetLength(), this); | 596 nStart == wsExpression.GetLength(), this); |
| 619 if (bCreate) { | 597 if (bCreate) { |
| 620 continue; | 598 continue; |
| 621 } else { | 599 } else { |
| 622 break; | 600 break; |
| 623 } | 601 } |
| 624 } | 602 } |
| 625 CXFA_ObjArray retNodes; | 603 CXFA_ObjArray retNodes; |
| 626 while (i < nNodes) { | 604 while (i < nNodes) { |
| 627 FX_BOOL bDataBind = FALSE; | 605 FX_BOOL bDataBind = FALSE; |
| 628 if (((dwStyles & XFA_RESOLVENODE_Bind) || | 606 if (((dwStyles & XFA_RESOLVENODE_Bind) || |
| 629 (dwStyles & XFA_RESOLVENODE_CreateNode)) && | 607 (dwStyles & XFA_RESOLVENODE_CreateNode)) && |
| 630 nNodes > 1) { | 608 nNodes > 1) { |
| 631 CXFA_ResolveNodesData rndBind; | 609 CXFA_ResolveNodesData rndBind; |
| 632 m_pResolveProcessor->XFA_ResolveNodes_GetFilter(wsExpression, nStart, | 610 m_ResolveProcessor->XFA_ResolveNodes_GetFilter(wsExpression, nStart, |
| 633 rndBind); | 611 rndBind); |
| 634 m_pResolveProcessor->XFA_ResolveNode_SetIndexDataBind( | 612 m_ResolveProcessor->XFA_ResolveNode_SetIndexDataBind( |
| 635 rndBind.m_wsCondition, i, nNodes); | 613 rndBind.m_wsCondition, i, nNodes); |
| 636 bDataBind = TRUE; | 614 bDataBind = TRUE; |
| 637 } | 615 } |
| 638 rndFind.m_CurNode = findNodes[i++]; | 616 rndFind.m_CurNode = findNodes[i++]; |
| 639 rndFind.m_nLevel = nLevel; | 617 rndFind.m_nLevel = nLevel; |
| 640 rndFind.m_dwFlag = XFA_RESOVENODE_RSTYPE_Nodes; | 618 rndFind.m_dwFlag = XFA_RESOVENODE_RSTYPE_Nodes; |
| 641 nRet = m_pResolveProcessor->XFA_ResolveNodes(rndFind); | 619 nRet = m_ResolveProcessor->XFA_ResolveNodes(rndFind); |
| 642 if (nRet < 1) { | 620 if (nRet < 1) { |
| 643 continue; | 621 continue; |
| 644 } | 622 } |
| 645 if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute && | 623 if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute && |
| 646 rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) { | 624 rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) { |
| 647 std::unique_ptr<CFXJSE_Value> pValue(new CFXJSE_Value(m_pIsolate)); | 625 std::unique_ptr<CFXJSE_Value> pValue(new CFXJSE_Value(m_pIsolate)); |
| 648 (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))( | 626 (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))( |
| 649 pValue.get(), FALSE, | 627 pValue.get(), FALSE, |
| 650 (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute); | 628 (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute); |
| 651 rndFind.m_Nodes.SetAt(0, ToObject(pValue.get(), nullptr)); | 629 rndFind.m_Nodes.SetAt(0, ToObject(pValue.get(), nullptr)); |
| 652 } | 630 } |
| 653 int32_t iSize = m_upObjectArray.GetSize(); | 631 int32_t iSize = m_upObjectArray.GetSize(); |
| 654 if (iSize) { | 632 if (iSize) { |
| 655 m_upObjectArray.RemoveAt(iSize - 1); | 633 m_upObjectArray.RemoveAt(iSize - 1); |
| 656 } | 634 } |
| 657 retNodes.Append(rndFind.m_Nodes); | 635 retNodes.Append(rndFind.m_Nodes); |
| 658 rndFind.m_Nodes.RemoveAll(); | 636 rndFind.m_Nodes.RemoveAll(); |
| 659 if (bDataBind) { | 637 if (bDataBind) { |
| 660 break; | 638 break; |
| 661 } | 639 } |
| 662 } | 640 } |
| 663 findNodes.RemoveAll(); | 641 findNodes.RemoveAll(); |
| 664 nNodes = retNodes.GetSize(); | 642 nNodes = retNodes.GetSize(); |
| 665 if (nNodes < 1) { | 643 if (nNodes < 1) { |
| 666 if (dwStyles & XFA_RESOLVENODE_CreateNode) { | 644 if (dwStyles & XFA_RESOLVENODE_CreateNode) { |
| 667 bNextCreate = TRUE; | 645 bNextCreate = TRUE; |
| 668 if (m_pResolveProcessor->GetNodeHelper()->m_pCreateParent == NULL) { | 646 if (m_ResolveProcessor->GetNodeHelper()->m_pCreateParent == nullptr) { |
| 669 m_pResolveProcessor->GetNodeHelper()->m_pCreateParent = | 647 m_ResolveProcessor->GetNodeHelper()->m_pCreateParent = |
| 670 ToNode(rndFind.m_CurNode); | 648 ToNode(rndFind.m_CurNode); |
| 671 m_pResolveProcessor->GetNodeHelper()->m_iCreateCount = 1; | 649 m_ResolveProcessor->GetNodeHelper()->m_iCreateCount = 1; |
| 672 } | 650 } |
| 673 FX_BOOL bCreate = | 651 FX_BOOL bCreate = |
| 674 m_pResolveProcessor->GetNodeHelper()->XFA_ResolveNodes_CreateNode( | 652 m_ResolveProcessor->GetNodeHelper()->XFA_ResolveNodes_CreateNode( |
| 675 rndFind.m_wsName, rndFind.m_wsCondition, | 653 rndFind.m_wsName, rndFind.m_wsCondition, |
| 676 nStart == wsExpression.GetLength(), this); | 654 nStart == wsExpression.GetLength(), this); |
| 677 if (bCreate) { | 655 if (bCreate) { |
| 678 continue; | 656 continue; |
| 679 } else { | 657 } else { |
| 680 break; | 658 break; |
| 681 } | 659 } |
| 682 } else { | 660 } else { |
| 683 break; | 661 break; |
| 684 } | 662 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 695 if (nNodes > 0) { | 673 if (nNodes > 0) { |
| 696 resolveNodeRS.nodes.Append(findNodes); | 674 resolveNodeRS.nodes.Append(findNodes); |
| 697 } | 675 } |
| 698 if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute) { | 676 if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute) { |
| 699 resolveNodeRS.pScriptAttribute = rndFind.m_pScriptAttribute; | 677 resolveNodeRS.pScriptAttribute = rndFind.m_pScriptAttribute; |
| 700 return 1; | 678 return 1; |
| 701 } | 679 } |
| 702 } | 680 } |
| 703 if (dwStyles & (XFA_RESOLVENODE_CreateNode | XFA_RESOLVENODE_Bind | | 681 if (dwStyles & (XFA_RESOLVENODE_CreateNode | XFA_RESOLVENODE_Bind | |
| 704 XFA_RESOLVENODE_BindNew)) { | 682 XFA_RESOLVENODE_BindNew)) { |
| 705 m_pResolveProcessor->XFA_ResolveNode_SetResultCreateNode( | 683 m_ResolveProcessor->XFA_ResolveNode_SetResultCreateNode( |
| 706 resolveNodeRS, rndFind.m_wsCondition); | 684 resolveNodeRS, rndFind.m_wsCondition); |
| 707 if (!bNextCreate && (dwStyles & XFA_RESOLVENODE_CreateNode)) { | 685 if (!bNextCreate && (dwStyles & XFA_RESOLVENODE_CreateNode)) { |
| 708 resolveNodeRS.dwFlags = XFA_RESOVENODE_RSTYPE_ExistNodes; | 686 resolveNodeRS.dwFlags = XFA_RESOVENODE_RSTYPE_ExistNodes; |
| 709 } | 687 } |
| 710 return resolveNodeRS.nodes.GetSize(); | 688 return resolveNodeRS.nodes.GetSize(); |
| 711 } | 689 } |
| 712 return nNodes; | 690 return nNodes; |
| 713 } | 691 } |
| 692 |
| 693 void CXFA_ScriptContext::AddToCacheList(std::unique_ptr<CXFA_NodeList> pList) { |
| 694 m_CacheList.push_back(std::move(pList)); |
| 695 } |
| 696 |
| 714 CFXJSE_Value* CXFA_ScriptContext::GetJSValueFromMap(CXFA_Object* pObject) { | 697 CFXJSE_Value* CXFA_ScriptContext::GetJSValueFromMap(CXFA_Object* pObject) { |
| 715 if (!pObject) | 698 if (!pObject) |
| 716 return nullptr; | 699 return nullptr; |
| 717 if (pObject->IsNode()) | 700 if (pObject->IsNode()) |
| 718 RunVariablesScript(pObject->AsNode()); | 701 RunVariablesScript(pObject->AsNode()); |
| 719 | 702 |
| 720 void* pValue = m_mapXFAToValue.GetValueAt(pObject); | 703 auto iter = m_mapObjectToValue.find(pObject); |
| 721 if (!pValue) { | 704 if (iter != m_mapObjectToValue.end()) |
| 722 CFXJSE_Value* jsValue = new CFXJSE_Value(m_pIsolate); | 705 return iter->second.get(); |
| 723 jsValue->SetObject(pObject, m_pJsClass); | 706 |
| 724 m_mapXFAToValue.SetAt(pObject, jsValue); | 707 std::unique_ptr<CFXJSE_Value> jsValue(new CFXJSE_Value(m_pIsolate)); |
| 725 pValue = jsValue; | 708 jsValue->SetObject(pObject, m_pJsClass); |
| 726 } | 709 CFXJSE_Value* pValue = jsValue.get(); |
| 727 return static_cast<CFXJSE_Value*>(pValue); | 710 m_mapObjectToValue.insert(std::make_pair(pObject, std::move(jsValue))); |
| 711 return pValue; |
| 728 } | 712 } |
| 729 int32_t CXFA_ScriptContext::GetIndexByName(CXFA_Node* refNode) { | 713 int32_t CXFA_ScriptContext::GetIndexByName(CXFA_Node* refNode) { |
| 730 CXFA_NodeHelper* lpNodeHelper = m_pResolveProcessor->GetNodeHelper(); | 714 CXFA_NodeHelper* lpNodeHelper = m_ResolveProcessor->GetNodeHelper(); |
| 731 return lpNodeHelper->XFA_GetIndex(refNode, XFA_LOGIC_Transparent, | 715 return lpNodeHelper->XFA_GetIndex(refNode, XFA_LOGIC_Transparent, |
| 732 lpNodeHelper->XFA_NodeIsProperty(refNode), | 716 lpNodeHelper->XFA_NodeIsProperty(refNode), |
| 733 FALSE); | 717 FALSE); |
| 734 } | 718 } |
| 735 int32_t CXFA_ScriptContext::GetIndexByClassName(CXFA_Node* refNode) { | 719 int32_t CXFA_ScriptContext::GetIndexByClassName(CXFA_Node* refNode) { |
| 736 CXFA_NodeHelper* lpNodeHelper = m_pResolveProcessor->GetNodeHelper(); | 720 CXFA_NodeHelper* lpNodeHelper = m_ResolveProcessor->GetNodeHelper(); |
| 737 return lpNodeHelper->XFA_GetIndex(refNode, XFA_LOGIC_Transparent, | 721 return lpNodeHelper->XFA_GetIndex(refNode, XFA_LOGIC_Transparent, |
| 738 lpNodeHelper->XFA_NodeIsProperty(refNode), | 722 lpNodeHelper->XFA_NodeIsProperty(refNode), |
| 739 TRUE); | 723 TRUE); |
| 740 } | 724 } |
| 741 void CXFA_ScriptContext::GetSomExpression(CXFA_Node* refNode, | 725 void CXFA_ScriptContext::GetSomExpression(CXFA_Node* refNode, |
| 742 CFX_WideString& wsExpression) { | 726 CFX_WideString& wsExpression) { |
| 743 CXFA_NodeHelper* lpNodeHelper = m_pResolveProcessor->GetNodeHelper(); | 727 CXFA_NodeHelper* lpNodeHelper = m_ResolveProcessor->GetNodeHelper(); |
| 744 lpNodeHelper->XFA_GetNameExpression(refNode, wsExpression, TRUE, | 728 lpNodeHelper->XFA_GetNameExpression(refNode, wsExpression, TRUE, |
| 745 XFA_LOGIC_Transparent); | 729 XFA_LOGIC_Transparent); |
| 746 } | 730 } |
| 747 void CXFA_ScriptContext::SetNodesOfRunScript(CXFA_NodeArray* pArray) { | 731 void CXFA_ScriptContext::SetNodesOfRunScript(CXFA_NodeArray* pArray) { |
| 748 m_pScriptNodeArray = pArray; | 732 m_pScriptNodeArray = pArray; |
| 749 } | 733 } |
| 750 void CXFA_ScriptContext::AddNodesOfRunScript(const CXFA_NodeArray& nodes) { | 734 void CXFA_ScriptContext::AddNodesOfRunScript(const CXFA_NodeArray& nodes) { |
| 751 if (!m_pScriptNodeArray) { | 735 if (!m_pScriptNodeArray) |
| 752 return; | 736 return; |
| 753 } | 737 if (nodes.GetSize() > 0) |
| 754 if (nodes.GetSize() > 0) { | |
| 755 m_pScriptNodeArray->Copy(nodes); | 738 m_pScriptNodeArray->Copy(nodes); |
| 756 } | |
| 757 } | 739 } |
| 758 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { | 740 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { |
| 759 if (!m_pScriptNodeArray) { | 741 if (!m_pScriptNodeArray) |
| 760 return; | 742 return; |
| 761 } | 743 if (m_pScriptNodeArray->Find(pNode) == -1) |
| 762 if (m_pScriptNodeArray->Find(pNode) == -1) { | |
| 763 m_pScriptNodeArray->Add(pNode); | 744 m_pScriptNodeArray->Add(pNode); |
| 764 } | |
| 765 } | 745 } |
| OLD | NEW |