Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: fpdfsdk/src/javascript/JS_Value.cpp

Issue 1603173004: Merge to XFA: Bugs in CJS_PublicMethods::ParseNumber(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/javascript/JS_Value.h ('k') | fpdfsdk/src/javascript/PublicMethods.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "JS_Value.h" 7 #include "JS_Value.h"
8 8
9 #include <time.h> 9 #include <time.h>
10 #include <cmath> 10 #include <cmath>
11 #include <limits> 11 #include <limits>
12 12
13 #include "Document.h" 13 #include "Document.h"
14 #include "JS_Define.h" 14 #include "JS_Define.h"
15 #include "JS_Object.h" 15 #include "JS_Object.h"
16 16
17 static const FX_DWORD g_nan[2] = {0, 0x7FF80000}; 17 static const FX_DWORD g_nan[2] = {0, 0x7FF80000};
18 static double GetNan() { 18 static double GetNan() {
19 return *(double*)g_nan; 19 return *(double*)g_nan;
20 } 20 }
21 21
22 /* ---------------------------- CJS_Value ---------------------------- */
23
24 CJS_Value::CJS_Value(CJS_Runtime* pRuntime) 22 CJS_Value::CJS_Value(CJS_Runtime* pRuntime)
25 : m_eType(VT_unknown), m_pJSRuntime(pRuntime) { 23 : m_eType(VT_unknown), m_pJSRuntime(pRuntime) {
26 } 24 }
27 25
28 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue, Type t) 26 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue, Type t)
29 : m_eType(t), m_pValue(pValue), m_pJSRuntime(pRuntime) { 27 : m_eType(t), m_pValue(pValue), m_pJSRuntime(pRuntime) {
30 } 28 }
31 29
32 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const int& iValue) 30 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const int& iValue)
33 : m_pJSRuntime(pRuntime) { 31 : m_pJSRuntime(pRuntime) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 void CJS_Value::Attach(CJS_Value* pValue) { 89 void CJS_Value::Attach(CJS_Value* pValue) {
92 if (pValue) 90 if (pValue)
93 Attach(pValue->ToV8Value(), pValue->GetType()); 91 Attach(pValue->ToV8Value(), pValue->GetType());
94 } 92 }
95 93
96 void CJS_Value::Detach() { 94 void CJS_Value::Detach() {
97 m_pValue = v8::Local<v8::Value>(); 95 m_pValue = v8::Local<v8::Value>();
98 m_eType = VT_unknown; 96 m_eType = VT_unknown;
99 } 97 }
100 98
101 /* ----------------------------------------------------------------------------- -----------
102 */
103
104 int CJS_Value::ToInt() const { 99 int CJS_Value::ToInt() const {
105 return FXJS_ToInt32(m_pJSRuntime->GetIsolate(), m_pValue); 100 return FXJS_ToInt32(m_pJSRuntime->GetIsolate(), m_pValue);
106 } 101 }
107 102
108 bool CJS_Value::ToBool() const { 103 bool CJS_Value::ToBool() const {
109 return FXJS_ToBoolean(m_pJSRuntime->GetIsolate(), m_pValue); 104 return FXJS_ToBoolean(m_pJSRuntime->GetIsolate(), m_pValue);
110 } 105 }
111 106
112 double CJS_Value::ToDouble() const { 107 double CJS_Value::ToDouble() const {
113 return FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pValue); 108 return FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pValue);
(...skipping 25 matching lines...) Expand all
139 return m_pValue; 134 return m_pValue;
140 } 135 }
141 136
142 v8::Local<v8::Array> CJS_Value::ToV8Array() const { 137 v8::Local<v8::Array> CJS_Value::ToV8Array() const {
143 if (IsArrayObject()) 138 if (IsArrayObject())
144 return v8::Local<v8::Array>::Cast( 139 return v8::Local<v8::Array>::Cast(
145 FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue)); 140 FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue));
146 return v8::Local<v8::Array>(); 141 return v8::Local<v8::Array>();
147 } 142 }
148 143
149 /* ----------------------------------------------------------------------------- ----------- 144 void CJS_Value::MaybeCoerceToNumber() {
150 */ 145 bool bAllowNaN = false;
146 if (m_eType == VT_string) {
147 CFX_ByteString bstr = ToCFXByteString();
148 if (bstr.GetLength() == 0)
149 return;
150 if (bstr == "NaN")
151 bAllowNaN = true;
152 }
153 v8::TryCatch(m_pJSRuntime->GetIsolate());
154 v8::MaybeLocal<v8::Number> maybeNum =
155 m_pValue->ToNumber(m_pJSRuntime->GetIsolate()->GetCurrentContext());
156 if (maybeNum.IsEmpty())
157 return;
158 v8::Local<v8::Number> num = maybeNum.ToLocalChecked();
159 if (std::isnan(num->Value()) && !bAllowNaN)
160 return;
161 m_pValue = num;
162 m_eType = VT_number;
163 }
151 164
152 void CJS_Value::operator=(int iValue) { 165 void CJS_Value::operator=(int iValue) {
153 m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), iValue); 166 m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), iValue);
154 m_eType = VT_number; 167 m_eType = VT_number;
155 } 168 }
156 169
157 void CJS_Value::operator=(bool bValue) { 170 void CJS_Value::operator=(bool bValue) {
158 m_pValue = FXJS_NewBoolean(m_pJSRuntime->GetIsolate(), bValue); 171 m_pValue = FXJS_NewBoolean(m_pJSRuntime->GetIsolate(), bValue);
159 m_eType = VT_boolean; 172 m_eType = VT_boolean;
160 } 173 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 m_pValue = FXJS_NewDate(m_pJSRuntime->GetIsolate(), (double)date); 223 m_pValue = FXJS_NewDate(m_pJSRuntime->GetIsolate(), (double)date);
211 m_eType = VT_date; 224 m_eType = VT_date;
212 } 225 }
213 226
214 void CJS_Value::operator=(CJS_Value value) { 227 void CJS_Value::operator=(CJS_Value value) {
215 m_pValue = value.ToV8Value(); 228 m_pValue = value.ToV8Value();
216 m_eType = value.m_eType; 229 m_eType = value.m_eType;
217 m_pJSRuntime = value.m_pJSRuntime; 230 m_pJSRuntime = value.m_pJSRuntime;
218 } 231 }
219 232
220 /* ----------------------------------------------------------------------------- -----------
221 */
222
223 CJS_Value::Type CJS_Value::GetType() const { 233 CJS_Value::Type CJS_Value::GetType() const {
224 if (m_pValue.IsEmpty()) 234 if (m_pValue.IsEmpty())
225 return VT_unknown; 235 return VT_unknown;
226 if (m_pValue->IsString()) 236 if (m_pValue->IsString())
227 return VT_string; 237 return VT_string;
228 if (m_pValue->IsNumber()) 238 if (m_pValue->IsNumber())
229 return VT_number; 239 return VT_number;
230 if (m_pValue->IsBoolean()) 240 if (m_pValue->IsBoolean())
231 return VT_boolean; 241 return VT_boolean;
232 if (m_pValue->IsDate()) 242 if (m_pValue->IsDate())
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 return day * 86400000 + time; 872 return day * 86400000 + time;
863 } 873 }
864 874
865 bool JS_PortIsNan(double d) { 875 bool JS_PortIsNan(double d) {
866 return d != d; 876 return d != d;
867 } 877 }
868 878
869 double JS_LocalTime(double d) { 879 double JS_LocalTime(double d) {
870 return JS_GetDateTime() + _getDaylightSavingTA(d); 880 return JS_GetDateTime() + _getDaylightSavingTA(d);
871 } 881 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_Value.h ('k') | fpdfsdk/src/javascript/PublicMethods.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698