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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 int CJS_Value::ToInt() const | 99 int CJS_Value::ToInt() const |
100 { | 100 { |
101 » return JS_ToInt32(m_pValue); | 101 » return JS_ToInt32(m_isolate, m_pValue); |
102 } | 102 } |
103 | 103 |
104 bool CJS_Value::ToBool() const | 104 bool CJS_Value::ToBool() const |
105 { | 105 { |
106 » return JS_ToBoolean(m_pValue); | 106 » return JS_ToBoolean(m_isolate, m_pValue); |
107 } | 107 } |
108 | 108 |
109 double CJS_Value::ToDouble() const | 109 double CJS_Value::ToDouble() const |
110 { | 110 { |
111 » return JS_ToNumber(m_pValue); | 111 » return JS_ToNumber(m_isolate, m_pValue); |
112 } | 112 } |
113 | 113 |
114 float CJS_Value::ToFloat() const | 114 float CJS_Value::ToFloat() const |
115 { | 115 { |
116 return (float)ToDouble(); | 116 return (float)ToDouble(); |
117 } | 117 } |
118 | 118 |
119 CJS_Object* CJS_Value::ToCJSObject() const | 119 CJS_Object* CJS_Value::ToCJSObject() const |
120 { | 120 { |
121 » v8::Handle<v8::Object>» pObj = JS_ToObject(m_pValue); | 121 » v8::Handle<v8::Object>» pObj = JS_ToObject(m_isolate, m_pValue); |
122 return (CJS_Object*)JS_GetPrivate(m_isolate, pObj); | 122 return (CJS_Object*)JS_GetPrivate(m_isolate, pObj); |
123 } | 123 } |
124 | 124 |
125 v8::Handle<v8::Object> CJS_Value::ToV8Object() const | 125 v8::Handle<v8::Object> CJS_Value::ToV8Object() const |
126 { | 126 { |
127 » return JS_ToObject(m_pValue); | 127 » return JS_ToObject(m_isolate, m_pValue); |
128 } | 128 } |
129 | 129 |
130 CFX_WideString CJS_Value::ToCFXWideString() const | 130 CFX_WideString CJS_Value::ToCFXWideString() const |
131 { | 131 { |
132 » return JS_ToString(m_pValue); | 132 » return JS_ToString(m_isolate, m_pValue); |
133 } | 133 } |
134 | 134 |
135 CFX_ByteString CJS_Value::ToCFXByteString() const | 135 CFX_ByteString CJS_Value::ToCFXByteString() const |
136 { | 136 { |
137 return CFX_ByteString::FromUnicode(ToCFXWideString()); | 137 return CFX_ByteString::FromUnicode(ToCFXWideString()); |
138 } | 138 } |
139 | 139 |
140 v8::Handle<v8::Value> CJS_Value::ToV8Value() const | 140 v8::Handle<v8::Value> CJS_Value::ToV8Value() const |
141 { | 141 { |
142 return m_pValue; | 142 return m_pValue; |
143 } | 143 } |
144 | 144 |
145 v8::Handle<v8::Array>CJS_Value::ToV8Array() const | 145 v8::Handle<v8::Array>CJS_Value::ToV8Array() const |
146 { | 146 { |
147 if (IsArrayObject()) | 147 if (IsArrayObject()) |
148 » » return v8::Handle<v8::Array>::Cast(JS_ToObject(m_pValue)); | 148 » » return v8::Handle<v8::Array>::Cast(JS_ToObject(m_isolate, m_pVal
ue)); |
149 return v8::Handle<v8::Array>(); | 149 return v8::Handle<v8::Array>(); |
150 } | 150 } |
151 | 151 |
152 /* -----------------------------------------------------------------------------
----------- */ | 152 /* -----------------------------------------------------------------------------
----------- */ |
153 | 153 |
154 void CJS_Value::operator =(int iValue) | 154 void CJS_Value::operator =(int iValue) |
155 { | 155 { |
156 m_pValue = JS_NewNumber(m_isolate, iValue); | 156 m_pValue = JS_NewNumber(m_isolate, iValue); |
157 | 157 |
158 m_eType = VT_number; | 158 m_eType = VT_number; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 m_pValue = JS_NewDate(m_isolate, (double)date); | 231 m_pValue = JS_NewDate(m_isolate, (double)date); |
232 | 232 |
233 m_eType = VT_date; | 233 m_eType = VT_date; |
234 } | 234 } |
235 | 235 |
236 void CJS_Value::operator = (CJS_Value value) | 236 void CJS_Value::operator = (CJS_Value value) |
237 { | 237 { |
238 m_pValue = value.ToV8Value(); | 238 m_pValue = value.ToV8Value(); |
239 | 239 |
240 m_eType = value.m_eType; | 240 m_eType = value.m_eType; |
| 241 m_isolate = value.m_isolate; |
241 } | 242 } |
242 | 243 |
243 /* -----------------------------------------------------------------------------
----------- */ | 244 /* -----------------------------------------------------------------------------
----------- */ |
244 | 245 |
245 FXJSVALUETYPE CJS_Value::GetType() const | 246 FXJSVALUETYPE CJS_Value::GetType() const |
246 { | 247 { |
247 if(m_pValue.IsEmpty()) return VT_unknown; | 248 if(m_pValue.IsEmpty()) return VT_unknown; |
248 if(m_pValue->IsString()) return VT_string; | 249 if(m_pValue->IsString()) return VT_string; |
249 if(m_pValue->IsNumber()) return VT_number; | 250 if(m_pValue->IsNumber()) return VT_number; |
250 if(m_pValue->IsBoolean()) return VT_boolean; | 251 if(m_pValue->IsBoolean()) return VT_boolean; |
(...skipping 14 matching lines...) Expand all Loading... |
265 { | 266 { |
266 if(m_pValue.IsEmpty()) return FALSE; | 267 if(m_pValue.IsEmpty()) return FALSE; |
267 return m_pValue->IsDate(); | 268 return m_pValue->IsDate(); |
268 } | 269 } |
269 | 270 |
270 //CJS_Value::operator CJS_Array() | 271 //CJS_Value::operator CJS_Array() |
271 FX_BOOL CJS_Value::ConvertToArray(CJS_Array &array) const | 272 FX_BOOL CJS_Value::ConvertToArray(CJS_Array &array) const |
272 { | 273 { |
273 if (IsArrayObject()) | 274 if (IsArrayObject()) |
274 { | 275 { |
275 » » array.Attach(JS_ToArray(m_pValue)); | 276 » » array.Attach(JS_ToArray(m_isolate, m_pValue)); |
276 return TRUE; | 277 return TRUE; |
277 } | 278 } |
278 | 279 |
279 return FALSE; | 280 return FALSE; |
280 } | 281 } |
281 | 282 |
282 FX_BOOL CJS_Value::ConvertToDate(CJS_Date &date) const | 283 FX_BOOL CJS_Value::ConvertToDate(CJS_Date &date) const |
283 { | 284 { |
284 // if (GetType() == VT_date) | 285 // if (GetType() == VT_date) |
285 // { | 286 // { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 | 482 |
482 FX_BOOL CJS_Array::IsAttached() | 483 FX_BOOL CJS_Array::IsAttached() |
483 { | 484 { |
484 return FALSE; | 485 return FALSE; |
485 } | 486 } |
486 | 487 |
487 void CJS_Array::GetElement(unsigned index,CJS_Value &value) | 488 void CJS_Array::GetElement(unsigned index,CJS_Value &value) |
488 { | 489 { |
489 if (m_pArray.IsEmpty()) | 490 if (m_pArray.IsEmpty()) |
490 return; | 491 return; |
491 » v8::Handle<v8::Value> p = JS_GetArrayElemnet(m_pArray,index); | 492 » v8::Handle<v8::Value> p = JS_GetArrayElement(m_isolate, m_pArray,index)
; |
492 value.Attach(p,VT_object); | 493 value.Attach(p,VT_object); |
493 } | 494 } |
494 | 495 |
495 void CJS_Array::SetElement(unsigned index,CJS_Value value) | 496 void CJS_Array::SetElement(unsigned index,CJS_Value value) |
496 { | 497 { |
497 if (m_pArray.IsEmpty()) | 498 if (m_pArray.IsEmpty()) |
498 m_pArray = JS_NewArray(m_isolate); | 499 m_pArray = JS_NewArray(m_isolate); |
499 | 500 |
500 » JS_PutArrayElement(m_pArray, index, value.ToV8Value(), value.GetType()); | 501 » JS_PutArrayElement(m_isolate, m_pArray, index, value.ToV8Value(), value.
GetType()); |
501 } | 502 } |
502 | 503 |
503 int CJS_Array::GetLength() | 504 int CJS_Array::GetLength() |
504 { | 505 { |
505 if (m_pArray.IsEmpty()) | 506 if (m_pArray.IsEmpty()) |
506 return 0; | 507 return 0; |
507 return JS_GetArrayLength(m_pArray); | 508 return JS_GetArrayLength(m_pArray); |
508 } | 509 } |
509 | 510 |
510 CJS_Array:: operator v8::Handle<v8::Array>() | 511 CJS_Array:: operator v8::Handle<v8::Array>() |
(...skipping 27 matching lines...) Expand all Loading... |
538 return JS_MakeDate(JS_MakeDay(year,mon,day), JS_MakeTime(hour,min,sec,ms
)); | 539 return JS_MakeDate(JS_MakeDay(year,mon,day), JS_MakeTime(hour,min,sec,ms
)); |
539 } | 540 } |
540 | 541 |
541 CJS_Date::~CJS_Date() | 542 CJS_Date::~CJS_Date() |
542 { | 543 { |
543 } | 544 } |
544 | 545 |
545 FX_BOOL CJS_Date::IsValidDate() | 546 FX_BOOL CJS_Date::IsValidDate() |
546 { | 547 { |
547 if(m_pDate.IsEmpty()) return FALSE; | 548 if(m_pDate.IsEmpty()) return FALSE; |
548 » return !JS_PortIsNan(JS_ToNumber(m_pDate)); | 549 » return !JS_PortIsNan(JS_ToNumber(m_isolate, m_pDate)); |
549 } | 550 } |
550 | 551 |
551 void CJS_Date::Attach(v8::Handle<v8::Value> pDate) | 552 void CJS_Date::Attach(v8::Handle<v8::Value> pDate) |
552 { | 553 { |
553 m_pDate = pDate; | 554 m_pDate = pDate; |
554 } | 555 } |
555 | 556 |
556 int CJS_Date::GetYear() | 557 int CJS_Date::GetYear() |
557 { | 558 { |
558 if (IsValidDate()) | 559 if (IsValidDate()) |
559 » » return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_pDate))); | 560 » » return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_
pDate))); |
560 | 561 |
561 return 0; | 562 return 0; |
562 } | 563 } |
563 | 564 |
564 void CJS_Date::SetYear(int iYear) | 565 void CJS_Date::SetYear(int iYear) |
565 { | 566 { |
566 double date = MakeDate(iYear,GetMonth(),GetDay(),GetHours(),GetMinutes()
,GetSeconds(),0); | 567 double date = MakeDate(iYear,GetMonth(),GetDay(),GetHours(),GetMinutes()
,GetSeconds(),0); |
567 JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date)); | 568 JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date)); |
568 } | 569 } |
569 | 570 |
570 int CJS_Date::GetMonth() | 571 int CJS_Date::GetMonth() |
571 { | 572 { |
572 if (IsValidDate()) | 573 if (IsValidDate()) |
573 » » return JS_GetMonthFromTime(JS_LocalTime(JS_ToNumber(m_pDate))); | 574 » » return JS_GetMonthFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m
_pDate))); |
574 | 575 |
575 return 0; | 576 return 0; |
576 } | 577 } |
577 | 578 |
578 void CJS_Date::SetMonth(int iMonth) | 579 void CJS_Date::SetMonth(int iMonth) |
579 { | 580 { |
580 | 581 |
581 double date = MakeDate(GetYear(),iMonth,GetDay(),GetHours(),GetMinutes()
,GetSeconds(),0); | 582 double date = MakeDate(GetYear(),iMonth,GetDay(),GetHours(),GetMinutes()
,GetSeconds(),0); |
582 JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date)); | 583 JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date)); |
583 | 584 |
584 } | 585 } |
585 | 586 |
586 int CJS_Date::GetDay() | 587 int CJS_Date::GetDay() |
587 { | 588 { |
588 if (IsValidDate()) | 589 if (IsValidDate()) |
589 » » return JS_GetDayFromTime(JS_LocalTime(JS_ToNumber(m_pDate))); | 590 » » return JS_GetDayFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_p
Date))); |
590 | 591 |
591 return 0; | 592 return 0; |
592 } | 593 } |
593 | 594 |
594 void CJS_Date::SetDay(int iDay) | 595 void CJS_Date::SetDay(int iDay) |
595 { | 596 { |
596 | 597 |
597 double date = MakeDate(GetYear(),GetMonth(),iDay,GetHours(),GetMinutes()
,GetSeconds(),0); | 598 double date = MakeDate(GetYear(),GetMonth(),iDay,GetHours(),GetMinutes()
,GetSeconds(),0); |
598 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); | 599 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); |
599 | 600 |
600 } | 601 } |
601 | 602 |
602 int CJS_Date::GetHours() | 603 int CJS_Date::GetHours() |
603 { | 604 { |
604 if (IsValidDate()) | 605 if (IsValidDate()) |
605 » » return JS_GetHourFromTime(JS_LocalTime(JS_ToNumber(m_pDate))); | 606 » » return JS_GetHourFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_
pDate))); |
606 | 607 |
607 return 0; | 608 return 0; |
608 } | 609 } |
609 | 610 |
610 void CJS_Date::SetHours(int iHours) | 611 void CJS_Date::SetHours(int iHours) |
611 { | 612 { |
612 double date = MakeDate(GetYear(),GetMonth(),GetDay(),iHours,GetMinutes()
,GetSeconds(),0); | 613 double date = MakeDate(GetYear(),GetMonth(),GetDay(),iHours,GetMinutes()
,GetSeconds(),0); |
613 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); | 614 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); |
614 } | 615 } |
615 | 616 |
616 int CJS_Date::GetMinutes() | 617 int CJS_Date::GetMinutes() |
617 { | 618 { |
618 if (IsValidDate()) | 619 if (IsValidDate()) |
619 » » return JS_GetMinFromTime(JS_LocalTime(JS_ToNumber(m_pDate))); | 620 » » return JS_GetMinFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_p
Date))); |
620 | 621 |
621 return 0; | 622 return 0; |
622 } | 623 } |
623 | 624 |
624 void CJS_Date::SetMinutes(int minutes) | 625 void CJS_Date::SetMinutes(int minutes) |
625 { | 626 { |
626 double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),minutes,
GetSeconds(),0); | 627 double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),minutes,
GetSeconds(),0); |
627 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); | 628 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); |
628 } | 629 } |
629 | 630 |
630 int CJS_Date::GetSeconds() | 631 int CJS_Date::GetSeconds() |
631 { | 632 { |
632 if (IsValidDate()) | 633 if (IsValidDate()) |
633 » » return JS_GetSecFromTime(JS_LocalTime(JS_ToNumber(m_pDate))); | 634 » » return JS_GetSecFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_p
Date))); |
634 | 635 |
635 return 0; | 636 return 0; |
636 } | 637 } |
637 | 638 |
638 void CJS_Date::SetSeconds(int seconds) | 639 void CJS_Date::SetSeconds(int seconds) |
639 { | 640 { |
640 double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),GetMinut
es(),seconds,0); | 641 double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),GetMinut
es(),seconds,0); |
641 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); | 642 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); |
642 } | 643 } |
643 | 644 |
644 CJS_Date::operator v8::Handle<v8::Value>() | 645 CJS_Date::operator v8::Handle<v8::Value>() |
645 { | 646 { |
646 return m_pDate; | 647 return m_pDate; |
647 } | 648 } |
648 | 649 |
649 CJS_Date::operator double() const | 650 CJS_Date::operator double() const |
650 { | 651 { |
651 if(m_pDate.IsEmpty()) | 652 if(m_pDate.IsEmpty()) |
652 return 0.0; | 653 return 0.0; |
653 » return JS_ToNumber(m_pDate); | 654 » return JS_ToNumber(m_isolate, m_pDate); |
654 } | 655 } |
655 | 656 |
656 CFX_WideString CJS_Date::ToString() const | 657 CFX_WideString CJS_Date::ToString() const |
657 { | 658 { |
658 if(m_pDate.IsEmpty()) | 659 if(m_pDate.IsEmpty()) |
659 return L""; | 660 return L""; |
660 » return JS_ToString(m_pDate); | 661 » return JS_ToString(m_isolate, m_pDate); |
661 } | 662 } |
OLD | NEW |