John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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 _JS_VALUE_H_ |
| 8 | #define _JS_VALUE_H_ |
| 9 | |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame^] | 10 | #include "../jsapi/fxjs_v8.h" |
| 11 | #include "../../../core/include/fxcrt/fx_basic.h" |
| 12 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 13 | class CJS_Array; |
| 14 | class CJS_Date; |
Tom Sepez | f79a69c | 2014-10-30 13:23:42 -0700 | [diff] [blame] | 15 | class CJS_Document; |
| 16 | class CJS_Object; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | |
| 18 | class CJS_Value |
| 19 | { |
| 20 | public: |
| 21 | CJS_Value(v8::Isolate* isolate); |
| 22 | CJS_Value(v8::Isolate* isolate, v8::Handle<v8::Value> pValue,FXJSVALUETYPE t); |
| 23 | CJS_Value(v8::Isolate* isolate, const int &iValue); |
| 24 | CJS_Value(v8::Isolate* isolate, const double &dValue); |
Tom Sepez | f79a69c | 2014-10-30 13:23:42 -0700 | [diff] [blame] | 25 | CJS_Value(v8::Isolate* isolate, const float &fValue); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 26 | CJS_Value(v8::Isolate* isolate, const bool &bValue); |
| 27 | CJS_Value(v8::Isolate* isolate, JSFXObject); |
Tom Sepez | f79a69c | 2014-10-30 13:23:42 -0700 | [diff] [blame] | 28 | CJS_Value(v8::Isolate* isolate, CJS_Object*); |
| 29 | CJS_Value(v8::Isolate* isolate, CJS_Document*); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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); |
Tom Sepez | f79a69c | 2014-10-30 13:23:42 -0700 | [diff] [blame] | 33 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | ~CJS_Value(); |
| 35 | |
| 36 | void SetNull(); |
| 37 | void Attach(v8::Handle<v8::Value> pValue,FXJSVALUETYPE t); |
| 38 | void Attach(CJS_Value *pValue); |
| 39 | void Detach(); |
| 40 | |
| 41 | |
| 42 | operator int() const; |
| 43 | operator bool() const; |
| 44 | operator double() const; |
| 45 | operator float() const; |
Tom Sepez | f79a69c | 2014-10-30 13:23:42 -0700 | [diff] [blame] | 46 | operator CJS_Object*() const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 47 | operator v8::Handle<v8::Object>() const; |
| 48 | operator v8::Handle<v8::Array>() const; |
| 49 | operator CFX_WideString() const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | operator CFX_ByteString() const; |
| 51 | v8::Handle<v8::Value> ToJSValue(); |
| 52 | |
| 53 | void operator = (int iValue); |
Tom Sepez | f79a69c | 2014-10-30 13:23:42 -0700 | [diff] [blame] | 54 | void operator = (bool bValue); |
| 55 | void operator = (double); |
| 56 | void operator = (float); |
| 57 | void operator = (CJS_Object*); |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 58 | void operator = (CJS_Document*); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | void operator = (v8::Handle<v8::Object>); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 60 | void operator = (CJS_Array &); |
| 61 | void operator = (CJS_Date &); |
Tom Sepez | f79a69c | 2014-10-30 13:23:42 -0700 | [diff] [blame] | 62 | void operator = (FX_LPCWSTR pWstr); |
| 63 | void operator = (FX_LPCSTR pStr); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 64 | void operator = (CJS_Value value); |
Tom Sepez | f79a69c | 2014-10-30 13:23:42 -0700 | [diff] [blame] | 65 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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 | |
| 73 | v8::Isolate* GetIsolate() {return m_isolate;} |
Tom Sepez | f79a69c | 2014-10-30 13:23:42 -0700 | [diff] [blame] | 74 | protected: |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 75 | v8::Handle<v8::Value> m_pValue; |
| 76 | FXJSVALUETYPE m_eType; |
| 77 | v8::Isolate* m_isolate; |
| 78 | }; |
| 79 | |
Tom Sepez | 2f3dfef | 2015-03-02 15:35:26 -0800 | [diff] [blame] | 80 | class CJS_Parameters : public CFX_ArrayTemplate<CJS_Value> |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 81 | { |
| 82 | public: |
Tom Sepez | 2f3dfef | 2015-03-02 15:35:26 -0800 | [diff] [blame] | 83 | void push_back(const CJS_Value& newElement) { |
| 84 | CFX_ArrayTemplate<CJS_Value>::Add(newElement); |
| 85 | } |
| 86 | int size() const { |
| 87 | return CFX_ArrayTemplate<CJS_Value>::GetSize(); |
| 88 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 89 | }; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 90 | |
| 91 | class CJS_PropValue: public CJS_Value |
| 92 | { |
| 93 | public: |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 94 | CJS_PropValue(const CJS_Value&); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 95 | CJS_PropValue(v8::Isolate* isolate); |
| 96 | ~CJS_PropValue(); |
| 97 | public: |
| 98 | FX_BOOL IsSetting(); |
| 99 | FX_BOOL IsGetting(); |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 100 | void operator<<(int); |
| 101 | void operator>>(int&) const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 102 | void operator<<(bool); |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 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; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 110 | void operator<<(CFX_ByteString); |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 111 | void operator>>(CFX_ByteString&) const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 112 | void operator<<(CFX_WideString); |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 113 | void operator>>(CFX_WideString&) const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 114 | void operator<<(FX_LPCWSTR c_string); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 115 | void operator<<(JSFXObject); |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 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; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 121 | operator v8::Handle<v8::Value>() const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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::Handle<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::Handle<v8::Array>(); |
| 140 | |
| 141 | v8::Isolate* GetIsolate() {return m_isolate;} |
| 142 | private: |
| 143 | v8::Handle<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::Handle<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::Handle<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::Handle<v8::Value> m_pDate; |
| 186 | v8::Isolate* m_isolate; |
| 187 | }; |
| 188 | |
| 189 | #endif //_JS_VALUE_H_ |
| 190 | |