Пример #1
0
void CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
  javascript << RUNTIMEFUNCTIONRETURNVALUE;
  javascript << FX_WSTRC(L" = 0;\n");
  javascript << FX_WSTRC(L"{\n");
  javascript << FX_WSTRC(L"var ");
  if (m_wsIdentifier.GetAt(0) == L'!') {
    CFX_WideString tempIdentifier =
        EXCLAMATION_IN_IDENTIFIER + m_wsIdentifier.Mid(1);
    javascript << tempIdentifier;
  } else {
    javascript << m_wsIdentifier;
  }
  javascript << FX_WSTRC(L" = null;\n");
  javascript << FX_WSTRC(L"var ");
  javascript << RUNTIMEBLOCKTEMPARRAY;
  javascript << FX_WSTRC(L" = ");
  javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT);
  javascript << FX_WSTRC(L"(");
  int32_t iSize = m_pAccessors->GetSize();
  int32_t index = 0;
  CXFA_FMSimpleExpression* s = 0;
  while (index < iSize) {
    s = (CXFA_FMSimpleExpression*)m_pAccessors->GetAt(index);
    s->ToJavaScript(javascript);
    if (index + 1 < iSize) {
      javascript << FX_WSTRC(L", ");
    }
    index++;
  }
  s = 0;
  javascript << FX_WSTRC(L");\n");
  javascript << FX_WSTRC(L"var ");
  javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
  javascript << FX_WSTRC(L" = 0;\n");
  javascript << FX_WSTRC(L"while(");
  javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
  javascript << FX_WSTRC(L" < ");
  javascript << RUNTIMEBLOCKTEMPARRAY;
  javascript << FX_WSTRC(L".length)\n{\n");
  if (m_wsIdentifier.GetAt(0) == L'!') {
    CFX_WideString tempIdentifier =
        EXCLAMATION_IN_IDENTIFIER + m_wsIdentifier.Mid(1);
    javascript << tempIdentifier;
  } else {
    javascript << m_wsIdentifier;
  }
  javascript << FX_WSTRC(L" = ");
  javascript << RUNTIMEBLOCKTEMPARRAY;
  javascript << FX_WSTRC(L"[");
  javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
  javascript << FX_WSTRC(L"++];\n");
  m_pList->ToImpliedReturnJS(javascript);
  javascript << FX_WSTRC(L"}\n");
  javascript << FX_WSTRC(L"}\n");
}
Пример #2
0
void CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
  javascript << FX_WSTRC(L"{\n");
  javascript << FX_WSTRC(L"var ");
  if (m_wsIdentifier.GetAt(0) == L'!') {
    CFX_WideString tempIdentifier =
        EXCLAMATION_IN_IDENTIFIER + m_wsIdentifier.Mid(1);
    javascript << tempIdentifier;
  } else {
    javascript << m_wsIdentifier;
  }
  javascript << FX_WSTRC(L" = null;\n");
  javascript << FX_WSTRC(L"var ");
  javascript << RUNTIMEBLOCKTEMPARRAY;
  javascript << FX_WSTRC(L" = ");
  javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT);
  javascript << FX_WSTRC(L"(");

  for (int i = 0; i < m_pAccessors->GetSize(); ++i) {
    CXFA_FMSimpleExpression* s =
        reinterpret_cast<CXFA_FMSimpleExpression*>(m_pAccessors->GetAt(i));
    s->ToJavaScript(javascript);
    if (i + 1 < m_pAccessors->GetSize()) {
      javascript << FX_WSTRC(L", ");
    }
  }
  javascript << FX_WSTRC(L");\n");
  javascript << FX_WSTRC(L"var ");
  javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
  javascript << FX_WSTRC(L" = 0;\n");
  javascript << FX_WSTRC(L"while(");
  javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
  javascript << FX_WSTRC(L" < ");
  javascript << RUNTIMEBLOCKTEMPARRAY;
  javascript << FX_WSTRC(L".length)\n{\n");
  if (m_wsIdentifier.GetAt(0) == L'!') {
    CFX_WideString tempIdentifier =
        EXCLAMATION_IN_IDENTIFIER + m_wsIdentifier.Mid(1);
    javascript << tempIdentifier;
  } else {
    javascript << m_wsIdentifier;
  }
  javascript << FX_WSTRC(L" = ");
  javascript << RUNTIMEBLOCKTEMPARRAY;
  javascript << FX_WSTRC(L"[");
  javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
  javascript << FX_WSTRC(L"++];\n");
  m_pList->ToJavaScript(javascript);
  javascript << FX_WSTRC(L"}\n");
  javascript << FX_WSTRC(L"}\n");
}
Пример #3
0
void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
  CFX_WideTextBuf funcName;
  m_pExp->ToJavaScript(funcName);
  if (m_bIsSomMethod) {
    javascript << funcName;
    javascript << FX_WSTRC(L"(");
    if (m_pArguments) {
      uint32_t methodPara = IsMethodWithObjParam(funcName.AsStringC());
      if (methodPara > 0) {
        for (int i = 0; i < m_pArguments->GetSize(); ++i) {
          // Currently none of our expressions use objects for a parameter over
          // the 6th. Make sure we don't overflow the shift when doing this
          // check. If we ever need more the 32 object params we can revisit.
          if (i < 32 && (methodPara & (0x01 << i)) > 0) {
            javascript << gs_lpStrExpFuncName[GETFMJSOBJ];
          } else {
            javascript << gs_lpStrExpFuncName[GETFMVALUE];
          }
          javascript << FX_WSTRC(L"(");
          CXFA_FMSimpleExpression* e = m_pArguments->GetAt(i);
          e->ToJavaScript(javascript);
          javascript << FX_WSTRC(L")");
          if (i + 1 < m_pArguments->GetSize()) {
            javascript << FX_WSTRC(L", ");
          }
        }
      } else {
        for (int i = 0; i < m_pArguments->GetSize(); ++i) {
          javascript << gs_lpStrExpFuncName[GETFMVALUE];
          javascript << FX_WSTRC(L"(");
          CXFA_FMSimpleExpression* e = m_pArguments->GetAt(i);
          e->ToJavaScript(javascript);
          javascript << FX_WSTRC(L")");
          if (i + 1 < m_pArguments->GetSize()) {
            javascript << FX_WSTRC(L", ");
          }
        }
      }
    }
    javascript << FX_WSTRC(L")");
  } else {
    bool isEvalFunc = false;
    bool isExistsFunc = false;
    if (IsBuildInFunc(&funcName)) {
      if (funcName.AsStringC() == FX_WSTRC(L"Eval")) {
        isEvalFunc = true;
        javascript << FX_WSTRC(L"eval.call(this, ");
        javascript << gs_lpStrExpFuncName[CALL];
        javascript << FX_WSTRC(L"Translate");
      } else if (funcName.AsStringC() == FX_WSTRC(L"Exists")) {
        isExistsFunc = true;
        javascript << gs_lpStrExpFuncName[CALL];
        javascript << funcName;
      } else {
        javascript << gs_lpStrExpFuncName[CALL];
        javascript << funcName;
      }
    } else {
      javascript << funcName;
    }
    javascript << FX_WSTRC(L"(");
    if (isExistsFunc) {
      javascript << FX_WSTRC(L"\n(\nfunction ()\n{\ntry\n{\n");
      if (m_pArguments && m_pArguments->GetSize() > 0) {
        CXFA_FMSimpleExpression* e = m_pArguments->GetAt(0);
        javascript << FX_WSTRC(L"return ");
        e->ToJavaScript(javascript);
        javascript << FX_WSTRC(L";\n}\n");
      } else {
        javascript << FX_WSTRC(L"return 0;\n}\n");
      }
      javascript << FX_WSTRC(
          L"catch(accessExceptions)\n{\nreturn 0;\n}\n}\n).call(this)\n");
    } else if (m_pArguments) {
      for (int i = 0; i < m_pArguments->GetSize(); ++i) {
        CXFA_FMSimpleExpression* e = m_pArguments->GetAt(i);
        e->ToJavaScript(javascript);
        if (i + 1 < m_pArguments->GetSize()) {
          javascript << FX_WSTRC(L", ");
        }
      }
    }
    javascript << FX_WSTRC(L")");
    if (isEvalFunc) {
      javascript << FX_WSTRC(L")");
    }
  }
}