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 { 20 public: 21 CJS_Value(v8::Isolate* isolate); 22 CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue,FXJSVALUETYPE t); 23 CJS_Value(v8::Isolate* isolate, const int &iValue); 24 CJS_Value(v8::Isolate* isolate, const double &dValue); 25 CJS_Value(v8::Isolate* isolate, const float &fValue); 26 CJS_Value(v8::Isolate* isolate, const bool &bValue); 27 CJS_Value(v8::Isolate* isolate, JSFXObject); 28 CJS_Value(v8::Isolate* isolate, CJS_Object*); 29 CJS_Value(v8::Isolate* isolate, CJS_Document*); 30 CJS_Value(v8::Isolate* isolate, FX_LPCSTR pStr); 31 CJS_Value(v8::Isolate* isolate, FX_LPCWSTR pWstr); 32 CJS_Value(v8::Isolate* isolate, CJS_Array& array); 33 34 ~CJS_Value(); 35 36 void SetNull(); 37 void Attach(v8::Local<v8::Value> pValue,FXJSVALUETYPE t); 38 void Attach(CJS_Value *pValue); 39 void Detach(); 40 41 42 int ToInt() const; 43 bool ToBool() const; 44 double ToDouble() const; 45 float ToFloat() const; 46 CJS_Object* ToCJSObject() const; 47 CFX_WideString ToCFXWideString() const; 48 CFX_ByteString ToCFXByteString() const; 49 v8::Local<v8::Object> ToV8Object() const; 50 v8::Local<v8::Array> ToV8Array() const; 51 v8::Local<v8::Value> ToV8Value() const; 52 53 void operator = (int iValue); 54 void operator = (bool bValue); 55 void operator = (double); 56 void operator = (float); 57 void operator = (CJS_Object*); 58 void operator = (CJS_Document*); 59 void operator = (v8::Local<v8::Object>); 60 void operator = (CJS_Array &); 61 void operator = (CJS_Date &); 62 void operator = (FX_LPCWSTR pWstr); 63 void operator = (FX_LPCSTR pStr); 64 void operator = (CJS_Value value); 65 66 FX_BOOL IsArrayObject() const; 67 FX_BOOL IsDateObject() const; 68 FXJSVALUETYPE GetType() const; 69 70 FX_BOOL ConvertToArray(CJS_Array &) const; 71 FX_BOOL ConvertToDate(CJS_Date &) const; 72 GetIsolate()73 v8::Isolate* GetIsolate() {return m_isolate;} 74 protected: 75 v8::Local<v8::Value> m_pValue; 76 FXJSVALUETYPE m_eType; 77 v8::Isolate* m_isolate; 78 }; 79 80 class CJS_Parameters : public CFX_ArrayTemplate<CJS_Value> 81 { 82 public: push_back(const CJS_Value & newElement)83 void push_back(const CJS_Value& newElement) { 84 CFX_ArrayTemplate<CJS_Value>::Add(newElement); 85 } size()86 int size() const { 87 return CFX_ArrayTemplate<CJS_Value>::GetSize(); 88 } 89 }; 90 91 class CJS_PropValue: public CJS_Value 92 { 93 public: 94 CJS_PropValue(const CJS_Value&); 95 CJS_PropValue(v8::Isolate* isolate); 96 ~CJS_PropValue(); 97 public: 98 FX_BOOL IsSetting(); 99 FX_BOOL IsGetting(); 100 void operator<<(int); 101 void operator>>(int&) const; 102 void operator<<(bool); 103 void operator>>(bool&) const; 104 void operator<<(double); 105 void operator>>(double&) const; 106 void operator<<(CJS_Object* pObj); 107 void operator>>(CJS_Object*& ppObj) const; 108 void operator<<(CJS_Document* pJsDoc); 109 void operator>>(CJS_Document*& ppJsDoc) const; 110 void operator<<(CFX_ByteString); 111 void operator>>(CFX_ByteString&) const; 112 void operator<<(CFX_WideString); 113 void operator>>(CFX_WideString&) const; 114 void operator<<(FX_LPCWSTR c_string); 115 void operator<<(JSFXObject); 116 void operator>>(JSFXObject&) const; 117 void operator>>(CJS_Array& array) const; 118 void operator<<(CJS_Array& array); 119 void operator<<(CJS_Date& date); 120 void operator>>(CJS_Date& date) const; 121 operator v8::Local<v8::Value>() const; 122 void StartSetting(); 123 void StartGetting(); 124 private: 125 FX_BOOL m_bIsSetting; 126 }; 127 128 class CJS_Array 129 { 130 public: 131 CJS_Array(v8::Isolate* isolate); 132 virtual ~CJS_Array(); 133 134 void Attach(v8::Local<v8::Array> pArray); 135 void GetElement(unsigned index,CJS_Value &value); 136 void SetElement(unsigned index,CJS_Value value); 137 int GetLength(); 138 FX_BOOL IsAttached(); 139 operator v8::Local<v8::Array>(); 140 GetIsolate()141 v8::Isolate* GetIsolate() {return m_isolate;} 142 private: 143 v8::Local<v8::Array> m_pArray; 144 v8::Isolate* m_isolate; 145 }; 146 147 class CJS_Date 148 { 149 friend class CJS_Value; 150 public: 151 CJS_Date(v8::Isolate* isolate); 152 CJS_Date(v8::Isolate* isolate,double dMsec_time); 153 CJS_Date(v8::Isolate* isolate,int year, int mon, int day,int hour, int min, int sec); 154 virtual ~CJS_Date(); 155 void Attach(v8::Local<v8::Value> pDate); 156 157 int GetYear(); 158 void SetYear(int iYear); 159 160 int GetMonth(); 161 void SetMonth(int iMonth); 162 163 int GetDay(); 164 void SetDay(int iDay); 165 166 int GetHours(); 167 void SetHours(int iHours); 168 169 int GetMinutes(); 170 void SetMinutes(int minutes); 171 172 int GetSeconds(); 173 void SetSeconds(int seconds); 174 175 operator v8::Local<v8::Value>(); 176 operator double() const; 177 178 CFX_WideString ToString() const; 179 180 static double MakeDate(int year, int mon, int mday,int hour, int min, int sec,int ms); 181 182 FX_BOOL IsValidDate(); 183 184 protected: 185 v8::Local<v8::Value> m_pDate; 186 v8::Isolate* m_isolate; 187 }; 188 189 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_VALUE_H_ 190