diff options
author | Tom Sepez <tsepez@chromium.org> | 2016-01-20 11:48:29 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2016-01-20 11:48:29 -0800 |
commit | 4246b0015732d7611ad6838b76b85161fab3795e (patch) | |
tree | 97591bdfa54a443abd025943788af65a9a82291f /fpdfsdk/src/javascript/JS_Value.cpp | |
parent | c4fd5c183142aef5ae93b918b65a0bf01d2a0a1e (diff) | |
download | pdfium-4246b0015732d7611ad6838b76b85161fab3795e.tar.xz |
Merge to XFA: Bugs in CJS_PublicMethods::ParseNumber().
Original Review URL: https://codereview.chromium.org/1586203006 .
(cherry picked from commit f13d510cf267c27f4c123494de67670ec201cedc)
BUG=pdfium:361
R=ochang@chromium.org
TBR=ochang@chromium.org
Review URL: https://codereview.chromium.org/1603173004 .
Diffstat (limited to 'fpdfsdk/src/javascript/JS_Value.cpp')
-rw-r--r-- | fpdfsdk/src/javascript/JS_Value.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/fpdfsdk/src/javascript/JS_Value.cpp b/fpdfsdk/src/javascript/JS_Value.cpp index bd00adcf49..cfa565e4d4 100644 --- a/fpdfsdk/src/javascript/JS_Value.cpp +++ b/fpdfsdk/src/javascript/JS_Value.cpp @@ -19,8 +19,6 @@ static double GetNan() { return *(double*)g_nan; } -/* ---------------------------- CJS_Value ---------------------------- */ - CJS_Value::CJS_Value(CJS_Runtime* pRuntime) : m_eType(VT_unknown), m_pJSRuntime(pRuntime) { } @@ -98,9 +96,6 @@ void CJS_Value::Detach() { m_eType = VT_unknown; } -/* ---------------------------------------------------------------------------------------- - */ - int CJS_Value::ToInt() const { return FXJS_ToInt32(m_pJSRuntime->GetIsolate(), m_pValue); } @@ -146,8 +141,26 @@ v8::Local<v8::Array> CJS_Value::ToV8Array() const { return v8::Local<v8::Array>(); } -/* ---------------------------------------------------------------------------------------- - */ +void CJS_Value::MaybeCoerceToNumber() { + bool bAllowNaN = false; + if (m_eType == VT_string) { + CFX_ByteString bstr = ToCFXByteString(); + if (bstr.GetLength() == 0) + return; + if (bstr == "NaN") + bAllowNaN = true; + } + v8::TryCatch(m_pJSRuntime->GetIsolate()); + v8::MaybeLocal<v8::Number> maybeNum = + m_pValue->ToNumber(m_pJSRuntime->GetIsolate()->GetCurrentContext()); + if (maybeNum.IsEmpty()) + return; + v8::Local<v8::Number> num = maybeNum.ToLocalChecked(); + if (std::isnan(num->Value()) && !bAllowNaN) + return; + m_pValue = num; + m_eType = VT_number; +} void CJS_Value::operator=(int iValue) { m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), iValue); @@ -217,9 +230,6 @@ void CJS_Value::operator=(CJS_Value value) { m_pJSRuntime = value.m_pJSRuntime; } -/* ---------------------------------------------------------------------------------------- - */ - CJS_Value::Type CJS_Value::GetType() const { if (m_pValue.IsEmpty()) return VT_unknown; |