From e4fde52cc2c827e637c96e8e1f76ba4644cf718a Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 23 Apr 2015 11:23:10 -0700 Subject: 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(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 --- fpdfsdk/src/javascript/util.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'fpdfsdk/src/javascript/util.cpp') 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 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 cFormat = (FX_LPCWSTR)p1.operator CFX_WideString(); + std::basic_string 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); -- cgit v1.2.3