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_fm2js.h" | 7 #include "xfa_fm2js.h" |
8 static CFX_WideStringC gs_lpStrExpFuncName[] = { | 8 static CFX_WideStringC gs_lpStrExpFuncName[] = { |
9 FX_WSTRC(L"foxit_xfa_formcalc_runtime.assign_value_operator"), | 9 FX_WSTRC(L"foxit_xfa_formcalc_runtime.assign_value_operator"), |
10 FX_WSTRC(L"foxit_xfa_formcalc_runtime.logical_or_operator"), | 10 FX_WSTRC(L"foxit_xfa_formcalc_runtime.logical_or_operator"), |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 : CXFA_FMSimpleExpression(line, TOKstring), | 161 : CXFA_FMSimpleExpression(line, TOKstring), |
162 m_wsString(wsString) | 162 m_wsString(wsString) |
163 { | 163 { |
164 } | 164 } |
165 void CXFA_FMStringExpression::ToJavaScript(CFX_WideTextBuf& javascript) | 165 void CXFA_FMStringExpression::ToJavaScript(CFX_WideTextBuf& javascript) |
166 { | 166 { |
167 CFX_WideString tempStr = m_wsString; | 167 CFX_WideString tempStr = m_wsString; |
168 if (tempStr.GetLength() > 2) { | 168 if (tempStr.GetLength() > 2) { |
169 javascript.AppendChar(L'\"'); | 169 javascript.AppendChar(L'\"'); |
170 FX_WCHAR oneChar; | 170 FX_WCHAR oneChar; |
171 for (FX_INT16 i = 1; i < tempStr.GetLength() - 1; i++) { | 171 for (int16_t i = 1; i < tempStr.GetLength() - 1; i++) { |
172 oneChar = tempStr[i]; | 172 oneChar = tempStr[i]; |
173 switch (oneChar) { | 173 switch (oneChar) { |
174 case L'\"': { | 174 case L'\"': { |
175 i++; | 175 i++; |
176 javascript << FX_WSTRC(L"\\\""); | 176 javascript << FX_WSTRC(L"\\\""); |
177 } | 177 } |
178 break; | 178 break; |
179 case 0x0d: | 179 case 0x0d: |
180 break; | 180 break; |
181 case 0x0a: { | 181 case 0x0a: { |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 } | 482 } |
483 CXFA_FMCallExpression::CXFA_FMCallExpression(FX_DWORD line, CXFA_FMSimpleExpress
ion *pExp, CFX_PtrArray *pArguments, FX_BOOL bIsSomMethod) | 483 CXFA_FMCallExpression::CXFA_FMCallExpression(FX_DWORD line, CXFA_FMSimpleExpress
ion *pExp, CFX_PtrArray *pArguments, FX_BOOL bIsSomMethod) |
484 : CXFA_FMUnaryExpression(line, TOKcall, pExp), | 484 : CXFA_FMUnaryExpression(line, TOKcall, pExp), |
485 m_pArguments(pArguments), | 485 m_pArguments(pArguments), |
486 m_bIsSomMethod(bIsSomMethod) | 486 m_bIsSomMethod(bIsSomMethod) |
487 { | 487 { |
488 } | 488 } |
489 CXFA_FMCallExpression::~CXFA_FMCallExpression() | 489 CXFA_FMCallExpression::~CXFA_FMCallExpression() |
490 { | 490 { |
491 if (m_pArguments) { | 491 if (m_pArguments) { |
492 FX_INT32 argc = m_pArguments->GetSize(); | 492 int32_t argc = m_pArguments->GetSize(); |
493 FX_INT32 index = 0; | 493 int32_t index = 0; |
494 CXFA_FMSimpleExpression *e = 0; | 494 CXFA_FMSimpleExpression *e = 0; |
495 while (index < argc) { | 495 while (index < argc) { |
496 e = (CXFA_FMSimpleExpression *)m_pArguments->GetAt(index); | 496 e = (CXFA_FMSimpleExpression *)m_pArguments->GetAt(index); |
497 delete e; | 497 delete e; |
498 index++; | 498 index++; |
499 } | 499 } |
500 m_pArguments->RemoveAll(); | 500 m_pArguments->RemoveAll(); |
501 delete m_pArguments; | 501 delete m_pArguments; |
502 m_pArguments = 0; | 502 m_pArguments = 0; |
503 } | 503 } |
504 } | 504 } |
505 FX_BOOL CXFA_FMCallExpression::IsBuildInFunc(CFX_WideTextBuf& funcName) | 505 FX_BOOL CXFA_FMCallExpression::IsBuildInFunc(CFX_WideTextBuf& funcName) |
506 { | 506 { |
507 FX_INT32 iLength = funcName.GetLength(); | 507 int32_t iLength = funcName.GetLength(); |
508 FX_UINT32 uHash = FX_HashCode_String_GetW(funcName.GetBuffer(), iLength, TRU
E); | 508 uint32_t uHash = FX_HashCode_String_GetW(funcName.GetBuffer(), iLength, TRUE
); |
509 XFA_FMBuildInFunc buildinfunction; | 509 XFA_FMBuildInFunc buildinfunction; |
510 FX_INT32 iStart = 0, iEnd = (sizeof(buildInFuncs) / sizeof(buildInFuncs[0]))
- 1; | 510 int32_t iStart = 0, iEnd = (sizeof(buildInFuncs) / sizeof(buildInFuncs[0]))
- 1; |
511 FX_INT32 iMid = (iStart + iEnd) / 2; | 511 int32_t iMid = (iStart + iEnd) / 2; |
512 do { | 512 do { |
513 iMid = (iStart + iEnd) / 2; | 513 iMid = (iStart + iEnd) / 2; |
514 buildinfunction = buildInFuncs[iMid]; | 514 buildinfunction = buildInFuncs[iMid]; |
515 if (uHash == buildinfunction.m_uHash) { | 515 if (uHash == buildinfunction.m_uHash) { |
516 funcName.Clear(); | 516 funcName.Clear(); |
517 funcName << buildinfunction.m_buildinfunc; | 517 funcName << buildinfunction.m_buildinfunc; |
518 return TRUE; | 518 return TRUE; |
519 } else if (uHash < buildinfunction.m_uHash) { | 519 } else if (uHash < buildinfunction.m_uHash) { |
520 iEnd = iMid - 1; | 520 iEnd = iMid - 1; |
521 } else { | 521 } else { |
522 iStart = iMid + 1; | 522 iStart = iMid + 1; |
523 } | 523 } |
524 } while (iStart <= iEnd); | 524 } while (iStart <= iEnd); |
525 return FALSE; | 525 return FALSE; |
526 } | 526 } |
527 FX_DWORD CXFA_FMCallExpression::IsSomMethodWithObjPara(FX_WSTR methodName) | 527 FX_DWORD CXFA_FMCallExpression::IsSomMethodWithObjPara(FX_WSTR methodName) |
528 { | 528 { |
529 FX_INT32 iLength = methodName.GetLength(); | 529 int32_t iLength = methodName.GetLength(); |
530 FX_UINT32 uHash = FX_HashCode_String_GetW(methodName.GetPtr(), iLength); | 530 uint32_t uHash = FX_HashCode_String_GetW(methodName.GetPtr(), iLength); |
531 XFA_FMSOMMethod somMethodWithObjPara; | 531 XFA_FMSOMMethod somMethodWithObjPara; |
532 FX_DWORD parameters = 0x00; | 532 FX_DWORD parameters = 0x00; |
533 FX_INT32 iStart = 0, iEnd = (sizeof(gs_FMSomMethods) / sizeof(gs_FMSomMethod
s[0])) - 1; | 533 int32_t iStart = 0, iEnd = (sizeof(gs_FMSomMethods) / sizeof(gs_FMSomMethods
[0])) - 1; |
534 FX_INT32 iMid = (iStart + iEnd) / 2; | 534 int32_t iMid = (iStart + iEnd) / 2; |
535 do { | 535 do { |
536 iMid = (iStart + iEnd) / 2; | 536 iMid = (iStart + iEnd) / 2; |
537 somMethodWithObjPara = gs_FMSomMethods[iMid]; | 537 somMethodWithObjPara = gs_FMSomMethods[iMid]; |
538 if (uHash == somMethodWithObjPara.m_uHash) { | 538 if (uHash == somMethodWithObjPara.m_uHash) { |
539 parameters = somMethodWithObjPara.m_dParameters; | 539 parameters = somMethodWithObjPara.m_dParameters; |
540 break; | 540 break; |
541 } else if (uHash < somMethodWithObjPara.m_uHash) { | 541 } else if (uHash < somMethodWithObjPara.m_uHash) { |
542 iEnd = iMid - 1; | 542 iEnd = iMid - 1; |
543 } else { | 543 } else { |
544 iStart = iMid + 1; | 544 iStart = iMid + 1; |
545 } | 545 } |
546 } while (iStart <= iEnd); | 546 } while (iStart <= iEnd); |
547 return parameters; | 547 return parameters; |
548 } | 548 } |
549 void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) | 549 void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) |
550 { | 550 { |
551 CFX_WideTextBuf funcName; | 551 CFX_WideTextBuf funcName; |
552 m_pExp->ToJavaScript(funcName); | 552 m_pExp->ToJavaScript(funcName); |
553 if (m_bIsSomMethod) { | 553 if (m_bIsSomMethod) { |
554 javascript << funcName; | 554 javascript << funcName; |
555 javascript << FX_WSTRC(L"("); | 555 javascript << FX_WSTRC(L"("); |
556 if (m_pArguments) { | 556 if (m_pArguments) { |
557 FX_INT32 argc = m_pArguments->GetSize(); | 557 int32_t argc = m_pArguments->GetSize(); |
558 FX_INT32 index = 0; | 558 int32_t index = 0; |
559 FX_DWORD methodPara = IsSomMethodWithObjPara(funcName.GetWideString(
)); | 559 FX_DWORD methodPara = IsSomMethodWithObjPara(funcName.GetWideString(
)); |
560 if (methodPara > 0) { | 560 if (methodPara > 0) { |
561 CXFA_FMSimpleExpression *e = 0; | 561 CXFA_FMSimpleExpression *e = 0; |
562 while (index < argc) { | 562 while (index < argc) { |
563 if ((methodPara & (0x01 << index)) > 0) { | 563 if ((methodPara & (0x01 << index)) > 0) { |
564 javascript << gs_lpStrExpFuncName[GETFMJSOBJ]; | 564 javascript << gs_lpStrExpFuncName[GETFMJSOBJ]; |
565 } else { | 565 } else { |
566 javascript << gs_lpStrExpFuncName[GETFMVALUE]; | 566 javascript << gs_lpStrExpFuncName[GETFMVALUE]; |
567 } | 567 } |
568 javascript << FX_WSTRC(L"("); | 568 javascript << FX_WSTRC(L"("); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 if (m_pArguments && m_pArguments->GetSize() > 0) { | 616 if (m_pArguments && m_pArguments->GetSize() > 0) { |
617 CXFA_FMSimpleExpression *e = (CXFA_FMSimpleExpression *)m_pArgum
ents->GetAt(0); | 617 CXFA_FMSimpleExpression *e = (CXFA_FMSimpleExpression *)m_pArgum
ents->GetAt(0); |
618 javascript << FX_WSTRC(L"return "); | 618 javascript << FX_WSTRC(L"return "); |
619 e->ToJavaScript(javascript); | 619 e->ToJavaScript(javascript); |
620 javascript << FX_WSTRC(L";\n}\n"); | 620 javascript << FX_WSTRC(L";\n}\n"); |
621 } else { | 621 } else { |
622 javascript << FX_WSTRC(L"return 0;\n}\n"); | 622 javascript << FX_WSTRC(L"return 0;\n}\n"); |
623 } | 623 } |
624 javascript << FX_WSTRC(L"catch(accessExceptions)\n{\nreturn 0;\n}\n}
\n).call(this)\n"); | 624 javascript << FX_WSTRC(L"catch(accessExceptions)\n{\nreturn 0;\n}\n}
\n).call(this)\n"); |
625 } else if (m_pArguments) { | 625 } else if (m_pArguments) { |
626 FX_INT32 argc = m_pArguments->GetSize(); | 626 int32_t argc = m_pArguments->GetSize(); |
627 FX_INT32 index = 0; | 627 int32_t index = 0; |
628 CXFA_FMSimpleExpression *e = 0; | 628 CXFA_FMSimpleExpression *e = 0; |
629 while (index < argc) { | 629 while (index < argc) { |
630 e = (CXFA_FMSimpleExpression *)m_pArguments->GetAt(index); | 630 e = (CXFA_FMSimpleExpression *)m_pArguments->GetAt(index); |
631 e->ToJavaScript(javascript); | 631 e->ToJavaScript(javascript); |
632 if (index + 1 < argc) { | 632 if (index + 1 < argc) { |
633 javascript << FX_WSTRC(L", "); | 633 javascript << FX_WSTRC(L", "); |
634 } | 634 } |
635 index++; | 635 index++; |
636 } | 636 } |
637 } | 637 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 javascript << FX_WSTRC(L"for(var index = accessor_object.length - 1; index >
1; index--)\n{\n"); | 749 javascript << FX_WSTRC(L"for(var index = accessor_object.length - 1; index >
1; index--)\n{\n"); |
750 javascript << FX_WSTRC(L"method_return_value = accessor_object[index]."); | 750 javascript << FX_WSTRC(L"method_return_value = accessor_object[index]."); |
751 m_pExp2->ToJavaScript(javascript); | 751 m_pExp2->ToJavaScript(javascript); |
752 javascript << FX_WSTRC(L";\n}\n}\n"); | 752 javascript << FX_WSTRC(L";\n}\n}\n"); |
753 javascript << FX_WSTRC(L"else\n{\nmethod_return_value = accessor_object."); | 753 javascript << FX_WSTRC(L"else\n{\nmethod_return_value = accessor_object."); |
754 m_pExp2->ToJavaScript(javascript); | 754 m_pExp2->ToJavaScript(javascript); |
755 javascript << FX_WSTRC(L";\n}\n"); | 755 javascript << FX_WSTRC(L";\n}\n"); |
756 javascript << FX_WSTRC(L"return method_return_value;\n"); | 756 javascript << FX_WSTRC(L"return method_return_value;\n"); |
757 javascript << FX_WSTRC(L"}\n).call(this)"); | 757 javascript << FX_WSTRC(L"}\n).call(this)"); |
758 } | 758 } |
OLD | NEW |