summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript/util.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-04-23 11:23:10 -0700
committerTom Sepez <tsepez@chromium.org>2015-04-23 11:23:10 -0700
commite4fde52cc2c827e637c96e8e1f76ba4644cf718a (patch)
tree01208f95d013429d2682a228577880a64ae1845b /fpdfsdk/src/javascript/util.cpp
parent4eeef1d776ce7368063f9a7698cfa736821d4186 (diff)
downloadpdfium-e4fde52cc2c827e637c96e8e1f76ba4644cf718a.tar.xz
Kill overloaded cast operators in CJS_Value.
The red-flag here is the explicit invocation of things like params[1].operator CFX_WideString() rather than static_cast<CFX_WideString>(params[1]) to invoke the conversion. Turns out the above won't compile due to ambiguity given the number of implicit constructors for widestrings. CJS_Value has both constructors and assignment operators for the primitive types, which means that conversions can take place unexpectedly in both directions, a second red flag. We don't want the compiler invoking these at will since it may hide bugs. In fact, when they are removed, three such places were discovered. Also rename ToJSValue to ToV8Value to match the other ToV8xxxxx functions added. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1096813008
Diffstat (limited to 'fpdfsdk/src/javascript/util.cpp')
-rw-r--r--fpdfsdk/src/javascript/util.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/fpdfsdk/src/javascript/util.cpp b/fpdfsdk/src/javascript/util.cpp
index 0ac98ddbac..6898d0c1a2 100644
--- a/fpdfsdk/src/javascript/util.cpp
+++ b/fpdfsdk/src/javascript/util.cpp
@@ -142,7 +142,7 @@ FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
int iSize = params.size();
if (iSize < 1)
return FALSE;
- std::wstring c_ConvChar((const wchar_t*)(FX_LPCWSTR)params[0].operator CFX_WideString());
+ std::wstring c_ConvChar(params[0].ToCFXWideString().c_str());
std::vector<std::wstring> c_strConvers;
int iOffset = 0;
int iOffend = 0;
@@ -182,13 +182,13 @@ FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
switch (ParstDataType(&c_strFormat))
{
case UTIL_INT:
- strSegment.Format(c_strFormat.c_str(),(int)params[iIndex]);
+ strSegment.Format(c_strFormat.c_str(), params[iIndex].ToInt());
break;
case UTIL_DOUBLE:
- strSegment.Format(c_strFormat.c_str(),(double)params[iIndex]);
+ strSegment.Format(c_strFormat.c_str(), params[iIndex].ToDouble());
break;
case UTIL_STRING:
- strSegment.Format(c_strFormat.c_str(),(FX_LPCWSTR)params[iIndex].operator CFX_WideString());
+ strSegment.Format(c_strFormat.c_str(), params[iIndex].ToCFXWideString().c_str());
break;
default:
strSegment.Format(L"%S", c_strFormat.c_str());
@@ -229,8 +229,7 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
if (p1.GetType() == VT_number)
{
- int nFormat = p1;
-
+ int nFormat = p1.ToInt();
CFX_WideString swResult;
switch (nFormat)
@@ -271,13 +270,12 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
}
else if (p1.GetType() == VT_string)
{
- std::basic_string<wchar_t> cFormat = (FX_LPCWSTR)p1.operator CFX_WideString();
+ std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str();
bool bXFAPicture = false;
if (iSize > 2)
{
- //CJS_Value value;
- bXFAPicture = params[2];
+ bXFAPicture = params[2].ToBool();
}
if (bXFAPicture)
@@ -467,8 +465,8 @@ FX_BOOL util::printx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
int iSize = params.size();
if (iSize<2)
return FALSE;
- CFX_WideString sFormat = params[0].operator CFX_WideString();
- CFX_WideString sSource = params[1].operator CFX_WideString();
+ CFX_WideString sFormat = params[0].ToCFXWideString();
+ CFX_WideString sSource = params[1].ToCFXWideString();
std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str();
std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str();
std::string cDest;
@@ -582,9 +580,9 @@ FX_BOOL util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
int iSize = params.size();
if (iSize < 2)
return FALSE;
- CFX_WideString sFormat = params[0].operator CFX_WideString();
- CFX_WideString sDate = params[1].operator CFX_WideString();
+ CFX_WideString sFormat = params[0].ToCFXWideString();
+ CFX_WideString sDate = params[1].ToCFXWideString();
double dDate = JS_GetDateTime();
if (sDate.GetLength() > 0)
{
@@ -638,7 +636,7 @@ FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va
int iSize = params.size();
if (iSize == 0)
return FALSE;
- int nByte = (int)params[0];
+ int nByte = params[0].ToInt();
unsigned char cByte = (unsigned char)nByte;
CFX_WideString csValue;
csValue.Format(L"%c", cByte);