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_SRC_JAVASCRIPT_JS_VALUE_H_ | 7 #ifndef FPDFSDK_SRC_JAVASCRIPT_JS_VALUE_H_ |
8 #define FPDFSDK_SRC_JAVASCRIPT_JS_VALUE_H_ | 8 #define FPDFSDK_SRC_JAVASCRIPT_JS_VALUE_H_ |
9 | 9 |
10 #include "../../../core/include/fxcrt/fx_basic.h" | 10 #include "../../../core/include/fxcrt/fx_basic.h" |
11 #include "../../include/jsapi/fxjs_v8.h" | 11 #include "../../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 class CJS_Runtime; |
17 | 18 |
18 class CJS_Value { | 19 class CJS_Value { |
19 public: | 20 public: |
20 enum Type { | 21 enum Type { |
21 VT_unknown, | 22 VT_unknown, |
22 VT_string, | 23 VT_string, |
23 VT_number, | 24 VT_number, |
24 VT_boolean, | 25 VT_boolean, |
25 VT_date, | 26 VT_date, |
26 VT_object, | 27 VT_object, |
27 VT_fxobject, | 28 VT_fxobject, |
28 VT_null, | 29 VT_null, |
29 VT_undefined | 30 VT_undefined |
30 }; | 31 }; |
31 | 32 |
32 CJS_Value(v8::Isolate* isolate); | 33 CJS_Value(CJS_Runtime* pRuntime); |
33 CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue, Type t); | 34 CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue, Type t); |
34 CJS_Value(v8::Isolate* isolate, const int& iValue); | 35 CJS_Value(CJS_Runtime* pRuntime, const int& iValue); |
35 CJS_Value(v8::Isolate* isolate, const double& dValue); | 36 CJS_Value(CJS_Runtime* pRuntime, const double& dValue); |
36 CJS_Value(v8::Isolate* isolate, const float& fValue); | 37 CJS_Value(CJS_Runtime* pRuntime, const float& fValue); |
37 CJS_Value(v8::Isolate* isolate, const bool& bValue); | 38 CJS_Value(CJS_Runtime* pRuntime, const bool& bValue); |
38 CJS_Value(v8::Isolate* isolate, v8::Local<v8::Object>); | 39 CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Object>); |
39 CJS_Value(v8::Isolate* isolate, CJS_Object*); | 40 CJS_Value(CJS_Runtime* pRuntime, CJS_Object*); |
40 CJS_Value(v8::Isolate* isolate, CJS_Document*); | 41 CJS_Value(CJS_Runtime* pRuntime, CJS_Document*); |
41 CJS_Value(v8::Isolate* isolate, const FX_CHAR* pStr); | 42 CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr); |
42 CJS_Value(v8::Isolate* isolate, const FX_WCHAR* pWstr); | 43 CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr); |
43 CJS_Value(v8::Isolate* isolate, CJS_Array& array); | 44 CJS_Value(CJS_Runtime* pRuntime, CJS_Array& array); |
44 | 45 |
45 ~CJS_Value(); | 46 ~CJS_Value(); |
46 | 47 |
47 void SetNull(); | 48 void SetNull(); |
48 void Attach(v8::Local<v8::Value> pValue, Type t); | 49 void Attach(v8::Local<v8::Value> pValue, Type t); |
49 void Attach(CJS_Value* pValue); | 50 void Attach(CJS_Value* pValue); |
50 void Detach(); | 51 void Detach(); |
51 | 52 |
52 Type GetType() const; | 53 Type GetType() const; |
53 int ToInt() const; | 54 int ToInt() const; |
(...skipping 18 matching lines...) Expand all Loading... |
72 void operator=(CJS_Date&); | 73 void operator=(CJS_Date&); |
73 void operator=(const FX_WCHAR* pWstr); | 74 void operator=(const FX_WCHAR* pWstr); |
74 void operator=(const FX_CHAR* pStr); | 75 void operator=(const FX_CHAR* pStr); |
75 void operator=(CJS_Value value); | 76 void operator=(CJS_Value value); |
76 | 77 |
77 FX_BOOL IsArrayObject() const; | 78 FX_BOOL IsArrayObject() const; |
78 FX_BOOL IsDateObject() const; | 79 FX_BOOL IsDateObject() const; |
79 FX_BOOL ConvertToArray(CJS_Array&) const; | 80 FX_BOOL ConvertToArray(CJS_Array&) const; |
80 FX_BOOL ConvertToDate(CJS_Date&) const; | 81 FX_BOOL ConvertToDate(CJS_Date&) const; |
81 | 82 |
82 v8::Isolate* GetIsolate() { return m_isolate; } | 83 CJS_Runtime* GetJSRuntime() const { return m_pJSRuntime; } |
83 | 84 |
84 protected: | 85 protected: |
85 Type m_eType; | 86 Type m_eType; |
86 v8::Local<v8::Value> m_pValue; | 87 v8::Local<v8::Value> m_pValue; |
87 v8::Isolate* m_isolate; | 88 CJS_Runtime* m_pJSRuntime; |
88 }; | 89 }; |
89 | 90 |
90 class CJS_Parameters : public CFX_ArrayTemplate<CJS_Value> { | 91 class CJS_Parameters : public CFX_ArrayTemplate<CJS_Value> { |
91 public: | 92 public: |
92 void push_back(const CJS_Value& newElement) { | 93 void push_back(const CJS_Value& newElement) { |
93 CFX_ArrayTemplate<CJS_Value>::Add(newElement); | 94 CFX_ArrayTemplate<CJS_Value>::Add(newElement); |
94 } | 95 } |
95 int size() const { return CFX_ArrayTemplate<CJS_Value>::GetSize(); } | 96 int size() const { return CFX_ArrayTemplate<CJS_Value>::GetSize(); } |
96 }; | 97 }; |
97 | 98 |
98 class CJS_PropValue : public CJS_Value { | 99 class CJS_PropValue : public CJS_Value { |
99 public: | 100 public: |
100 CJS_PropValue(const CJS_Value&); | 101 CJS_PropValue(const CJS_Value&); |
101 CJS_PropValue(v8::Isolate* isolate); | 102 CJS_PropValue(CJS_Runtime* pRuntime); |
102 ~CJS_PropValue(); | 103 ~CJS_PropValue(); |
103 | 104 |
104 public: | 105 FX_BOOL IsSetting() const { return m_bIsSetting; } |
105 FX_BOOL IsSetting(); | 106 FX_BOOL IsGetting() const { return !m_bIsSetting; } |
106 FX_BOOL IsGetting(); | 107 |
107 void operator<<(int); | 108 void operator<<(int); |
108 void operator>>(int&) const; | 109 void operator>>(int&) const; |
109 void operator<<(bool); | 110 void operator<<(bool); |
110 void operator>>(bool&) const; | 111 void operator>>(bool&) const; |
111 void operator<<(double); | 112 void operator<<(double); |
112 void operator>>(double&) const; | 113 void operator>>(double&) const; |
113 void operator<<(CJS_Object* pObj); | 114 void operator<<(CJS_Object* pObj); |
114 void operator>>(CJS_Object*& ppObj) const; | 115 void operator>>(CJS_Object*& ppObj) const; |
115 void operator<<(CJS_Document* pJsDoc); | 116 void operator<<(CJS_Document* pJsDoc); |
116 void operator>>(CJS_Document*& ppJsDoc) const; | 117 void operator>>(CJS_Document*& ppJsDoc) const; |
(...skipping 11 matching lines...) Expand all Loading... |
128 operator v8::Local<v8::Value>() const; | 129 operator v8::Local<v8::Value>() const; |
129 void StartSetting(); | 130 void StartSetting(); |
130 void StartGetting(); | 131 void StartGetting(); |
131 | 132 |
132 private: | 133 private: |
133 FX_BOOL m_bIsSetting; | 134 FX_BOOL m_bIsSetting; |
134 }; | 135 }; |
135 | 136 |
136 class CJS_Array { | 137 class CJS_Array { |
137 public: | 138 public: |
138 CJS_Array(v8::Isolate* isolate); | 139 CJS_Array(CJS_Runtime* pRuntime); |
139 virtual ~CJS_Array(); | 140 virtual ~CJS_Array(); |
140 | 141 |
141 void Attach(v8::Local<v8::Array> pArray); | 142 void Attach(v8::Local<v8::Array> pArray); |
142 void GetElement(unsigned index, CJS_Value& value); | 143 void GetElement(unsigned index, CJS_Value& value); |
143 void SetElement(unsigned index, CJS_Value value); | 144 void SetElement(unsigned index, CJS_Value value); |
144 int GetLength(); | 145 int GetLength(); |
145 FX_BOOL IsAttached(); | 146 FX_BOOL IsAttached(); |
146 operator v8::Local<v8::Array>(); | 147 operator v8::Local<v8::Array>(); |
147 | 148 |
148 v8::Isolate* GetIsolate() { return m_isolate; } | 149 CJS_Runtime* GetJSRuntime() const { return m_pJSRuntime; } |
149 | 150 |
150 private: | 151 private: |
151 v8::Local<v8::Array> m_pArray; | 152 v8::Local<v8::Array> m_pArray; |
152 v8::Isolate* m_isolate; | 153 CJS_Runtime* m_pJSRuntime; |
153 }; | 154 }; |
154 | 155 |
155 class CJS_Date { | 156 class CJS_Date { |
156 friend class CJS_Value; | 157 friend class CJS_Value; |
157 | 158 |
158 public: | 159 public: |
159 CJS_Date(v8::Isolate* isolate); | 160 CJS_Date(CJS_Runtime* pRuntime); |
160 CJS_Date(v8::Isolate* isolate, double dMsec_time); | 161 CJS_Date(CJS_Runtime* pRuntime, double dMsec_time); |
161 CJS_Date(v8::Isolate* isolate, | 162 CJS_Date(CJS_Runtime* pRuntime, |
162 int year, | 163 int year, |
163 int mon, | 164 int mon, |
164 int day, | 165 int day, |
165 int hour, | 166 int hour, |
166 int min, | 167 int min, |
167 int sec); | 168 int sec); |
168 virtual ~CJS_Date(); | 169 virtual ~CJS_Date(); |
169 void Attach(v8::Local<v8::Value> pDate); | 170 void Attach(v8::Local<v8::Value> pDate); |
170 | 171 |
171 int GetYear(); | 172 int GetYear(); |
(...skipping 19 matching lines...) Expand all Loading... |
191 | 192 |
192 CFX_WideString ToString() const; | 193 CFX_WideString ToString() const; |
193 | 194 |
194 static double | 195 static double |
195 MakeDate(int year, int mon, int mday, int hour, int min, int sec, int ms); | 196 MakeDate(int year, int mon, int mday, int hour, int min, int sec, int ms); |
196 | 197 |
197 FX_BOOL IsValidDate(); | 198 FX_BOOL IsValidDate(); |
198 | 199 |
199 protected: | 200 protected: |
200 v8::Local<v8::Value> m_pDate; | 201 v8::Local<v8::Value> m_pDate; |
201 v8::Isolate* m_isolate; | 202 CJS_Runtime* m_pJSRuntime; |
202 }; | 203 }; |
203 | 204 |
204 double JS_GetDateTime(); | 205 double JS_GetDateTime(); |
205 int JS_GetYearFromTime(double dt); | 206 int JS_GetYearFromTime(double dt); |
206 int JS_GetMonthFromTime(double dt); | 207 int JS_GetMonthFromTime(double dt); |
207 int JS_GetDayFromTime(double dt); | 208 int JS_GetDayFromTime(double dt); |
208 int JS_GetHourFromTime(double dt); | 209 int JS_GetHourFromTime(double dt); |
209 int JS_GetMinFromTime(double dt); | 210 int JS_GetMinFromTime(double dt); |
210 int JS_GetSecFromTime(double dt); | 211 int JS_GetSecFromTime(double dt); |
211 double JS_DateParse(const wchar_t* string); | 212 double JS_DateParse(const wchar_t* string); |
212 double JS_MakeDay(int nYear, int nMonth, int nDay); | 213 double JS_MakeDay(int nYear, int nMonth, int nDay); |
213 double JS_MakeTime(int nHour, int nMin, int nSec, int nMs); | 214 double JS_MakeTime(int nHour, int nMin, int nSec, int nMs); |
214 double JS_MakeDate(double day, double time); | 215 double JS_MakeDate(double day, double time); |
215 bool JS_PortIsNan(double d); | 216 bool JS_PortIsNan(double d); |
216 double JS_LocalTime(double d); | 217 double JS_LocalTime(double d); |
217 | 218 |
218 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_VALUE_H_ | 219 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_VALUE_H_ |
OLD | NEW |