summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript/util.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-03-29 09:21:54 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-29 09:21:54 -0700
commit90d87793cf55f3c4e57e9db6c8de692ebef41e29 (patch)
treedab4c366cabd24503fee99005f9f336a128c87fb /fpdfsdk/javascript/util.cpp
parent41a53ad771411db3cdd98822f9d240456767fba8 (diff)
downloadpdfium-90d87793cf55f3c4e57e9db6c8de692ebef41e29.tar.xz
Add test for util.byteToChar() and fix error msg.
Review URL: https://codereview.chromium.org/1838543002
Diffstat (limited to 'fpdfsdk/javascript/util.cpp')
-rw-r--r--fpdfsdk/javascript/util.cpp18
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;
}