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

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

Issue 2245863002: Push v8::Isolate into CFXJS_Engine class (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Null isolate before letting CFXJS_Engine dtor invoked Created 4 years, 4 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/javascript/JS_Value.h ('k') | fpdfsdk/javascript/PublicMethods.cpp » ('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 "fpdfsdk/javascript/JS_Value.h" 7 #include "fpdfsdk/javascript/JS_Value.h"
8 8
9 #include <time.h> 9 #include <time.h>
10 10
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 33
34 } // namespace 34 } // namespace
35 35
36 CJS_Value::CJS_Value(CJS_Runtime* pRuntime) {} 36 CJS_Value::CJS_Value(CJS_Runtime* pRuntime) {}
37 37
38 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue) 38 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue)
39 : m_pValue(pValue) {} 39 : m_pValue(pValue) {}
40 40
41 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const int& iValue) 41 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const int& iValue)
42 : m_pValue(FXJS_NewNumber(pRuntime->GetIsolate(), iValue)) {} 42 : m_pValue(pRuntime->NewNumber(iValue)) {}
43 43
44 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const bool& bValue) 44 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const bool& bValue)
45 : m_pValue(FXJS_NewBoolean(pRuntime->GetIsolate(), bValue)) {} 45 : m_pValue(pRuntime->NewBoolean(bValue)) {}
46 46
47 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const float& fValue) 47 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const float& fValue)
48 : m_pValue(FXJS_NewNumber(pRuntime->GetIsolate(), fValue)) {} 48 : m_pValue(pRuntime->NewNumber(fValue)) {}
49 49
50 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const double& dValue) 50 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const double& dValue)
51 : m_pValue(FXJS_NewNumber(pRuntime->GetIsolate(), dValue)) {} 51 : m_pValue(pRuntime->NewNumber(dValue)) {}
52 52
53 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Object* pObj) { 53 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Object* pObj) {
54 if (pObj) 54 if (pObj)
55 m_pValue = pObj->ToV8Object(); 55 m_pValue = pObj->ToV8Object();
56 } 56 }
57 57
58 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr) 58 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr)
59 : m_pValue(FXJS_NewString(pRuntime->GetIsolate(), (wchar_t*)pWstr)) {} 59 : m_pValue(pRuntime->NewString(pWstr)) {}
60 60
61 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr) 61 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr)
62 : m_pValue(FXJS_NewString(pRuntime->GetIsolate(), 62 : m_pValue(pRuntime->NewString(CFX_WideString::FromLocal(pStr).c_str())) {}
63 CFX_WideString::FromLocal(pStr).c_str())) {}
64 63
65 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const CJS_Array& array) 64 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const CJS_Array& array)
66 : m_pValue(array.ToV8Array(pRuntime->GetIsolate())) {} 65 : m_pValue(array.ToV8Array(pRuntime)) {}
67 66
68 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const CJS_Date& date) 67 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const CJS_Date& date)
69 : m_pValue(date.ToV8Date(pRuntime->GetIsolate())) {} 68 : m_pValue(date.ToV8Date(pRuntime)) {}
70 69
71 CJS_Value::~CJS_Value() {} 70 CJS_Value::~CJS_Value() {}
72 71
73 CJS_Value::CJS_Value(const CJS_Value& other) = default; 72 CJS_Value::CJS_Value(const CJS_Value& other) = default;
74 73
75 void CJS_Value::Attach(v8::Local<v8::Value> pValue) { 74 void CJS_Value::Attach(v8::Local<v8::Value> pValue) {
76 m_pValue = pValue; 75 m_pValue = pValue;
77 } 76 }
78 77
79 void CJS_Value::Detach() { 78 void CJS_Value::Detach() {
80 m_pValue = v8::Local<v8::Value>(); 79 m_pValue = v8::Local<v8::Value>();
81 } 80 }
82 81
83 int CJS_Value::ToInt(v8::Isolate* pIsolate) const { 82 int CJS_Value::ToInt(CJS_Runtime* pRuntime) const {
84 return FXJS_ToInt32(pIsolate, m_pValue); 83 return pRuntime->ToInt32(m_pValue);
85 } 84 }
86 85
87 bool CJS_Value::ToBool(v8::Isolate* pIsolate) const { 86 bool CJS_Value::ToBool(CJS_Runtime* pRuntime) const {
88 return FXJS_ToBoolean(pIsolate, m_pValue); 87 return pRuntime->ToBoolean(m_pValue);
89 } 88 }
90 89
91 double CJS_Value::ToDouble(v8::Isolate* pIsolate) const { 90 double CJS_Value::ToDouble(CJS_Runtime* pRuntime) const {
92 return FXJS_ToNumber(pIsolate, m_pValue); 91 return pRuntime->ToNumber(m_pValue);
93 } 92 }
94 93
95 float CJS_Value::ToFloat(v8::Isolate* pIsolate) const { 94 float CJS_Value::ToFloat(CJS_Runtime* pRuntime) const {
96 return (float)ToDouble(pIsolate); 95 return (float)ToDouble(pRuntime);
97 } 96 }
98 97
99 CJS_Object* CJS_Value::ToCJSObject(v8::Isolate* pIsolate) const { 98 CJS_Object* CJS_Value::ToCJSObject(CJS_Runtime* pRuntime) const {
100 v8::Local<v8::Object> pObj = FXJS_ToObject(pIsolate, m_pValue); 99 v8::Local<v8::Object> pObj = pRuntime->ToObject(m_pValue);
101 return (CJS_Object*)FXJS_GetPrivate(pIsolate, pObj); 100 return static_cast<CJS_Object*>(pRuntime->GetObjectPrivate(pObj));
102 } 101 }
103 102
104 v8::Local<v8::Object> CJS_Value::ToV8Object(v8::Isolate* pIsolate) const { 103 v8::Local<v8::Object> CJS_Value::ToV8Object(CJS_Runtime* pRuntime) const {
105 return FXJS_ToObject(pIsolate, m_pValue); 104 return pRuntime->ToObject(m_pValue);
106 } 105 }
107 106
108 CFX_WideString CJS_Value::ToCFXWideString(v8::Isolate* pIsolate) const { 107 CFX_WideString CJS_Value::ToCFXWideString(CJS_Runtime* pRuntime) const {
109 return FXJS_ToString(pIsolate, m_pValue); 108 return pRuntime->ToString(m_pValue);
110 } 109 }
111 110
112 CFX_ByteString CJS_Value::ToCFXByteString(v8::Isolate* pIsolate) const { 111 CFX_ByteString CJS_Value::ToCFXByteString(CJS_Runtime* pRuntime) const {
113 return CFX_ByteString::FromUnicode(ToCFXWideString(pIsolate)); 112 return CFX_ByteString::FromUnicode(ToCFXWideString(pRuntime));
114 } 113 }
115 114
116 v8::Local<v8::Value> CJS_Value::ToV8Value(v8::Isolate* pIsolate) const { 115 v8::Local<v8::Value> CJS_Value::ToV8Value(CJS_Runtime* pRuntime) const {
117 return m_pValue; 116 return m_pValue;
118 } 117 }
119 118
120 v8::Local<v8::Array> CJS_Value::ToV8Array(v8::Isolate* pIsolate) const { 119 v8::Local<v8::Array> CJS_Value::ToV8Array(CJS_Runtime* pRuntime) const {
121 if (IsArrayObject()) 120 if (IsArrayObject())
122 return v8::Local<v8::Array>::Cast(FXJS_ToObject(pIsolate, m_pValue)); 121 return v8::Local<v8::Array>::Cast(pRuntime->ToObject(m_pValue));
123 return v8::Local<v8::Array>(); 122 return v8::Local<v8::Array>();
124 } 123 }
125 124
126 void CJS_Value::SetNull(CJS_Runtime* pRuntime) { 125 void CJS_Value::SetNull(CJS_Runtime* pRuntime) {
127 m_pValue = FXJS_NewNull(pRuntime->GetIsolate()); 126 m_pValue = pRuntime->NewNull();
128 } 127 }
129 128
130 void CJS_Value::MaybeCoerceToNumber(v8::Isolate* pIsolate) { 129 void CJS_Value::MaybeCoerceToNumber(CJS_Runtime* pRuntime) {
131 bool bAllowNaN = false; 130 bool bAllowNaN = false;
132 if (GetType() == VT_string) { 131 if (GetType() == VT_string) {
133 CFX_ByteString bstr = ToCFXByteString(pIsolate); 132 CFX_ByteString bstr = ToCFXByteString(pRuntime);
134 if (bstr.GetLength() == 0) 133 if (bstr.GetLength() == 0)
135 return; 134 return;
136 if (bstr == "NaN") 135 if (bstr == "NaN")
137 bAllowNaN = true; 136 bAllowNaN = true;
138 } 137 }
138 v8::Isolate* pIsolate = pRuntime->GetIsolate();
139 v8::TryCatch try_catch(pIsolate); 139 v8::TryCatch try_catch(pIsolate);
140 v8::MaybeLocal<v8::Number> maybeNum = 140 v8::MaybeLocal<v8::Number> maybeNum =
141 m_pValue->ToNumber(pIsolate->GetCurrentContext()); 141 m_pValue->ToNumber(pIsolate->GetCurrentContext());
142 if (maybeNum.IsEmpty()) 142 if (maybeNum.IsEmpty())
143 return; 143 return;
144 v8::Local<v8::Number> num = maybeNum.ToLocalChecked(); 144 v8::Local<v8::Number> num = maybeNum.ToLocalChecked();
145 if (std::isnan(num->Value()) && !bAllowNaN) 145 if (std::isnan(num->Value()) && !bAllowNaN)
146 return; 146 return;
147 m_pValue = num; 147 m_pValue = num;
148 } 148 }
(...skipping 20 matching lines...) Expand all
169 } 169 }
170 170
171 bool CJS_Value::IsArrayObject() const { 171 bool CJS_Value::IsArrayObject() const {
172 return !m_pValue.IsEmpty() && m_pValue->IsArray(); 172 return !m_pValue.IsEmpty() && m_pValue->IsArray();
173 } 173 }
174 174
175 bool CJS_Value::IsDateObject() const { 175 bool CJS_Value::IsDateObject() const {
176 return !m_pValue.IsEmpty() && m_pValue->IsDate(); 176 return !m_pValue.IsEmpty() && m_pValue->IsDate();
177 } 177 }
178 178
179 bool CJS_Value::ConvertToArray(v8::Isolate* pIsolate, CJS_Array& array) const { 179 bool CJS_Value::ConvertToArray(CJS_Runtime* pRuntime, CJS_Array& array) const {
180 if (!IsArrayObject()) 180 if (!IsArrayObject())
181 return false; 181 return false;
182 array.Attach(FXJS_ToArray(pIsolate, m_pValue)); 182 array.Attach(pRuntime->ToArray(m_pValue));
183 return true; 183 return true;
184 } 184 }
185 185
186 bool CJS_Value::ConvertToDate(v8::Isolate* pIsolate, CJS_Date& date) const { 186 bool CJS_Value::ConvertToDate(CJS_Runtime* pRuntime, CJS_Date& date) const {
187 if (!IsDateObject()) 187 if (!IsDateObject())
188 return false; 188 return false;
189 v8::Local<v8::Value> mutable_value = m_pValue; 189 v8::Local<v8::Value> mutable_value = m_pValue;
190 date.Attach(mutable_value.As<v8::Date>()); 190 date.Attach(mutable_value.As<v8::Date>());
191 return true; 191 return true;
192 } 192 }
193 193
194 CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime) 194 CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime)
195 : m_bIsSetting(0), m_Value(pRuntime), m_pJSRuntime(pRuntime) {} 195 : m_bIsSetting(0), m_Value(pRuntime), m_pJSRuntime(pRuntime) {}
196 196
197 CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime, const CJS_Value& value) 197 CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime, const CJS_Value& value)
198 : m_bIsSetting(0), m_Value(value), m_pJSRuntime(pRuntime) {} 198 : m_bIsSetting(0), m_Value(value), m_pJSRuntime(pRuntime) {}
199 199
200 CJS_PropValue::~CJS_PropValue() {} 200 CJS_PropValue::~CJS_PropValue() {}
201 201
202 void CJS_PropValue::operator<<(int iValue) { 202 void CJS_PropValue::operator<<(int iValue) {
203 ASSERT(!m_bIsSetting); 203 ASSERT(!m_bIsSetting);
204 m_Value = CJS_Value(m_pJSRuntime, iValue); 204 m_Value = CJS_Value(m_pJSRuntime, iValue);
205 } 205 }
206 206
207 void CJS_PropValue::operator>>(int& iValue) const { 207 void CJS_PropValue::operator>>(int& iValue) const {
208 ASSERT(m_bIsSetting); 208 ASSERT(m_bIsSetting);
209 iValue = m_Value.ToInt(m_pJSRuntime->GetIsolate()); 209 iValue = m_Value.ToInt(m_pJSRuntime);
210 } 210 }
211 211
212 void CJS_PropValue::operator<<(bool bValue) { 212 void CJS_PropValue::operator<<(bool bValue) {
213 ASSERT(!m_bIsSetting); 213 ASSERT(!m_bIsSetting);
214 m_Value = CJS_Value(m_pJSRuntime, bValue); 214 m_Value = CJS_Value(m_pJSRuntime, bValue);
215 } 215 }
216 216
217 void CJS_PropValue::operator>>(bool& bValue) const { 217 void CJS_PropValue::operator>>(bool& bValue) const {
218 ASSERT(m_bIsSetting); 218 ASSERT(m_bIsSetting);
219 bValue = m_Value.ToBool(m_pJSRuntime->GetIsolate()); 219 bValue = m_Value.ToBool(m_pJSRuntime);
220 } 220 }
221 221
222 void CJS_PropValue::operator<<(double dValue) { 222 void CJS_PropValue::operator<<(double dValue) {
223 ASSERT(!m_bIsSetting); 223 ASSERT(!m_bIsSetting);
224 m_Value = CJS_Value(m_pJSRuntime, dValue); 224 m_Value = CJS_Value(m_pJSRuntime, dValue);
225 } 225 }
226 226
227 void CJS_PropValue::operator>>(double& dValue) const { 227 void CJS_PropValue::operator>>(double& dValue) const {
228 ASSERT(m_bIsSetting); 228 ASSERT(m_bIsSetting);
229 dValue = m_Value.ToDouble(m_pJSRuntime->GetIsolate()); 229 dValue = m_Value.ToDouble(m_pJSRuntime);
230 } 230 }
231 231
232 void CJS_PropValue::operator<<(CJS_Object* pObj) { 232 void CJS_PropValue::operator<<(CJS_Object* pObj) {
233 ASSERT(!m_bIsSetting); 233 ASSERT(!m_bIsSetting);
234 m_Value = CJS_Value(m_pJSRuntime, pObj); 234 m_Value = CJS_Value(m_pJSRuntime, pObj);
235 } 235 }
236 236
237 void CJS_PropValue::operator>>(CJS_Object*& ppObj) const { 237 void CJS_PropValue::operator>>(CJS_Object*& ppObj) const {
238 ASSERT(m_bIsSetting); 238 ASSERT(m_bIsSetting);
239 ppObj = m_Value.ToCJSObject(m_pJSRuntime->GetIsolate()); 239 ppObj = m_Value.ToCJSObject(m_pJSRuntime);
240 } 240 }
241 241
242 void CJS_PropValue::operator<<(CJS_Document* pJsDoc) { 242 void CJS_PropValue::operator<<(CJS_Document* pJsDoc) {
243 ASSERT(!m_bIsSetting); 243 ASSERT(!m_bIsSetting);
244 m_Value = CJS_Value(m_pJSRuntime, pJsDoc); 244 m_Value = CJS_Value(m_pJSRuntime, pJsDoc);
245 } 245 }
246 246
247 void CJS_PropValue::operator>>(CJS_Document*& ppJsDoc) const { 247 void CJS_PropValue::operator>>(CJS_Document*& ppJsDoc) const {
248 ASSERT(m_bIsSetting); 248 ASSERT(m_bIsSetting);
249 ppJsDoc = static_cast<CJS_Document*>( 249 ppJsDoc = static_cast<CJS_Document*>(m_Value.ToCJSObject(m_pJSRuntime));
250 m_Value.ToCJSObject(m_pJSRuntime->GetIsolate()));
251 } 250 }
252 251
253 void CJS_PropValue::operator<<(v8::Local<v8::Object> pObj) { 252 void CJS_PropValue::operator<<(v8::Local<v8::Object> pObj) {
254 ASSERT(!m_bIsSetting); 253 ASSERT(!m_bIsSetting);
255 m_Value = CJS_Value(m_pJSRuntime, pObj); 254 m_Value = CJS_Value(m_pJSRuntime, pObj);
256 } 255 }
257 256
258 void CJS_PropValue::operator>>(v8::Local<v8::Object>& ppObj) const { 257 void CJS_PropValue::operator>>(v8::Local<v8::Object>& ppObj) const {
259 ASSERT(m_bIsSetting); 258 ASSERT(m_bIsSetting);
260 ppObj = m_Value.ToV8Object(m_pJSRuntime->GetIsolate()); 259 ppObj = m_Value.ToV8Object(m_pJSRuntime);
261 } 260 }
262 261
263 void CJS_PropValue::operator<<(CFX_ByteString str) { 262 void CJS_PropValue::operator<<(CFX_ByteString str) {
264 ASSERT(!m_bIsSetting); 263 ASSERT(!m_bIsSetting);
265 m_Value = CJS_Value(m_pJSRuntime, str.c_str()); 264 m_Value = CJS_Value(m_pJSRuntime, str.c_str());
266 } 265 }
267 266
268 void CJS_PropValue::operator>>(CFX_ByteString& str) const { 267 void CJS_PropValue::operator>>(CFX_ByteString& str) const {
269 ASSERT(m_bIsSetting); 268 ASSERT(m_bIsSetting);
270 str = m_Value.ToCFXByteString(m_pJSRuntime->GetIsolate()); 269 str = m_Value.ToCFXByteString(m_pJSRuntime);
271 } 270 }
272 271
273 void CJS_PropValue::operator<<(const FX_WCHAR* str) { 272 void CJS_PropValue::operator<<(const FX_WCHAR* str) {
274 ASSERT(!m_bIsSetting); 273 ASSERT(!m_bIsSetting);
275 m_Value = CJS_Value(m_pJSRuntime, str); 274 m_Value = CJS_Value(m_pJSRuntime, str);
276 } 275 }
277 276
278 void CJS_PropValue::operator>>(CFX_WideString& wide_string) const { 277 void CJS_PropValue::operator>>(CFX_WideString& wide_string) const {
279 ASSERT(m_bIsSetting); 278 ASSERT(m_bIsSetting);
280 wide_string = m_Value.ToCFXWideString(m_pJSRuntime->GetIsolate()); 279 wide_string = m_Value.ToCFXWideString(m_pJSRuntime);
281 } 280 }
282 281
283 void CJS_PropValue::operator<<(CFX_WideString wide_string) { 282 void CJS_PropValue::operator<<(CFX_WideString wide_string) {
284 ASSERT(!m_bIsSetting); 283 ASSERT(!m_bIsSetting);
285 m_Value = CJS_Value(m_pJSRuntime, wide_string.c_str()); 284 m_Value = CJS_Value(m_pJSRuntime, wide_string.c_str());
286 } 285 }
287 286
288 void CJS_PropValue::operator>>(CJS_Array& array) const { 287 void CJS_PropValue::operator>>(CJS_Array& array) const {
289 ASSERT(m_bIsSetting); 288 ASSERT(m_bIsSetting);
290 m_Value.ConvertToArray(m_pJSRuntime->GetIsolate(), array); 289 m_Value.ConvertToArray(m_pJSRuntime, array);
291 } 290 }
292 291
293 void CJS_PropValue::operator<<(CJS_Array& array) { 292 void CJS_PropValue::operator<<(CJS_Array& array) {
294 ASSERT(!m_bIsSetting); 293 ASSERT(!m_bIsSetting);
295 m_Value = 294 m_Value = CJS_Value(m_pJSRuntime, array.ToV8Array(m_pJSRuntime));
296 CJS_Value(m_pJSRuntime, array.ToV8Array(m_pJSRuntime->GetIsolate()));
297 } 295 }
298 296
299 void CJS_PropValue::operator>>(CJS_Date& date) const { 297 void CJS_PropValue::operator>>(CJS_Date& date) const {
300 ASSERT(m_bIsSetting); 298 ASSERT(m_bIsSetting);
301 m_Value.ConvertToDate(m_pJSRuntime->GetIsolate(), date); 299 m_Value.ConvertToDate(m_pJSRuntime, date);
302 } 300 }
303 301
304 void CJS_PropValue::operator<<(CJS_Date& date) { 302 void CJS_PropValue::operator<<(CJS_Date& date) {
305 ASSERT(!m_bIsSetting); 303 ASSERT(!m_bIsSetting);
306 m_Value = CJS_Value(m_pJSRuntime, date); 304 m_Value = CJS_Value(m_pJSRuntime, date);
307 } 305 }
308 306
309 CJS_Array::CJS_Array() {} 307 CJS_Array::CJS_Array() {}
310 308
311 CJS_Array::CJS_Array(const CJS_Array& other) = default; 309 CJS_Array::CJS_Array(const CJS_Array& other) = default;
312 310
313 CJS_Array::~CJS_Array() {} 311 CJS_Array::~CJS_Array() {}
314 312
315 void CJS_Array::Attach(v8::Local<v8::Array> pArray) { 313 void CJS_Array::Attach(v8::Local<v8::Array> pArray) {
316 m_pArray = pArray; 314 m_pArray = pArray;
317 } 315 }
318 316
319 void CJS_Array::GetElement(v8::Isolate* pIsolate, 317 void CJS_Array::GetElement(CJS_Runtime* pRuntime,
320 unsigned index, 318 unsigned index,
321 CJS_Value& value) const { 319 CJS_Value& value) const {
322 if (!m_pArray.IsEmpty()) 320 if (!m_pArray.IsEmpty())
323 value.Attach(FXJS_GetArrayElement(pIsolate, m_pArray, index)); 321 value.Attach(pRuntime->GetArrayElement(m_pArray, index));
324 } 322 }
325 323
326 void CJS_Array::SetElement(v8::Isolate* pIsolate, 324 void CJS_Array::SetElement(CJS_Runtime* pRuntime,
327 unsigned index, 325 unsigned index,
328 const CJS_Value& value) { 326 const CJS_Value& value) {
329 if (m_pArray.IsEmpty()) 327 if (m_pArray.IsEmpty())
330 m_pArray = FXJS_NewArray(pIsolate); 328 m_pArray = pRuntime->NewArray();
331 329
332 FXJS_PutArrayElement(pIsolate, m_pArray, index, value.ToV8Value(pIsolate)); 330 pRuntime->PutArrayElement(m_pArray, index, value.ToV8Value(pRuntime));
333 } 331 }
334 332
335 int CJS_Array::GetLength() const { 333 int CJS_Array::GetLength(CJS_Runtime* pRuntime) const {
336 if (m_pArray.IsEmpty()) 334 if (m_pArray.IsEmpty())
337 return 0; 335 return 0;
338 return FXJS_GetArrayLength(m_pArray); 336 return pRuntime->GetArrayLength(m_pArray);
339 } 337 }
340 338
341 v8::Local<v8::Array> CJS_Array::ToV8Array(v8::Isolate* pIsolate) const { 339 v8::Local<v8::Array> CJS_Array::ToV8Array(CJS_Runtime* pRuntime) const {
342 if (m_pArray.IsEmpty()) 340 if (m_pArray.IsEmpty())
343 m_pArray = FXJS_NewArray(pIsolate); 341 m_pArray = pRuntime->NewArray();
344 342
345 return m_pArray; 343 return m_pArray;
346 } 344 }
347 345
348 CJS_Date::CJS_Date() {} 346 CJS_Date::CJS_Date() {}
349 347
350 CJS_Date::CJS_Date(v8::Isolate* pIsolate, double dMsecTime) 348 CJS_Date::CJS_Date(CJS_Runtime* pRuntime, double dMsecTime)
351 : m_pDate(FXJS_NewDate(pIsolate, dMsecTime)) {} 349 : m_pDate(pRuntime->NewDate(dMsecTime)) {}
352 350
353 CJS_Date::CJS_Date(v8::Isolate* pIsolate, 351 CJS_Date::CJS_Date(CJS_Runtime* pRuntime,
354 int year, 352 int year,
355 int mon, 353 int mon,
356 int day, 354 int day,
357 int hour, 355 int hour,
358 int min, 356 int min,
359 int sec) 357 int sec)
360 : m_pDate(FXJS_NewDate(pIsolate, 358 : m_pDate(pRuntime->NewDate(MakeDate(year, mon, day, hour, min, sec, 0))) {}
361 MakeDate(year, mon, day, hour, min, sec, 0))) {}
362 359
363 CJS_Date::~CJS_Date() {} 360 CJS_Date::~CJS_Date() {}
364 361
365 bool CJS_Date::IsValidDate(v8::Isolate* pIsolate) const { 362 bool CJS_Date::IsValidDate(CJS_Runtime* pRuntime) const {
366 return !m_pDate.IsEmpty() && !JS_PortIsNan(FXJS_ToNumber(pIsolate, m_pDate)); 363 return !m_pDate.IsEmpty() && !JS_PortIsNan(pRuntime->ToNumber(m_pDate));
367 } 364 }
368 365
369 void CJS_Date::Attach(v8::Local<v8::Date> pDate) { 366 void CJS_Date::Attach(v8::Local<v8::Date> pDate) {
370 m_pDate = pDate; 367 m_pDate = pDate;
371 } 368 }
372 369
373 int CJS_Date::GetYear(v8::Isolate* pIsolate) const { 370 int CJS_Date::GetYear(CJS_Runtime* pRuntime) const {
374 if (!IsValidDate(pIsolate)) 371 if (!IsValidDate(pRuntime))
375 return 0; 372 return 0;
376 373
377 return JS_GetYearFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate))); 374 return JS_GetYearFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate)));
378 } 375 }
379 376
380 void CJS_Date::SetYear(v8::Isolate* pIsolate, int iYear) { 377 void CJS_Date::SetYear(CJS_Runtime* pRuntime, int iYear) {
381 m_pDate = FXJS_NewDate( 378 m_pDate = pRuntime->NewDate(
382 pIsolate, 379 MakeDate(iYear, GetMonth(pRuntime), GetDay(pRuntime), GetHours(pRuntime),
383 MakeDate(iYear, GetMonth(pIsolate), GetDay(pIsolate), GetHours(pIsolate), 380 GetMinutes(pRuntime), GetSeconds(pRuntime), 0));
384 GetMinutes(pIsolate), GetSeconds(pIsolate), 0));
385 } 381 }
386 382
387 int CJS_Date::GetMonth(v8::Isolate* pIsolate) const { 383 int CJS_Date::GetMonth(CJS_Runtime* pRuntime) const {
388 if (!IsValidDate(pIsolate)) 384 if (!IsValidDate(pRuntime))
389 return 0; 385 return 0;
390 386
391 return JS_GetMonthFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate))); 387 return JS_GetMonthFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate)));
392 } 388 }
393 389
394 void CJS_Date::SetMonth(v8::Isolate* pIsolate, int iMonth) { 390 void CJS_Date::SetMonth(CJS_Runtime* pRuntime, int iMonth) {
395 m_pDate = FXJS_NewDate( 391 m_pDate = pRuntime->NewDate(
396 pIsolate, 392 MakeDate(GetYear(pRuntime), iMonth, GetDay(pRuntime), GetHours(pRuntime),
397 MakeDate(GetYear(pIsolate), iMonth, GetDay(pIsolate), GetHours(pIsolate), 393 GetMinutes(pRuntime), GetSeconds(pRuntime), 0));
398 GetMinutes(pIsolate), GetSeconds(pIsolate), 0));
399 } 394 }
400 395
401 int CJS_Date::GetDay(v8::Isolate* pIsolate) const { 396 int CJS_Date::GetDay(CJS_Runtime* pRuntime) const {
402 if (!IsValidDate(pIsolate)) 397 if (!IsValidDate(pRuntime))
403 return 0; 398 return 0;
404 399
405 return JS_GetDayFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate))); 400 return JS_GetDayFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate)));
406 } 401 }
407 402
408 void CJS_Date::SetDay(v8::Isolate* pIsolate, int iDay) { 403 void CJS_Date::SetDay(CJS_Runtime* pRuntime, int iDay) {
409 m_pDate = FXJS_NewDate( 404 m_pDate = pRuntime->NewDate(
410 pIsolate, 405 MakeDate(GetYear(pRuntime), GetMonth(pRuntime), iDay, GetHours(pRuntime),
411 MakeDate(GetYear(pIsolate), GetMonth(pIsolate), iDay, GetHours(pIsolate), 406 GetMinutes(pRuntime), GetSeconds(pRuntime), 0));
412 GetMinutes(pIsolate), GetSeconds(pIsolate), 0));
413 } 407 }
414 408
415 int CJS_Date::GetHours(v8::Isolate* pIsolate) const { 409 int CJS_Date::GetHours(CJS_Runtime* pRuntime) const {
416 if (!IsValidDate(pIsolate)) 410 if (!IsValidDate(pRuntime))
417 return 0; 411 return 0;
418 412
419 return JS_GetHourFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate))); 413 return JS_GetHourFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate)));
420 } 414 }
421 415
422 void CJS_Date::SetHours(v8::Isolate* pIsolate, int iHours) { 416 void CJS_Date::SetHours(CJS_Runtime* pRuntime, int iHours) {
423 m_pDate = FXJS_NewDate( 417 m_pDate = pRuntime->NewDate(
424 pIsolate, 418 MakeDate(GetYear(pRuntime), GetMonth(pRuntime), GetDay(pRuntime), iHours,
425 MakeDate(GetYear(pIsolate), GetMonth(pIsolate), GetDay(pIsolate), iHours, 419 GetMinutes(pRuntime), GetSeconds(pRuntime), 0));
426 GetMinutes(pIsolate), GetSeconds(pIsolate), 0));
427 } 420 }
428 421
429 int CJS_Date::GetMinutes(v8::Isolate* pIsolate) const { 422 int CJS_Date::GetMinutes(CJS_Runtime* pRuntime) const {
430 if (!IsValidDate(pIsolate)) 423 if (!IsValidDate(pRuntime))
431 return 0; 424 return 0;
432 425
433 return JS_GetMinFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate))); 426 return JS_GetMinFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate)));
434 } 427 }
435 428
436 void CJS_Date::SetMinutes(v8::Isolate* pIsolate, int minutes) { 429 void CJS_Date::SetMinutes(CJS_Runtime* pRuntime, int minutes) {
437 m_pDate = 430 m_pDate = pRuntime->NewDate(MakeDate(GetYear(pRuntime), GetMonth(pRuntime),
438 FXJS_NewDate(pIsolate, MakeDate(GetYear(pIsolate), GetMonth(pIsolate), 431 GetDay(pRuntime), GetHours(pRuntime),
439 GetDay(pIsolate), GetHours(pIsolate), 432 minutes, GetSeconds(pRuntime), 0));
440 minutes, GetSeconds(pIsolate), 0));
441 } 433 }
442 434
443 int CJS_Date::GetSeconds(v8::Isolate* pIsolate) const { 435 int CJS_Date::GetSeconds(CJS_Runtime* pRuntime) const {
444 if (!IsValidDate(pIsolate)) 436 if (!IsValidDate(pRuntime))
445 return 0; 437 return 0;
446 438
447 return JS_GetSecFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate))); 439 return JS_GetSecFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate)));
448 } 440 }
449 441
450 void CJS_Date::SetSeconds(v8::Isolate* pIsolate, int seconds) { 442 void CJS_Date::SetSeconds(CJS_Runtime* pRuntime, int seconds) {
451 m_pDate = 443 m_pDate = pRuntime->NewDate(MakeDate(GetYear(pRuntime), GetMonth(pRuntime),
452 FXJS_NewDate(pIsolate, MakeDate(GetYear(pIsolate), GetMonth(pIsolate), 444 GetDay(pRuntime), GetHours(pRuntime),
453 GetDay(pIsolate), GetHours(pIsolate), 445 GetMinutes(pRuntime), seconds, 0));
454 GetMinutes(pIsolate), seconds, 0));
455 } 446 }
456 447
457 double CJS_Date::ToDouble(v8::Isolate* pIsolate) const { 448 double CJS_Date::ToDouble(CJS_Runtime* pRuntime) const {
458 return !m_pDate.IsEmpty() ? FXJS_ToNumber(pIsolate, m_pDate) : 0.0; 449 return !m_pDate.IsEmpty() ? pRuntime->ToNumber(m_pDate) : 0.0;
459 } 450 }
460 451
461 CFX_WideString CJS_Date::ToString(v8::Isolate* pIsolate) const { 452 CFX_WideString CJS_Date::ToString(CJS_Runtime* pRuntime) const {
462 return !m_pDate.IsEmpty() ? FXJS_ToString(pIsolate, m_pDate) 453 return !m_pDate.IsEmpty() ? pRuntime->ToString(m_pDate) : CFX_WideString();
463 : CFX_WideString();
464 } 454 }
465 455
466 v8::Local<v8::Date> CJS_Date::ToV8Date(v8::Isolate* pIsolate) const { 456 v8::Local<v8::Date> CJS_Date::ToV8Date(CJS_Runtime* pRuntime) const {
467 return m_pDate; 457 return m_pDate;
468 } 458 }
469 459
470 double _getLocalTZA() { 460 double _getLocalTZA() {
471 if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) 461 if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
472 return 0; 462 return 0;
473 time_t t = 0; 463 time_t t = 0;
474 time(&t); 464 time(&t);
475 localtime(&t); 465 localtime(&t);
476 #if _MSC_VER >= 1900 466 #if _MSC_VER >= 1900
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 .ToLocalChecked(); 671 .ToLocalChecked();
682 if (v->IsObject()) { 672 if (v->IsObject()) {
683 v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked(); 673 v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked();
684 v = o->Get(context, v8::String::NewFromUtf8(pIsolate, "parse", 674 v = o->Get(context, v8::String::NewFromUtf8(pIsolate, "parse",
685 v8::NewStringType::kNormal) 675 v8::NewStringType::kNormal)
686 .ToLocalChecked()) 676 .ToLocalChecked())
687 .ToLocalChecked(); 677 .ToLocalChecked();
688 if (v->IsFunction()) { 678 if (v->IsFunction()) {
689 v8::Local<v8::Function> funC = v8::Local<v8::Function>::Cast(v); 679 v8::Local<v8::Function> funC = v8::Local<v8::Function>::Cast(v);
690 const int argc = 1; 680 const int argc = 1;
691 v8::Local<v8::String> timeStr = FXJS_WSToJSString(pIsolate, str); 681 v8::Local<v8::String> timeStr =
682 CJS_Runtime::CurrentRuntimeFromIsolate(pIsolate)->WSToJSString(str);
692 v8::Local<v8::Value> argv[argc] = {timeStr}; 683 v8::Local<v8::Value> argv[argc] = {timeStr};
693 v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked(); 684 v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked();
694 if (v->IsNumber()) { 685 if (v->IsNumber()) {
695 double date = v->ToNumber(context).ToLocalChecked()->Value(); 686 double date = v->ToNumber(context).ToLocalChecked()->Value();
696 if (!_isfinite(date)) 687 if (!_isfinite(date))
697 return date; 688 return date;
698 return JS_LocalTime(date); 689 return JS_LocalTime(date);
699 } 690 }
700 } 691 }
701 } 692 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 747
757 std::vector<CJS_Value> result(nKeywords, CJS_Value(pRuntime)); 748 std::vector<CJS_Value> result(nKeywords, CJS_Value(pRuntime));
758 size_t size = std::min(originals.size(), nKeywords); 749 size_t size = std::min(originals.size(), nKeywords);
759 for (size_t i = 0; i < size; ++i) 750 for (size_t i = 0; i < size; ++i)
760 result[i] = originals[i]; 751 result[i] = originals[i];
761 752
762 if (originals.size() != 1 || originals[0].GetType() != CJS_Value::VT_object || 753 if (originals.size() != 1 || originals[0].GetType() != CJS_Value::VT_object ||
763 originals[0].IsArrayObject()) { 754 originals[0].IsArrayObject()) {
764 return result; 755 return result;
765 } 756 }
766 v8::Local<v8::Object> pObj = originals[0].ToV8Object(pRuntime->GetIsolate()); 757 v8::Local<v8::Object> pObj = originals[0].ToV8Object(pRuntime);
767 result[0] = CJS_Value(pRuntime); // Make unknown. 758 result[0] = CJS_Value(pRuntime); // Make unknown.
768 759
769 va_list ap; 760 va_list ap;
770 va_start(ap, nKeywords); 761 va_start(ap, nKeywords);
771 for (size_t i = 0; i < nKeywords; ++i) { 762 for (size_t i = 0; i < nKeywords; ++i) {
772 const wchar_t* property = va_arg(ap, const wchar_t*); 763 const wchar_t* property = va_arg(ap, const wchar_t*);
773 v8::Local<v8::Value> v8Value = 764 v8::Local<v8::Value> v8Value = pRuntime->GetObjectProperty(pObj, property);
774 FXJS_GetObjectProperty(pRuntime->GetIsolate(), pObj, property);
775 if (!v8Value->IsUndefined()) 765 if (!v8Value->IsUndefined())
776 result[i] = CJS_Value(pRuntime, v8Value); 766 result[i] = CJS_Value(pRuntime, v8Value);
777 } 767 }
778 va_end(ap); 768 va_end(ap);
779 return result; 769 return result;
780 } 770 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/JS_Value.h ('k') | fpdfsdk/javascript/PublicMethods.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698