summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-08-09 07:30:38 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-09 07:30:38 -0700
commitf3c883239be0e016d0577f0d9d52185387f64856 (patch)
treedffbabaaa85f77dbcd78dba8863fb96d41584f94 /fpdfsdk
parentfb362089d952950212ccf159f86a46923f223172 (diff)
downloadpdfium-f3c883239be0e016d0577f0d9d52185387f64856.tar.xz
Remove back-pointer to CJS_Runtime from CJS_Date
Review-Url: https://codereview.chromium.org/2224113003
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/javascript/JS_Value.cpp141
-rw-r--r--fpdfsdk/javascript/JS_Value.h43
-rw-r--r--fpdfsdk/javascript/util.cpp53
3 files changed, 117 insertions, 120 deletions
diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp
index ab81aa0b46..df7bdf4746 100644
--- a/fpdfsdk/javascript/JS_Value.cpp
+++ b/fpdfsdk/javascript/JS_Value.cpp
@@ -191,11 +191,6 @@ void CJS_Value::operator=(const FX_CHAR* pStr) {
operator=(CFX_WideString::FromLocal(pStr).c_str());
}
-void CJS_Value::operator=(const CJS_Date& date) {
- ASSERT(m_pJSRuntime == date.GetJSRuntime());
- m_pValue = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date.ToDouble());
-}
-
void CJS_Value::operator=(const CJS_Value& value) {
ASSERT(m_pJSRuntime == value.m_pJSRuntime);
m_pValue = value.ToV8Value();
@@ -364,7 +359,7 @@ void CJS_PropValue::operator>>(CJS_Date& date) const {
void CJS_PropValue::operator<<(CJS_Date& date) {
ASSERT(!m_bIsSetting);
- CJS_Value::operator=(date);
+ m_pValue = date.ToV8Date(m_pJSRuntime->GetIsolate());
}
CJS_Array::CJS_Array() {}
@@ -406,132 +401,126 @@ v8::Local<v8::Array> CJS_Array::ToV8Array(v8::Isolate* pIsolate) const {
return m_pArray;
}
-CJS_Date::CJS_Date(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) {}
+CJS_Date::CJS_Date() {}
-CJS_Date::CJS_Date(CJS_Runtime* pRuntime, double dMsecTime)
- : m_pJSRuntime(pRuntime) {
- m_pDate = FXJS_NewDate(pRuntime->GetIsolate(), dMsecTime);
-}
+CJS_Date::CJS_Date(v8::Isolate* pIsolate, double dMsecTime)
+ : m_pDate(FXJS_NewDate(pIsolate, dMsecTime)) {}
-CJS_Date::CJS_Date(CJS_Runtime* pRuntime,
+CJS_Date::CJS_Date(v8::Isolate* pIsolate,
int year,
int mon,
int day,
int hour,
int min,
int sec)
- : m_pJSRuntime(pRuntime) {
- m_pDate = FXJS_NewDate(pRuntime->GetIsolate(),
- MakeDate(year, mon, day, hour, min, sec, 0));
-}
+ : m_pDate(FXJS_NewDate(pIsolate,
+ MakeDate(year, mon, day, hour, min, sec, 0))) {}
CJS_Date::~CJS_Date() {}
-bool CJS_Date::IsValidDate() const {
- return !m_pDate.IsEmpty() &&
- !JS_PortIsNan(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate));
+bool CJS_Date::IsValidDate(v8::Isolate* pIsolate) const {
+ return !m_pDate.IsEmpty() && !JS_PortIsNan(FXJS_ToNumber(pIsolate, m_pDate));
}
void CJS_Date::Attach(v8::Local<v8::Date> pDate) {
m_pDate = pDate;
}
-int CJS_Date::GetYear() const {
- if (!IsValidDate())
+int CJS_Date::GetYear(v8::Isolate* pIsolate) const {
+ if (!IsValidDate(pIsolate))
return 0;
- return JS_GetYearFromTime(
- JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)));
+ return JS_GetYearFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate)));
}
-void CJS_Date::SetYear(int iYear) {
- double date = MakeDate(iYear, GetMonth(), GetDay(), GetHours(), GetMinutes(),
- GetSeconds(), 0);
- m_pDate = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date);
+void CJS_Date::SetYear(v8::Isolate* pIsolate, int iYear) {
+ m_pDate = FXJS_NewDate(
+ pIsolate,
+ MakeDate(iYear, GetMonth(pIsolate), GetDay(pIsolate), GetHours(pIsolate),
+ GetMinutes(pIsolate), GetSeconds(pIsolate), 0));
}
-int CJS_Date::GetMonth() const {
- if (!IsValidDate())
+int CJS_Date::GetMonth(v8::Isolate* pIsolate) const {
+ if (!IsValidDate(pIsolate))
return 0;
- return JS_GetMonthFromTime(
- JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)));
+ return JS_GetMonthFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate)));
}
-void CJS_Date::SetMonth(int iMonth) {
- double date = MakeDate(GetYear(), iMonth, GetDay(), GetHours(), GetMinutes(),
- GetSeconds(), 0);
- m_pDate = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date);
+void CJS_Date::SetMonth(v8::Isolate* pIsolate, int iMonth) {
+ m_pDate = FXJS_NewDate(
+ pIsolate,
+ MakeDate(GetYear(pIsolate), iMonth, GetDay(pIsolate), GetHours(pIsolate),
+ GetMinutes(pIsolate), GetSeconds(pIsolate), 0));
}
-int CJS_Date::GetDay() const {
- if (!IsValidDate())
+int CJS_Date::GetDay(v8::Isolate* pIsolate) const {
+ if (!IsValidDate(pIsolate))
return 0;
- return JS_GetDayFromTime(
- JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)));
+ return JS_GetDayFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate)));
}
-void CJS_Date::SetDay(int iDay) {
- double date = MakeDate(GetYear(), GetMonth(), iDay, GetHours(), GetMinutes(),
- GetSeconds(), 0);
- m_pDate = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date);
+void CJS_Date::SetDay(v8::Isolate* pIsolate, int iDay) {
+ m_pDate = FXJS_NewDate(
+ pIsolate,
+ MakeDate(GetYear(pIsolate), GetMonth(pIsolate), iDay, GetHours(pIsolate),
+ GetMinutes(pIsolate), GetSeconds(pIsolate), 0));
}
-int CJS_Date::GetHours() const {
- if (!IsValidDate())
+int CJS_Date::GetHours(v8::Isolate* pIsolate) const {
+ if (!IsValidDate(pIsolate))
return 0;
- return JS_GetHourFromTime(
- JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)));
+ return JS_GetHourFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate)));
}
-void CJS_Date::SetHours(int iHours) {
- double date = MakeDate(GetYear(), GetMonth(), GetDay(), iHours, GetMinutes(),
- GetSeconds(), 0);
- m_pDate = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date);
+void CJS_Date::SetHours(v8::Isolate* pIsolate, int iHours) {
+ m_pDate = FXJS_NewDate(
+ pIsolate,
+ MakeDate(GetYear(pIsolate), GetMonth(pIsolate), GetDay(pIsolate), iHours,
+ GetMinutes(pIsolate), GetSeconds(pIsolate), 0));
}
-int CJS_Date::GetMinutes() const {
- if (!IsValidDate())
+int CJS_Date::GetMinutes(v8::Isolate* pIsolate) const {
+ if (!IsValidDate(pIsolate))
return 0;
- return JS_GetMinFromTime(
- JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)));
+ return JS_GetMinFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate)));
}
-void CJS_Date::SetMinutes(int minutes) {
- double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), minutes,
- GetSeconds(), 0);
- m_pDate = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date);
+void CJS_Date::SetMinutes(v8::Isolate* pIsolate, int minutes) {
+ m_pDate =
+ FXJS_NewDate(pIsolate, MakeDate(GetYear(pIsolate), GetMonth(pIsolate),
+ GetDay(pIsolate), GetHours(pIsolate),
+ minutes, GetSeconds(pIsolate), 0));
}
-int CJS_Date::GetSeconds() const {
- if (!IsValidDate())
+int CJS_Date::GetSeconds(v8::Isolate* pIsolate) const {
+ if (!IsValidDate(pIsolate))
return 0;
- return JS_GetSecFromTime(
- JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)));
+ return JS_GetSecFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate)));
}
-void CJS_Date::SetSeconds(int seconds) {
- double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(),
- GetMinutes(), seconds, 0);
- m_pDate = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date);
+void CJS_Date::SetSeconds(v8::Isolate* pIsolate, int seconds) {
+ m_pDate =
+ FXJS_NewDate(pIsolate, MakeDate(GetYear(pIsolate), GetMonth(pIsolate),
+ GetDay(pIsolate), GetHours(pIsolate),
+ GetMinutes(pIsolate), seconds, 0));
}
-double CJS_Date::ToDouble() const {
- if (m_pDate.IsEmpty())
- return 0.0;
-
- return FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate);
+double CJS_Date::ToDouble(v8::Isolate* pIsolate) const {
+ return !m_pDate.IsEmpty() ? FXJS_ToNumber(pIsolate, m_pDate) : 0.0;
}
-CFX_WideString CJS_Date::ToString() const {
- if (m_pDate.IsEmpty())
- return L"";
+CFX_WideString CJS_Date::ToString(v8::Isolate* pIsolate) const {
+ return !m_pDate.IsEmpty() ? FXJS_ToString(pIsolate, m_pDate)
+ : CFX_WideString();
+}
- return FXJS_ToString(m_pJSRuntime->GetIsolate(), m_pDate);
+v8::Local<v8::Date> CJS_Date::ToV8Date(v8::Isolate* pIsolate) const {
+ return m_pDate;
}
double _getLocalTZA() {
diff --git a/fpdfsdk/javascript/JS_Value.h b/fpdfsdk/javascript/JS_Value.h
index 75c40a60a1..4c0d8cceac 100644
--- a/fpdfsdk/javascript/JS_Value.h
+++ b/fpdfsdk/javascript/JS_Value.h
@@ -41,6 +41,7 @@ class CJS_Value {
CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr);
CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr);
CJS_Value(CJS_Runtime* pRuntime, const CJS_Array& array);
+ CJS_Value(CJS_Runtime* pRuntime, const CJS_Date& date);
CJS_Value(const CJS_Value& other);
~CJS_Value();
@@ -72,8 +73,6 @@ class CJS_Value {
void operator=(float val);
void operator=(CJS_Object* val);
void operator=(v8::Local<v8::Object> val);
- void operator=(const CJS_Array& val);
- void operator=(const CJS_Date& val);
void operator=(const CJS_Value& value);
void operator=(const FX_CHAR* pStr);
void operator=(const FX_WCHAR* pWstr);
@@ -150,9 +149,9 @@ class CJS_Array {
class CJS_Date {
public:
- explicit CJS_Date(CJS_Runtime* pRuntime);
- CJS_Date(CJS_Runtime* pRuntime, double dMsec_time);
- CJS_Date(CJS_Runtime* pRuntime,
+ CJS_Date();
+ CJS_Date(v8::Isolate* pIsolate, double dMsec_time);
+ CJS_Date(v8::Isolate* pIsolate,
int year,
int mon,
int day,
@@ -162,34 +161,32 @@ class CJS_Date {
virtual ~CJS_Date();
void Attach(v8::Local<v8::Date> pDate);
- bool IsValidDate() const;
+ bool IsValidDate(v8::Isolate* pIsolate) const;
- int GetYear() const;
- void SetYear(int iYear);
+ int GetYear(v8::Isolate* pIsolate) const;
+ void SetYear(v8::Isolate* pIsolate, int iYear);
- int GetMonth() const;
- void SetMonth(int iMonth);
+ int GetMonth(v8::Isolate* pIsolate) const;
+ void SetMonth(v8::Isolate* pIsolate, int iMonth);
- int GetDay() const;
- void SetDay(int iDay);
+ int GetDay(v8::Isolate* pIsolate) const;
+ void SetDay(v8::Isolate* pIsolate, int iDay);
- int GetHours() const;
- void SetHours(int iHours);
+ int GetHours(v8::Isolate* pIsolate) const;
+ void SetHours(v8::Isolate* pIsolate, int iHours);
- int GetMinutes() const;
- void SetMinutes(int minutes);
+ int GetMinutes(v8::Isolate* pIsolate) const;
+ void SetMinutes(v8::Isolate* pIsolate, int minutes);
- int GetSeconds() const;
- void SetSeconds(int seconds);
+ int GetSeconds(v8::Isolate* pIsolate) const;
+ void SetSeconds(v8::Isolate* pIsolate, int seconds);
- CJS_Runtime* GetJSRuntime() const { return m_pJSRuntime; }
- v8::Local<v8::Value> ToV8Value() const { return m_pDate; }
- double ToDouble() const;
- CFX_WideString ToString() const;
+ v8::Local<v8::Date> ToV8Date(v8::Isolate* pIsolate) const;
+ double ToDouble(v8::Isolate* pIsolate) const;
+ CFX_WideString ToString(v8::Isolate* pIsolate) const;
protected:
v8::Local<v8::Date> m_pDate;
- CJS_Runtime* const m_pJSRuntime;
};
double JS_GetDateTime();
diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp
index 4f2d834208..82c85a0268 100644
--- a/fpdfsdk/javascript/util.cpp
+++ b/fpdfsdk/javascript/util.cpp
@@ -186,13 +186,13 @@ FX_BOOL util::printd(IJS_Context* cc,
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CJS_Value p1 = params[0];
CJS_Value p2 = params[1];
- CJS_Date jsDate(pRuntime);
+ CJS_Date jsDate;
if (!p2.ConvertToDate(jsDate)) {
sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1);
return FALSE;
}
- if (!jsDate.IsValidDate()) {
+ if (!jsDate.IsValidDate(pRuntime->GetIsolate())) {
sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2);
return FALSE;
}
@@ -201,22 +201,31 @@ FX_BOOL util::printd(IJS_Context* cc,
CFX_WideString swResult;
switch (p1.ToInt()) {
case 0:
- swResult.Format(L"D:%04d%02d%02d%02d%02d%02d", jsDate.GetYear(),
- jsDate.GetMonth() + 1, jsDate.GetDay(),
- jsDate.GetHours(), jsDate.GetMinutes(),
- jsDate.GetSeconds());
+ swResult.Format(L"D:%04d%02d%02d%02d%02d%02d",
+ jsDate.GetYear(pRuntime->GetIsolate()),
+ jsDate.GetMonth(pRuntime->GetIsolate()) + 1,
+ jsDate.GetDay(pRuntime->GetIsolate()),
+ jsDate.GetHours(pRuntime->GetIsolate()),
+ jsDate.GetMinutes(pRuntime->GetIsolate()),
+ jsDate.GetSeconds(pRuntime->GetIsolate()));
break;
case 1:
- swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d", jsDate.GetYear(),
- jsDate.GetMonth() + 1, jsDate.GetDay(),
- jsDate.GetHours(), jsDate.GetMinutes(),
- jsDate.GetSeconds());
+ swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d",
+ jsDate.GetYear(pRuntime->GetIsolate()),
+ jsDate.GetMonth(pRuntime->GetIsolate()) + 1,
+ jsDate.GetDay(pRuntime->GetIsolate()),
+ jsDate.GetHours(pRuntime->GetIsolate()),
+ jsDate.GetMinutes(pRuntime->GetIsolate()),
+ jsDate.GetSeconds(pRuntime->GetIsolate()));
break;
case 2:
- swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d", jsDate.GetYear(),
- jsDate.GetMonth() + 1, jsDate.GetDay(),
- jsDate.GetHours(), jsDate.GetMinutes(),
- jsDate.GetSeconds());
+ swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d",
+ jsDate.GetYear(pRuntime->GetIsolate()),
+ jsDate.GetMonth(pRuntime->GetIsolate()) + 1,
+ jsDate.GetDay(pRuntime->GetIsolate()),
+ jsDate.GetHours(pRuntime->GetIsolate()),
+ jsDate.GetMinutes(pRuntime->GetIsolate()),
+ jsDate.GetSeconds(pRuntime->GetIsolate()));
break;
default:
sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSVALUEERROR);
@@ -250,12 +259,12 @@ FX_BOOL util::printd(IJS_Context* cc,
}
}
- int iYear = jsDate.GetYear();
- int iMonth = jsDate.GetMonth();
- int iDay = jsDate.GetDay();
- int iHour = jsDate.GetHours();
- int iMin = jsDate.GetMinutes();
- int iSec = jsDate.GetSeconds();
+ int iYear = jsDate.GetYear(pRuntime->GetIsolate());
+ int iMonth = jsDate.GetMonth(pRuntime->GetIsolate());
+ int iDay = jsDate.GetDay(pRuntime->GetIsolate());
+ int iHour = jsDate.GetHours(pRuntime->GetIsolate());
+ int iMin = jsDate.GetMinutes(pRuntime->GetIsolate());
+ int iSec = jsDate.GetSeconds(pRuntime->GetIsolate());
TbConvertAdditional cTableAd[] = {
{L"m", iMonth + 1}, {L"d", iDay},
@@ -434,7 +443,9 @@ FX_BOOL util::scand(IJS_Context* cc,
}
if (!JS_PortIsNan(dDate)) {
- vRet = CJS_Date(CJS_Runtime::FromContext(cc), dDate);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ vRet = CJS_Value(pRuntime, CJS_Date(pRuntime->GetIsolate(), dDate)
+ .ToV8Date(pRuntime->GetIsolate()));
} else {
vRet.SetNull();
}