blob: 165898cf339e2ee3d33744200c693b7c8d39fabb [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*);
JUN FANG33f6f0d2015-04-06 12:39:51 -070055 void operator = (CJS_Document*);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056 void operator = (v8::Handle<v8::Object>);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070057 void operator = (CJS_Array &);
58 void operator = (CJS_Date &);
Tom Sepezf79a69c2014-10-30 13:23:42 -070059 void operator = (FX_LPCWSTR pWstr);
60 void operator = (FX_LPCSTR pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070061 void operator = (CJS_Value value);
Tom Sepezf79a69c2014-10-30 13:23:42 -070062
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070063 FX_BOOL IsArrayObject() const;
64 FX_BOOL IsDateObject() const;
65 FXJSVALUETYPE GetType() const;
66
67 FX_BOOL ConvertToArray(CJS_Array &) const;
68 FX_BOOL ConvertToDate(CJS_Date &) const;
69
70 v8::Isolate* GetIsolate() {return m_isolate;}
Tom Sepezf79a69c2014-10-30 13:23:42 -070071protected:
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072 v8::Handle<v8::Value> m_pValue;
73 FXJSVALUETYPE m_eType;
74 v8::Isolate* m_isolate;
75};
76
Tom Sepez2f3dfef2015-03-02 15:35:26 -080077class CJS_Parameters : public CFX_ArrayTemplate<CJS_Value>
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078{
79public:
Tom Sepez2f3dfef2015-03-02 15:35:26 -080080 void push_back(const CJS_Value& newElement) {
81 CFX_ArrayTemplate<CJS_Value>::Add(newElement);
82 }
83 int size() const {
84 return CFX_ArrayTemplate<CJS_Value>::GetSize();
85 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070087
88class CJS_PropValue: public CJS_Value
89{
90public:
JUN FANG33f6f0d2015-04-06 12:39:51 -070091 CJS_PropValue(const CJS_Value&);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092 CJS_PropValue(v8::Isolate* isolate);
93 ~CJS_PropValue();
94public:
95 FX_BOOL IsSetting();
96 FX_BOOL IsGetting();
JUN FANG33f6f0d2015-04-06 12:39:51 -070097 void operator<<(int);
98 void operator>>(int&) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099 void operator<<(bool);
JUN FANG33f6f0d2015-04-06 12:39:51 -0700100 void operator>>(bool&) const;
101 void operator<<(double);
102 void operator>>(double&) const;
103 void operator<<(CJS_Object* pObj);
104 void operator>>(CJS_Object*& ppObj) const;
105 void operator<<(CJS_Document* pJsDoc);
106 void operator>>(CJS_Document*& ppJsDoc) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107 void operator<<(CFX_ByteString);
JUN FANG33f6f0d2015-04-06 12:39:51 -0700108 void operator>>(CFX_ByteString&) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109 void operator<<(CFX_WideString);
JUN FANG33f6f0d2015-04-06 12:39:51 -0700110 void operator>>(CFX_WideString&) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111 void operator<<(FX_LPCWSTR c_string);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700112 void operator<<(JSFXObject);
JUN FANG33f6f0d2015-04-06 12:39:51 -0700113 void operator>>(JSFXObject&) const;
114 void operator>>(CJS_Array& array) const;
115 void operator<<(CJS_Array& array);
116 void operator<<(CJS_Date& date);
117 void operator>>(CJS_Date& date) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700118 operator v8::Handle<v8::Value>() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119 void StartSetting();
120 void StartGetting();
121private:
122 FX_BOOL m_bIsSetting;
123};
124
125class CJS_Array
126{
127public:
128 CJS_Array(v8::Isolate* isolate);
129 virtual ~CJS_Array();
130
131 void Attach(v8::Handle<v8::Array> pArray);
132 void GetElement(unsigned index,CJS_Value &value);
133 void SetElement(unsigned index,CJS_Value value);
134 int GetLength();
135 FX_BOOL IsAttached();
136 operator v8::Handle<v8::Array>();
137
138 v8::Isolate* GetIsolate() {return m_isolate;}
139private:
140 v8::Handle<v8::Array> m_pArray;
141 v8::Isolate* m_isolate;
142};
143
144class CJS_Date
145{
146friend class CJS_Value;
147public:
148 CJS_Date(v8::Isolate* isolate);
149 CJS_Date(v8::Isolate* isolate,double dMsec_time);
150 CJS_Date(v8::Isolate* isolate,int year, int mon, int day,int hour, int min, int sec);
151 virtual ~CJS_Date();
152 void Attach(v8::Handle<v8::Value> pDate);
153
154 int GetYear();
155 void SetYear(int iYear);
156
157 int GetMonth();
158 void SetMonth(int iMonth);
159
160 int GetDay();
161 void SetDay(int iDay);
162
163 int GetHours();
164 void SetHours(int iHours);
165
166 int GetMinutes();
167 void SetMinutes(int minutes);
168
169 int GetSeconds();
170 void SetSeconds(int seconds);
171
172 operator v8::Handle<v8::Value>();
173 operator double() const;
174
175 CFX_WideString ToString() const;
176
177 static double MakeDate(int year, int mon, int mday,int hour, int min, int sec,int ms);
178
179 FX_BOOL IsValidDate();
180
181protected:
182 v8::Handle<v8::Value> m_pDate;
183 v8::Isolate* m_isolate;
184};
185
186#endif //_JS_VALUE_H_
187