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" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 void CJS_Value::Attach(v8::Handle<v8::Value> pValue,FXJSVALUETYPE t) | 79 void CJS_Value::Attach(v8::Handle<v8::Value> pValue,FXJSVALUETYPE t) |
80 { | 80 { |
81 m_pValue = pValue; | 81 m_pValue = pValue; |
82 m_eType = t; | 82 m_eType = t; |
83 } | 83 } |
84 | 84 |
85 void CJS_Value::Attach(CJS_Value *pValue) | 85 void CJS_Value::Attach(CJS_Value *pValue) |
86 { | 86 { |
87 if (pValue) | 87 if (pValue) |
88 » » Attach(pValue->ToJSValue(),pValue->GetType()); | 88 » » Attach(pValue->ToV8Value(), pValue->GetType()); |
89 } | 89 } |
90 | 90 |
91 void CJS_Value::Detach() | 91 void CJS_Value::Detach() |
92 { | 92 { |
93 m_pValue = v8::Handle<v8::Value>(); | 93 m_pValue = v8::Handle<v8::Value>(); |
94 m_eType = VT_unknown; | 94 m_eType = VT_unknown; |
95 } | 95 } |
96 | 96 |
97 /* -----------------------------------------------------------------------------
----------- */ | 97 /* -----------------------------------------------------------------------------
----------- */ |
98 | 98 |
99 CJS_Value::operator int() const | 99 int CJS_Value::ToInt() const |
100 { | 100 { |
101 | |
102 return JS_ToInt32(m_pValue); | 101 return JS_ToInt32(m_pValue); |
103 | |
104 } | 102 } |
105 | 103 |
106 CJS_Value::operator bool() const | 104 bool CJS_Value::ToBool() const |
107 { | 105 { |
108 | |
109 return JS_ToBoolean(m_pValue); | 106 return JS_ToBoolean(m_pValue); |
110 | |
111 } | 107 } |
112 | 108 |
113 CJS_Value::operator double() const | 109 double CJS_Value::ToDouble() const |
114 { | 110 { |
115 | |
116 return JS_ToNumber(m_pValue); | 111 return JS_ToNumber(m_pValue); |
117 | |
118 } | 112 } |
119 | 113 |
120 CJS_Value::operator float() const | 114 float CJS_Value::ToFloat() const |
121 { | 115 { |
122 | 116 » return (float)ToDouble(); |
123 » return (float)JS_ToNumber(m_pValue); | |
124 | |
125 } | 117 } |
126 | 118 |
127 CJS_Value::operator CJS_Object *() const | 119 CJS_Object* CJS_Value::ToCJSObject() const |
128 { | 120 { |
129 | |
130 v8::Handle<v8::Object> pObj = JS_ToObject(m_pValue); | 121 v8::Handle<v8::Object> pObj = JS_ToObject(m_pValue); |
131 return (CJS_Object*)JS_GetPrivate(m_isolate, pObj); | 122 return (CJS_Object*)JS_GetPrivate(m_isolate, pObj); |
132 } | 123 } |
133 | 124 |
134 CJS_Value::operator v8::Handle<v8::Object>() const | 125 v8::Handle<v8::Object> CJS_Value::ToV8Object() const |
135 { | 126 { |
136 return JS_ToObject(m_pValue); | 127 return JS_ToObject(m_pValue); |
137 } | 128 } |
138 | 129 |
139 CJS_Value::operator CFX_WideString() const | 130 CFX_WideString CJS_Value::ToCFXWideString() const |
140 { | 131 { |
141 return JS_ToString(m_pValue); | 132 return JS_ToString(m_pValue); |
142 } | 133 } |
143 | 134 |
144 CJS_Value::operator CFX_ByteString() const | 135 CFX_ByteString CJS_Value::ToCFXByteString() const |
145 { | 136 { |
146 » return CFX_ByteString::FromUnicode(operator CFX_WideString()); | 137 » return CFX_ByteString::FromUnicode(ToCFXWideString()); |
147 } | 138 } |
148 | 139 |
149 v8::Handle<v8::Value> CJS_Value::ToJSValue() | 140 v8::Handle<v8::Value> CJS_Value::ToV8Value() const |
150 { | 141 { |
151 return m_pValue; | 142 return m_pValue; |
152 } | 143 } |
153 | 144 |
154 | 145 v8::Handle<v8::Array>CJS_Value::ToV8Array() const |
155 CJS_Value::operator v8::Handle<v8::Array>() const | |
156 { | 146 { |
157 if (IsArrayObject()) | 147 if (IsArrayObject()) |
158 return v8::Handle<v8::Array>::Cast(JS_ToObject(m_pValue)); | 148 return v8::Handle<v8::Array>::Cast(JS_ToObject(m_pValue)); |
159 return v8::Handle<v8::Array>(); | 149 return v8::Handle<v8::Array>(); |
160 } | 150 } |
161 | 151 |
162 /* -----------------------------------------------------------------------------
----------- */ | 152 /* -----------------------------------------------------------------------------
----------- */ |
163 | 153 |
164 void CJS_Value::operator =(int iValue) | 154 void CJS_Value::operator =(int iValue) |
165 { | 155 { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 228 |
239 void CJS_Value::operator = (CJS_Date & date) | 229 void CJS_Value::operator = (CJS_Date & date) |
240 { | 230 { |
241 m_pValue = JS_NewDate(m_isolate, (double)date); | 231 m_pValue = JS_NewDate(m_isolate, (double)date); |
242 | 232 |
243 m_eType = VT_date; | 233 m_eType = VT_date; |
244 } | 234 } |
245 | 235 |
246 void CJS_Value::operator = (CJS_Value value) | 236 void CJS_Value::operator = (CJS_Value value) |
247 { | 237 { |
248 » m_pValue = value.ToJSValue(); | 238 » m_pValue = value.ToV8Value(); |
249 | 239 |
250 m_eType = value.m_eType; | 240 m_eType = value.m_eType; |
251 } | 241 } |
252 | 242 |
253 /* -----------------------------------------------------------------------------
----------- */ | 243 /* -----------------------------------------------------------------------------
----------- */ |
254 | 244 |
255 FXJSVALUETYPE CJS_Value::GetType() const | 245 FXJSVALUETYPE CJS_Value::GetType() const |
256 { | 246 { |
257 if(m_pValue.IsEmpty()) return VT_unknown; | 247 if(m_pValue.IsEmpty()) return VT_unknown; |
258 if(m_pValue->IsString()) return VT_string; | 248 if(m_pValue->IsString()) return VT_string; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 | 325 |
336 void CJS_PropValue::operator <<(int iValue) | 326 void CJS_PropValue::operator <<(int iValue) |
337 { | 327 { |
338 ASSERT(!m_bIsSetting); | 328 ASSERT(!m_bIsSetting); |
339 CJS_Value::operator =(iValue); | 329 CJS_Value::operator =(iValue); |
340 } | 330 } |
341 | 331 |
342 void CJS_PropValue::operator >>(int & iValue) const | 332 void CJS_PropValue::operator >>(int & iValue) const |
343 { | 333 { |
344 ASSERT(m_bIsSetting); | 334 ASSERT(m_bIsSetting); |
345 » iValue = CJS_Value::operator int(); | 335 » iValue = CJS_Value::ToInt(); |
346 } | 336 } |
347 | 337 |
348 | 338 |
349 void CJS_PropValue::operator <<(bool bValue) | 339 void CJS_PropValue::operator <<(bool bValue) |
350 { | 340 { |
351 ASSERT(!m_bIsSetting); | 341 ASSERT(!m_bIsSetting); |
352 CJS_Value::operator =(bValue); | 342 CJS_Value::operator =(bValue); |
353 } | 343 } |
354 | 344 |
355 void CJS_PropValue::operator >>(bool& bValue) const | 345 void CJS_PropValue::operator >>(bool& bValue) const |
356 { | 346 { |
357 ASSERT(m_bIsSetting); | 347 ASSERT(m_bIsSetting); |
358 » bValue = CJS_Value::operator bool(); | 348 » bValue = CJS_Value::ToBool(); |
359 | |
360 } | 349 } |
361 | 350 |
362 void CJS_PropValue::operator <<(double dValue) | 351 void CJS_PropValue::operator <<(double dValue) |
363 { | 352 { |
364 ASSERT(!m_bIsSetting); | 353 ASSERT(!m_bIsSetting); |
365 CJS_Value::operator =(dValue); | 354 CJS_Value::operator =(dValue); |
366 } | 355 } |
367 | 356 |
368 void CJS_PropValue::operator >>(double& dValue) const | 357 void CJS_PropValue::operator >>(double& dValue) const |
369 { | 358 { |
370 ASSERT(m_bIsSetting); | 359 ASSERT(m_bIsSetting); |
371 » dValue = CJS_Value::operator double(); | 360 » dValue = CJS_Value::ToDouble(); |
372 } | 361 } |
373 | 362 |
374 void CJS_PropValue::operator <<(CJS_Object* pObj) | 363 void CJS_PropValue::operator <<(CJS_Object* pObj) |
375 { | 364 { |
376 ASSERT(!m_bIsSetting); | 365 ASSERT(!m_bIsSetting); |
377 CJS_Value::operator = (pObj); | 366 CJS_Value::operator = (pObj); |
378 } | 367 } |
379 | 368 |
380 void CJS_PropValue::operator >>(CJS_Object*& ppObj) const | 369 void CJS_PropValue::operator >>(CJS_Object*& ppObj) const |
381 { | 370 { |
382 ASSERT(m_bIsSetting); | 371 ASSERT(m_bIsSetting); |
383 » ppObj = CJS_Value::operator CJS_Object *(); | 372 » ppObj = CJS_Value::ToCJSObject(); |
384 } | 373 } |
385 | 374 |
386 void CJS_PropValue::operator <<(CJS_Document* pJsDoc) | 375 void CJS_PropValue::operator <<(CJS_Document* pJsDoc) |
387 { | 376 { |
388 ASSERT(!m_bIsSetting); | 377 ASSERT(!m_bIsSetting); |
389 CJS_Value::operator = (pJsDoc); | 378 CJS_Value::operator = (pJsDoc); |
390 } | 379 } |
391 | 380 |
392 void CJS_PropValue::operator >>(CJS_Document*& ppJsDoc) const | 381 void CJS_PropValue::operator >>(CJS_Document*& ppJsDoc) const |
393 { | 382 { |
394 ASSERT(m_bIsSetting); | 383 ASSERT(m_bIsSetting); |
395 » ppJsDoc = static_cast<CJS_Document*>(CJS_Value::operator CJS_Object *())
; | 384 » ppJsDoc = static_cast<CJS_Document*>(CJS_Value::ToCJSObject()); |
396 } | 385 } |
397 | 386 |
398 void CJS_PropValue::operator<<(JSFXObject pObj) | 387 void CJS_PropValue::operator<<(JSFXObject pObj) |
399 { | 388 { |
400 ASSERT(!m_bIsSetting); | 389 ASSERT(!m_bIsSetting); |
401 CJS_Value::operator = (pObj); | 390 CJS_Value::operator = (pObj); |
402 } | 391 } |
403 | 392 |
404 void CJS_PropValue::operator>>(JSFXObject &ppObj) const | 393 void CJS_PropValue::operator>>(JSFXObject &ppObj) const |
405 { | 394 { |
406 ASSERT(m_bIsSetting); | 395 ASSERT(m_bIsSetting); |
407 » ppObj = CJS_Value::operator JSFXObject (); | 396 » ppObj = CJS_Value::ToV8Object(); |
408 } | 397 } |
409 | 398 |
410 | 399 |
411 void CJS_PropValue::StartSetting() | 400 void CJS_PropValue::StartSetting() |
412 { | 401 { |
413 m_bIsSetting = 1; | 402 m_bIsSetting = 1; |
414 } | 403 } |
415 | 404 |
416 void CJS_PropValue::StartGetting() | 405 void CJS_PropValue::StartGetting() |
417 { | 406 { |
418 m_bIsSetting = 0; | 407 m_bIsSetting = 0; |
419 } | 408 } |
420 void CJS_PropValue::operator <<(CFX_ByteString string) | 409 void CJS_PropValue::operator <<(CFX_ByteString string) |
421 { | 410 { |
422 ASSERT(!m_bIsSetting); | 411 ASSERT(!m_bIsSetting); |
423 CJS_Value::operator = (string.c_str()); | 412 CJS_Value::operator = (string.c_str()); |
424 } | 413 } |
425 | 414 |
426 void CJS_PropValue::operator >>(CFX_ByteString &string) const | 415 void CJS_PropValue::operator >>(CFX_ByteString &string) const |
427 { | 416 { |
428 ASSERT(m_bIsSetting); | 417 ASSERT(m_bIsSetting); |
429 » string = CJS_Value::operator CFX_ByteString(); | 418 » string = CJS_Value::ToCFXByteString(); |
430 } | 419 } |
431 | 420 |
432 void CJS_PropValue::operator <<(FX_LPCWSTR c_string) | 421 void CJS_PropValue::operator <<(FX_LPCWSTR c_string) |
433 { | 422 { |
434 ASSERT(!m_bIsSetting); | 423 ASSERT(!m_bIsSetting); |
435 CJS_Value::operator =(c_string); | 424 CJS_Value::operator =(c_string); |
436 } | 425 } |
437 | 426 |
438 void CJS_PropValue::operator >>(CFX_WideString &wide_string) const | 427 void CJS_PropValue::operator >>(CFX_WideString &wide_string) const |
439 { | 428 { |
440 ASSERT(m_bIsSetting); | 429 ASSERT(m_bIsSetting); |
441 » wide_string = CJS_Value::operator CFX_WideString(); | 430 » wide_string = CJS_Value::ToCFXWideString(); |
442 } | 431 } |
443 | 432 |
444 void CJS_PropValue::operator <<(CFX_WideString wide_string) | 433 void CJS_PropValue::operator <<(CFX_WideString wide_string) |
445 { | 434 { |
446 ASSERT(!m_bIsSetting); | 435 ASSERT(!m_bIsSetting); |
447 CJS_Value::operator = (wide_string); | 436 CJS_Value::operator = (wide_string); |
448 } | 437 } |
449 | 438 |
450 void CJS_PropValue::operator >>(CJS_Array &array) const | 439 void CJS_PropValue::operator >>(CJS_Array &array) const |
451 { | 440 { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 return; | 490 return; |
502 v8::Handle<v8::Value> p = JS_GetArrayElemnet(m_pArray,index); | 491 v8::Handle<v8::Value> p = JS_GetArrayElemnet(m_pArray,index); |
503 value.Attach(p,VT_object); | 492 value.Attach(p,VT_object); |
504 } | 493 } |
505 | 494 |
506 void CJS_Array::SetElement(unsigned index,CJS_Value value) | 495 void CJS_Array::SetElement(unsigned index,CJS_Value value) |
507 { | 496 { |
508 if (m_pArray.IsEmpty()) | 497 if (m_pArray.IsEmpty()) |
509 m_pArray = JS_NewArray(m_isolate); | 498 m_pArray = JS_NewArray(m_isolate); |
510 | 499 |
511 » JS_PutArrayElement(m_pArray,index,value.ToJSValue(),value.GetType()); | 500 » JS_PutArrayElement(m_pArray, index, value.ToV8Value(), value.GetType()); |
512 } | 501 } |
513 | 502 |
514 int CJS_Array::GetLength() | 503 int CJS_Array::GetLength() |
515 { | 504 { |
516 if (m_pArray.IsEmpty()) | 505 if (m_pArray.IsEmpty()) |
517 return 0; | 506 return 0; |
518 return JS_GetArrayLength(m_pArray); | 507 return JS_GetArrayLength(m_pArray); |
519 } | 508 } |
520 | 509 |
521 CJS_Array:: operator v8::Handle<v8::Array>() | 510 CJS_Array:: operator v8::Handle<v8::Array>() |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 return 0.0; | 652 return 0.0; |
664 return JS_ToNumber(m_pDate); | 653 return JS_ToNumber(m_pDate); |
665 } | 654 } |
666 | 655 |
667 CFX_WideString CJS_Date::ToString() const | 656 CFX_WideString CJS_Date::ToString() const |
668 { | 657 { |
669 if(m_pDate.IsEmpty()) | 658 if(m_pDate.IsEmpty()) |
670 return L""; | 659 return L""; |
671 return JS_ToString(m_pDate); | 660 return JS_ToString(m_pDate); |
672 } | 661 } |
OLD | NEW |