| OLD | NEW |
| (Empty) |
| 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 FPDFSDK_INCLUDE_JAVASCRIPT_JS_VALUE_H_ | |
| 8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_VALUE_H_ | |
| 9 | |
| 10 #include "../../../core/include/fxcrt/fx_basic.h" | |
| 11 #include "../jsapi/fxjs_v8.h" | |
| 12 | |
| 13 class CJS_Array; | |
| 14 class CJS_Date; | |
| 15 class CJS_Document; | |
| 16 class CJS_Object; | |
| 17 | |
| 18 class CJS_Value { | |
| 19 public: | |
| 20 enum Type { | |
| 21 VT_unknown, | |
| 22 VT_string, | |
| 23 VT_number, | |
| 24 VT_boolean, | |
| 25 VT_date, | |
| 26 VT_object, | |
| 27 VT_fxobject, | |
| 28 VT_null, | |
| 29 VT_undefined | |
| 30 }; | |
| 31 | |
| 32 CJS_Value(v8::Isolate* isolate); | |
| 33 CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue, Type t); | |
| 34 CJS_Value(v8::Isolate* isolate, const int& iValue); | |
| 35 CJS_Value(v8::Isolate* isolate, const double& dValue); | |
| 36 CJS_Value(v8::Isolate* isolate, const float& fValue); | |
| 37 CJS_Value(v8::Isolate* isolate, const bool& bValue); | |
| 38 CJS_Value(v8::Isolate* isolate, v8::Local<v8::Object>); | |
| 39 CJS_Value(v8::Isolate* isolate, CJS_Object*); | |
| 40 CJS_Value(v8::Isolate* isolate, CJS_Document*); | |
| 41 CJS_Value(v8::Isolate* isolate, const FX_CHAR* pStr); | |
| 42 CJS_Value(v8::Isolate* isolate, const FX_WCHAR* pWstr); | |
| 43 CJS_Value(v8::Isolate* isolate, CJS_Array& array); | |
| 44 | |
| 45 ~CJS_Value(); | |
| 46 | |
| 47 void SetNull(); | |
| 48 void Attach(v8::Local<v8::Value> pValue, Type t); | |
| 49 void Attach(CJS_Value* pValue); | |
| 50 void Detach(); | |
| 51 | |
| 52 Type GetType() const; | |
| 53 int ToInt() const; | |
| 54 bool ToBool() const; | |
| 55 double ToDouble() const; | |
| 56 float ToFloat() const; | |
| 57 CJS_Object* ToCJSObject() const; | |
| 58 CFX_WideString ToCFXWideString() const; | |
| 59 CFX_ByteString ToCFXByteString() const; | |
| 60 v8::Local<v8::Object> ToV8Object() const; | |
| 61 v8::Local<v8::Array> ToV8Array() const; | |
| 62 v8::Local<v8::Value> ToV8Value() const; | |
| 63 | |
| 64 void operator=(int iValue); | |
| 65 void operator=(bool bValue); | |
| 66 void operator=(double); | |
| 67 void operator=(float); | |
| 68 void operator=(CJS_Object*); | |
| 69 void operator=(CJS_Document*); | |
| 70 void operator=(v8::Local<v8::Object>); | |
| 71 void operator=(CJS_Array&); | |
| 72 void operator=(CJS_Date&); | |
| 73 void operator=(const FX_WCHAR* pWstr); | |
| 74 void operator=(const FX_CHAR* pStr); | |
| 75 void operator=(CJS_Value value); | |
| 76 | |
| 77 FX_BOOL IsArrayObject() const; | |
| 78 FX_BOOL IsDateObject() const; | |
| 79 FX_BOOL ConvertToArray(CJS_Array&) const; | |
| 80 FX_BOOL ConvertToDate(CJS_Date&) const; | |
| 81 | |
| 82 v8::Isolate* GetIsolate() { return m_isolate; } | |
| 83 | |
| 84 protected: | |
| 85 Type m_eType; | |
| 86 v8::Local<v8::Value> m_pValue; | |
| 87 v8::Isolate* m_isolate; | |
| 88 }; | |
| 89 | |
| 90 class CJS_Parameters : public CFX_ArrayTemplate<CJS_Value> { | |
| 91 public: | |
| 92 void push_back(const CJS_Value& newElement) { | |
| 93 CFX_ArrayTemplate<CJS_Value>::Add(newElement); | |
| 94 } | |
| 95 int size() const { return CFX_ArrayTemplate<CJS_Value>::GetSize(); } | |
| 96 }; | |
| 97 | |
| 98 class CJS_PropValue : public CJS_Value { | |
| 99 public: | |
| 100 CJS_PropValue(const CJS_Value&); | |
| 101 CJS_PropValue(v8::Isolate* isolate); | |
| 102 ~CJS_PropValue(); | |
| 103 | |
| 104 public: | |
| 105 FX_BOOL IsSetting(); | |
| 106 FX_BOOL IsGetting(); | |
| 107 void operator<<(int); | |
| 108 void operator>>(int&) const; | |
| 109 void operator<<(bool); | |
| 110 void operator>>(bool&) const; | |
| 111 void operator<<(double); | |
| 112 void operator>>(double&) const; | |
| 113 void operator<<(CJS_Object* pObj); | |
| 114 void operator>>(CJS_Object*& ppObj) const; | |
| 115 void operator<<(CJS_Document* pJsDoc); | |
| 116 void operator>>(CJS_Document*& ppJsDoc) const; | |
| 117 void operator<<(CFX_ByteString); | |
| 118 void operator>>(CFX_ByteString&) const; | |
| 119 void operator<<(CFX_WideString); | |
| 120 void operator>>(CFX_WideString&) const; | |
| 121 void operator<<(const FX_WCHAR* c_string); | |
| 122 void operator<<(v8::Local<v8::Object>); | |
| 123 void operator>>(v8::Local<v8::Object>&) const; | |
| 124 void operator>>(CJS_Array& array) const; | |
| 125 void operator<<(CJS_Array& array); | |
| 126 void operator<<(CJS_Date& date); | |
| 127 void operator>>(CJS_Date& date) const; | |
| 128 operator v8::Local<v8::Value>() const; | |
| 129 void StartSetting(); | |
| 130 void StartGetting(); | |
| 131 | |
| 132 private: | |
| 133 FX_BOOL m_bIsSetting; | |
| 134 }; | |
| 135 | |
| 136 class CJS_Array { | |
| 137 public: | |
| 138 CJS_Array(v8::Isolate* isolate); | |
| 139 virtual ~CJS_Array(); | |
| 140 | |
| 141 void Attach(v8::Local<v8::Array> pArray); | |
| 142 void GetElement(unsigned index, CJS_Value& value); | |
| 143 void SetElement(unsigned index, CJS_Value value); | |
| 144 int GetLength(); | |
| 145 FX_BOOL IsAttached(); | |
| 146 operator v8::Local<v8::Array>(); | |
| 147 | |
| 148 v8::Isolate* GetIsolate() { return m_isolate; } | |
| 149 | |
| 150 private: | |
| 151 v8::Local<v8::Array> m_pArray; | |
| 152 v8::Isolate* m_isolate; | |
| 153 }; | |
| 154 | |
| 155 class CJS_Date { | |
| 156 friend class CJS_Value; | |
| 157 | |
| 158 public: | |
| 159 CJS_Date(v8::Isolate* isolate); | |
| 160 CJS_Date(v8::Isolate* isolate, double dMsec_time); | |
| 161 CJS_Date(v8::Isolate* isolate, | |
| 162 int year, | |
| 163 int mon, | |
| 164 int day, | |
| 165 int hour, | |
| 166 int min, | |
| 167 int sec); | |
| 168 virtual ~CJS_Date(); | |
| 169 void Attach(v8::Local<v8::Value> pDate); | |
| 170 | |
| 171 int GetYear(); | |
| 172 void SetYear(int iYear); | |
| 173 | |
| 174 int GetMonth(); | |
| 175 void SetMonth(int iMonth); | |
| 176 | |
| 177 int GetDay(); | |
| 178 void SetDay(int iDay); | |
| 179 | |
| 180 int GetHours(); | |
| 181 void SetHours(int iHours); | |
| 182 | |
| 183 int GetMinutes(); | |
| 184 void SetMinutes(int minutes); | |
| 185 | |
| 186 int GetSeconds(); | |
| 187 void SetSeconds(int seconds); | |
| 188 | |
| 189 operator v8::Local<v8::Value>(); | |
| 190 operator double() const; | |
| 191 | |
| 192 CFX_WideString ToString() const; | |
| 193 | |
| 194 static double | |
| 195 MakeDate(int year, int mon, int mday, int hour, int min, int sec, int ms); | |
| 196 | |
| 197 FX_BOOL IsValidDate(); | |
| 198 | |
| 199 protected: | |
| 200 v8::Local<v8::Value> m_pDate; | |
| 201 v8::Isolate* m_isolate; | |
| 202 }; | |
| 203 | |
| 204 double JS_GetDateTime(); | |
| 205 int JS_GetYearFromTime(double dt); | |
| 206 int JS_GetMonthFromTime(double dt); | |
| 207 int JS_GetDayFromTime(double dt); | |
| 208 int JS_GetHourFromTime(double dt); | |
| 209 int JS_GetMinFromTime(double dt); | |
| 210 int JS_GetSecFromTime(double dt); | |
| 211 double JS_DateParse(const wchar_t* string); | |
| 212 double JS_MakeDay(int nYear, int nMonth, int nDay); | |
| 213 double JS_MakeTime(int nHour, int nMin, int nSec, int nMs); | |
| 214 double JS_MakeDate(double day, double time); | |
| 215 bool JS_PortIsNan(double d); | |
| 216 double JS_LocalTime(double d); | |
| 217 | |
| 218 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_VALUE_H_ | |
| OLD | NEW |