| 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 "fpdfsdk/javascript/JS_Value.h" | 7 #include "fpdfsdk/javascript/JS_Value.h" |
| 8 | 8 |
| 9 #include <time.h> | 9 #include <time.h> |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr) | 66 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr) |
| 67 : m_pJSRuntime(pRuntime) { | 67 : m_pJSRuntime(pRuntime) { |
| 68 operator=(pWstr); | 68 operator=(pWstr); |
| 69 } | 69 } |
| 70 | 70 |
| 71 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr) | 71 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr) |
| 72 : m_pJSRuntime(pRuntime) { | 72 : m_pJSRuntime(pRuntime) { |
| 73 operator=(pStr); | 73 operator=(pStr); |
| 74 } | 74 } |
| 75 | 75 |
| 76 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Array& array) | 76 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const CJS_Array& array) |
| 77 : m_pJSRuntime(pRuntime) { | 77 : m_pValue(array.ToV8Array(pRuntime->GetIsolate())), |
| 78 operator=(array); | 78 m_pJSRuntime(pRuntime) {} |
| 79 } | |
| 80 | 79 |
| 81 CJS_Value::~CJS_Value() {} | 80 CJS_Value::~CJS_Value() {} |
| 82 | 81 |
| 83 CJS_Value::CJS_Value(const CJS_Value& other) = default; | 82 CJS_Value::CJS_Value(const CJS_Value& other) = default; |
| 84 | 83 |
| 85 void CJS_Value::Attach(v8::Local<v8::Value> pValue) { | 84 void CJS_Value::Attach(v8::Local<v8::Value> pValue) { |
| 86 m_pValue = pValue; | 85 m_pValue = pValue; |
| 87 } | 86 } |
| 88 | 87 |
| 89 void CJS_Value::Detach() { | 88 void CJS_Value::Detach() { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 184 } |
| 186 | 185 |
| 187 void CJS_Value::SetNull() { | 186 void CJS_Value::SetNull() { |
| 188 m_pValue = FXJS_NewNull(m_pJSRuntime->GetIsolate()); | 187 m_pValue = FXJS_NewNull(m_pJSRuntime->GetIsolate()); |
| 189 } | 188 } |
| 190 | 189 |
| 191 void CJS_Value::operator=(const FX_CHAR* pStr) { | 190 void CJS_Value::operator=(const FX_CHAR* pStr) { |
| 192 operator=(CFX_WideString::FromLocal(pStr).c_str()); | 191 operator=(CFX_WideString::FromLocal(pStr).c_str()); |
| 193 } | 192 } |
| 194 | 193 |
| 195 void CJS_Value::operator=(const CJS_Array& array) { | |
| 196 ASSERT(m_pJSRuntime == array.GetJSRuntime()); | |
| 197 m_pValue = array.ToV8Array(); | |
| 198 } | |
| 199 | |
| 200 void CJS_Value::operator=(const CJS_Date& date) { | 194 void CJS_Value::operator=(const CJS_Date& date) { |
| 201 ASSERT(m_pJSRuntime == date.GetJSRuntime()); | 195 ASSERT(m_pJSRuntime == date.GetJSRuntime()); |
| 202 m_pValue = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date.ToDouble()); | 196 m_pValue = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date.ToDouble()); |
| 203 } | 197 } |
| 204 | 198 |
| 205 void CJS_Value::operator=(const CJS_Value& value) { | 199 void CJS_Value::operator=(const CJS_Value& value) { |
| 206 ASSERT(m_pJSRuntime == value.m_pJSRuntime); | 200 ASSERT(m_pJSRuntime == value.m_pJSRuntime); |
| 207 m_pValue = value.ToV8Value(); | 201 m_pValue = value.ToV8Value(); |
| 208 } | 202 } |
| 209 | 203 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 CJS_Value::operator=(wide_string.c_str()); | 346 CJS_Value::operator=(wide_string.c_str()); |
| 353 } | 347 } |
| 354 | 348 |
| 355 void CJS_PropValue::operator>>(CJS_Array& array) const { | 349 void CJS_PropValue::operator>>(CJS_Array& array) const { |
| 356 ASSERT(m_bIsSetting); | 350 ASSERT(m_bIsSetting); |
| 357 ConvertToArray(array); | 351 ConvertToArray(array); |
| 358 } | 352 } |
| 359 | 353 |
| 360 void CJS_PropValue::operator<<(CJS_Array& array) { | 354 void CJS_PropValue::operator<<(CJS_Array& array) { |
| 361 ASSERT(!m_bIsSetting); | 355 ASSERT(!m_bIsSetting); |
| 362 CJS_Value::operator=(array); | 356 m_pValue = array.ToV8Array(m_pJSRuntime->GetIsolate()); |
| 363 } | 357 } |
| 364 | 358 |
| 365 void CJS_PropValue::operator>>(CJS_Date& date) const { | 359 void CJS_PropValue::operator>>(CJS_Date& date) const { |
| 366 ASSERT(m_bIsSetting); | 360 ASSERT(m_bIsSetting); |
| 367 ConvertToDate(date); | 361 ConvertToDate(date); |
| 368 } | 362 } |
| 369 | 363 |
| 370 void CJS_PropValue::operator<<(CJS_Date& date) { | 364 void CJS_PropValue::operator<<(CJS_Date& date) { |
| 371 ASSERT(!m_bIsSetting); | 365 ASSERT(!m_bIsSetting); |
| 372 CJS_Value::operator=(date); | 366 CJS_Value::operator=(date); |
| 373 } | 367 } |
| 374 | 368 |
| 375 CJS_Array::CJS_Array(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) {} | 369 CJS_Array::CJS_Array() {} |
| 370 |
| 371 CJS_Array::CJS_Array(const CJS_Array& other) = default; |
| 376 | 372 |
| 377 CJS_Array::~CJS_Array() {} | 373 CJS_Array::~CJS_Array() {} |
| 378 | 374 |
| 379 CJS_Array::CJS_Array(const CJS_Array& other) = default; | |
| 380 | |
| 381 void CJS_Array::Attach(v8::Local<v8::Array> pArray) { | 375 void CJS_Array::Attach(v8::Local<v8::Array> pArray) { |
| 382 m_pArray = pArray; | 376 m_pArray = pArray; |
| 383 } | 377 } |
| 384 | 378 |
| 385 void CJS_Array::GetElement(unsigned index, CJS_Value& value) const { | 379 void CJS_Array::GetElement(v8::Isolate* pIsolate, |
| 386 if (m_pArray.IsEmpty()) | 380 unsigned index, |
| 387 return; | 381 CJS_Value& value) const { |
| 388 v8::Local<v8::Value> p = | 382 if (!m_pArray.IsEmpty()) |
| 389 FXJS_GetArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index); | 383 value.Attach(FXJS_GetArrayElement(pIsolate, m_pArray, index)); |
| 390 value.Attach(p); | |
| 391 } | 384 } |
| 392 | 385 |
| 393 void CJS_Array::SetElement(unsigned index, CJS_Value value) { | 386 void CJS_Array::SetElement(v8::Isolate* pIsolate, |
| 387 unsigned index, |
| 388 const CJS_Value& value) { |
| 394 if (m_pArray.IsEmpty()) | 389 if (m_pArray.IsEmpty()) |
| 395 m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate()); | 390 m_pArray = FXJS_NewArray(pIsolate); |
| 396 | 391 |
| 397 FXJS_PutArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index, | 392 FXJS_PutArrayElement(pIsolate, m_pArray, index, value.ToV8Value()); |
| 398 value.ToV8Value()); | |
| 399 } | 393 } |
| 400 | 394 |
| 401 int CJS_Array::GetLength() const { | 395 int CJS_Array::GetLength() const { |
| 402 if (m_pArray.IsEmpty()) | 396 if (m_pArray.IsEmpty()) |
| 403 return 0; | 397 return 0; |
| 404 return FXJS_GetArrayLength(m_pArray); | 398 return FXJS_GetArrayLength(m_pArray); |
| 405 } | 399 } |
| 406 | 400 |
| 407 v8::Local<v8::Array> CJS_Array::ToV8Array() const { | 401 v8::Local<v8::Array> CJS_Array::ToV8Array(v8::Isolate* pIsolate) const { |
| 408 if (m_pArray.IsEmpty()) | 402 if (m_pArray.IsEmpty()) |
| 409 m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate()); | 403 m_pArray = FXJS_NewArray(pIsolate); |
| 410 | 404 |
| 411 return m_pArray; | 405 return m_pArray; |
| 412 } | 406 } |
| 413 | 407 |
| 414 CJS_Date::CJS_Date(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) {} | 408 CJS_Date::CJS_Date(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) {} |
| 415 | 409 |
| 416 CJS_Date::CJS_Date(CJS_Runtime* pRuntime, double dMsecTime) | 410 CJS_Date::CJS_Date(CJS_Runtime* pRuntime, double dMsecTime) |
| 417 : m_pJSRuntime(pRuntime) { | 411 : m_pJSRuntime(pRuntime) { |
| 418 m_pDate = FXJS_NewDate(pRuntime->GetIsolate(), dMsecTime); | 412 m_pDate = FXJS_NewDate(pRuntime->GetIsolate(), dMsecTime); |
| 419 } | 413 } |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 for (size_t i = 0; i < nKeywords; ++i) { | 837 for (size_t i = 0; i < nKeywords; ++i) { |
| 844 const wchar_t* property = va_arg(ap, const wchar_t*); | 838 const wchar_t* property = va_arg(ap, const wchar_t*); |
| 845 v8::Local<v8::Value> v8Value = | 839 v8::Local<v8::Value> v8Value = |
| 846 FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property); | 840 FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property); |
| 847 if (!v8Value->IsUndefined()) | 841 if (!v8Value->IsUndefined()) |
| 848 result[i] = CJS_Value(pRuntime, v8Value); | 842 result[i] = CJS_Value(pRuntime, v8Value); |
| 849 } | 843 } |
| 850 va_end(ap); | 844 va_end(ap); |
| 851 return result; | 845 return result; |
| 852 } | 846 } |
| OLD | NEW |