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 #include "../../include/javascript/JavaScript.h" | 7 #include "../../include/javascript/JavaScript.h" |
8 #include "../../include/javascript/JS_Define.h" | 8 #include "../../include/javascript/JS_Define.h" |
9 #include "../../include/javascript/JS_Object.h" | 9 #include "../../include/javascript/JS_Object.h" |
10 #include "../../include/javascript/JS_Value.h" | 10 #include "../../include/javascript/JS_Value.h" |
11 #include "../../include/javascript/Document.h" | 11 #include "../../include/javascript/Document.h" |
12 | 12 |
13 /* ---------------------------- CJS_Value ---------------------------- */ | 13 /* ---------------------------- CJS_Value ---------------------------- */ |
14 | 14 |
15 CJS_Value::CJS_Value(v8::Isolate* isolate) : m_eType(VT_unknown),m_isolate(isola
te) | 15 CJS_Value::CJS_Value(v8::Isolate* isolate) |
16 { | 16 : m_eType(VT_unknown), m_isolate(isolate) {} |
17 } | 17 CJS_Value::CJS_Value(v8::Isolate* isolate, |
18 CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue,FXJSVALUE
TYPE t) : | 18 v8::Local<v8::Value> pValue, |
19 m_pValue(pValue), m_eType(t), m_isolate(isolate) | 19 FXJSVALUETYPE t) |
20 { | 20 : m_pValue(pValue), m_eType(t), m_isolate(isolate) {} |
21 } | 21 |
22 | 22 CJS_Value::CJS_Value(v8::Isolate* isolate, const int& iValue) |
23 CJS_Value::CJS_Value(v8::Isolate* isolate, const int &iValue):m_isolate(isolate) | 23 : m_isolate(isolate) { |
24 { | 24 operator=(iValue); |
25 operator =(iValue); | 25 } |
26 } | 26 |
27 | 27 CJS_Value::CJS_Value(v8::Isolate* isolate, const bool& bValue) |
28 CJS_Value::CJS_Value(v8::Isolate* isolate, const bool &bValue):m_isolate(isolate
) | 28 : m_isolate(isolate) { |
29 { | 29 operator=(bValue); |
30 operator =(bValue); | 30 } |
31 } | 31 |
32 | 32 CJS_Value::CJS_Value(v8::Isolate* isolate, const float& fValue) |
33 CJS_Value::CJS_Value(v8::Isolate* isolate, const float &fValue):m_isolate(isolat
e) | 33 : m_isolate(isolate) { |
34 { | 34 operator=(fValue); |
35 operator =(fValue); | 35 } |
36 } | 36 |
37 | 37 CJS_Value::CJS_Value(v8::Isolate* isolate, const double& dValue) |
38 CJS_Value::CJS_Value(v8::Isolate* isolate, const double &dValue):m_isolate(isola
te) | 38 : m_isolate(isolate) { |
39 { | 39 operator=(dValue); |
40 operator =(dValue); | 40 } |
41 } | 41 |
42 | 42 CJS_Value::CJS_Value(v8::Isolate* isolate, JSFXObject pJsObj) |
43 CJS_Value::CJS_Value(v8::Isolate* isolate, JSFXObject pJsObj):m_isolate(isolate
) | 43 : m_isolate(isolate) { |
44 { | 44 operator=(pJsObj); |
45 operator =(pJsObj); | 45 } |
46 } | 46 |
47 | 47 CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Object* pJsObj) |
48 CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Object* pJsObj):m_isolate(isolate
) | 48 : m_isolate(isolate) { |
49 { | 49 operator=(pJsObj); |
50 operator =(pJsObj); | 50 } |
51 } | 51 |
52 | 52 CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Document* pJsDoc) |
53 CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Document* pJsDoc):m_isolate(isola
te) | 53 : m_isolate(isolate) { |
54 { | 54 m_eType = VT_object; |
55 m_eType = VT_object; | 55 if (pJsDoc) |
56 if (pJsDoc) | 56 m_pValue = (JSFXObject)*pJsDoc; |
57 m_pValue = (JSFXObject)*pJsDoc; | 57 } |
58 } | 58 |
59 | 59 CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_WCHAR* pWstr) |
60 CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_WCHAR* pWstr):m_isolate(isol
ate) | 60 : m_isolate(isolate) { |
61 { | 61 operator=(pWstr); |
62 operator =(pWstr); | 62 } |
63 } | 63 |
64 | 64 CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_CHAR* pStr) |
65 CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_CHAR* pStr):m_isolate(isolat
e) | 65 : m_isolate(isolate) { |
66 { | 66 operator=(pStr); |
67 operator = (pStr); | 67 } |
68 } | 68 |
69 | 69 CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Array& array) |
70 CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Array& array):m_isolate(isolate) | 70 : m_isolate(isolate) { |
71 { | 71 operator=(array); |
72 operator = (array); | 72 } |
73 } | 73 |
74 | 74 CJS_Value::~CJS_Value() {} |
75 CJS_Value::~CJS_Value() | 75 |
76 { | 76 void CJS_Value::Attach(v8::Local<v8::Value> pValue, FXJSVALUETYPE t) { |
77 } | 77 m_pValue = pValue; |
78 | 78 m_eType = t; |
79 void CJS_Value::Attach(v8::Local<v8::Value> pValue,FXJSVALUETYPE t) | 79 } |
80 { | 80 |
81 m_pValue = pValue; | 81 void CJS_Value::Attach(CJS_Value* pValue) { |
82 m_eType = t; | 82 if (pValue) |
83 } | 83 Attach(pValue->ToV8Value(), pValue->GetType()); |
84 | 84 } |
85 void CJS_Value::Attach(CJS_Value *pValue) | 85 |
86 { | 86 void CJS_Value::Detach() { |
87 if (pValue) | 87 m_pValue = v8::Local<v8::Value>(); |
88 Attach(pValue->ToV8Value(), pValue->GetType()); | 88 m_eType = VT_unknown; |
89 } | 89 } |
90 | 90 |
91 void CJS_Value::Detach() | 91 /* -----------------------------------------------------------------------------
----------- |
92 { | 92 */ |
93 m_pValue = v8::Local<v8::Value>(); | 93 |
94 m_eType = VT_unknown; | 94 int CJS_Value::ToInt() const { |
95 } | 95 return JS_ToInt32(m_isolate, m_pValue); |
96 | 96 } |
97 /* -----------------------------------------------------------------------------
----------- */ | 97 |
98 | 98 bool CJS_Value::ToBool() const { |
99 int CJS_Value::ToInt() const | 99 return JS_ToBoolean(m_isolate, m_pValue); |
100 { | 100 } |
101 return JS_ToInt32(m_isolate, m_pValue); | 101 |
102 } | 102 double CJS_Value::ToDouble() const { |
103 | 103 return JS_ToNumber(m_isolate, m_pValue); |
104 bool CJS_Value::ToBool() const | 104 } |
105 { | 105 |
106 return JS_ToBoolean(m_isolate, m_pValue); | 106 float CJS_Value::ToFloat() const { |
107 } | 107 return (float)ToDouble(); |
108 | 108 } |
109 double CJS_Value::ToDouble() const | 109 |
110 { | 110 CJS_Object* CJS_Value::ToCJSObject() const { |
111 return JS_ToNumber(m_isolate, m_pValue); | 111 v8::Local<v8::Object> pObj = JS_ToObject(m_isolate, m_pValue); |
112 } | 112 return (CJS_Object*)JS_GetPrivate(m_isolate, pObj); |
113 | 113 } |
114 float CJS_Value::ToFloat() const | 114 |
115 { | 115 v8::Local<v8::Object> CJS_Value::ToV8Object() const { |
116 return (float)ToDouble(); | 116 return JS_ToObject(m_isolate, m_pValue); |
117 } | 117 } |
118 | 118 |
119 CJS_Object* CJS_Value::ToCJSObject() const | 119 CFX_WideString CJS_Value::ToCFXWideString() const { |
120 { | 120 return JS_ToString(m_isolate, m_pValue); |
121 v8::Local<v8::Object> pObj = JS_ToObject(m_isolate, m_pValue); | 121 } |
122 return (CJS_Object*)JS_GetPrivate(m_isolate, pObj); | 122 |
123 } | 123 CFX_ByteString CJS_Value::ToCFXByteString() const { |
124 | 124 return CFX_ByteString::FromUnicode(ToCFXWideString()); |
125 v8::Local<v8::Object> CJS_Value::ToV8Object() const | 125 } |
126 { | 126 |
127 return JS_ToObject(m_isolate, m_pValue); | 127 v8::Local<v8::Value> CJS_Value::ToV8Value() const { |
128 } | 128 return m_pValue; |
129 | 129 } |
130 CFX_WideString CJS_Value::ToCFXWideString() const | 130 |
131 { | 131 v8::Local<v8::Array> CJS_Value::ToV8Array() const { |
132 return JS_ToString(m_isolate, m_pValue); | 132 if (IsArrayObject()) |
133 } | 133 return v8::Local<v8::Array>::Cast(JS_ToObject(m_isolate, m_pValue)); |
134 | 134 return v8::Local<v8::Array>(); |
135 CFX_ByteString CJS_Value::ToCFXByteString() const | 135 } |
136 { | 136 |
137 return CFX_ByteString::FromUnicode(ToCFXWideString()); | 137 /* -----------------------------------------------------------------------------
----------- |
138 } | 138 */ |
139 | 139 |
140 v8::Local<v8::Value> CJS_Value::ToV8Value() const | 140 void CJS_Value::operator=(int iValue) { |
141 { | 141 m_pValue = JS_NewNumber(m_isolate, iValue); |
142 return m_pValue; | 142 |
143 } | 143 m_eType = VT_number; |
144 | 144 } |
145 v8::Local<v8::Array>CJS_Value::ToV8Array() const | 145 |
146 { | 146 void CJS_Value::operator=(bool bValue) { |
147 if (IsArrayObject()) | 147 m_pValue = JS_NewBoolean(m_isolate, bValue); |
148 return v8::Local<v8::Array>::Cast(JS_ToObject(m_isolate, m_pValu
e)); | 148 |
149 return v8::Local<v8::Array>(); | 149 m_eType = VT_boolean; |
150 } | 150 } |
151 | 151 |
152 /* -----------------------------------------------------------------------------
----------- */ | 152 void CJS_Value::operator=(double dValue) { |
153 | 153 m_pValue = JS_NewNumber(m_isolate, dValue); |
154 void CJS_Value::operator =(int iValue) | 154 |
155 { | 155 m_eType = VT_number; |
156 m_pValue = JS_NewNumber(m_isolate, iValue); | 156 } |
157 | 157 |
158 m_eType = VT_number; | 158 void CJS_Value::operator=(float fValue) { |
159 } | 159 m_pValue = JS_NewNumber(m_isolate, fValue); |
160 | 160 m_eType = VT_number; |
161 void CJS_Value::operator =(bool bValue) | 161 } |
162 { | 162 |
163 m_pValue = JS_NewBoolean(m_isolate, bValue); | 163 void CJS_Value::operator=(v8::Local<v8::Object> pObj) { |
164 | 164 m_pValue = JS_NewObject(m_isolate, pObj); |
165 m_eType = VT_boolean; | 165 |
166 } | 166 m_eType = VT_fxobject; |
167 | 167 } |
168 void CJS_Value::operator =(double dValue) | 168 |
169 { | 169 void CJS_Value::operator=(CJS_Object* pObj) { |
170 m_pValue = JS_NewNumber(m_isolate,dValue); | 170 if (pObj) |
171 | 171 operator=((JSFXObject)*pObj); |
172 m_eType = VT_number; | 172 } |
173 } | 173 |
174 | 174 void CJS_Value::operator=(CJS_Document* pJsDoc) { |
175 void CJS_Value::operator = (float fValue) | 175 m_eType = VT_object; |
176 { | 176 if (pJsDoc) { |
177 m_pValue = JS_NewNumber(m_isolate,fValue); | 177 m_pValue = static_cast<JSFXObject>(*pJsDoc); |
178 m_eType = VT_number; | 178 } |
179 } | 179 } |
180 | 180 |
181 void CJS_Value::operator =(v8::Local<v8::Object> pObj) | 181 void CJS_Value::operator=(const FX_WCHAR* pWstr) { |
182 { | 182 m_pValue = JS_NewString(m_isolate, (wchar_t*)pWstr); |
183 | 183 |
184 m_pValue = JS_NewObject(m_isolate,pObj); | 184 m_eType = VT_string; |
185 | 185 } |
186 m_eType = VT_fxobject; | 186 |
187 } | 187 void CJS_Value::SetNull() { |
188 | 188 m_pValue = JS_NewNull(); |
189 void CJS_Value::operator =(CJS_Object * pObj) | 189 |
190 { | 190 m_eType = VT_null; |
191 if (pObj) | 191 } |
192 operator = ((JSFXObject)*pObj); | 192 |
193 } | 193 void CJS_Value::operator=(const FX_CHAR* pStr) { |
194 | 194 operator=(CFX_WideString::FromLocal(pStr).c_str()); |
195 void CJS_Value::operator = (CJS_Document* pJsDoc) | 195 } |
196 { | 196 |
197 m_eType = VT_object; | 197 void CJS_Value::operator=(CJS_Array& array) { |
198 if (pJsDoc) { | 198 m_pValue = JS_NewObject2(m_isolate, (v8::Local<v8::Array>)array); |
199 m_pValue = static_cast<JSFXObject>(*pJsDoc); | 199 |
200 } | 200 m_eType = VT_object; |
201 } | 201 } |
202 | 202 |
203 void CJS_Value::operator =(const FX_WCHAR* pWstr) | 203 void CJS_Value::operator=(CJS_Date& date) { |
204 { | 204 m_pValue = JS_NewDate(m_isolate, (double)date); |
205 m_pValue = JS_NewString(m_isolate,(wchar_t *)pWstr); | 205 |
206 | 206 m_eType = VT_date; |
207 m_eType = VT_string; | 207 } |
208 } | 208 |
209 | 209 void CJS_Value::operator=(CJS_Value value) { |
210 void CJS_Value::SetNull() | 210 m_pValue = value.ToV8Value(); |
211 { | 211 |
212 m_pValue = JS_NewNull(); | 212 m_eType = value.m_eType; |
213 | 213 m_isolate = value.m_isolate; |
214 m_eType = VT_null; | 214 } |
215 } | 215 |
216 | 216 /* -----------------------------------------------------------------------------
----------- |
217 void CJS_Value::operator = (const FX_CHAR* pStr) | 217 */ |
218 { | 218 |
219 operator = (CFX_WideString::FromLocal(pStr).c_str()); | 219 FXJSVALUETYPE CJS_Value::GetType() const { |
220 } | 220 if (m_pValue.IsEmpty()) |
221 | 221 return VT_unknown; |
222 void CJS_Value::operator = (CJS_Array & array) | 222 if (m_pValue->IsString()) |
223 { | 223 return VT_string; |
224 m_pValue = JS_NewObject2(m_isolate,(v8::Local<v8::Array>)array); | 224 if (m_pValue->IsNumber()) |
225 | 225 return VT_number; |
226 m_eType = VT_object; | 226 if (m_pValue->IsBoolean()) |
227 } | 227 return VT_boolean; |
228 | 228 if (m_pValue->IsDate()) |
229 void CJS_Value::operator = (CJS_Date & date) | 229 return VT_date; |
230 { | 230 if (m_pValue->IsObject()) |
231 m_pValue = JS_NewDate(m_isolate, (double)date); | 231 return VT_object; |
232 | 232 if (m_pValue->IsNull()) |
233 m_eType = VT_date; | 233 return VT_null; |
234 } | 234 if (m_pValue->IsUndefined()) |
235 | 235 return VT_undefined; |
236 void CJS_Value::operator = (CJS_Value value) | 236 return VT_unknown; |
237 { | 237 } |
238 m_pValue = value.ToV8Value(); | 238 |
239 | 239 FX_BOOL CJS_Value::IsArrayObject() const { |
240 m_eType = value.m_eType; | 240 if (m_pValue.IsEmpty()) |
241 m_isolate = value.m_isolate; | 241 return FALSE; |
242 } | 242 return m_pValue->IsArray(); |
243 | 243 } |
244 /* -----------------------------------------------------------------------------
----------- */ | 244 |
245 | 245 FX_BOOL CJS_Value::IsDateObject() const { |
246 FXJSVALUETYPE CJS_Value::GetType() const | 246 if (m_pValue.IsEmpty()) |
247 { | 247 return FALSE; |
248 if(m_pValue.IsEmpty()) return VT_unknown; | 248 return m_pValue->IsDate(); |
249 if(m_pValue->IsString()) return VT_string; | 249 } |
250 if(m_pValue->IsNumber()) return VT_number; | 250 |
251 if(m_pValue->IsBoolean()) return VT_boolean; | 251 // CJS_Value::operator CJS_Array() |
252 if(m_pValue->IsDate()) return VT_date; | 252 FX_BOOL CJS_Value::ConvertToArray(CJS_Array& array) const { |
253 if(m_pValue->IsObject()) return VT_object; | 253 if (IsArrayObject()) { |
254 if(m_pValue->IsNull()) return VT_null; | 254 array.Attach(JS_ToArray(m_isolate, m_pValue)); |
255 if(m_pValue->IsUndefined()) return VT_undefined; | 255 return TRUE; |
256 return VT_unknown; | 256 } |
257 } | 257 |
258 | 258 return FALSE; |
259 FX_BOOL CJS_Value::IsArrayObject() const | 259 } |
260 { | 260 |
261 if(m_pValue.IsEmpty()) return FALSE; | 261 FX_BOOL CJS_Value::ConvertToDate(CJS_Date& date) const { |
262 return m_pValue->IsArray(); | 262 // if (GetType() == VT_date) |
263 } | 263 // { |
264 | 264 // date = (double)(*this); |
265 FX_BOOL CJS_Value::IsDateObject() const | 265 // return TRUE; |
266 { | 266 // } |
267 if(m_pValue.IsEmpty()) return FALSE; | 267 |
268 return m_pValue->IsDate(); | 268 if (IsDateObject()) { |
269 } | 269 date.Attach(m_pValue); |
270 | 270 return TRUE; |
271 //CJS_Value::operator CJS_Array() | 271 } |
272 FX_BOOL CJS_Value::ConvertToArray(CJS_Array &array) const | 272 |
273 { | 273 return FALSE; |
274 if (IsArrayObject()) | |
275 { | |
276 array.Attach(JS_ToArray(m_isolate, m_pValue)); | |
277 return TRUE; | |
278 } | |
279 | |
280 return FALSE; | |
281 } | |
282 | |
283 FX_BOOL CJS_Value::ConvertToDate(CJS_Date &date) const | |
284 { | |
285 // if (GetType() == VT_date) | |
286 // { | |
287 // date = (double)(*this); | |
288 // return TRUE; | |
289 // } | |
290 | |
291 if (IsDateObject()) | |
292 { | |
293 date.Attach(m_pValue); | |
294 return TRUE; | |
295 } | |
296 | |
297 return FALSE; | |
298 } | 274 } |
299 | 275 |
300 /* ---------------------------- CJS_PropValue ---------------------------- */ | 276 /* ---------------------------- CJS_PropValue ---------------------------- */ |
301 | 277 |
302 CJS_PropValue::CJS_PropValue(const CJS_Value &value) : | 278 CJS_PropValue::CJS_PropValue(const CJS_Value& value) |
303 CJS_Value(value), | 279 : CJS_Value(value), m_bIsSetting(0) {} |
304 m_bIsSetting(0) | 280 |
305 { | 281 CJS_PropValue::CJS_PropValue(v8::Isolate* isolate) |
306 } | 282 : CJS_Value(isolate), m_bIsSetting(0) {} |
307 | 283 |
308 CJS_PropValue::CJS_PropValue(v8::Isolate* isolate) : CJS_Value(isolate), | 284 CJS_PropValue::~CJS_PropValue() {} |
309 m_bIsSetting(0) | 285 |
310 { | 286 FX_BOOL CJS_PropValue::IsSetting() { |
311 } | 287 return m_bIsSetting; |
312 | 288 } |
313 CJS_PropValue::~CJS_PropValue() | 289 |
314 { | 290 FX_BOOL CJS_PropValue::IsGetting() { |
315 } | 291 return !m_bIsSetting; |
316 | 292 } |
317 FX_BOOL CJS_PropValue::IsSetting() | 293 |
318 { | 294 void CJS_PropValue::operator<<(int iValue) { |
319 return m_bIsSetting; | 295 ASSERT(!m_bIsSetting); |
320 } | 296 CJS_Value::operator=(iValue); |
321 | 297 } |
322 FX_BOOL CJS_PropValue::IsGetting() | 298 |
323 { | 299 void CJS_PropValue::operator>>(int& iValue) const { |
324 return !m_bIsSetting; | 300 ASSERT(m_bIsSetting); |
325 } | 301 iValue = CJS_Value::ToInt(); |
326 | 302 } |
327 void CJS_PropValue::operator <<(int iValue) | 303 |
328 { | 304 void CJS_PropValue::operator<<(bool bValue) { |
329 ASSERT(!m_bIsSetting); | 305 ASSERT(!m_bIsSetting); |
330 CJS_Value::operator =(iValue); | 306 CJS_Value::operator=(bValue); |
331 } | 307 } |
332 | 308 |
333 void CJS_PropValue::operator >>(int & iValue) const | 309 void CJS_PropValue::operator>>(bool& bValue) const { |
334 { | 310 ASSERT(m_bIsSetting); |
335 ASSERT(m_bIsSetting); | 311 bValue = CJS_Value::ToBool(); |
336 iValue = CJS_Value::ToInt(); | 312 } |
337 } | 313 |
338 | 314 void CJS_PropValue::operator<<(double dValue) { |
339 | 315 ASSERT(!m_bIsSetting); |
340 void CJS_PropValue::operator <<(bool bValue) | 316 CJS_Value::operator=(dValue); |
341 { | 317 } |
342 ASSERT(!m_bIsSetting); | 318 |
343 CJS_Value::operator =(bValue); | 319 void CJS_PropValue::operator>>(double& dValue) const { |
344 } | 320 ASSERT(m_bIsSetting); |
345 | 321 dValue = CJS_Value::ToDouble(); |
346 void CJS_PropValue::operator >>(bool& bValue) const | 322 } |
347 { | 323 |
348 ASSERT(m_bIsSetting); | 324 void CJS_PropValue::operator<<(CJS_Object* pObj) { |
349 bValue = CJS_Value::ToBool(); | 325 ASSERT(!m_bIsSetting); |
350 } | 326 CJS_Value::operator=(pObj); |
351 | 327 } |
352 void CJS_PropValue::operator <<(double dValue) | 328 |
353 { | 329 void CJS_PropValue::operator>>(CJS_Object*& ppObj) const { |
354 ASSERT(!m_bIsSetting); | 330 ASSERT(m_bIsSetting); |
355 CJS_Value::operator =(dValue); | 331 ppObj = CJS_Value::ToCJSObject(); |
356 } | 332 } |
357 | 333 |
358 void CJS_PropValue::operator >>(double& dValue) const | 334 void CJS_PropValue::operator<<(CJS_Document* pJsDoc) { |
359 { | 335 ASSERT(!m_bIsSetting); |
360 ASSERT(m_bIsSetting); | 336 CJS_Value::operator=(pJsDoc); |
361 dValue = CJS_Value::ToDouble(); | 337 } |
362 } | 338 |
363 | 339 void CJS_PropValue::operator>>(CJS_Document*& ppJsDoc) const { |
364 void CJS_PropValue::operator <<(CJS_Object* pObj) | 340 ASSERT(m_bIsSetting); |
365 { | 341 ppJsDoc = static_cast<CJS_Document*>(CJS_Value::ToCJSObject()); |
366 ASSERT(!m_bIsSetting); | 342 } |
367 CJS_Value::operator = (pObj); | 343 |
368 } | 344 void CJS_PropValue::operator<<(JSFXObject pObj) { |
369 | 345 ASSERT(!m_bIsSetting); |
370 void CJS_PropValue::operator >>(CJS_Object*& ppObj) const | 346 CJS_Value::operator=(pObj); |
371 { | 347 } |
372 ASSERT(m_bIsSetting); | 348 |
373 ppObj = CJS_Value::ToCJSObject(); | 349 void CJS_PropValue::operator>>(JSFXObject& ppObj) const { |
374 } | 350 ASSERT(m_bIsSetting); |
375 | 351 ppObj = CJS_Value::ToV8Object(); |
376 void CJS_PropValue::operator <<(CJS_Document* pJsDoc) | 352 } |
377 { | 353 |
378 ASSERT(!m_bIsSetting); | 354 void CJS_PropValue::StartSetting() { |
379 CJS_Value::operator = (pJsDoc); | 355 m_bIsSetting = 1; |
380 } | 356 } |
381 | 357 |
382 void CJS_PropValue::operator >>(CJS_Document*& ppJsDoc) const | 358 void CJS_PropValue::StartGetting() { |
383 { | 359 m_bIsSetting = 0; |
384 ASSERT(m_bIsSetting); | 360 } |
385 ppJsDoc = static_cast<CJS_Document*>(CJS_Value::ToCJSObject()); | 361 void CJS_PropValue::operator<<(CFX_ByteString string) { |
386 } | 362 ASSERT(!m_bIsSetting); |
387 | 363 CJS_Value::operator=(string.c_str()); |
388 void CJS_PropValue::operator<<(JSFXObject pObj) | 364 } |
389 { | 365 |
390 ASSERT(!m_bIsSetting); | 366 void CJS_PropValue::operator>>(CFX_ByteString& string) const { |
391 CJS_Value::operator = (pObj); | 367 ASSERT(m_bIsSetting); |
392 } | 368 string = CJS_Value::ToCFXByteString(); |
393 | 369 } |
394 void CJS_PropValue::operator>>(JSFXObject &ppObj) const | 370 |
395 { | 371 void CJS_PropValue::operator<<(const FX_WCHAR* c_string) { |
396 ASSERT(m_bIsSetting); | 372 ASSERT(!m_bIsSetting); |
397 ppObj = CJS_Value::ToV8Object(); | 373 CJS_Value::operator=(c_string); |
398 } | 374 } |
399 | 375 |
400 | 376 void CJS_PropValue::operator>>(CFX_WideString& wide_string) const { |
401 void CJS_PropValue::StartSetting() | 377 ASSERT(m_bIsSetting); |
402 { | 378 wide_string = CJS_Value::ToCFXWideString(); |
403 m_bIsSetting = 1; | 379 } |
404 } | 380 |
405 | 381 void CJS_PropValue::operator<<(CFX_WideString wide_string) { |
406 void CJS_PropValue::StartGetting() | 382 ASSERT(!m_bIsSetting); |
407 { | 383 CJS_Value::operator=(wide_string.c_str()); |
408 m_bIsSetting = 0; | 384 } |
409 } | 385 |
410 void CJS_PropValue::operator <<(CFX_ByteString string) | 386 void CJS_PropValue::operator>>(CJS_Array& array) const { |
411 { | 387 ASSERT(m_bIsSetting); |
412 ASSERT(!m_bIsSetting); | 388 ConvertToArray(array); |
413 CJS_Value::operator = (string.c_str()); | 389 } |
414 } | 390 |
415 | 391 void CJS_PropValue::operator<<(CJS_Array& array) { |
416 void CJS_PropValue::operator >>(CFX_ByteString &string) const | 392 ASSERT(!m_bIsSetting); |
417 { | 393 CJS_Value::operator=(array); |
418 ASSERT(m_bIsSetting); | 394 } |
419 string = CJS_Value::ToCFXByteString(); | 395 |
420 } | 396 void CJS_PropValue::operator>>(CJS_Date& date) const { |
421 | 397 ASSERT(m_bIsSetting); |
422 void CJS_PropValue::operator <<(const FX_WCHAR* c_string) | 398 ConvertToDate(date); |
423 { | 399 } |
424 ASSERT(!m_bIsSetting); | 400 |
425 CJS_Value::operator =(c_string); | 401 void CJS_PropValue::operator<<(CJS_Date& date) { |
426 } | 402 ASSERT(!m_bIsSetting); |
427 | 403 CJS_Value::operator=(date); |
428 void CJS_PropValue::operator >>(CFX_WideString &wide_string) const | 404 } |
429 { | 405 |
430 ASSERT(m_bIsSetting); | 406 CJS_PropValue::operator v8::Local<v8::Value>() const { |
431 wide_string = CJS_Value::ToCFXWideString(); | 407 return m_pValue; |
432 } | 408 } |
433 | 409 |
434 void CJS_PropValue::operator <<(CFX_WideString wide_string) | 410 /* ======================================== CJS_Array |
435 { | 411 * ========================================= */ |
436 ASSERT(!m_bIsSetting); | 412 CJS_Array::CJS_Array(v8::Isolate* isolate) : m_isolate(isolate) {} |
437 CJS_Value::operator = (wide_string.c_str()); | 413 |
438 } | 414 CJS_Array::~CJS_Array() {} |
439 | 415 |
440 void CJS_PropValue::operator >>(CJS_Array &array) const | 416 void CJS_Array::Attach(v8::Local<v8::Array> pArray) { |
441 { | 417 m_pArray = pArray; |
442 ASSERT(m_bIsSetting); | 418 } |
443 ConvertToArray(array); | 419 |
444 } | 420 FX_BOOL CJS_Array::IsAttached() { |
445 | 421 return FALSE; |
446 void CJS_PropValue::operator <<(CJS_Array &array) | 422 } |
447 { | 423 |
448 ASSERT(!m_bIsSetting); | 424 void CJS_Array::GetElement(unsigned index, CJS_Value& value) { |
449 CJS_Value::operator=(array); | 425 if (m_pArray.IsEmpty()) |
450 } | 426 return; |
451 | 427 v8::Local<v8::Value> p = JS_GetArrayElement(m_isolate, m_pArray, index); |
452 void CJS_PropValue::operator>>(CJS_Date &date) const | 428 value.Attach(p, VT_object); |
453 { | 429 } |
454 ASSERT(m_bIsSetting); | 430 |
455 ConvertToDate(date); | 431 void CJS_Array::SetElement(unsigned index, CJS_Value value) { |
456 } | 432 if (m_pArray.IsEmpty()) |
457 | 433 m_pArray = JS_NewArray(m_isolate); |
458 void CJS_PropValue::operator<<(CJS_Date &date) | 434 |
459 { | 435 JS_PutArrayElement(m_isolate, m_pArray, index, value.ToV8Value(), |
460 ASSERT(!m_bIsSetting); | 436 value.GetType()); |
461 CJS_Value::operator=(date); | 437 } |
462 } | 438 |
463 | 439 int CJS_Array::GetLength() { |
464 CJS_PropValue::operator v8::Local<v8::Value>() const | 440 if (m_pArray.IsEmpty()) |
465 { | 441 return 0; |
466 return m_pValue; | 442 return JS_GetArrayLength(m_pArray); |
467 } | 443 } |
468 | 444 |
469 /* ======================================== CJS_Array ==========================
=============== */ | 445 CJS_Array::operator v8::Local<v8::Array>() { |
470 CJS_Array::CJS_Array(v8::Isolate* isolate):m_isolate(isolate) | 446 if (m_pArray.IsEmpty()) |
471 { | 447 m_pArray = JS_NewArray(m_isolate); |
472 } | 448 |
473 | 449 return m_pArray; |
474 CJS_Array::~CJS_Array() | 450 } |
475 { | 451 |
476 } | 452 /* ======================================== CJS_Date |
477 | 453 * ========================================= */ |
478 void CJS_Array::Attach(v8::Local<v8::Array> pArray) | 454 |
479 { | 455 CJS_Date::CJS_Date(v8::Isolate* isolate) : m_isolate(isolate) {} |
480 m_pArray = pArray; | 456 |
481 } | 457 CJS_Date::CJS_Date(v8::Isolate* isolate, double dMsec_time) { |
482 | 458 m_isolate = isolate; |
483 FX_BOOL CJS_Array::IsAttached() | 459 m_pDate = JS_NewDate(isolate, dMsec_time); |
484 { | 460 } |
485 return FALSE; | 461 |
486 } | 462 CJS_Date::CJS_Date(v8::Isolate* isolate, |
487 | 463 int year, |
488 void CJS_Array::GetElement(unsigned index,CJS_Value &value) | 464 int mon, |
489 { | 465 int day, |
490 if (m_pArray.IsEmpty()) | 466 int hour, |
491 return; | 467 int min, |
492 v8::Local<v8::Value> p = JS_GetArrayElement(m_isolate, m_pArray,index); | 468 int sec) { |
493 value.Attach(p,VT_object); | 469 m_isolate = isolate; |
494 } | 470 m_pDate = JS_NewDate(isolate, MakeDate(year, mon, day, hour, min, sec, 0)); |
495 | 471 } |
496 void CJS_Array::SetElement(unsigned index,CJS_Value value) | 472 |
497 { | 473 double CJS_Date::MakeDate(int year, |
498 if (m_pArray.IsEmpty()) | 474 int mon, |
499 m_pArray = JS_NewArray(m_isolate); | 475 int day, |
500 | 476 int hour, |
501 JS_PutArrayElement(m_isolate, m_pArray, index, value.ToV8Value(), value.
GetType()); | 477 int min, |
502 } | 478 int sec, |
503 | 479 int ms) { |
504 int CJS_Array::GetLength() | 480 return JS_MakeDate(JS_MakeDay(year, mon, day), |
505 { | 481 JS_MakeTime(hour, min, sec, ms)); |
506 if (m_pArray.IsEmpty()) | 482 } |
507 return 0; | 483 |
508 return JS_GetArrayLength(m_pArray); | 484 CJS_Date::~CJS_Date() {} |
509 } | 485 |
510 | 486 FX_BOOL CJS_Date::IsValidDate() { |
511 CJS_Array:: operator v8::Local<v8::Array>() | 487 if (m_pDate.IsEmpty()) |
512 { | 488 return FALSE; |
513 if (m_pArray.IsEmpty()) | 489 return !JS_PortIsNan(JS_ToNumber(m_isolate, m_pDate)); |
514 m_pArray = JS_NewArray(m_isolate); | 490 } |
515 | 491 |
516 return m_pArray; | 492 void CJS_Date::Attach(v8::Local<v8::Value> pDate) { |
517 } | 493 m_pDate = pDate; |
518 | 494 } |
519 /* ======================================== CJS_Date ===========================
============== */ | 495 |
520 | 496 int CJS_Date::GetYear() { |
521 CJS_Date::CJS_Date(v8::Isolate* isolate) :m_isolate(isolate) | 497 if (IsValidDate()) |
522 { | 498 return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); |
523 } | 499 |
524 | 500 return 0; |
525 CJS_Date::CJS_Date(v8::Isolate* isolate,double dMsec_time) | 501 } |
526 { | 502 |
527 m_isolate = isolate; | 503 void CJS_Date::SetYear(int iYear) { |
528 m_pDate = JS_NewDate(isolate,dMsec_time); | 504 double date = MakeDate(iYear, GetMonth(), GetDay(), GetHours(), GetMinutes(), |
529 } | 505 GetSeconds(), 0); |
530 | 506 JS_ValueCopy(m_pDate, JS_NewDate(m_isolate, date)); |
531 CJS_Date::CJS_Date(v8::Isolate* isolate,int year, int mon, int day,int hour, int
min, int sec) | 507 } |
532 { | 508 |
533 m_isolate = isolate; | 509 int CJS_Date::GetMonth() { |
534 m_pDate = JS_NewDate(isolate,MakeDate(year,mon,day,hour,min,sec,0)); | 510 if (IsValidDate()) |
535 } | 511 return JS_GetMonthFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); |
536 | 512 |
537 double CJS_Date::MakeDate(int year, int mon, int day,int hour, int min, int sec,
int ms) | 513 return 0; |
538 { | 514 } |
539 return JS_MakeDate(JS_MakeDay(year,mon,day), JS_MakeTime(hour,min,sec,ms
)); | 515 |
540 } | 516 void CJS_Date::SetMonth(int iMonth) { |
541 | 517 double date = MakeDate(GetYear(), iMonth, GetDay(), GetHours(), GetMinutes(), |
542 CJS_Date::~CJS_Date() | 518 GetSeconds(), 0); |
543 { | 519 JS_ValueCopy(m_pDate, JS_NewDate(m_isolate, date)); |
544 } | 520 } |
545 | 521 |
546 FX_BOOL CJS_Date::IsValidDate() | 522 int CJS_Date::GetDay() { |
547 { | 523 if (IsValidDate()) |
548 if(m_pDate.IsEmpty()) return FALSE; | 524 return JS_GetDayFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); |
549 return !JS_PortIsNan(JS_ToNumber(m_isolate, m_pDate)); | 525 |
550 } | 526 return 0; |
551 | 527 } |
552 void CJS_Date::Attach(v8::Local<v8::Value> pDate) | 528 |
553 { | 529 void CJS_Date::SetDay(int iDay) { |
554 m_pDate = pDate; | 530 double date = MakeDate(GetYear(), GetMonth(), iDay, GetHours(), GetMinutes(), |
555 } | 531 GetSeconds(), 0); |
556 | 532 JS_ValueCopy(m_pDate, JS_NewDate(m_isolate, date)); |
557 int CJS_Date::GetYear() | 533 } |
558 { | 534 |
559 if (IsValidDate()) | 535 int CJS_Date::GetHours() { |
560 return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_
pDate))); | 536 if (IsValidDate()) |
561 | 537 return JS_GetHourFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); |
562 return 0; | 538 |
563 } | 539 return 0; |
564 | 540 } |
565 void CJS_Date::SetYear(int iYear) | 541 |
566 { | 542 void CJS_Date::SetHours(int iHours) { |
567 double date = MakeDate(iYear,GetMonth(),GetDay(),GetHours(),GetMinutes()
,GetSeconds(),0); | 543 double date = MakeDate(GetYear(), GetMonth(), GetDay(), iHours, GetMinutes(), |
568 JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date)); | 544 GetSeconds(), 0); |
569 } | 545 JS_ValueCopy(m_pDate, JS_NewDate(m_isolate, date)); |
570 | 546 } |
571 int CJS_Date::GetMonth() | 547 |
572 { | 548 int CJS_Date::GetMinutes() { |
573 if (IsValidDate()) | 549 if (IsValidDate()) |
574 return JS_GetMonthFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m
_pDate))); | 550 return JS_GetMinFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); |
575 | 551 |
576 return 0; | 552 return 0; |
577 } | 553 } |
578 | 554 |
579 void CJS_Date::SetMonth(int iMonth) | 555 void CJS_Date::SetMinutes(int minutes) { |
580 { | 556 double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), minutes, |
581 | 557 GetSeconds(), 0); |
582 double date = MakeDate(GetYear(),iMonth,GetDay(),GetHours(),GetMinutes()
,GetSeconds(),0); | 558 JS_ValueCopy(m_pDate, JS_NewDate(m_isolate, date)); |
583 JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date)); | 559 } |
584 | 560 |
585 } | 561 int CJS_Date::GetSeconds() { |
586 | 562 if (IsValidDate()) |
587 int CJS_Date::GetDay() | 563 return JS_GetSecFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); |
588 { | 564 |
589 if (IsValidDate()) | 565 return 0; |
590 return JS_GetDayFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_p
Date))); | 566 } |
591 | 567 |
592 return 0; | 568 void CJS_Date::SetSeconds(int seconds) { |
593 } | 569 double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), |
594 | 570 GetMinutes(), seconds, 0); |
595 void CJS_Date::SetDay(int iDay) | 571 JS_ValueCopy(m_pDate, JS_NewDate(m_isolate, date)); |
596 { | 572 } |
597 | 573 |
598 double date = MakeDate(GetYear(),GetMonth(),iDay,GetHours(),GetMinutes()
,GetSeconds(),0); | 574 CJS_Date::operator v8::Local<v8::Value>() { |
599 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); | 575 return m_pDate; |
600 | 576 } |
601 } | 577 |
602 | 578 CJS_Date::operator double() const { |
603 int CJS_Date::GetHours() | 579 if (m_pDate.IsEmpty()) |
604 { | 580 return 0.0; |
605 if (IsValidDate()) | 581 return JS_ToNumber(m_isolate, m_pDate); |
606 return JS_GetHourFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_
pDate))); | 582 } |
607 | 583 |
608 return 0; | 584 CFX_WideString CJS_Date::ToString() const { |
609 } | 585 if (m_pDate.IsEmpty()) |
610 | 586 return L""; |
611 void CJS_Date::SetHours(int iHours) | 587 return JS_ToString(m_isolate, m_pDate); |
612 { | 588 } |
613 double date = MakeDate(GetYear(),GetMonth(),GetDay(),iHours,GetMinutes()
,GetSeconds(),0); | |
614 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); | |
615 } | |
616 | |
617 int CJS_Date::GetMinutes() | |
618 { | |
619 if (IsValidDate()) | |
620 return JS_GetMinFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_p
Date))); | |
621 | |
622 return 0; | |
623 } | |
624 | |
625 void CJS_Date::SetMinutes(int minutes) | |
626 { | |
627 double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),minutes,
GetSeconds(),0); | |
628 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); | |
629 } | |
630 | |
631 int CJS_Date::GetSeconds() | |
632 { | |
633 if (IsValidDate()) | |
634 return JS_GetSecFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_p
Date))); | |
635 | |
636 return 0; | |
637 } | |
638 | |
639 void CJS_Date::SetSeconds(int seconds) | |
640 { | |
641 double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),GetMinut
es(),seconds,0); | |
642 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); | |
643 } | |
644 | |
645 CJS_Date::operator v8::Local<v8::Value>() | |
646 { | |
647 return m_pDate; | |
648 } | |
649 | |
650 CJS_Date::operator double() const | |
651 { | |
652 if(m_pDate.IsEmpty()) | |
653 return 0.0; | |
654 return JS_ToNumber(m_isolate, m_pDate); | |
655 } | |
656 | |
657 CFX_WideString CJS_Date::ToString() const | |
658 { | |
659 if(m_pDate.IsEmpty()) | |
660 return L""; | |
661 return JS_ToString(m_isolate, m_pDate); | |
662 } | |
OLD | NEW |