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 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 } | 780 } |
781 | 781 |
782 int JS_GetMinFromTime(double dt) { | 782 int JS_GetMinFromTime(double dt) { |
783 return (int)_Mod(floor(dt / (60 * 1000)), 60); | 783 return (int)_Mod(floor(dt / (60 * 1000)), 60); |
784 } | 784 } |
785 | 785 |
786 int JS_GetSecFromTime(double dt) { | 786 int JS_GetSecFromTime(double dt) { |
787 return (int)_Mod(floor(dt / 1000), 60); | 787 return (int)_Mod(floor(dt / 1000), 60); |
788 } | 788 } |
789 | 789 |
790 double JS_DateParse(const wchar_t* str) { | 790 double JS_DateParse(const CFX_WideString& str) { |
791 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); | 791 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); |
792 v8::Isolate::Scope isolate_scope(pIsolate); | 792 v8::Isolate::Scope isolate_scope(pIsolate); |
793 v8::HandleScope scope(pIsolate); | 793 v8::HandleScope scope(pIsolate); |
794 | 794 |
795 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 795 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
796 | 796 |
797 // Use the built-in object method. | 797 // Use the built-in object method. |
798 v8::Local<v8::Value> v = | 798 v8::Local<v8::Value> v = |
799 context->Global() | 799 context->Global() |
800 ->Get(context, v8::String::NewFromUtf8(pIsolate, "Date", | 800 ->Get(context, v8::String::NewFromUtf8(pIsolate, "Date", |
801 v8::NewStringType::kNormal) | 801 v8::NewStringType::kNormal) |
802 .ToLocalChecked()) | 802 .ToLocalChecked()) |
803 .ToLocalChecked(); | 803 .ToLocalChecked(); |
804 if (v->IsObject()) { | 804 if (v->IsObject()) { |
805 v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked(); | 805 v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked(); |
806 v = o->Get(context, v8::String::NewFromUtf8(pIsolate, "parse", | 806 v = o->Get(context, v8::String::NewFromUtf8(pIsolate, "parse", |
807 v8::NewStringType::kNormal) | 807 v8::NewStringType::kNormal) |
808 .ToLocalChecked()) | 808 .ToLocalChecked()) |
809 .ToLocalChecked(); | 809 .ToLocalChecked(); |
810 if (v->IsFunction()) { | 810 if (v->IsFunction()) { |
811 v8::Local<v8::Function> funC = v8::Local<v8::Function>::Cast(v); | 811 v8::Local<v8::Function> funC = v8::Local<v8::Function>::Cast(v); |
812 | |
813 const int argc = 1; | 812 const int argc = 1; |
814 v8::Local<v8::String> timeStr = FXJS_WSToJSString(pIsolate, str); | 813 v8::Local<v8::String> timeStr = FXJS_WSToJSString(pIsolate, str); |
815 v8::Local<v8::Value> argv[argc] = {timeStr}; | 814 v8::Local<v8::Value> argv[argc] = {timeStr}; |
816 v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked(); | 815 v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked(); |
817 if (v->IsNumber()) { | 816 if (v->IsNumber()) { |
818 double date = v->ToNumber(context).ToLocalChecked()->Value(); | 817 double date = v->ToNumber(context).ToLocalChecked()->Value(); |
819 if (!_isfinite(date)) | 818 if (!_isfinite(date)) |
820 return date; | 819 return date; |
821 return JS_LocalTime(date); | 820 return JS_LocalTime(date); |
822 } | 821 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 for (size_t i = 0; i < nKeywords; ++i) { | 893 for (size_t i = 0; i < nKeywords; ++i) { |
895 const wchar_t* property = va_arg(ap, const wchar_t*); | 894 const wchar_t* property = va_arg(ap, const wchar_t*); |
896 v8::Local<v8::Value> v8Value = | 895 v8::Local<v8::Value> v8Value = |
897 FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property); | 896 FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property); |
898 if (!v8Value->IsUndefined()) | 897 if (!v8Value->IsUndefined()) |
899 result[i] = CJS_Value(pRuntime, v8Value, CJS_Value::VT_unknown); | 898 result[i] = CJS_Value(pRuntime, v8Value, CJS_Value::VT_unknown); |
900 } | 899 } |
901 va_end(ap); | 900 va_end(ap); |
902 return result; | 901 return result; |
903 } | 902 } |
OLD | NEW |