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

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

Issue 2637503002: Tidy FXJS_V8, backfill tests. (Closed)
Patch Set: rebase Created 3 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/javascript/Document.cpp ('k') | fpdfsdk/javascript/global.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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 int CJS_Value::ToInt(CJS_Runtime* pRuntime) const { 82 int CJS_Value::ToInt(CJS_Runtime* pRuntime) const {
83 return pRuntime->ToInt32(m_pValue); 83 return pRuntime->ToInt32(m_pValue);
84 } 84 }
85 85
86 bool CJS_Value::ToBool(CJS_Runtime* pRuntime) const { 86 bool CJS_Value::ToBool(CJS_Runtime* pRuntime) const {
87 return pRuntime->ToBoolean(m_pValue); 87 return pRuntime->ToBoolean(m_pValue);
88 } 88 }
89 89
90 double CJS_Value::ToDouble(CJS_Runtime* pRuntime) const { 90 double CJS_Value::ToDouble(CJS_Runtime* pRuntime) const {
91 return pRuntime->ToNumber(m_pValue); 91 return pRuntime->ToDouble(m_pValue);
92 } 92 }
93 93
94 float CJS_Value::ToFloat(CJS_Runtime* pRuntime) const { 94 float CJS_Value::ToFloat(CJS_Runtime* pRuntime) const {
95 return (float)ToDouble(pRuntime); 95 return (float)ToDouble(pRuntime);
96 } 96 }
97 97
98 CJS_Object* CJS_Value::ToCJSObject(CJS_Runtime* pRuntime) const { 98 CJS_Object* CJS_Value::ToCJSObject(CJS_Runtime* pRuntime) const {
99 v8::Local<v8::Object> pObj = pRuntime->ToObject(m_pValue); 99 v8::Local<v8::Object> pObj = pRuntime->ToObject(m_pValue);
100 return static_cast<CJS_Object*>(pRuntime->GetObjectPrivate(pObj)); 100 return static_cast<CJS_Object*>(pRuntime->GetObjectPrivate(pObj));
101 } 101 }
102 102
103 v8::Local<v8::Object> CJS_Value::ToV8Object(CJS_Runtime* pRuntime) const { 103 v8::Local<v8::Object> CJS_Value::ToV8Object(CJS_Runtime* pRuntime) const {
104 return pRuntime->ToObject(m_pValue); 104 return pRuntime->ToObject(m_pValue);
105 } 105 }
106 106
107 CFX_WideString CJS_Value::ToCFXWideString(CJS_Runtime* pRuntime) const { 107 CFX_WideString CJS_Value::ToCFXWideString(CJS_Runtime* pRuntime) const {
108 return pRuntime->ToString(m_pValue); 108 return pRuntime->ToWideString(m_pValue);
109 } 109 }
110 110
111 CFX_ByteString CJS_Value::ToCFXByteString(CJS_Runtime* pRuntime) const { 111 CFX_ByteString CJS_Value::ToCFXByteString(CJS_Runtime* pRuntime) const {
112 return CFX_ByteString::FromUnicode(ToCFXWideString(pRuntime)); 112 return CFX_ByteString::FromUnicode(ToCFXWideString(pRuntime));
113 } 113 }
114 114
115 v8::Local<v8::Value> CJS_Value::ToV8Value(CJS_Runtime* pRuntime) const { 115 v8::Local<v8::Value> CJS_Value::ToV8Value(CJS_Runtime* pRuntime) const {
116 return m_pValue; 116 return m_pValue;
117 } 117 }
118 118
119 v8::Local<v8::Array> CJS_Value::ToV8Array(CJS_Runtime* pRuntime) const { 119 v8::Local<v8::Array> CJS_Value::ToV8Array(CJS_Runtime* pRuntime) const {
120 if (IsArrayObject()) 120 return pRuntime->ToArray(m_pValue);
121 return v8::Local<v8::Array>::Cast(pRuntime->ToObject(m_pValue));
122 return v8::Local<v8::Array>();
123 } 121 }
124 122
125 void CJS_Value::SetNull(CJS_Runtime* pRuntime) { 123 void CJS_Value::SetNull(CJS_Runtime* pRuntime) {
126 m_pValue = pRuntime->NewNull(); 124 m_pValue = pRuntime->NewNull();
127 } 125 }
128 126
129 void CJS_Value::MaybeCoerceToNumber(CJS_Runtime* pRuntime) { 127 void CJS_Value::MaybeCoerceToNumber(CJS_Runtime* pRuntime) {
130 bool bAllowNaN = false; 128 bool bAllowNaN = false;
131 if (GetType() == VT_string) { 129 if (GetType() == VT_string) {
132 CFX_ByteString bstr = ToCFXByteString(pRuntime); 130 CFX_ByteString bstr = ToCFXByteString(pRuntime);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 int mon, 351 int mon,
354 int day, 352 int day,
355 int hour, 353 int hour,
356 int min, 354 int min,
357 int sec) 355 int sec)
358 : m_pDate(pRuntime->NewDate(MakeDate(year, mon, day, hour, min, sec, 0))) {} 356 : m_pDate(pRuntime->NewDate(MakeDate(year, mon, day, hour, min, sec, 0))) {}
359 357
360 CJS_Date::~CJS_Date() {} 358 CJS_Date::~CJS_Date() {}
361 359
362 bool CJS_Date::IsValidDate(CJS_Runtime* pRuntime) const { 360 bool CJS_Date::IsValidDate(CJS_Runtime* pRuntime) const {
363 return !m_pDate.IsEmpty() && !JS_PortIsNan(pRuntime->ToNumber(m_pDate)); 361 return !m_pDate.IsEmpty() && !JS_PortIsNan(pRuntime->ToDouble(m_pDate));
364 } 362 }
365 363
366 void CJS_Date::Attach(v8::Local<v8::Date> pDate) { 364 void CJS_Date::Attach(v8::Local<v8::Date> pDate) {
367 m_pDate = pDate; 365 m_pDate = pDate;
368 } 366 }
369 367
370 int CJS_Date::GetYear(CJS_Runtime* pRuntime) const { 368 int CJS_Date::GetYear(CJS_Runtime* pRuntime) const {
371 if (!IsValidDate(pRuntime)) 369 if (!IsValidDate(pRuntime))
372 return 0; 370 return 0;
373 371
374 return JS_GetYearFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate))); 372 return JS_GetYearFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate)));
375 } 373 }
376 374
377 void CJS_Date::SetYear(CJS_Runtime* pRuntime, int iYear) { 375 void CJS_Date::SetYear(CJS_Runtime* pRuntime, int iYear) {
378 m_pDate = pRuntime->NewDate( 376 m_pDate = pRuntime->NewDate(
379 MakeDate(iYear, GetMonth(pRuntime), GetDay(pRuntime), GetHours(pRuntime), 377 MakeDate(iYear, GetMonth(pRuntime), GetDay(pRuntime), GetHours(pRuntime),
380 GetMinutes(pRuntime), GetSeconds(pRuntime), 0)); 378 GetMinutes(pRuntime), GetSeconds(pRuntime), 0));
381 } 379 }
382 380
383 int CJS_Date::GetMonth(CJS_Runtime* pRuntime) const { 381 int CJS_Date::GetMonth(CJS_Runtime* pRuntime) const {
384 if (!IsValidDate(pRuntime)) 382 if (!IsValidDate(pRuntime))
385 return 0; 383 return 0;
386 384
387 return JS_GetMonthFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate))); 385 return JS_GetMonthFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate)));
388 } 386 }
389 387
390 void CJS_Date::SetMonth(CJS_Runtime* pRuntime, int iMonth) { 388 void CJS_Date::SetMonth(CJS_Runtime* pRuntime, int iMonth) {
391 m_pDate = pRuntime->NewDate( 389 m_pDate = pRuntime->NewDate(
392 MakeDate(GetYear(pRuntime), iMonth, GetDay(pRuntime), GetHours(pRuntime), 390 MakeDate(GetYear(pRuntime), iMonth, GetDay(pRuntime), GetHours(pRuntime),
393 GetMinutes(pRuntime), GetSeconds(pRuntime), 0)); 391 GetMinutes(pRuntime), GetSeconds(pRuntime), 0));
394 } 392 }
395 393
396 int CJS_Date::GetDay(CJS_Runtime* pRuntime) const { 394 int CJS_Date::GetDay(CJS_Runtime* pRuntime) const {
397 if (!IsValidDate(pRuntime)) 395 if (!IsValidDate(pRuntime))
398 return 0; 396 return 0;
399 397
400 return JS_GetDayFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate))); 398 return JS_GetDayFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate)));
401 } 399 }
402 400
403 void CJS_Date::SetDay(CJS_Runtime* pRuntime, int iDay) { 401 void CJS_Date::SetDay(CJS_Runtime* pRuntime, int iDay) {
404 m_pDate = pRuntime->NewDate( 402 m_pDate = pRuntime->NewDate(
405 MakeDate(GetYear(pRuntime), GetMonth(pRuntime), iDay, GetHours(pRuntime), 403 MakeDate(GetYear(pRuntime), GetMonth(pRuntime), iDay, GetHours(pRuntime),
406 GetMinutes(pRuntime), GetSeconds(pRuntime), 0)); 404 GetMinutes(pRuntime), GetSeconds(pRuntime), 0));
407 } 405 }
408 406
409 int CJS_Date::GetHours(CJS_Runtime* pRuntime) const { 407 int CJS_Date::GetHours(CJS_Runtime* pRuntime) const {
410 if (!IsValidDate(pRuntime)) 408 if (!IsValidDate(pRuntime))
411 return 0; 409 return 0;
412 410
413 return JS_GetHourFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate))); 411 return JS_GetHourFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate)));
414 } 412 }
415 413
416 void CJS_Date::SetHours(CJS_Runtime* pRuntime, int iHours) { 414 void CJS_Date::SetHours(CJS_Runtime* pRuntime, int iHours) {
417 m_pDate = pRuntime->NewDate( 415 m_pDate = pRuntime->NewDate(
418 MakeDate(GetYear(pRuntime), GetMonth(pRuntime), GetDay(pRuntime), iHours, 416 MakeDate(GetYear(pRuntime), GetMonth(pRuntime), GetDay(pRuntime), iHours,
419 GetMinutes(pRuntime), GetSeconds(pRuntime), 0)); 417 GetMinutes(pRuntime), GetSeconds(pRuntime), 0));
420 } 418 }
421 419
422 int CJS_Date::GetMinutes(CJS_Runtime* pRuntime) const { 420 int CJS_Date::GetMinutes(CJS_Runtime* pRuntime) const {
423 if (!IsValidDate(pRuntime)) 421 if (!IsValidDate(pRuntime))
424 return 0; 422 return 0;
425 423
426 return JS_GetMinFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate))); 424 return JS_GetMinFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate)));
427 } 425 }
428 426
429 void CJS_Date::SetMinutes(CJS_Runtime* pRuntime, int minutes) { 427 void CJS_Date::SetMinutes(CJS_Runtime* pRuntime, int minutes) {
430 m_pDate = pRuntime->NewDate(MakeDate(GetYear(pRuntime), GetMonth(pRuntime), 428 m_pDate = pRuntime->NewDate(MakeDate(GetYear(pRuntime), GetMonth(pRuntime),
431 GetDay(pRuntime), GetHours(pRuntime), 429 GetDay(pRuntime), GetHours(pRuntime),
432 minutes, GetSeconds(pRuntime), 0)); 430 minutes, GetSeconds(pRuntime), 0));
433 } 431 }
434 432
435 int CJS_Date::GetSeconds(CJS_Runtime* pRuntime) const { 433 int CJS_Date::GetSeconds(CJS_Runtime* pRuntime) const {
436 if (!IsValidDate(pRuntime)) 434 if (!IsValidDate(pRuntime))
437 return 0; 435 return 0;
438 436
439 return JS_GetSecFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate))); 437 return JS_GetSecFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate)));
440 } 438 }
441 439
442 void CJS_Date::SetSeconds(CJS_Runtime* pRuntime, int seconds) { 440 void CJS_Date::SetSeconds(CJS_Runtime* pRuntime, int seconds) {
443 m_pDate = pRuntime->NewDate(MakeDate(GetYear(pRuntime), GetMonth(pRuntime), 441 m_pDate = pRuntime->NewDate(MakeDate(GetYear(pRuntime), GetMonth(pRuntime),
444 GetDay(pRuntime), GetHours(pRuntime), 442 GetDay(pRuntime), GetHours(pRuntime),
445 GetMinutes(pRuntime), seconds, 0)); 443 GetMinutes(pRuntime), seconds, 0));
446 } 444 }
447 445
448 double CJS_Date::ToDouble(CJS_Runtime* pRuntime) const { 446 double CJS_Date::ToDouble(CJS_Runtime* pRuntime) const {
449 return !m_pDate.IsEmpty() ? pRuntime->ToNumber(m_pDate) : 0.0; 447 return !m_pDate.IsEmpty() ? pRuntime->ToDouble(m_pDate) : 0.0;
450 } 448 }
451 449
452 CFX_WideString CJS_Date::ToString(CJS_Runtime* pRuntime) const { 450 CFX_WideString CJS_Date::ToString(CJS_Runtime* pRuntime) const {
453 return !m_pDate.IsEmpty() ? pRuntime->ToString(m_pDate) : CFX_WideString(); 451 return !m_pDate.IsEmpty() ? pRuntime->ToWideString(m_pDate)
452 : CFX_WideString();
454 } 453 }
455 454
456 v8::Local<v8::Date> CJS_Date::ToV8Date(CJS_Runtime* pRuntime) const { 455 v8::Local<v8::Date> CJS_Date::ToV8Date(CJS_Runtime* pRuntime) const {
457 return m_pDate; 456 return m_pDate;
458 } 457 }
459 458
460 double _getLocalTZA() { 459 double _getLocalTZA() {
461 if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) 460 if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
462 return 0; 461 return 0;
463 time_t t = 0; 462 time_t t = 0;
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 va_start(ap, nKeywords); 760 va_start(ap, nKeywords);
762 for (size_t i = 0; i < nKeywords; ++i) { 761 for (size_t i = 0; i < nKeywords; ++i) {
763 const wchar_t* property = va_arg(ap, const wchar_t*); 762 const wchar_t* property = va_arg(ap, const wchar_t*);
764 v8::Local<v8::Value> v8Value = pRuntime->GetObjectProperty(pObj, property); 763 v8::Local<v8::Value> v8Value = pRuntime->GetObjectProperty(pObj, property);
765 if (!v8Value->IsUndefined()) 764 if (!v8Value->IsUndefined())
766 result[i] = CJS_Value(pRuntime, v8Value); 765 result[i] = CJS_Value(pRuntime, v8Value);
767 } 766 }
768 va_end(ap); 767 va_end(ap);
769 return result; 768 return result;
770 } 769 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/Document.cpp ('k') | fpdfsdk/javascript/global.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698