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