blob: 4962ddcf3dc81c9c22ce265b553aedf4dec3eb2c [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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
10class CJS_Array;
11class CJS_Date;
Tom Sepezf79a69c2014-10-30 13:23:42 -070012class CJS_Document;
13class CJS_Object;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070014
15class CJS_Value
16{
17public:
18 CJS_Value(v8::Isolate* isolate);
19 CJS_Value(v8::Isolate* isolate, v8::Handle<v8::Value> pValue,FXJSVALUETYPE t);
20 CJS_Value(v8::Isolate* isolate, const int &iValue);
21 CJS_Value(v8::Isolate* isolate, const double &dValue);
Tom Sepezf79a69c2014-10-30 13:23:42 -070022 CJS_Value(v8::Isolate* isolate, const float &fValue);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023 CJS_Value(v8::Isolate* isolate, const bool &bValue);
24 CJS_Value(v8::Isolate* isolate, JSFXObject);
Tom Sepezf79a69c2014-10-30 13:23:42 -070025 CJS_Value(v8::Isolate* isolate, CJS_Object*);
26 CJS_Value(v8::Isolate* isolate, CJS_Document*);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027 CJS_Value(v8::Isolate* isolate, FX_LPCSTR pStr);
28 CJS_Value(v8::Isolate* isolate, FX_LPCWSTR pWstr);
29 CJS_Value(v8::Isolate* isolate, CJS_Array& array);
Tom Sepezf79a69c2014-10-30 13:23:42 -070030
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031 ~CJS_Value();
32
33 void SetNull();
34 void Attach(v8::Handle<v8::Value> pValue,FXJSVALUETYPE t);
35 void Attach(CJS_Value *pValue);
36 void Detach();
37
38
39 operator int() const;
40 operator bool() const;
41 operator double() const;
42 operator float() const;
Tom Sepezf79a69c2014-10-30 13:23:42 -070043 operator CJS_Object*() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044 operator v8::Handle<v8::Object>() const;
45 operator v8::Handle<v8::Array>() const;
46 operator CFX_WideString() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070047 operator CFX_ByteString() const;
48 v8::Handle<v8::Value> ToJSValue();
49
50 void operator = (int iValue);
Tom Sepezf79a69c2014-10-30 13:23:42 -070051 void operator = (bool bValue);
52 void operator = (double);
53 void operator = (float);
54 void operator = (CJS_Object*);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070055 void operator = (v8::Handle<v8::Object>);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056 void operator = (CJS_Array &);
57 void operator = (CJS_Date &);
Tom Sepezf79a69c2014-10-30 13:23:42 -070058 void operator = (FX_LPCWSTR pWstr);
59 void operator = (FX_LPCSTR pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070060 void operator = (CJS_Value value);
Tom Sepezf79a69c2014-10-30 13:23:42 -070061
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070062 FX_BOOL IsArrayObject() const;
63 FX_BOOL IsDateObject() const;
64 FXJSVALUETYPE GetType() const;
65
66 FX_BOOL ConvertToArray(CJS_Array &) const;
67 FX_BOOL ConvertToDate(CJS_Date &) const;
68
69 v8::Isolate* GetIsolate() {return m_isolate;}
Tom Sepezf79a69c2014-10-30 13:23:42 -070070protected:
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071 v8::Handle<v8::Value> m_pValue;
72 FXJSVALUETYPE m_eType;
73 v8::Isolate* m_isolate;
74};
75
Tom Sepez2f3dfef2015-03-02 15:35:26 -080076class CJS_Parameters : public CFX_ArrayTemplate<CJS_Value>
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077{
78public:
Tom Sepez2f3dfef2015-03-02 15:35:26 -080079 void push_back(const CJS_Value& newElement) {
80 CFX_ArrayTemplate<CJS_Value>::Add(newElement);
81 }
82 int size() const {
83 return CFX_ArrayTemplate<CJS_Value>::GetSize();
84 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070085};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086
87class CJS_PropValue: public CJS_Value
88{
89public:
90 CJS_PropValue(const CJS_Value &);
91 CJS_PropValue(v8::Isolate* isolate);
92 ~CJS_PropValue();
93public:
94 FX_BOOL IsSetting();
95 FX_BOOL IsGetting();
96 void operator<<(int );
97 void operator>>(int &) const;
98 void operator<<(bool);
99 void operator>>(bool &) const;
100 void operator<<(double );
101 void operator>>(double &) const;
102 void operator<<(CJS_Object *pObj);
103 void operator>>(CJS_Object *&ppObj) const;
104 void operator<<(CFX_ByteString);
105 void operator>>(CFX_ByteString &) const;
106 void operator<<(CFX_WideString);
107 void operator>>(CFX_WideString &) const;
108 void operator<<(FX_LPCWSTR c_string);
109
110 void operator<<(JSFXObject);
111 void operator>>(JSFXObject &) const;
112
113 void operator>>(CJS_Array &array) const;
114 void operator<<(CJS_Array &array);
115
116 void operator<<(CJS_Date &date);
117 void operator>>(CJS_Date &date) const;
118
119 operator v8::Handle<v8::Value>() const;
120
121 void StartSetting();
122 void StartGetting();
123private:
124 FX_BOOL m_bIsSetting;
125};
126
127class CJS_Array
128{
129public:
130 CJS_Array(v8::Isolate* isolate);
131 virtual ~CJS_Array();
132
133 void Attach(v8::Handle<v8::Array> pArray);
134 void GetElement(unsigned index,CJS_Value &value);
135 void SetElement(unsigned index,CJS_Value value);
136 int GetLength();
137 FX_BOOL IsAttached();
138 operator v8::Handle<v8::Array>();
139
140 v8::Isolate* GetIsolate() {return m_isolate;}
141private:
142 v8::Handle<v8::Array> m_pArray;
143 v8::Isolate* m_isolate;
144};
145
146class CJS_Date
147{
148friend class CJS_Value;
149public:
150 CJS_Date(v8::Isolate* isolate);
151 CJS_Date(v8::Isolate* isolate,double dMsec_time);
152 CJS_Date(v8::Isolate* isolate,int year, int mon, int day,int hour, int min, int sec);
153 virtual ~CJS_Date();
154 void Attach(v8::Handle<v8::Value> pDate);
155
156 int GetYear();
157 void SetYear(int iYear);
158
159 int GetMonth();
160 void SetMonth(int iMonth);
161
162 int GetDay();
163 void SetDay(int iDay);
164
165 int GetHours();
166 void SetHours(int iHours);
167
168 int GetMinutes();
169 void SetMinutes(int minutes);
170
171 int GetSeconds();
172 void SetSeconds(int seconds);
173
174 operator v8::Handle<v8::Value>();
175 operator double() const;
176
177 CFX_WideString ToString() const;
178
179 static double MakeDate(int year, int mon, int mday,int hour, int min, int sec,int ms);
180
181 FX_BOOL IsValidDate();
182
183protected:
184 v8::Handle<v8::Value> m_pDate;
185 v8::Isolate* m_isolate;
186};
187
188#endif //_JS_VALUE_H_
189