1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef FXJS_CJS_PUBLICMETHODS_H_ 8 #define FXJS_CJS_PUBLICMETHODS_H_ 9 10 #include <string> 11 #include <vector> 12 13 #include "fxjs/JS_Define.h" 14 15 class CJS_PublicMethods : public CJS_Object { 16 public: 17 explicit CJS_PublicMethods(v8::Local<v8::Object> pObject); 18 ~CJS_PublicMethods() override; 19 20 static void DefineJSObjects(CFXJS_Engine* pEngine); 21 static double MakeRegularDate(const WideString& value, 22 const WideString& format, 23 bool* bWrongFormat); 24 25 // Exposed for testing. 26 static WideString MakeFormatDate(double dDate, const WideString& format); 27 static bool IsNumber(const WideString& str); 28 29 static CJS_Return AFNumber_Format( 30 CJS_Runtime* pRuntime, 31 const std::vector<v8::Local<v8::Value>>& params); 32 static CJS_Return AFNumber_Keystroke( 33 CJS_Runtime* pRuntime, 34 const std::vector<v8::Local<v8::Value>>& params); 35 static CJS_Return AFPercent_Format( 36 CJS_Runtime* pRuntime, 37 const std::vector<v8::Local<v8::Value>>& params); 38 static CJS_Return AFPercent_Keystroke( 39 CJS_Runtime* pRuntime, 40 const std::vector<v8::Local<v8::Value>>& params); 41 static CJS_Return AFDate_FormatEx( 42 CJS_Runtime* pRuntime, 43 const std::vector<v8::Local<v8::Value>>& params); 44 static CJS_Return AFDate_KeystrokeEx( 45 CJS_Runtime* pRuntime, 46 const std::vector<v8::Local<v8::Value>>& params); 47 static CJS_Return AFDate_Format( 48 CJS_Runtime* pRuntime, 49 const std::vector<v8::Local<v8::Value>>& params); 50 static CJS_Return AFDate_Keystroke( 51 CJS_Runtime* pRuntime, 52 const std::vector<v8::Local<v8::Value>>& params); 53 static CJS_Return AFTime_FormatEx( 54 CJS_Runtime* pRuntime, 55 const std::vector<v8::Local<v8::Value>>& params); 56 static CJS_Return AFTime_KeystrokeEx( 57 CJS_Runtime* pRuntime, 58 const std::vector<v8::Local<v8::Value>>& params); 59 static CJS_Return AFTime_Format( 60 CJS_Runtime* pRuntime, 61 const std::vector<v8::Local<v8::Value>>& params); 62 static CJS_Return AFTime_Keystroke( 63 CJS_Runtime* pRuntime, 64 const std::vector<v8::Local<v8::Value>>& params); 65 static CJS_Return AFSpecial_Format( 66 CJS_Runtime* pRuntime, 67 const std::vector<v8::Local<v8::Value>>& params); 68 static CJS_Return AFSpecial_Keystroke( 69 CJS_Runtime* pRuntime, 70 const std::vector<v8::Local<v8::Value>>& params); 71 static CJS_Return AFSpecial_KeystrokeEx( 72 CJS_Runtime* pRuntime, 73 const std::vector<v8::Local<v8::Value>>& params); 74 static CJS_Return AFSimple(CJS_Runtime* pRuntime, 75 const std::vector<v8::Local<v8::Value>>& params); 76 static CJS_Return AFMakeNumber( 77 CJS_Runtime* pRuntime, 78 const std::vector<v8::Local<v8::Value>>& params); 79 static CJS_Return AFSimple_Calculate( 80 CJS_Runtime* pRuntime, 81 const std::vector<v8::Local<v8::Value>>& params); 82 static CJS_Return AFRange_Validate( 83 CJS_Runtime* pRuntime, 84 const std::vector<v8::Local<v8::Value>>& params); 85 static CJS_Return AFMergeChange( 86 CJS_Runtime* pRuntime, 87 const std::vector<v8::Local<v8::Value>>& params); 88 static CJS_Return AFParseDateEx( 89 CJS_Runtime* pRuntime, 90 const std::vector<v8::Local<v8::Value>>& params); 91 static CJS_Return AFExtractNums( 92 CJS_Runtime* pRuntime, 93 const std::vector<v8::Local<v8::Value>>& params); 94 95 static void AFNumber_Format_static( 96 const v8::FunctionCallbackInfo<v8::Value>& info); 97 static void AFNumber_Keystroke_static( 98 const v8::FunctionCallbackInfo<v8::Value>& info); 99 static void AFPercent_Format_static( 100 const v8::FunctionCallbackInfo<v8::Value>& info); 101 static void AFPercent_Keystroke_static( 102 const v8::FunctionCallbackInfo<v8::Value>& info); 103 static void AFDate_FormatEx_static( 104 const v8::FunctionCallbackInfo<v8::Value>& info); 105 static void AFDate_KeystrokeEx_static( 106 const v8::FunctionCallbackInfo<v8::Value>& info); 107 static void AFDate_Format_static( 108 const v8::FunctionCallbackInfo<v8::Value>& info); 109 static void AFDate_Keystroke_static( 110 const v8::FunctionCallbackInfo<v8::Value>& info); 111 static void AFTime_FormatEx_static( 112 const v8::FunctionCallbackInfo<v8::Value>& info); 113 static void AFTime_KeystrokeEx_static( 114 const v8::FunctionCallbackInfo<v8::Value>& info); 115 static void AFTime_Format_static( 116 const v8::FunctionCallbackInfo<v8::Value>& info); 117 static void AFTime_Keystroke_static( 118 const v8::FunctionCallbackInfo<v8::Value>& info); 119 static void AFSpecial_Format_static( 120 const v8::FunctionCallbackInfo<v8::Value>& info); 121 static void AFSpecial_Keystroke_static( 122 const v8::FunctionCallbackInfo<v8::Value>& info); 123 static void AFSpecial_KeystrokeEx_static( 124 const v8::FunctionCallbackInfo<v8::Value>& info); 125 static void AFSimple_static(const v8::FunctionCallbackInfo<v8::Value>& info); 126 static void AFMakeNumber_static( 127 const v8::FunctionCallbackInfo<v8::Value>& info); 128 static void AFSimple_Calculate_static( 129 const v8::FunctionCallbackInfo<v8::Value>& info); 130 static void AFRange_Validate_static( 131 const v8::FunctionCallbackInfo<v8::Value>& info); 132 static void AFMergeChange_static( 133 const v8::FunctionCallbackInfo<v8::Value>& info); 134 static void AFParseDateEx_static( 135 const v8::FunctionCallbackInfo<v8::Value>& info); 136 static void AFExtractNums_static( 137 const v8::FunctionCallbackInfo<v8::Value>& info); 138 139 static const JSMethodSpec GlobalFunctionSpecs[]; 140 static int ParseStringInteger(const WideString& string, 141 size_t nStart, 142 size_t* pSkip, 143 size_t nMaxStep); 144 static WideString ParseStringString(const WideString& string, 145 size_t nStart, 146 size_t* pSkip); 147 static double ParseNormalDate(const WideString& value, bool* bWrongFormat); 148 static double MakeInterDate(const WideString& value); 149 150 static bool MaskSatisfied(wchar_t c_Change, wchar_t c_Mask); 151 static bool IsReservedMaskChar(wchar_t ch); 152 153 static double AF_Simple(const wchar_t* sFuction, 154 double dValue1, 155 double dValue2); 156 static v8::Local<v8::Array> AF_MakeArrayFromList(CJS_Runtime* pRuntime, 157 v8::Local<v8::Value> val); 158 }; 159 160 #endif // FXJS_CJS_PUBLICMETHODS_H_ 161