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