| 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/src/javascript/JS_Value.h" | 7 #include "fpdfsdk/src/javascript/JS_Value.h" |
| 8 | 8 |
| 9 #include <time.h> | 9 #include <time.h> |
| 10 |
| 10 #include <algorithm> | 11 #include <algorithm> |
| 11 #include <cmath> | 12 #include <cmath> |
| 12 #include <limits> | 13 #include <limits> |
| 14 #include <vector> |
| 13 | 15 |
| 14 #include "fpdfsdk/src/javascript/Document.h" | 16 #include "fpdfsdk/src/javascript/Document.h" |
| 15 #include "fpdfsdk/src/javascript/JS_Define.h" | 17 #include "fpdfsdk/src/javascript/JS_Define.h" |
| 16 #include "fpdfsdk/src/javascript/JS_Object.h" | 18 #include "fpdfsdk/src/javascript/JS_Object.h" |
| 17 | 19 |
| 18 static const FX_DWORD g_nan[2] = {0, 0x7FF80000}; | 20 static const FX_DWORD g_nan[2] = {0, 0x7FF80000}; |
| 19 static double GetNan() { | 21 static double GetNan() { |
| 20 return *(double*)g_nan; | 22 return *(double*)g_nan; |
| 21 } | 23 } |
| 22 | 24 |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 ppObj = CJS_Value::ToV8Object(); | 356 ppObj = CJS_Value::ToV8Object(); |
| 355 } | 357 } |
| 356 | 358 |
| 357 void CJS_PropValue::StartSetting() { | 359 void CJS_PropValue::StartSetting() { |
| 358 m_bIsSetting = 1; | 360 m_bIsSetting = 1; |
| 359 } | 361 } |
| 360 | 362 |
| 361 void CJS_PropValue::StartGetting() { | 363 void CJS_PropValue::StartGetting() { |
| 362 m_bIsSetting = 0; | 364 m_bIsSetting = 0; |
| 363 } | 365 } |
| 364 void CJS_PropValue::operator<<(CFX_ByteString string) { | 366 void CJS_PropValue::operator<<(CFX_ByteString str) { |
| 365 ASSERT(!m_bIsSetting); | 367 ASSERT(!m_bIsSetting); |
| 366 CJS_Value::operator=(string.c_str()); | 368 CJS_Value::operator=(str.c_str()); |
| 367 } | 369 } |
| 368 | 370 |
| 369 void CJS_PropValue::operator>>(CFX_ByteString& string) const { | 371 void CJS_PropValue::operator>>(CFX_ByteString& str) const { |
| 370 ASSERT(m_bIsSetting); | 372 ASSERT(m_bIsSetting); |
| 371 string = CJS_Value::ToCFXByteString(); | 373 str = CJS_Value::ToCFXByteString(); |
| 372 } | 374 } |
| 373 | 375 |
| 374 void CJS_PropValue::operator<<(const FX_WCHAR* c_string) { | 376 void CJS_PropValue::operator<<(const FX_WCHAR* c_string) { |
| 375 ASSERT(!m_bIsSetting); | 377 ASSERT(!m_bIsSetting); |
| 376 CJS_Value::operator=(c_string); | 378 CJS_Value::operator=(c_string); |
| 377 } | 379 } |
| 378 | 380 |
| 379 void CJS_PropValue::operator>>(CFX_WideString& wide_string) const { | 381 void CJS_PropValue::operator>>(CFX_WideString& wide_string) const { |
| 380 ASSERT(m_bIsSetting); | 382 ASSERT(m_bIsSetting); |
| 381 wide_string = CJS_Value::ToCFXWideString(); | 383 wide_string = CJS_Value::ToCFXWideString(); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 } | 789 } |
| 788 | 790 |
| 789 int JS_GetMinFromTime(double dt) { | 791 int JS_GetMinFromTime(double dt) { |
| 790 return (int)_Mod(FXSYS_floor((double)(dt / (60 * 1000))), 60); | 792 return (int)_Mod(FXSYS_floor((double)(dt / (60 * 1000))), 60); |
| 791 } | 793 } |
| 792 | 794 |
| 793 int JS_GetSecFromTime(double dt) { | 795 int JS_GetSecFromTime(double dt) { |
| 794 return (int)_Mod(FXSYS_floor((double)(dt / 1000)), 60); | 796 return (int)_Mod(FXSYS_floor((double)(dt / 1000)), 60); |
| 795 } | 797 } |
| 796 | 798 |
| 797 double JS_DateParse(const wchar_t* string) { | 799 double JS_DateParse(const wchar_t* str) { |
| 798 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); | 800 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); |
| 799 v8::Isolate::Scope isolate_scope(pIsolate); | 801 v8::Isolate::Scope isolate_scope(pIsolate); |
| 800 v8::HandleScope scope(pIsolate); | 802 v8::HandleScope scope(pIsolate); |
| 801 | 803 |
| 802 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 804 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
| 803 | 805 |
| 804 // Use the built-in object method. | 806 // Use the built-in object method. |
| 805 v8::Local<v8::Value> v = | 807 v8::Local<v8::Value> v = |
| 806 context->Global() | 808 context->Global() |
| 807 ->Get(context, v8::String::NewFromUtf8(pIsolate, "Date", | 809 ->Get(context, v8::String::NewFromUtf8(pIsolate, "Date", |
| 808 v8::NewStringType::kNormal) | 810 v8::NewStringType::kNormal) |
| 809 .ToLocalChecked()) | 811 .ToLocalChecked()) |
| 810 .ToLocalChecked(); | 812 .ToLocalChecked(); |
| 811 if (v->IsObject()) { | 813 if (v->IsObject()) { |
| 812 v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked(); | 814 v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked(); |
| 813 v = o->Get(context, v8::String::NewFromUtf8(pIsolate, "parse", | 815 v = o->Get(context, v8::String::NewFromUtf8(pIsolate, "parse", |
| 814 v8::NewStringType::kNormal) | 816 v8::NewStringType::kNormal) |
| 815 .ToLocalChecked()).ToLocalChecked(); | 817 .ToLocalChecked()).ToLocalChecked(); |
| 816 if (v->IsFunction()) { | 818 if (v->IsFunction()) { |
| 817 v8::Local<v8::Function> funC = v8::Local<v8::Function>::Cast(v); | 819 v8::Local<v8::Function> funC = v8::Local<v8::Function>::Cast(v); |
| 818 | 820 |
| 819 const int argc = 1; | 821 const int argc = 1; |
| 820 v8::Local<v8::String> timeStr = FXJS_WSToJSString(pIsolate, string); | 822 v8::Local<v8::String> timeStr = FXJS_WSToJSString(pIsolate, str); |
| 821 v8::Local<v8::Value> argv[argc] = {timeStr}; | 823 v8::Local<v8::Value> argv[argc] = {timeStr}; |
| 822 v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked(); | 824 v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked(); |
| 823 if (v->IsNumber()) { | 825 if (v->IsNumber()) { |
| 824 double date = v->ToNumber(context).ToLocalChecked()->Value(); | 826 double date = v->ToNumber(context).ToLocalChecked()->Value(); |
| 825 if (!_isfinite(date)) | 827 if (!_isfinite(date)) |
| 826 return date; | 828 return date; |
| 827 return date + _getLocalTZA() + _getDaylightSavingTA(date); | 829 return date + _getLocalTZA() + _getDaylightSavingTA(date); |
| 828 } | 830 } |
| 829 } | 831 } |
| 830 } | 832 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 for (int i = 0; i < nKeywords; ++i) { | 902 for (int i = 0; i < nKeywords; ++i) { |
| 901 const wchar_t* property = va_arg(ap, const wchar_t*); | 903 const wchar_t* property = va_arg(ap, const wchar_t*); |
| 902 v8::Local<v8::Value> v8Value = | 904 v8::Local<v8::Value> v8Value = |
| 903 FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property); | 905 FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property); |
| 904 if (!v8Value->IsUndefined()) | 906 if (!v8Value->IsUndefined()) |
| 905 result[i] = CJS_Value(pRuntime, v8Value, CJS_Value::VT_unknown); | 907 result[i] = CJS_Value(pRuntime, v8Value, CJS_Value::VT_unknown); |
| 906 } | 908 } |
| 907 va_end(ap); | 909 va_end(ap); |
| 908 return result; | 910 return result; |
| 909 } | 911 } |
| OLD | NEW |