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) : m_eType(VT_unknown),m_isolate(isola
te) |
16 { | 16 { |
17 } | 17 } |
18 CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Handle<v8::Value> pValue,FXJSVALU
ETYPE t) : | 18 CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue,FXJSVALUE
TYPE t) : |
19 m_pValue(pValue), m_eType(t), m_isolate(isolate) | 19 m_pValue(pValue), m_eType(t), m_isolate(isolate) |
20 { | 20 { |
21 } | 21 } |
22 | 22 |
23 CJS_Value::CJS_Value(v8::Isolate* isolate, const int &iValue):m_isolate(isolate) | 23 CJS_Value::CJS_Value(v8::Isolate* isolate, const int &iValue):m_isolate(isolate) |
24 { | 24 { |
25 operator =(iValue); | 25 operator =(iValue); |
26 } | 26 } |
27 | 27 |
28 CJS_Value::CJS_Value(v8::Isolate* isolate, const bool &bValue):m_isolate(isolate
) | 28 CJS_Value::CJS_Value(v8::Isolate* isolate, const bool &bValue):m_isolate(isolate
) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Array& array):m_isolate(isolate) | 70 CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Array& array):m_isolate(isolate) |
71 { | 71 { |
72 operator = (array); | 72 operator = (array); |
73 } | 73 } |
74 | 74 |
75 CJS_Value::~CJS_Value() | 75 CJS_Value::~CJS_Value() |
76 { | 76 { |
77 } | 77 } |
78 | 78 |
79 void CJS_Value::Attach(v8::Handle<v8::Value> pValue,FXJSVALUETYPE t) | 79 void CJS_Value::Attach(v8::Local<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->ToV8Value(), 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::Local<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_isolate, 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_isolate, 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_isolate, 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_isolate, m_pValue); | 121 » v8::Local<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::Local<v8::Object> CJS_Value::ToV8Object() const |
126 { | 126 { |
127 return JS_ToObject(m_isolate, 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_isolate, 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::Local<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::Local<v8::Array>CJS_Value::ToV8Array() const |
146 { | 146 { |
147 if (IsArrayObject()) | 147 if (IsArrayObject()) |
148 » » return v8::Handle<v8::Array>::Cast(JS_ToObject(m_isolate, m_pVal
ue)); | 148 » » return v8::Local<v8::Array>::Cast(JS_ToObject(m_isolate, m_pValu
e)); |
149 » return v8::Handle<v8::Array>(); | 149 » return v8::Local<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; |
159 } | 159 } |
(...skipping 11 matching lines...) Expand all Loading... |
171 | 171 |
172 m_eType = VT_number; | 172 m_eType = VT_number; |
173 } | 173 } |
174 | 174 |
175 void CJS_Value::operator = (float fValue) | 175 void CJS_Value::operator = (float fValue) |
176 { | 176 { |
177 m_pValue = JS_NewNumber(m_isolate,fValue); | 177 m_pValue = JS_NewNumber(m_isolate,fValue); |
178 m_eType = VT_number; | 178 m_eType = VT_number; |
179 } | 179 } |
180 | 180 |
181 void CJS_Value::operator =(v8::Handle<v8::Object> pObj) | 181 void CJS_Value::operator =(v8::Local<v8::Object> pObj) |
182 { | 182 { |
183 | 183 |
184 m_pValue = JS_NewObject(m_isolate,pObj); | 184 m_pValue = JS_NewObject(m_isolate,pObj); |
185 | 185 |
186 m_eType = VT_fxobject; | 186 m_eType = VT_fxobject; |
187 } | 187 } |
188 | 188 |
189 void CJS_Value::operator =(CJS_Object * pObj) | 189 void CJS_Value::operator =(CJS_Object * pObj) |
190 { | 190 { |
191 if (pObj) | 191 if (pObj) |
(...skipping 22 matching lines...) Expand all Loading... |
214 m_eType = VT_null; | 214 m_eType = VT_null; |
215 } | 215 } |
216 | 216 |
217 void CJS_Value::operator = (FX_LPCSTR pStr) | 217 void CJS_Value::operator = (FX_LPCSTR pStr) |
218 { | 218 { |
219 operator = (CFX_WideString::FromLocal(pStr).c_str()); | 219 operator = (CFX_WideString::FromLocal(pStr).c_str()); |
220 } | 220 } |
221 | 221 |
222 void CJS_Value::operator = (CJS_Array & array) | 222 void CJS_Value::operator = (CJS_Array & array) |
223 { | 223 { |
224 » m_pValue = JS_NewObject2(m_isolate,(v8::Handle<v8::Array>)array); | 224 » m_pValue = JS_NewObject2(m_isolate,(v8::Local<v8::Array>)array); |
225 | 225 |
226 m_eType = VT_object; | 226 m_eType = VT_object; |
227 } | 227 } |
228 | 228 |
229 void CJS_Value::operator = (CJS_Date & date) | 229 void CJS_Value::operator = (CJS_Date & date) |
230 { | 230 { |
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 } |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 ASSERT(m_bIsSetting); | 454 ASSERT(m_bIsSetting); |
455 ConvertToDate(date); | 455 ConvertToDate(date); |
456 } | 456 } |
457 | 457 |
458 void CJS_PropValue::operator<<(CJS_Date &date) | 458 void CJS_PropValue::operator<<(CJS_Date &date) |
459 { | 459 { |
460 ASSERT(!m_bIsSetting); | 460 ASSERT(!m_bIsSetting); |
461 CJS_Value::operator=(date); | 461 CJS_Value::operator=(date); |
462 } | 462 } |
463 | 463 |
464 CJS_PropValue::operator v8::Handle<v8::Value>() const | 464 CJS_PropValue::operator v8::Local<v8::Value>() const |
465 { | 465 { |
466 return m_pValue; | 466 return m_pValue; |
467 } | 467 } |
468 | 468 |
469 /* ======================================== CJS_Array ==========================
=============== */ | 469 /* ======================================== CJS_Array ==========================
=============== */ |
470 CJS_Array::CJS_Array(v8::Isolate* isolate):m_isolate(isolate) | 470 CJS_Array::CJS_Array(v8::Isolate* isolate):m_isolate(isolate) |
471 { | 471 { |
472 } | 472 } |
473 | 473 |
474 CJS_Array::~CJS_Array() | 474 CJS_Array::~CJS_Array() |
475 { | 475 { |
476 } | 476 } |
477 | 477 |
478 void CJS_Array::Attach(v8::Handle<v8::Array> pArray) | 478 void CJS_Array::Attach(v8::Local<v8::Array> pArray) |
479 { | 479 { |
480 m_pArray = pArray; | 480 m_pArray = pArray; |
481 } | 481 } |
482 | 482 |
483 FX_BOOL CJS_Array::IsAttached() | 483 FX_BOOL CJS_Array::IsAttached() |
484 { | 484 { |
485 return FALSE; | 485 return FALSE; |
486 } | 486 } |
487 | 487 |
488 void CJS_Array::GetElement(unsigned index,CJS_Value &value) | 488 void CJS_Array::GetElement(unsigned index,CJS_Value &value) |
489 { | 489 { |
490 if (m_pArray.IsEmpty()) | 490 if (m_pArray.IsEmpty()) |
491 return; | 491 return; |
492 » v8::Handle<v8::Value> p = JS_GetArrayElement(m_isolate, m_pArray,index)
; | 492 » v8::Local<v8::Value> p = JS_GetArrayElement(m_isolate, m_pArray,index); |
493 value.Attach(p,VT_object); | 493 value.Attach(p,VT_object); |
494 } | 494 } |
495 | 495 |
496 void CJS_Array::SetElement(unsigned index,CJS_Value value) | 496 void CJS_Array::SetElement(unsigned index,CJS_Value value) |
497 { | 497 { |
498 if (m_pArray.IsEmpty()) | 498 if (m_pArray.IsEmpty()) |
499 m_pArray = JS_NewArray(m_isolate); | 499 m_pArray = JS_NewArray(m_isolate); |
500 | 500 |
501 JS_PutArrayElement(m_isolate, m_pArray, index, value.ToV8Value(), value.
GetType()); | 501 JS_PutArrayElement(m_isolate, m_pArray, index, value.ToV8Value(), value.
GetType()); |
502 } | 502 } |
503 | 503 |
504 int CJS_Array::GetLength() | 504 int CJS_Array::GetLength() |
505 { | 505 { |
506 if (m_pArray.IsEmpty()) | 506 if (m_pArray.IsEmpty()) |
507 return 0; | 507 return 0; |
508 return JS_GetArrayLength(m_pArray); | 508 return JS_GetArrayLength(m_pArray); |
509 } | 509 } |
510 | 510 |
511 CJS_Array:: operator v8::Handle<v8::Array>() | 511 CJS_Array:: operator v8::Local<v8::Array>() |
512 { | 512 { |
513 if (m_pArray.IsEmpty()) | 513 if (m_pArray.IsEmpty()) |
514 m_pArray = JS_NewArray(m_isolate); | 514 m_pArray = JS_NewArray(m_isolate); |
515 | 515 |
516 return m_pArray; | 516 return m_pArray; |
517 } | 517 } |
518 | 518 |
519 /* ======================================== CJS_Date ===========================
============== */ | 519 /* ======================================== CJS_Date ===========================
============== */ |
520 | 520 |
521 CJS_Date::CJS_Date(v8::Isolate* isolate) :m_isolate(isolate) | 521 CJS_Date::CJS_Date(v8::Isolate* isolate) :m_isolate(isolate) |
(...skipping 20 matching lines...) Expand all Loading... |
542 CJS_Date::~CJS_Date() | 542 CJS_Date::~CJS_Date() |
543 { | 543 { |
544 } | 544 } |
545 | 545 |
546 FX_BOOL CJS_Date::IsValidDate() | 546 FX_BOOL CJS_Date::IsValidDate() |
547 { | 547 { |
548 if(m_pDate.IsEmpty()) return FALSE; | 548 if(m_pDate.IsEmpty()) return FALSE; |
549 return !JS_PortIsNan(JS_ToNumber(m_isolate, m_pDate)); | 549 return !JS_PortIsNan(JS_ToNumber(m_isolate, m_pDate)); |
550 } | 550 } |
551 | 551 |
552 void CJS_Date::Attach(v8::Handle<v8::Value> pDate) | 552 void CJS_Date::Attach(v8::Local<v8::Value> pDate) |
553 { | 553 { |
554 m_pDate = pDate; | 554 m_pDate = pDate; |
555 } | 555 } |
556 | 556 |
557 int CJS_Date::GetYear() | 557 int CJS_Date::GetYear() |
558 { | 558 { |
559 if (IsValidDate()) | 559 if (IsValidDate()) |
560 return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_
pDate))); | 560 return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_
pDate))); |
561 | 561 |
562 return 0; | 562 return 0; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 | 635 |
636 return 0; | 636 return 0; |
637 } | 637 } |
638 | 638 |
639 void CJS_Date::SetSeconds(int seconds) | 639 void CJS_Date::SetSeconds(int seconds) |
640 { | 640 { |
641 double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),GetMinut
es(),seconds,0); | 641 double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),GetMinut
es(),seconds,0); |
642 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); | 642 JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date)); |
643 } | 643 } |
644 | 644 |
645 CJS_Date::operator v8::Handle<v8::Value>() | 645 CJS_Date::operator v8::Local<v8::Value>() |
646 { | 646 { |
647 return m_pDate; | 647 return m_pDate; |
648 } | 648 } |
649 | 649 |
650 CJS_Date::operator double() const | 650 CJS_Date::operator double() const |
651 { | 651 { |
652 if(m_pDate.IsEmpty()) | 652 if(m_pDate.IsEmpty()) |
653 return 0.0; | 653 return 0.0; |
654 return JS_ToNumber(m_isolate, m_pDate); | 654 return JS_ToNumber(m_isolate, m_pDate); |
655 } | 655 } |
656 | 656 |
657 CFX_WideString CJS_Date::ToString() const | 657 CFX_WideString CJS_Date::ToString() const |
658 { | 658 { |
659 if(m_pDate.IsEmpty()) | 659 if(m_pDate.IsEmpty()) |
660 return L""; | 660 return L""; |
661 return JS_ToString(m_isolate, m_pDate); | 661 return JS_ToString(m_isolate, m_pDate); |
662 } | 662 } |
OLD | NEW |