blob: 1431349552439814d627959ef400ba8b529c9d23 [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
Tom Sepez9a3f8122015-04-07 15:35:48 -070010#include "../jsapi/fxjs_v8.h"
11#include "../../../core/include/fxcrt/fx_basic.h"
12
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070013class CJS_Array;
14class CJS_Date;
Tom Sepezf79a69c2014-10-30 13:23:42 -070015class CJS_Document;
16class CJS_Object;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017
18class CJS_Value
19{
20public:
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 Sepezf79a69c2014-10-30 13:23:42 -070025 CJS_Value(v8::Isolate* isolate, const float &fValue);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070026 CJS_Value(v8::Isolate* isolate, const bool &bValue);
27 CJS_Value(v8::Isolate* isolate, JSFXObject);
Tom Sepezf79a69c2014-10-30 13:23:42 -070028 CJS_Value(v8::Isolate* isolate, CJS_Object*);
29 CJS_Value(v8::Isolate* isolate, CJS_Document*);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030 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 Sepezf79a69c2014-10-30 13:23:42 -070033
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034 ~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 Sepezf79a69c2014-10-30 13:23:42 -070046 operator CJS_Object*() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070047 operator v8::Handle<v8::Object>() const;
48 operator v8::Handle<v8::Array>() const;
49 operator CFX_WideString() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050 operator CFX_ByteString() const;
51 v8::Handle<v8::Value> ToJSValue();
52
53 void operator = (int iValue);
Tom Sepezf79a69c2014-10-30 13:23:42 -070054 void operator = (bool bValue);
55 void operator = (double);
56 void operator = (float);
57 void operator = (CJS_Object*);
JUN FANG33f6f0d2015-04-06 12:39:51 -070058 void operator = (CJS_Document*);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059 void operator = (v8::Handle<v8::Object>);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070060 void operator = (CJS_Array &);
61 void operator = (CJS_Date &);
Tom Sepezf79a69c2014-10-30 13:23:42 -070062 void operator = (FX_LPCWSTR pWstr);
63 void operator = (FX_LPCSTR pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070064 void operator = (CJS_Value value);
Tom Sepezf79a69c2014-10-30 13:23:42 -070065
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070066 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 Sepezf79a69c2014-10-30 13:23:42 -070074protected:
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075 v8::Handle<v8::Value> m_pValue;
76 FXJSVALUETYPE m_eType;
77 v8::Isolate* m_isolate;
78};
79
Tom Sepez2f3dfef2015-03-02 15:35:26 -080080class CJS_Parameters : public CFX_ArrayTemplate<CJS_Value>
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081{
82public:
Tom Sepez2f3dfef2015-03-02 15:35:26 -080083 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-Malek3f3b45c2014-05-23 17:28:10 -070089};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090
91class CJS_PropValue: public CJS_Value
92{
93public:
JUN FANG33f6f0d2015-04-06 12:39:51 -070094 CJS_PropValue(const CJS_Value&);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095 CJS_PropValue(v8::Isolate* isolate);
96 ~CJS_PropValue();
97public:
98 FX_BOOL IsSetting();
99 FX_BOOL IsGetting();
JUN FANG33f6f0d2015-04-06 12:39:51 -0700100 void operator<<(int);
101 void operator>>(int&) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700102 void operator<<(bool);
JUN FANG33f6f0d2015-04-06 12:39:51 -0700103 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-Malek3f3b45c2014-05-23 17:28:10 -0700110 void operator<<(CFX_ByteString);
JUN FANG33f6f0d2015-04-06 12:39:51 -0700111 void operator>>(CFX_ByteString&) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700112 void operator<<(CFX_WideString);
JUN FANG33f6f0d2015-04-06 12:39:51 -0700113 void operator>>(CFX_WideString&) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114 void operator<<(FX_LPCWSTR c_string);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700115 void operator<<(JSFXObject);
JUN FANG33f6f0d2015-04-06 12:39:51 -0700116 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-Malek3f3b45c2014-05-23 17:28:10 -0700121 operator v8::Handle<v8::Value>() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700122 void StartSetting();
123 void StartGetting();
124private:
125 FX_BOOL m_bIsSetting;
126};
127
128class CJS_Array
129{
130public:
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;}
142private:
143 v8::Handle<v8::Array> m_pArray;
144 v8::Isolate* m_isolate;
145};
146
147class CJS_Date
148{
149friend class CJS_Value;
150public:
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
184protected:
185 v8::Handle<v8::Value> m_pDate;
186 v8::Isolate* m_isolate;
187};
188
189#endif //_JS_VALUE_H_
190