| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 CJS_Value::operator=(wide_string.c_str()); | 347 CJS_Value::operator=(wide_string.c_str()); |
| 354 } | 348 } |
| 355 | 349 |
| 356 void CJS_PropValue::operator>>(CJS_Array& array) const { | 350 void CJS_PropValue::operator>>(CJS_Array& array) const { |
| 357 ASSERT(m_bIsSetting); | 351 ASSERT(m_bIsSetting); |
| 358 ConvertToArray(array); | 352 ConvertToArray(array); |
| 359 } | 353 } |
| 360 | 354 |
| 361 void CJS_PropValue::operator<<(CJS_Array& array) { | 355 void CJS_PropValue::operator<<(CJS_Array& array) { |
| 362 ASSERT(!m_bIsSetting); | 356 ASSERT(!m_bIsSetting); |
| 363 CJS_Value::operator=(array); | 357 m_pValue = array.ToV8Array(m_pJSRuntime->GetIsolate()); |
| 364 } | 358 } |
| 365 | 359 |
| 366 void CJS_PropValue::operator>>(CJS_Date& date) const { | 360 void CJS_PropValue::operator>>(CJS_Date& date) const { |
| 367 ASSERT(m_bIsSetting); | 361 ASSERT(m_bIsSetting); |
| 368 ConvertToDate(date); | 362 ConvertToDate(date); |
| 369 } | 363 } |
| 370 | 364 |
| 371 void CJS_PropValue::operator<<(CJS_Date& date) { | 365 void CJS_PropValue::operator<<(CJS_Date& date) { |
| 372 ASSERT(!m_bIsSetting); | 366 ASSERT(!m_bIsSetting); |
| 373 CJS_Value::operator=(date); | 367 CJS_Value::operator=(date); |
| 374 } | 368 } |
| 375 | 369 |
| 376 CJS_Array::CJS_Array(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) {} | 370 CJS_Array::CJS_Array() {} |
| 371 |
| 372 CJS_Array::CJS_Array(const CJS_Array& other) = default; |
| 377 | 373 |
| 378 CJS_Array::~CJS_Array() {} | 374 CJS_Array::~CJS_Array() {} |
| 379 | 375 |
| 380 CJS_Array::CJS_Array(const CJS_Array& other) = default; | |
| 381 | |
| 382 void CJS_Array::Attach(v8::Local<v8::Array> pArray) { | 376 void CJS_Array::Attach(v8::Local<v8::Array> pArray) { |
| 383 m_pArray = pArray; | 377 m_pArray = pArray; |
| 384 } | 378 } |
| 385 | 379 |
| 386 void CJS_Array::GetElement(unsigned index, CJS_Value& value) const { | 380 void CJS_Array::GetElement(v8::Isolate* pIsolate, |
| 387 if (m_pArray.IsEmpty()) | 381 unsigned index, |
| 388 return; | 382 CJS_Value& value) const { |
| 389 v8::Local<v8::Value> p = | 383 if (!m_pArray.IsEmpty()) |
| 390 FXJS_GetArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index); | 384 value.Attach(FXJS_GetArrayElement(pIsolate, m_pArray, index)); |
| 391 value.Attach(p); | |
| 392 } | 385 } |
| 393 | 386 |
| 394 void CJS_Array::SetElement(unsigned index, CJS_Value value) { | 387 void CJS_Array::SetElement(v8::Isolate* pIsolate, |
| 388 unsigned index, |
| 389 const CJS_Value& value) { |
| 395 if (m_pArray.IsEmpty()) | 390 if (m_pArray.IsEmpty()) |
| 396 m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate()); | 391 m_pArray = FXJS_NewArray(pIsolate); |
| 397 | 392 |
| 398 FXJS_PutArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index, | 393 FXJS_PutArrayElement(pIsolate, m_pArray, index, value.ToV8Value()); |
| 399 value.ToV8Value()); | |
| 400 } | 394 } |
| 401 | 395 |
| 402 int CJS_Array::GetLength() const { | 396 int CJS_Array::GetLength() const { |
| 403 if (m_pArray.IsEmpty()) | 397 if (m_pArray.IsEmpty()) |
| 404 return 0; | 398 return 0; |
| 405 return FXJS_GetArrayLength(m_pArray); | 399 return FXJS_GetArrayLength(m_pArray); |
| 406 } | 400 } |
| 407 | 401 |
| 408 v8::Local<v8::Array> CJS_Array::ToV8Array() const { | 402 v8::Local<v8::Array> CJS_Array::ToV8Array(v8::Isolate* pIsolate) const { |
| 409 if (m_pArray.IsEmpty()) | 403 if (m_pArray.IsEmpty()) |
| 410 m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate()); | 404 m_pArray = FXJS_NewArray(pIsolate); |
| 411 | 405 |
| 412 return m_pArray; | 406 return m_pArray; |
| 413 } | 407 } |
| 414 | 408 |
| 415 CJS_Date::CJS_Date(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) {} | 409 CJS_Date::CJS_Date(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) {} |
| 416 | 410 |
| 417 CJS_Date::CJS_Date(CJS_Runtime* pRuntime, double dMsecTime) | 411 CJS_Date::CJS_Date(CJS_Runtime* pRuntime, double dMsecTime) |
| 418 : m_pJSRuntime(pRuntime) { | 412 : m_pJSRuntime(pRuntime) { |
| 419 m_pDate = FXJS_NewDate(pRuntime->GetIsolate(), dMsecTime); | 413 m_pDate = FXJS_NewDate(pRuntime->GetIsolate(), dMsecTime); |
| 420 } | 414 } |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 for (size_t i = 0; i < nKeywords; ++i) { | 838 for (size_t i = 0; i < nKeywords; ++i) { |
| 845 const wchar_t* property = va_arg(ap, const wchar_t*); | 839 const wchar_t* property = va_arg(ap, const wchar_t*); |
| 846 v8::Local<v8::Value> v8Value = | 840 v8::Local<v8::Value> v8Value = |
| 847 FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property); | 841 FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property); |
| 848 if (!v8Value->IsUndefined()) | 842 if (!v8Value->IsUndefined()) |
| 849 result[i] = CJS_Value(pRuntime, v8Value); | 843 result[i] = CJS_Value(pRuntime, v8Value); |
| 850 } | 844 } |
| 851 va_end(ap); | 845 va_end(ap); |
| 852 return result; | 846 return result; |
| 853 } | 847 } |
| OLD | NEW |