diff options
author | tsepez <tsepez@chromium.org> | 2016-03-29 09:21:54 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-29 09:21:54 -0700 |
commit | 90d87793cf55f3c4e57e9db6c8de692ebef41e29 (patch) | |
tree | dab4c366cabd24503fee99005f9f336a128c87fb /fpdfsdk | |
parent | 41a53ad771411db3cdd98822f9d240456767fba8 (diff) | |
download | pdfium-90d87793cf55f3c4e57e9db6c8de692ebef41e29.tar.xz |
Add test for util.byteToChar() and fix error msg.
Review URL: https://codereview.chromium.org/1838543002
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/javascript/util.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp index f7b2d7fbfa..0f50daf38c 100644 --- a/fpdfsdk/javascript/util.cpp +++ b/fpdfsdk/javascript/util.cpp @@ -446,13 +446,17 @@ FX_BOOL util::byteToChar(IJS_Context* cc, const std::vector<CJS_Value>& params, CJS_Value& vRet, CFX_WideString& sError) { - int iSize = params.size(); - if (iSize == 0) + CJS_Context* pContext = static_cast<CJS_Context*>(cc); + if (params.size() < 1) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } + int arg = params[0].ToInt(); + if (arg < 0 || arg > 255) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); return FALSE; - int nByte = params[0].ToInt(); - unsigned char cByte = (unsigned char)nByte; - CFX_WideString csValue; - csValue.Format(L"%c", cByte); - vRet = csValue.c_str(); + } + CFX_WideString wStr(static_cast<FX_WCHAR>(arg)); + vRet = wStr.c_str(); return TRUE; } |