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

Side by Side Diff: xfa/fxfa/fm2js/xfa_simpleexpression.cpp

Issue 2530933002: Use unique pointers in CXFA_FMParse (Closed)
Patch Set: You mad Windows? Created 4 years 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
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/fm2js/xfa_simpleexpression.h" 7 #include "xfa/fxfa/fm2js/xfa_simpleexpression.h"
8 8
9 #include <utility>
10
9 #include "core/fxcrt/fx_ext.h" 11 #include "core/fxcrt/fx_ext.h"
10 12
11 namespace { 13 namespace {
12 14
13 const FX_WCHAR* const gs_lpStrExpFuncName[] = { 15 const FX_WCHAR* const gs_lpStrExpFuncName[] = {
14 L"foxit_xfa_formcalc_runtime.assign_value_operator", 16 L"foxit_xfa_formcalc_runtime.assign_value_operator",
15 L"foxit_xfa_formcalc_runtime.logical_or_operator", 17 L"foxit_xfa_formcalc_runtime.logical_or_operator",
16 L"foxit_xfa_formcalc_runtime.logical_and_operator", 18 L"foxit_xfa_formcalc_runtime.logical_and_operator",
17 L"foxit_xfa_formcalc_runtime.equality_operator", 19 L"foxit_xfa_formcalc_runtime.equality_operator",
18 L"foxit_xfa_formcalc_runtime.notequality_operator", 20 L"foxit_xfa_formcalc_runtime.notequality_operator",
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 void CXFA_FMNotExpression::ToJavaScript(CFX_WideTextBuf& javascript) { 472 void CXFA_FMNotExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
471 javascript << gs_lpStrExpFuncName[NOT]; 473 javascript << gs_lpStrExpFuncName[NOT];
472 javascript << FX_WSTRC(L"("); 474 javascript << FX_WSTRC(L"(");
473 m_pExp->ToJavaScript(javascript); 475 m_pExp->ToJavaScript(javascript);
474 javascript << FX_WSTRC(L")"); 476 javascript << FX_WSTRC(L")");
475 } 477 }
476 478
477 CXFA_FMCallExpression::CXFA_FMCallExpression( 479 CXFA_FMCallExpression::CXFA_FMCallExpression(
478 uint32_t line, 480 uint32_t line,
479 CXFA_FMSimpleExpression* pExp, 481 CXFA_FMSimpleExpression* pExp,
480 CFX_ArrayTemplate<CXFA_FMSimpleExpression*>* pArguments, 482 std::vector<std::unique_ptr<CXFA_FMSimpleExpression>>&& pArguments,
481 bool bIsSomMethod) 483 bool bIsSomMethod)
482 : CXFA_FMUnaryExpression(line, TOKcall, pExp), 484 : CXFA_FMUnaryExpression(line, TOKcall, pExp),
483 m_bIsSomMethod(bIsSomMethod), 485 m_bIsSomMethod(bIsSomMethod),
484 m_pArguments(pArguments) {} 486 m_Arguments(std::move(pArguments)) {}
485 487
486 CXFA_FMCallExpression::~CXFA_FMCallExpression() { 488 CXFA_FMCallExpression::~CXFA_FMCallExpression() {}
487 if (m_pArguments) {
488 for (int i = 0; i < m_pArguments->GetSize(); ++i)
489 delete m_pArguments->GetAt(i);
490
491 delete m_pArguments;
492 }
493 }
494 489
495 bool CXFA_FMCallExpression::IsBuildInFunc(CFX_WideTextBuf* funcName) { 490 bool CXFA_FMCallExpression::IsBuildInFunc(CFX_WideTextBuf* funcName) {
496 uint32_t uHash = FX_HashCode_GetW(funcName->AsStringC(), true); 491 uint32_t uHash = FX_HashCode_GetW(funcName->AsStringC(), true);
497 const XFA_FMBuildInFunc* pEnd = g_BuildInFuncs + FX_ArraySize(g_BuildInFuncs); 492 const XFA_FMBuildInFunc* pEnd = g_BuildInFuncs + FX_ArraySize(g_BuildInFuncs);
498 const XFA_FMBuildInFunc* pFunc = 493 const XFA_FMBuildInFunc* pFunc =
499 std::lower_bound(g_BuildInFuncs, pEnd, uHash, 494 std::lower_bound(g_BuildInFuncs, pEnd, uHash,
500 [](const XFA_FMBuildInFunc& func, uint32_t hash) { 495 [](const XFA_FMBuildInFunc& func, uint32_t hash) {
501 return func.m_uHash < hash; 496 return func.m_uHash < hash;
502 }); 497 });
503 if (pFunc < pEnd && uHash == pFunc->m_uHash) { 498 if (pFunc < pEnd && uHash == pFunc->m_uHash) {
(...skipping 26 matching lines...) Expand all
530 } while (iStart <= iEnd); 525 } while (iStart <= iEnd);
531 return parameters; 526 return parameters;
532 } 527 }
533 528
534 void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { 529 void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
535 CFX_WideTextBuf funcName; 530 CFX_WideTextBuf funcName;
536 m_pExp->ToJavaScript(funcName); 531 m_pExp->ToJavaScript(funcName);
537 if (m_bIsSomMethod) { 532 if (m_bIsSomMethod) {
538 javascript << funcName; 533 javascript << funcName;
539 javascript << FX_WSTRC(L"("); 534 javascript << FX_WSTRC(L"(");
540 if (m_pArguments) { 535 uint32_t methodPara = IsMethodWithObjParam(funcName.AsStringC());
541 uint32_t methodPara = IsMethodWithObjParam(funcName.AsStringC()); 536 if (methodPara > 0) {
542 if (methodPara > 0) { 537 for (size_t i = 0; i < m_Arguments.size(); ++i) {
543 for (int i = 0; i < m_pArguments->GetSize(); ++i) { 538 // Currently none of our expressions use objects for a parameter over
544 // Currently none of our expressions use objects for a parameter over 539 // the 6th. Make sure we don't overflow the shift when doing this
545 // the 6th. Make sure we don't overflow the shift when doing this 540 // check. If we ever need more the 32 object params we can revisit.
546 // check. If we ever need more the 32 object params we can revisit. 541 if (i < 32 && (methodPara & (0x01 << i)) > 0) {
npm 2016/11/28 20:04:39 Leaving i in this for loop for now because it is b
547 if (i < 32 && (methodPara & (0x01 << i)) > 0) { 542 javascript << gs_lpStrExpFuncName[GETFMJSOBJ];
548 javascript << gs_lpStrExpFuncName[GETFMJSOBJ]; 543 } else {
549 } else { 544 javascript << gs_lpStrExpFuncName[GETFMVALUE];
550 javascript << gs_lpStrExpFuncName[GETFMVALUE];
551 }
552 javascript << FX_WSTRC(L"(");
553 CXFA_FMSimpleExpression* e = m_pArguments->GetAt(i);
554 e->ToJavaScript(javascript);
555 javascript << FX_WSTRC(L")");
556 if (i + 1 < m_pArguments->GetSize()) {
557 javascript << FX_WSTRC(L", ");
558 }
559 } 545 }
560 } else { 546 javascript << FX_WSTRC(L"(");
561 for (int i = 0; i < m_pArguments->GetSize(); ++i) { 547 CXFA_FMSimpleExpression* e = m_Arguments.at(i).get();
562 javascript << gs_lpStrExpFuncName[GETFMVALUE]; 548 e->ToJavaScript(javascript);
563 javascript << FX_WSTRC(L"("); 549 javascript << FX_WSTRC(L")");
564 CXFA_FMSimpleExpression* e = m_pArguments->GetAt(i); 550 if (i + 1 < m_Arguments.size()) {
565 e->ToJavaScript(javascript); 551 javascript << FX_WSTRC(L", ");
566 javascript << FX_WSTRC(L")"); 552 }
567 if (i + 1 < m_pArguments->GetSize()) { 553 }
568 javascript << FX_WSTRC(L", "); 554 } else {
569 } 555 for (size_t i = 0; i < m_Arguments.size(); ++i) {
556 javascript << gs_lpStrExpFuncName[GETFMVALUE];
557 javascript << FX_WSTRC(L"(");
558 CXFA_FMSimpleExpression* e = m_Arguments.at(i).get();
559 e->ToJavaScript(javascript);
560 javascript << FX_WSTRC(L")");
561 if (i + 1 < m_Arguments.size()) {
562 javascript << FX_WSTRC(L", ");
570 } 563 }
571 } 564 }
572 } 565 }
573 javascript << FX_WSTRC(L")"); 566 javascript << FX_WSTRC(L")");
574 } else { 567 } else {
575 bool isEvalFunc = false; 568 bool isEvalFunc = false;
576 bool isExistsFunc = false; 569 bool isExistsFunc = false;
577 if (IsBuildInFunc(&funcName)) { 570 if (IsBuildInFunc(&funcName)) {
578 if (funcName.AsStringC() == FX_WSTRC(L"Eval")) { 571 if (funcName.AsStringC() == FX_WSTRC(L"Eval")) {
579 isEvalFunc = true; 572 isEvalFunc = true;
580 javascript << FX_WSTRC(L"eval.call(this, "); 573 javascript << FX_WSTRC(L"eval.call(this, ");
581 javascript << gs_lpStrExpFuncName[CALL]; 574 javascript << gs_lpStrExpFuncName[CALL];
582 javascript << FX_WSTRC(L"Translate"); 575 javascript << FX_WSTRC(L"Translate");
583 } else if (funcName.AsStringC() == FX_WSTRC(L"Exists")) { 576 } else if (funcName.AsStringC() == FX_WSTRC(L"Exists")) {
584 isExistsFunc = true; 577 isExistsFunc = true;
585 javascript << gs_lpStrExpFuncName[CALL]; 578 javascript << gs_lpStrExpFuncName[CALL];
586 javascript << funcName; 579 javascript << funcName;
587 } else { 580 } else {
588 javascript << gs_lpStrExpFuncName[CALL]; 581 javascript << gs_lpStrExpFuncName[CALL];
589 javascript << funcName; 582 javascript << funcName;
590 } 583 }
591 } else { 584 } else {
592 javascript << funcName; 585 javascript << funcName;
593 } 586 }
594 javascript << FX_WSTRC(L"("); 587 javascript << FX_WSTRC(L"(");
595 if (isExistsFunc) { 588 if (isExistsFunc) {
596 javascript << FX_WSTRC(L"\n(\nfunction ()\n{\ntry\n{\n"); 589 javascript << FX_WSTRC(L"\n(\nfunction ()\n{\ntry\n{\n");
597 if (m_pArguments && m_pArguments->GetSize() > 0) { 590 if (!m_Arguments.empty()) {
598 CXFA_FMSimpleExpression* e = m_pArguments->GetAt(0); 591 CXFA_FMSimpleExpression* e = m_Arguments.at(0).get();
Tom Sepez 2016/11/28 18:09:12 nit: same comments as before, also above loops.
599 javascript << FX_WSTRC(L"return "); 592 javascript << FX_WSTRC(L"return ");
600 e->ToJavaScript(javascript); 593 e->ToJavaScript(javascript);
601 javascript << FX_WSTRC(L";\n}\n"); 594 javascript << FX_WSTRC(L";\n}\n");
602 } else { 595 } else {
603 javascript << FX_WSTRC(L"return 0;\n}\n"); 596 javascript << FX_WSTRC(L"return 0;\n}\n");
604 } 597 }
605 javascript << FX_WSTRC( 598 javascript << FX_WSTRC(
606 L"catch(accessExceptions)\n{\nreturn 0;\n}\n}\n).call(this)\n"); 599 L"catch(accessExceptions)\n{\nreturn 0;\n}\n}\n).call(this)\n");
607 } else if (m_pArguments) { 600 } else {
608 for (int i = 0; i < m_pArguments->GetSize(); ++i) { 601 for (size_t i = 0; i < m_Arguments.size(); ++i) {
609 CXFA_FMSimpleExpression* e = m_pArguments->GetAt(i); 602 CXFA_FMSimpleExpression* e = m_Arguments.at(i).get();
610 e->ToJavaScript(javascript); 603 e->ToJavaScript(javascript);
611 if (i + 1 < m_pArguments->GetSize()) { 604 if (i + 1 < m_Arguments.size()) {
612 javascript << FX_WSTRC(L", "); 605 javascript << FX_WSTRC(L", ");
613 } 606 }
614 } 607 }
615 } 608 }
616 javascript << FX_WSTRC(L")"); 609 javascript << FX_WSTRC(L")");
617 if (isEvalFunc) { 610 if (isEvalFunc) {
618 javascript << FX_WSTRC(L")"); 611 javascript << FX_WSTRC(L")");
619 } 612 }
620 } 613 }
621 } 614 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 L"for(var index = accessor_object.length - 1; index > 1; index--)\n{\n"); 739 L"for(var index = accessor_object.length - 1; index > 1; index--)\n{\n");
747 javascript << FX_WSTRC(L"method_return_value = accessor_object[index]."); 740 javascript << FX_WSTRC(L"method_return_value = accessor_object[index].");
748 m_pExp2->ToJavaScript(javascript); 741 m_pExp2->ToJavaScript(javascript);
749 javascript << FX_WSTRC(L";\n}\n}\n"); 742 javascript << FX_WSTRC(L";\n}\n}\n");
750 javascript << FX_WSTRC(L"else\n{\nmethod_return_value = accessor_object."); 743 javascript << FX_WSTRC(L"else\n{\nmethod_return_value = accessor_object.");
751 m_pExp2->ToJavaScript(javascript); 744 m_pExp2->ToJavaScript(javascript);
752 javascript << FX_WSTRC(L";\n}\n"); 745 javascript << FX_WSTRC(L";\n}\n");
753 javascript << FX_WSTRC(L"return method_return_value;\n"); 746 javascript << FX_WSTRC(L"return method_return_value;\n");
754 javascript << FX_WSTRC(L"}\n).call(this)"); 747 javascript << FX_WSTRC(L"}\n).call(this)");
755 } 748 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698