Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: xfa/fxfa/parser/xfa_script_imp.cpp

Issue 2056733003: Change CFXJSE_Context::GetGlobalObject to return (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@to_string_return
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | xfa/fxjse/context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "xfa/fxfa/app/xfa_ffnotify.h" 10 #include "xfa/fxfa/app/xfa_ffnotify.h"
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); 495 CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent);
496 if (!variablesNode || variablesNode->GetClassID() != XFA_ELEMENT_Variables) 496 if (!variablesNode || variablesNode->GetClassID() != XFA_ELEMENT_Variables)
497 return FALSE; 497 return FALSE;
498 498
499 void* lpVariables = m_mapVariableToContext.GetValueAt(pScriptNode); 499 void* lpVariables = m_mapVariableToContext.GetValueAt(pScriptNode);
500 if (!lpVariables) 500 if (!lpVariables)
501 return FALSE; 501 return FALSE;
502 502
503 FX_BOOL bRes = FALSE; 503 FX_BOOL bRes = FALSE;
504 CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables); 504 CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables);
505 std::unique_ptr<CFXJSE_Value> pObject( 505 std::unique_ptr<CFXJSE_Value> pObject = pVariableContext->GetGlobalObject();
506 new CFXJSE_Value(pVariableContext->GetRuntime()));
507 pVariableContext->GetGlobalObject(pObject.get());
508
509 std::unique_ptr<CFXJSE_Value> hVariableValue(new CFXJSE_Value(m_pIsolate)); 506 std::unique_ptr<CFXJSE_Value> hVariableValue(new CFXJSE_Value(m_pIsolate));
510 if (!bGetter) { 507 if (!bGetter) {
511 pObject->SetObjectOwnProperty(szPropName, pValue); 508 pObject->SetObjectOwnProperty(szPropName, pValue);
512 bRes = TRUE; 509 bRes = TRUE;
513 } else if (pObject->HasObjectOwnProperty(szPropName, FALSE)) { 510 } else if (pObject->HasObjectOwnProperty(szPropName, FALSE)) {
514 pObject->GetObjectProperty(szPropName, hVariableValue.get()); 511 pObject->GetObjectProperty(szPropName, hVariableValue.get());
515 if (hVariableValue->IsFunction()) 512 if (hVariableValue->IsFunction())
516 pValue->SetFunctionBind(hVariableValue.get(), pObject.get()); 513 pValue->SetFunctionBind(hVariableValue.get(), pObject.get());
517 else if (bGetter) 514 else if (bGetter)
518 pValue->Assign(hVariableValue.get()); 515 pValue->Assign(hVariableValue.get());
519 else 516 else
520 hVariableValue.get()->Assign(pValue); 517 hVariableValue.get()->Assign(pValue);
521 bRes = TRUE; 518 bRes = TRUE;
522 } 519 }
523 return bRes; 520 return bRes;
524 } 521 }
525 522
526 void CXFA_ScriptContext::ReleaseVariablesMap() { 523 void CXFA_ScriptContext::ReleaseVariablesMap() {
527 FX_POSITION ps = m_mapVariableToContext.GetStartPosition(); 524 FX_POSITION ps = m_mapVariableToContext.GetStartPosition();
528 while (ps) { 525 while (ps) {
529 CXFA_Object* pScriptNode; 526 CXFA_Object* pScriptNode;
530 CFXJSE_Context* pVariableContext = nullptr; 527 CFXJSE_Context* pVariableContext = nullptr;
531 m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext); 528 m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext);
532 std::unique_ptr<CFXJSE_Value> pObject(
533 new CFXJSE_Value(pVariableContext->GetRuntime()));
534 pVariableContext->GetGlobalObject(pObject.get());
535 529
536 delete ToThisProxy(pObject.get(), nullptr); 530 delete ToThisProxy(pVariableContext->GetGlobalObject().get(), nullptr);
537 delete pVariableContext; 531 delete pVariableContext;
538 } 532 }
539 m_mapVariableToContext.RemoveAll(); 533 m_mapVariableToContext.RemoveAll();
540 } 534 }
541 535
542 void CXFA_ScriptContext::DefineJsClass() { 536 void CXFA_ScriptContext::DefineJsClass() {
543 m_pJsClass = CFXJSE_Class::Create(m_pJsContext, &NormalClassDescriptor); 537 m_pJsClass = CFXJSE_Class::Create(m_pJsContext, &NormalClassDescriptor);
544 } 538 }
545 539
546 void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { 540 void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const {
547 static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; 541 static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"};
548 std::unique_ptr<CFXJSE_Value> pObject( 542 std::unique_ptr<CFXJSE_Value> pObject = pContext->GetGlobalObject();
549 new CFXJSE_Value(pContext->GetRuntime()));
550 pContext->GetGlobalObject(pObject.get());
551
552 std::unique_ptr<CFXJSE_Value> hProp(new CFXJSE_Value(m_pIsolate)); 543 std::unique_ptr<CFXJSE_Value> hProp(new CFXJSE_Value(m_pIsolate));
553 for (int i = 0; i < 2; ++i) { 544 for (int i = 0; i < 2; ++i) {
554 if (pObject->GetObjectProperty(OBJ_NAME[i], hProp.get())) 545 if (pObject->GetObjectProperty(OBJ_NAME[i], hProp.get()))
555 pObject.get()->DeleteObjectProperty(OBJ_NAME[i]); 546 pObject->DeleteObjectProperty(OBJ_NAME[i]);
556 } 547 }
557 } 548 }
558 CFXJSE_Class* CXFA_ScriptContext::GetJseNormalClass() { 549 CFXJSE_Class* CXFA_ScriptContext::GetJseNormalClass() {
559 return m_pJsClass; 550 return m_pJsClass;
560 } 551 }
561 int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, 552 int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode,
562 const CFX_WideStringC& wsExpression, 553 const CFX_WideStringC& wsExpression,
563 XFA_RESOLVENODE_RS& resolveNodeRS, 554 XFA_RESOLVENODE_RS& resolveNodeRS,
564 uint32_t dwStyles, 555 uint32_t dwStyles,
565 CXFA_Node* bindNode) { 556 CXFA_Node* bindNode) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 } 756 }
766 } 757 }
767 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { 758 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) {
768 if (!m_pScriptNodeArray) { 759 if (!m_pScriptNodeArray) {
769 return; 760 return;
770 } 761 }
771 if (m_pScriptNodeArray->Find(pNode) == -1) { 762 if (m_pScriptNodeArray->Find(pNode) == -1) {
772 m_pScriptNodeArray->Add(pNode); 763 m_pScriptNodeArray->Add(pNode);
773 } 764 }
774 } 765 }
OLDNEW
« no previous file with comments | « no previous file | xfa/fxjse/context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698