| 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 "util.h" | 7 #include "util.h" |
| 8 | 8 |
| 9 #include "../../include/javascript/IJavaScript.h" | 9 #include "../../include/javascript/IJavaScript.h" |
| 10 #include "JS_Context.h" | 10 #include "JS_Context.h" |
| 11 #include "JS_Define.h" | 11 #include "JS_Define.h" |
| 12 #include "JS_EventHandler.h" | 12 #include "JS_EventHandler.h" |
| 13 #include "JS_Object.h" | 13 #include "JS_Object.h" |
| 14 #include "JS_Runtime.h" | 14 #include "JS_Runtime.h" |
| 15 #include "JS_Value.h" | 15 #include "JS_Value.h" |
| 16 #include "PublicMethods.h" | 16 #include "PublicMethods.h" |
| 17 #include "resource.h" | 17 #include "resource.h" |
| 18 | 18 |
| 19 #if _FX_OS_ == _FX_ANDROID_ | 19 #if _FX_OS_ == _FX_ANDROID_ |
| 20 #include <ctype.h> | 20 #include <ctype.h> |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 static v8::Isolate* GetIsolate(IJS_Context* cc) { | |
| 24 CJS_Context* pContext = (CJS_Context*)cc; | |
| 25 ASSERT(pContext != NULL); | |
| 26 | |
| 27 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
| 28 ASSERT(pRuntime != NULL); | |
| 29 | |
| 30 return pRuntime->GetIsolate(); | |
| 31 } | |
| 32 | |
| 33 BEGIN_JS_STATIC_CONST(CJS_Util) | 23 BEGIN_JS_STATIC_CONST(CJS_Util) |
| 34 END_JS_STATIC_CONST() | 24 END_JS_STATIC_CONST() |
| 35 | 25 |
| 36 BEGIN_JS_STATIC_PROP(CJS_Util) | 26 BEGIN_JS_STATIC_PROP(CJS_Util) |
| 37 END_JS_STATIC_PROP() | 27 END_JS_STATIC_PROP() |
| 38 | 28 |
| 39 BEGIN_JS_STATIC_METHOD(CJS_Util) | 29 BEGIN_JS_STATIC_METHOD(CJS_Util) |
| 40 JS_STATIC_METHOD_ENTRY(printd) | 30 JS_STATIC_METHOD_ENTRY(printd) |
| 41 JS_STATIC_METHOD_ENTRY(printf) | 31 JS_STATIC_METHOD_ENTRY(printf) |
| 42 JS_STATIC_METHOD_ENTRY(printx) | 32 JS_STATIC_METHOD_ENTRY(printx) |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 174 |
| 185 c_strResult.erase(c_strResult.begin()); | 175 c_strResult.erase(c_strResult.begin()); |
| 186 vRet = c_strResult.c_str(); | 176 vRet = c_strResult.c_str(); |
| 187 return TRUE; | 177 return TRUE; |
| 188 } | 178 } |
| 189 | 179 |
| 190 FX_BOOL util::printd(IJS_Context* cc, | 180 FX_BOOL util::printd(IJS_Context* cc, |
| 191 const CJS_Parameters& params, | 181 const CJS_Parameters& params, |
| 192 CJS_Value& vRet, | 182 CJS_Value& vRet, |
| 193 CFX_WideString& sError) { | 183 CFX_WideString& sError) { |
| 194 v8::Isolate* isolate = GetIsolate(cc); | |
| 195 | |
| 196 int iSize = params.size(); | 184 int iSize = params.size(); |
| 197 if (iSize < 2) | 185 if (iSize < 2) |
| 198 return FALSE; | 186 return FALSE; |
| 199 | 187 |
| 200 CJS_Value p1(isolate); | 188 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 189 CJS_Value p1(pRuntime); |
| 201 p1 = params[0]; | 190 p1 = params[0]; |
| 202 | 191 |
| 203 CJS_Value p2 = params[1]; | 192 CJS_Value p2 = params[1]; |
| 204 CJS_Date jsDate(isolate); | 193 CJS_Date jsDate(pRuntime); |
| 205 if (!p2.ConvertToDate(jsDate)) { | 194 if (!p2.ConvertToDate(jsDate)) { |
| 206 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1); | 195 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1); |
| 207 return FALSE; | 196 return FALSE; |
| 208 } | 197 } |
| 209 | 198 |
| 210 if (!jsDate.IsValidDate()) { | 199 if (!jsDate.IsValidDate()) { |
| 211 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2); | 200 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2); |
| 212 return FALSE; | 201 return FALSE; |
| 213 } | 202 } |
| 214 | 203 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 cPurpose += letter; | 486 cPurpose += letter; |
| 498 break; | 487 break; |
| 499 } | 488 } |
| 500 } | 489 } |
| 501 } | 490 } |
| 502 | 491 |
| 503 FX_BOOL util::scand(IJS_Context* cc, | 492 FX_BOOL util::scand(IJS_Context* cc, |
| 504 const CJS_Parameters& params, | 493 const CJS_Parameters& params, |
| 505 CJS_Value& vRet, | 494 CJS_Value& vRet, |
| 506 CFX_WideString& sError) { | 495 CFX_WideString& sError) { |
| 507 v8::Isolate* isolate = GetIsolate(cc); | |
| 508 int iSize = params.size(); | 496 int iSize = params.size(); |
| 509 if (iSize < 2) | 497 if (iSize < 2) |
| 510 return FALSE; | 498 return FALSE; |
| 511 | 499 |
| 512 CFX_WideString sFormat = params[0].ToCFXWideString(); | 500 CFX_WideString sFormat = params[0].ToCFXWideString(); |
| 513 CFX_WideString sDate = params[1].ToCFXWideString(); | 501 CFX_WideString sDate = params[1].ToCFXWideString(); |
| 514 double dDate = JS_GetDateTime(); | 502 double dDate = JS_GetDateTime(); |
| 515 if (sDate.GetLength() > 0) { | 503 if (sDate.GetLength() > 0) { |
| 516 FX_BOOL bWrongFormat = FALSE; | 504 FX_BOOL bWrongFormat = FALSE; |
| 517 dDate = CJS_PublicMethods::MakeRegularDate(sDate, sFormat, bWrongFormat); | 505 dDate = CJS_PublicMethods::MakeRegularDate(sDate, sFormat, bWrongFormat); |
| 518 } | 506 } |
| 519 | 507 |
| 520 if (!JS_PortIsNan(dDate)) { | 508 if (!JS_PortIsNan(dDate)) { |
| 521 CJS_Date date(isolate, dDate); | 509 vRet = CJS_Date(CJS_Runtime::FromContext(cc), dDate); |
| 522 vRet = date; | |
| 523 } else { | 510 } else { |
| 524 vRet.SetNull(); | 511 vRet.SetNull(); |
| 525 } | 512 } |
| 526 | 513 |
| 527 return TRUE; | 514 return TRUE; |
| 528 } | 515 } |
| 529 | 516 |
| 530 int64_t FX_atoi64(const char* nptr) { | 517 int64_t FX_atoi64(const char* nptr) { |
| 531 int c; /* current char */ | 518 int c; /* current char */ |
| 532 int64_t total; /* current total */ | 519 int64_t total; /* current total */ |
| (...skipping 25 matching lines...) Expand all Loading... |
| 558 int iSize = params.size(); | 545 int iSize = params.size(); |
| 559 if (iSize == 0) | 546 if (iSize == 0) |
| 560 return FALSE; | 547 return FALSE; |
| 561 int nByte = params[0].ToInt(); | 548 int nByte = params[0].ToInt(); |
| 562 unsigned char cByte = (unsigned char)nByte; | 549 unsigned char cByte = (unsigned char)nByte; |
| 563 CFX_WideString csValue; | 550 CFX_WideString csValue; |
| 564 csValue.Format(L"%c", cByte); | 551 csValue.Format(L"%c", cByte); |
| 565 vRet = csValue.c_str(); | 552 vRet = csValue.c_str(); |
| 566 return TRUE; | 553 return TRUE; |
| 567 } | 554 } |
| OLD | NEW |