190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright 2014 PDFium Authors. All rights reserved. 290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file. 490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#ifndef _JS_VALUE_H_ 890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#define _JS_VALUE_H_ 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class CJS_Array; 1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class CJS_Date; 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class CJS_Value 1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles){ 1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)public: 1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CJS_Value(v8::Isolate* isolate); 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CJS_Value(v8::Isolate* isolate, v8::Handle<v8::Value> pValue,FXJSVALUETYPE t); 1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CJS_Value(v8::Isolate* isolate, const int &iValue); 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CJS_Value(v8::Isolate* isolate, const double &dValue); 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CJS_Value(v8::Isolate* isolate, const float &fValue); 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CJS_Value(v8::Isolate* isolate, const bool &bValue); 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CJS_Value(v8::Isolate* isolate, JSFXObject); 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CJS_Value(v8::Isolate* isolate, CJS_Object *); 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CJS_Value(v8::Isolate* isolate, FX_LPCSTR pStr); 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CJS_Value(v8::Isolate* isolate, FX_LPCWSTR pWstr); 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CJS_Value(v8::Isolate* isolate, CJS_Array& array); 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ~CJS_Value(); 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void SetNull(); 3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void Attach(v8::Handle<v8::Value> pValue,FXJSVALUETYPE t); 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void Attach(CJS_Value *pValue); 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void Detach(); 3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) operator int() const; 3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) operator bool() const; 3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) operator double() const; 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) operator float() const; 4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) operator CJS_Object *() const; 4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) //operator JSFXObject *() const; 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) operator v8::Handle<v8::Object>() const; 4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) operator v8::Handle<v8::Array>() const; 4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) operator CFX_WideString() const; 4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) //operator FX_WCHAR *() const; 4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) operator CFX_ByteString() const; 4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) v8::Handle<v8::Value> ToJSValue(); 4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator = (int iValue); 5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator = (bool bValue); 5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator = (double); 5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator = (float); 5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator = (CJS_Object *); 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator = (v8::Handle<v8::Object>); 5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// void operator = (JSObject *); 5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator = (CJS_Array &); 5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator = (CJS_Date &); 5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator = (FX_LPCWSTR pWstr); 5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator = (FX_LPCSTR pStr); 6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator = (CJS_Value value); 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FX_BOOL IsArrayObject() const; 6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FX_BOOL IsDateObject() const; 6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FXJSVALUETYPE GetType() const; 6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FX_BOOL ConvertToArray(CJS_Array &) const; 6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FX_BOOL ConvertToDate(CJS_Date &) const; 6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) v8::Isolate* GetIsolate() {return m_isolate;} 7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)protected: 7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) v8::Handle<v8::Value> m_pValue; 7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FXJSVALUETYPE m_eType; 7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) v8::Isolate* m_isolate; 7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)template<class TYPE> class CJS_ParametersTmpl : public CFX_ArrayTemplate<TYPE> 7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles){ 7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)public: 7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void push_back(TYPE newElement){CFX_ArrayTemplate<TYPE>::Add(newElement);} 8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int size() const{return CFX_ArrayTemplate<TYPE>::GetSize();} 8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)typedef CJS_ParametersTmpl<CJS_Value> CJS_Parameters; 8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class CJS_PropValue: public CJS_Value 8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles){ 8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)public: 8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CJS_PropValue(const CJS_Value &); 8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CJS_PropValue(v8::Isolate* isolate); 8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ~CJS_PropValue(); 9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)public: 9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FX_BOOL IsSetting(); 9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FX_BOOL IsGetting(); 9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator<<(int ); 9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator>>(int &) const; 9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator<<(bool); 9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator>>(bool &) const; 9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator<<(double ); 9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator>>(double &) const; 9990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator<<(CJS_Object *pObj); 10090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator>>(CJS_Object *&ppObj) const; 10190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator<<(CFX_ByteString); 10290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator>>(CFX_ByteString &) const; 10390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator<<(CFX_WideString); 10490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator>>(CFX_WideString &) const; 10590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator<<(FX_LPCWSTR c_string); 10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 10790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator<<(JSFXObject); 10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator>>(JSFXObject &) const; 10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 11090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator>>(CJS_Array &array) const; 11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator<<(CJS_Array &array); 11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator<<(CJS_Date &date); 11490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void operator>>(CJS_Date &date) const; 11590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 11690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) operator v8::Handle<v8::Value>() const; 11790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 11890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void StartSetting(); 11990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void StartGetting(); 12090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)private: 12190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FX_BOOL m_bIsSetting; 12290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 12390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 12490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class CJS_Array 12590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles){ 126public: 127 CJS_Array(v8::Isolate* isolate); 128 virtual ~CJS_Array(); 129 130 void Attach(v8::Handle<v8::Array> pArray); 131 void GetElement(unsigned index,CJS_Value &value); 132 void SetElement(unsigned index,CJS_Value value); 133 int GetLength(); 134 FX_BOOL IsAttached(); 135 operator v8::Handle<v8::Array>(); 136 137 v8::Isolate* GetIsolate() {return m_isolate;} 138private: 139 v8::Handle<v8::Array> m_pArray; 140 v8::Isolate* m_isolate; 141}; 142 143class CJS_Date 144{ 145friend class CJS_Value; 146public: 147 CJS_Date(v8::Isolate* isolate); 148 CJS_Date(v8::Isolate* isolate,double dMsec_time); 149 CJS_Date(v8::Isolate* isolate,int year, int mon, int day,int hour, int min, int sec); 150 virtual ~CJS_Date(); 151 void Attach(v8::Handle<v8::Value> pDate); 152 153 int GetYear(); 154 void SetYear(int iYear); 155 156 int GetMonth(); 157 void SetMonth(int iMonth); 158 159 int GetDay(); 160 void SetDay(int iDay); 161 162 int GetHours(); 163 void SetHours(int iHours); 164 165 int GetMinutes(); 166 void SetMinutes(int minutes); 167 168 int GetSeconds(); 169 void SetSeconds(int seconds); 170 171 operator v8::Handle<v8::Value>(); 172 operator double() const; 173 174 CFX_WideString ToString() const; 175 176 static double MakeDate(int year, int mon, int mday,int hour, int min, int sec,int ms); 177 178 FX_BOOL IsValidDate(); 179 180protected: 181 v8::Handle<v8::Value> m_pDate; 182 v8::Isolate* m_isolate; 183}; 184 185#endif //_JS_VALUE_H_ 186 187