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/cxfa_scriptcontext.h" | 7 #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 : m_pDocument(pDocument), | 118 : m_pDocument(pDocument), |
119 m_pIsolate(nullptr), | 119 m_pIsolate(nullptr), |
120 m_pJsClass(nullptr), | 120 m_pJsClass(nullptr), |
121 m_eScriptType(XFA_SCRIPTLANGTYPE_Unkown), | 121 m_eScriptType(XFA_SCRIPTLANGTYPE_Unkown), |
122 m_pScriptNodeArray(nullptr), | 122 m_pScriptNodeArray(nullptr), |
123 m_pThisObject(nullptr), | 123 m_pThisObject(nullptr), |
124 m_dwBuiltInInFlags(0), | 124 m_dwBuiltInInFlags(0), |
125 m_eRunAtType(XFA_ATTRIBUTEENUM_Client) {} | 125 m_eRunAtType(XFA_ATTRIBUTEENUM_Client) {} |
126 | 126 |
127 CXFA_ScriptContext::~CXFA_ScriptContext() { | 127 CXFA_ScriptContext::~CXFA_ScriptContext() { |
128 FX_POSITION ps = m_mapVariableToContext.GetStartPosition(); | 128 for (const auto& pair : m_mapVariableToContext) { |
129 while (ps) { | 129 CFXJSE_Context* pVariableContext = pair.second; |
130 CXFA_Object* pScriptNode; | |
131 CFXJSE_Context* pVariableContext = nullptr; | |
132 m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext); | |
133 | |
134 delete ToThisProxy(pVariableContext->GetGlobalObject().get(), nullptr); | 130 delete ToThisProxy(pVariableContext->GetGlobalObject().get(), nullptr); |
135 delete pVariableContext; | 131 delete pVariableContext; |
136 } | 132 } |
137 m_mapVariableToContext.RemoveAll(); | 133 m_mapVariableToContext.clear(); |
138 | |
139 m_upObjectArray.RemoveAll(); | 134 m_upObjectArray.RemoveAll(); |
140 } | 135 } |
141 | 136 |
142 void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { | 137 void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { |
143 m_pIsolate = pIsolate; | 138 m_pIsolate = pIsolate; |
144 DefineJsContext(); | 139 DefineJsContext(); |
145 DefineJsClass(); | 140 DefineJsClass(); |
146 m_ResolveProcessor = pdfium::MakeUnique<CXFA_ResolveProcessor>(); | 141 m_ResolveProcessor = pdfium::MakeUnique<CXFA_ResolveProcessor>(); |
147 } | 142 } |
148 | 143 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 CXFA_Node* pScriptNode, | 449 CXFA_Node* pScriptNode, |
455 CXFA_Node* pSubform) { | 450 CXFA_Node* pSubform) { |
456 if (!pScriptNode || !pSubform) | 451 if (!pScriptNode || !pSubform) |
457 return nullptr; | 452 return nullptr; |
458 | 453 |
459 CFXJSE_Context* pVariablesContext = | 454 CFXJSE_Context* pVariablesContext = |
460 CFXJSE_Context::Create(m_pIsolate, &VariablesClassDescriptor, | 455 CFXJSE_Context::Create(m_pIsolate, &VariablesClassDescriptor, |
461 new CXFA_ThisProxy(pSubform, pScriptNode)); | 456 new CXFA_ThisProxy(pSubform, pScriptNode)); |
462 RemoveBuiltInObjs(pVariablesContext); | 457 RemoveBuiltInObjs(pVariablesContext); |
463 pVariablesContext->EnableCompatibleMode(); | 458 pVariablesContext->EnableCompatibleMode(); |
464 m_mapVariableToContext.SetAt(pScriptNode, pVariablesContext); | 459 m_mapVariableToContext[pScriptNode] = pVariablesContext; |
465 return pVariablesContext; | 460 return pVariablesContext; |
466 } | 461 } |
467 CXFA_Object* CXFA_ScriptContext::GetVariablesThis(CXFA_Object* pObject, | 462 CXFA_Object* CXFA_ScriptContext::GetVariablesThis(CXFA_Object* pObject, |
468 bool bScriptNode) { | 463 bool bScriptNode) { |
469 if (!pObject->IsVariablesThis()) | 464 if (!pObject->IsVariablesThis()) |
470 return pObject; | 465 return pObject; |
471 | 466 |
472 CXFA_ThisProxy* pProxy = static_cast<CXFA_ThisProxy*>(pObject); | 467 CXFA_ThisProxy* pProxy = static_cast<CXFA_ThisProxy*>(pObject); |
473 return bScriptNode ? pProxy->GetScriptNode() : pProxy->GetThisNode(); | 468 return bScriptNode ? pProxy->GetScriptNode() : pProxy->GetThisNode(); |
474 } | 469 } |
475 | 470 |
476 bool CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) { | 471 bool CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) { |
477 if (!pScriptNode) | 472 if (!pScriptNode) |
478 return false; | 473 return false; |
479 | 474 |
480 if (pScriptNode->GetElementType() != XFA_Element::Script) | 475 if (pScriptNode->GetElementType() != XFA_Element::Script) |
481 return true; | 476 return true; |
482 | 477 |
483 CXFA_Node* pParent = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); | 478 CXFA_Node* pParent = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); |
484 if (!pParent || pParent->GetElementType() != XFA_Element::Variables) | 479 if (!pParent || pParent->GetElementType() != XFA_Element::Variables) |
485 return false; | 480 return false; |
486 | 481 |
487 if (m_mapVariableToContext.GetValueAt(pScriptNode)) | 482 auto it = m_mapVariableToContext.find(pScriptNode); |
| 483 if (it != m_mapVariableToContext.end() && it->second) |
488 return true; | 484 return true; |
489 | 485 |
490 CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); | 486 CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
491 if (!pTextNode) | 487 if (!pTextNode) |
492 return false; | 488 return false; |
493 | 489 |
494 CFX_WideStringC wsScript; | 490 CFX_WideStringC wsScript; |
495 if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) | 491 if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) |
496 return false; | 492 return false; |
497 | 493 |
(...skipping 16 matching lines...) Expand all Loading... |
514 CFXJSE_Value* pValue, | 510 CFXJSE_Value* pValue, |
515 bool bGetter) { | 511 bool bGetter) { |
516 if (!pScriptNode || pScriptNode->GetElementType() != XFA_Element::Script) | 512 if (!pScriptNode || pScriptNode->GetElementType() != XFA_Element::Script) |
517 return false; | 513 return false; |
518 | 514 |
519 CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); | 515 CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); |
520 if (!variablesNode || | 516 if (!variablesNode || |
521 variablesNode->GetElementType() != XFA_Element::Variables) | 517 variablesNode->GetElementType() != XFA_Element::Variables) |
522 return false; | 518 return false; |
523 | 519 |
524 void* lpVariables = m_mapVariableToContext.GetValueAt(pScriptNode); | 520 auto it = m_mapVariableToContext.find(pScriptNode); |
525 if (!lpVariables) | 521 if (it == m_mapVariableToContext.end() || !it->second) |
526 return false; | 522 return false; |
527 | 523 |
| 524 void* lpVariables = it->second; |
528 bool bRes = false; | 525 bool bRes = false; |
529 CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables); | 526 CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables); |
530 std::unique_ptr<CFXJSE_Value> pObject = pVariableContext->GetGlobalObject(); | 527 std::unique_ptr<CFXJSE_Value> pObject = pVariableContext->GetGlobalObject(); |
531 std::unique_ptr<CFXJSE_Value> hVariableValue(new CFXJSE_Value(m_pIsolate)); | 528 std::unique_ptr<CFXJSE_Value> hVariableValue(new CFXJSE_Value(m_pIsolate)); |
532 if (!bGetter) { | 529 if (!bGetter) { |
533 pObject->SetObjectOwnProperty(szPropName, pValue); | 530 pObject->SetObjectOwnProperty(szPropName, pValue); |
534 bRes = true; | 531 bRes = true; |
535 } else if (pObject->HasObjectOwnProperty(szPropName, false)) { | 532 } else if (pObject->HasObjectOwnProperty(szPropName, false)) { |
536 pObject->GetObjectProperty(szPropName, hVariableValue.get()); | 533 pObject->GetObjectProperty(szPropName, hVariableValue.get()); |
537 if (hVariableValue->IsFunction()) | 534 if (hVariableValue->IsFunction()) |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 return; | 762 return; |
766 if (nodes.GetSize() > 0) | 763 if (nodes.GetSize() > 0) |
767 m_pScriptNodeArray->Copy(nodes); | 764 m_pScriptNodeArray->Copy(nodes); |
768 } | 765 } |
769 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { | 766 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { |
770 if (!m_pScriptNodeArray) | 767 if (!m_pScriptNodeArray) |
771 return; | 768 return; |
772 if (m_pScriptNodeArray->Find(pNode) == -1) | 769 if (m_pScriptNodeArray->Find(pNode) == -1) |
773 m_pScriptNodeArray->Add(pNode); | 770 m_pScriptNodeArray->Add(pNode); |
774 } | 771 } |
OLD | NEW |