From cbe23dbdff3f6e41843fd99cbf615000b52727ed Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 19 Oct 2017 14:29:33 -0400 Subject: Refactoring JS Callbacks. This CL updates the fpdfsdk/javascript callbacks to have explicit get/set methods instead of one method which worked differently depending on the mode. This allows better ownership of the passed in params, (get takes a * and set takes a const&). The Value object was changed to have To* and Set methods to make the code clearer compared to the operator<< and operator>> overloading. Bug: Change-Id: Id6ff20a4e3252adfd0a78b643e50b9f095085018 Reviewed-on: https://pdfium-review.googlesource.com/16330 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- fpdfsdk/javascript/JS_Value.cpp | 66 ++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 30 deletions(-) (limited to 'fpdfsdk/javascript/JS_Value.cpp') diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp index ee81102583..6529a9d604 100644 --- a/fpdfsdk/javascript/JS_Value.cpp +++ b/fpdfsdk/javascript/JS_Value.cpp @@ -338,107 +338,111 @@ CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime, const CJS_Value& value) CJS_PropValue::~CJS_PropValue() {} -void CJS_PropValue::operator<<(int iValue) { +void CJS_PropValue::Set(int iValue) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), iValue); } -void CJS_PropValue::operator>>(int& iValue) const { +int CJS_PropValue::ToInt() const { ASSERT(m_bIsSetting); - iValue = m_Value.ToInt(m_pJSRuntime.Get()); + return m_Value.ToInt(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(bool bValue) { +void CJS_PropValue::Set(bool bValue) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), bValue); } -void CJS_PropValue::operator>>(bool& bValue) const { +bool CJS_PropValue::ToBool() const { ASSERT(m_bIsSetting); - bValue = m_Value.ToBool(m_pJSRuntime.Get()); + return m_Value.ToBool(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(double dValue) { +void CJS_PropValue::Set(double dValue) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), dValue); } -void CJS_PropValue::operator>>(double& dValue) const { +double CJS_PropValue::ToDouble() const { ASSERT(m_bIsSetting); - dValue = m_Value.ToDouble(m_pJSRuntime.Get()); + return m_Value.ToDouble(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(CJS_Object* pObj) { +void CJS_PropValue::Set(CJS_Object* pObj) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), pObj); } -void CJS_PropValue::operator>>(CJS_Object*& ppObj) const { +CJS_Object* CJS_PropValue::ToObject() const { ASSERT(m_bIsSetting); - ppObj = m_Value.ToCJSObject(m_pJSRuntime.Get()); + return m_Value.ToCJSObject(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(CJS_Document* pJsDoc) { +void CJS_PropValue::Set(CJS_Document* pJsDoc) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), pJsDoc); } -void CJS_PropValue::operator>>(CJS_Document*& ppJsDoc) const { +CJS_Document* CJS_PropValue::ToDocument() const { ASSERT(m_bIsSetting); - ppJsDoc = static_cast(m_Value.ToCJSObject(m_pJSRuntime.Get())); + return static_cast(m_Value.ToCJSObject(m_pJSRuntime.Get())); } -void CJS_PropValue::operator<<(v8::Local pObj) { +void CJS_PropValue::Set(v8::Local pObj) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), pObj); } -void CJS_PropValue::operator>>(v8::Local& ppObj) const { +v8::Local CJS_PropValue::ToV8Object() const { ASSERT(m_bIsSetting); - ppObj = m_Value.ToV8Object(m_pJSRuntime.Get()); + return m_Value.ToV8Object(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(ByteString str) { +void CJS_PropValue::Set(const ByteString& str) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), str.c_str()); } -void CJS_PropValue::operator>>(ByteString& str) const { +ByteString CJS_PropValue::ToByteString() const { ASSERT(m_bIsSetting); - str = m_Value.ToCFXByteString(m_pJSRuntime.Get()); + return m_Value.ToCFXByteString(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(const wchar_t* str) { +void CJS_PropValue::Set(const wchar_t* str) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), str); } -void CJS_PropValue::operator>>(WideString& wide_string) const { +WideString CJS_PropValue::ToWideString() const { ASSERT(m_bIsSetting); - wide_string = m_Value.ToCFXWideString(m_pJSRuntime.Get()); + return m_Value.ToCFXWideString(m_pJSRuntime.Get()); } -void CJS_PropValue::operator<<(WideString wide_string) { +void CJS_PropValue::Set(const WideString& wide_string) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), wide_string.c_str()); } -void CJS_PropValue::operator>>(CJS_Array& array) const { +CJS_Array CJS_PropValue::ToArray() const { ASSERT(m_bIsSetting); - m_Value.ConvertToArray(m_pJSRuntime.Get(), array); + CJS_Array ary; + m_Value.ConvertToArray(m_pJSRuntime.Get(), ary); + return ary; } -void CJS_PropValue::operator<<(CJS_Array& array) { +void CJS_PropValue::Set(const CJS_Array& array) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), array.ToV8Array(m_pJSRuntime.Get())); } -void CJS_PropValue::operator>>(CJS_Date& date) const { +CJS_Date CJS_PropValue::ToDate() const { ASSERT(m_bIsSetting); + CJS_Date date; m_Value.ConvertToDate(m_pJSRuntime.Get(), date); + return date; } -void CJS_PropValue::operator<<(CJS_Date& date) { +void CJS_PropValue::Set(const CJS_Date& date) { ASSERT(!m_bIsSetting); m_Value = CJS_Value(m_pJSRuntime.Get(), date); } @@ -496,6 +500,8 @@ CJS_Date::CJS_Date(CJS_Runtime* pRuntime, int sec) : m_pDate(pRuntime->NewDate(MakeDate(year, mon, day, hour, min, sec, 0))) {} +CJS_Date::CJS_Date(const CJS_Date& other) = default; + CJS_Date::~CJS_Date() {} bool CJS_Date::IsValidDate(CJS_Runtime* pRuntime) const { -- cgit v1.2.3