OLD | NEW |
---|---|
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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 if (IsArrayObject()) { | 245 if (IsArrayObject()) { |
246 array.Attach(FXJS_ToArray(m_pJSRuntime->GetIsolate(), m_pValue)); | 246 array.Attach(FXJS_ToArray(m_pJSRuntime->GetIsolate(), m_pValue)); |
247 return TRUE; | 247 return TRUE; |
248 } | 248 } |
249 | 249 |
250 return FALSE; | 250 return FALSE; |
251 } | 251 } |
252 | 252 |
253 FX_BOOL CJS_Value::ConvertToDate(CJS_Date& date) const { | 253 FX_BOOL CJS_Value::ConvertToDate(CJS_Date& date) const { |
254 if (IsDateObject()) { | 254 if (IsDateObject()) { |
255 date.Attach(m_pValue); | 255 v8::Local<v8::Value> mutable_value = m_pValue; |
256 date.Attach(mutable_value.As<v8::Date>()); | |
Tom Sepez
2016/08/04 23:34:08
note: As<> missing const. Should it be?
jochen (gone - plz use gerrit)
2016/08/05 11:50:32
yeah, should probably be const
| |
256 return TRUE; | 257 return TRUE; |
257 } | 258 } |
258 | 259 |
259 return FALSE; | 260 return FALSE; |
260 } | 261 } |
261 | 262 |
262 CJS_PropValue::CJS_PropValue(const CJS_Value& value) | 263 CJS_PropValue::CJS_PropValue(const CJS_Value& value) |
263 : CJS_Value(value), m_bIsSetting(0) {} | 264 : CJS_Value(value), m_bIsSetting(0) {} |
264 | 265 |
265 CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime) | 266 CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime) |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 MakeDate(year, mon, day, hour, min, sec, 0)); | 431 MakeDate(year, mon, day, hour, min, sec, 0)); |
431 } | 432 } |
432 | 433 |
433 CJS_Date::~CJS_Date() {} | 434 CJS_Date::~CJS_Date() {} |
434 | 435 |
435 bool CJS_Date::IsValidDate() const { | 436 bool CJS_Date::IsValidDate() const { |
436 return !m_pDate.IsEmpty() && | 437 return !m_pDate.IsEmpty() && |
437 !JS_PortIsNan(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)); | 438 !JS_PortIsNan(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)); |
438 } | 439 } |
439 | 440 |
440 void CJS_Date::Attach(v8::Local<v8::Value> pDate) { | 441 void CJS_Date::Attach(v8::Local<v8::Date> pDate) { |
441 m_pDate = pDate; | 442 m_pDate = pDate; |
442 } | 443 } |
443 | 444 |
444 int CJS_Date::GetYear() const { | 445 int CJS_Date::GetYear() const { |
445 if (!IsValidDate()) | 446 if (!IsValidDate()) |
446 return 0; | 447 return 0; |
447 | 448 |
448 return JS_GetYearFromTime( | 449 return JS_GetYearFromTime( |
449 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); | 450 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
450 } | 451 } |
451 | 452 |
452 void CJS_Date::SetYear(int iYear) { | 453 void CJS_Date::SetYear(int iYear) { |
453 double date = MakeDate(iYear, GetMonth(), GetDay(), GetHours(), GetMinutes(), | 454 double date = MakeDate(iYear, GetMonth(), GetDay(), GetHours(), GetMinutes(), |
454 GetSeconds(), 0); | 455 GetSeconds(), 0); |
455 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); | 456 m_pDate = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date); |
456 } | 457 } |
457 | 458 |
458 int CJS_Date::GetMonth() const { | 459 int CJS_Date::GetMonth() const { |
459 if (!IsValidDate()) | 460 if (!IsValidDate()) |
460 return 0; | 461 return 0; |
461 | 462 |
462 return JS_GetMonthFromTime( | 463 return JS_GetMonthFromTime( |
463 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); | 464 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
464 } | 465 } |
465 | 466 |
466 void CJS_Date::SetMonth(int iMonth) { | 467 void CJS_Date::SetMonth(int iMonth) { |
467 double date = MakeDate(GetYear(), iMonth, GetDay(), GetHours(), GetMinutes(), | 468 double date = MakeDate(GetYear(), iMonth, GetDay(), GetHours(), GetMinutes(), |
468 GetSeconds(), 0); | 469 GetSeconds(), 0); |
469 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); | 470 m_pDate = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date); |
470 } | 471 } |
471 | 472 |
472 int CJS_Date::GetDay() const { | 473 int CJS_Date::GetDay() const { |
473 if (!IsValidDate()) | 474 if (!IsValidDate()) |
474 return 0; | 475 return 0; |
475 | 476 |
476 return JS_GetDayFromTime( | 477 return JS_GetDayFromTime( |
477 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); | 478 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
478 } | 479 } |
479 | 480 |
480 void CJS_Date::SetDay(int iDay) { | 481 void CJS_Date::SetDay(int iDay) { |
481 double date = MakeDate(GetYear(), GetMonth(), iDay, GetHours(), GetMinutes(), | 482 double date = MakeDate(GetYear(), GetMonth(), iDay, GetHours(), GetMinutes(), |
482 GetSeconds(), 0); | 483 GetSeconds(), 0); |
483 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); | 484 m_pDate = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date); |
484 } | 485 } |
485 | 486 |
486 int CJS_Date::GetHours() const { | 487 int CJS_Date::GetHours() const { |
487 if (!IsValidDate()) | 488 if (!IsValidDate()) |
488 return 0; | 489 return 0; |
489 | 490 |
490 return JS_GetHourFromTime( | 491 return JS_GetHourFromTime( |
491 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); | 492 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
492 } | 493 } |
493 | 494 |
494 void CJS_Date::SetHours(int iHours) { | 495 void CJS_Date::SetHours(int iHours) { |
495 double date = MakeDate(GetYear(), GetMonth(), GetDay(), iHours, GetMinutes(), | 496 double date = MakeDate(GetYear(), GetMonth(), GetDay(), iHours, GetMinutes(), |
496 GetSeconds(), 0); | 497 GetSeconds(), 0); |
497 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); | 498 m_pDate = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date); |
498 } | 499 } |
499 | 500 |
500 int CJS_Date::GetMinutes() const { | 501 int CJS_Date::GetMinutes() const { |
501 if (!IsValidDate()) | 502 if (!IsValidDate()) |
502 return 0; | 503 return 0; |
503 | 504 |
504 return JS_GetMinFromTime( | 505 return JS_GetMinFromTime( |
505 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); | 506 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
506 } | 507 } |
507 | 508 |
508 void CJS_Date::SetMinutes(int minutes) { | 509 void CJS_Date::SetMinutes(int minutes) { |
509 double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), minutes, | 510 double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), minutes, |
510 GetSeconds(), 0); | 511 GetSeconds(), 0); |
511 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); | 512 m_pDate = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date); |
512 } | 513 } |
513 | 514 |
514 int CJS_Date::GetSeconds() const { | 515 int CJS_Date::GetSeconds() const { |
515 if (!IsValidDate()) | 516 if (!IsValidDate()) |
516 return 0; | 517 return 0; |
517 | 518 |
518 return JS_GetSecFromTime( | 519 return JS_GetSecFromTime( |
519 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); | 520 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
520 } | 521 } |
521 | 522 |
522 void CJS_Date::SetSeconds(int seconds) { | 523 void CJS_Date::SetSeconds(int seconds) { |
523 double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), | 524 double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), |
524 GetMinutes(), seconds, 0); | 525 GetMinutes(), seconds, 0); |
525 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); | 526 m_pDate = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date); |
526 } | 527 } |
527 | 528 |
528 double CJS_Date::ToDouble() const { | 529 double CJS_Date::ToDouble() const { |
529 if (m_pDate.IsEmpty()) | 530 if (m_pDate.IsEmpty()) |
530 return 0.0; | 531 return 0.0; |
531 | 532 |
532 return FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate); | 533 return FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate); |
533 } | 534 } |
534 | 535 |
535 CFX_WideString CJS_Date::ToString() const { | 536 CFX_WideString CJS_Date::ToString() const { |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
843 for (size_t i = 0; i < nKeywords; ++i) { | 844 for (size_t i = 0; i < nKeywords; ++i) { |
844 const wchar_t* property = va_arg(ap, const wchar_t*); | 845 const wchar_t* property = va_arg(ap, const wchar_t*); |
845 v8::Local<v8::Value> v8Value = | 846 v8::Local<v8::Value> v8Value = |
846 FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property); | 847 FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property); |
847 if (!v8Value->IsUndefined()) | 848 if (!v8Value->IsUndefined()) |
848 result[i] = CJS_Value(pRuntime, v8Value); | 849 result[i] = CJS_Value(pRuntime, v8Value); |
849 } | 850 } |
850 va_end(ap); | 851 va_end(ap); |
851 return result; | 852 return result; |
852 } | 853 } |
OLD | NEW |