Replace calls to v8::Isolate::GetCurrent(), part 1
Bug: pdfium:1737
Change-Id: I6b40dacbee6bb00cfa05c8f75fcc6cac5ef3d08f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/86293
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/cfx_v8.cpp b/fxjs/cfx_v8.cpp
index 8fe7da2..46d18e4 100644
--- a/fxjs/cfx_v8.cpp
+++ b/fxjs/cfx_v8.cpp
@@ -77,8 +77,7 @@
}
v8::Local<v8::String> CFX_V8::NewString(ByteStringView str) {
- v8::Isolate* pIsolate = m_pIsolate ? GetIsolate() : v8::Isolate::GetCurrent();
- return fxv8::NewStringHelper(pIsolate, str);
+ return fxv8::NewStringHelper(GetIsolate(), str);
}
v8::Local<v8::String> CFX_V8::NewString(WideStringView str) {
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index e3f340c..420551d 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -348,7 +348,8 @@
return StrArray;
}
-double CJS_PublicMethods::ParseDate(const WideString& value,
+double CJS_PublicMethods::ParseDate(v8::Isolate* isolate,
+ const WideString& value,
bool* bWrongFormat) {
double dt = FX_GetDateTime();
int nYear = FX_GetYearFromTime(dt);
@@ -422,11 +423,13 @@
}
// TODO(thestig): Should we set |bWrongFormat| to false here too?
- return JS_DateParse(WideString::Format(L"%d/%d/%d %d:%d:%d", nMonth, nDay,
- nYear, nHour, nMin, nSec));
+ return JS_DateParse(
+ isolate, WideString::Format(L"%d/%d/%d %d:%d:%d", nMonth, nDay, nYear,
+ nHour, nMin, nSec));
}
-double CJS_PublicMethods::ParseDateUsingFormat(const WideString& value,
+double CJS_PublicMethods::ParseDateUsingFormat(v8::Isolate* isolate,
+ const WideString& value,
const WideString& format,
bool* bWrongFormat) {
double dRet = nan("");
@@ -435,13 +438,13 @@
return dRet;
if (status == fxjs::ConversionStatus::kBadDate) {
- dRet = JS_DateParse(value);
+ dRet = JS_DateParse(isolate, value);
if (!isnan(dRet))
return dRet;
}
bool bBadFormat = false;
- dRet = ParseDate(value, &bBadFormat);
+ dRet = ParseDate(isolate, value, &bBadFormat);
if (bWrongFormat)
*bWrongFormat = bBadFormat;
@@ -892,9 +895,10 @@
double dDate;
if (strValue.Contains(L"GMT")) {
// e.g. "Tue Aug 11 14:24:16 GMT+08002009"
- dDate = ParseDateAsGMT(strValue);
+ dDate = ParseDateAsGMT(pRuntime->GetIsolate(), strValue);
} else {
- dDate = ParseDateUsingFormat(strValue, sFormat, nullptr);
+ dDate = ParseDateUsingFormat(pRuntime->GetIsolate(), strValue, sFormat,
+ nullptr);
}
if (isnan(dDate)) {
@@ -908,7 +912,8 @@
return CJS_Result::Success();
}
-double CJS_PublicMethods::ParseDateAsGMT(const WideString& strValue) {
+double CJS_PublicMethods::ParseDateAsGMT(v8::Isolate* isolate,
+ const WideString& strValue) {
std::vector<WideString> wsArray;
WideString sTemp;
for (const auto& c : strValue) {
@@ -939,7 +944,7 @@
double dRet = FX_MakeDate(FX_MakeDay(nYear, nMonth - 1, nDay),
FX_MakeTime(nHour, nMin, nSec, 0));
if (isnan(dRet))
- dRet = JS_DateParse(strValue);
+ dRet = JS_DateParse(isolate, strValue);
return dRet;
}
@@ -966,7 +971,8 @@
bool bWrongFormat = false;
WideString sFormat = pRuntime->ToWideString(params[0]);
- double dRet = ParseDateUsingFormat(strValue, sFormat, &bWrongFormat);
+ double dRet = ParseDateUsingFormat(pRuntime->GetIsolate(), strValue, sFormat,
+ &bWrongFormat);
if (bWrongFormat || isnan(dRet)) {
WideString swMsg = WideString::Format(
JSGetStringFromID(JSMessage::kParseDateError).c_str(), sFormat.c_str());
@@ -1222,7 +1228,8 @@
WideString sValue = pRuntime->ToWideString(params[0]);
WideString sFormat = pRuntime->ToWideString(params[1]);
- double dDate = ParseDateUsingFormat(sValue, sFormat, nullptr);
+ double dDate =
+ ParseDateUsingFormat(pRuntime->GetIsolate(), sValue, sFormat, nullptr);
if (isnan(dDate)) {
WideString swMsg = WideString::Format(
JSGetStringFromID(JSMessage::kParseDateError).c_str(), sFormat.c_str());
diff --git a/fxjs/cjs_publicmethods.h b/fxjs/cjs_publicmethods.h
index 53a4dcc..bdf1362 100644
--- a/fxjs/cjs_publicmethods.h
+++ b/fxjs/cjs_publicmethods.h
@@ -18,9 +18,12 @@
static void DefineJSObjects(CFXJS_Engine* pEngine);
- static double ParseDate(const WideString& value, bool* bWrongFormat);
- static double ParseDateAsGMT(const WideString& value);
- static double ParseDateUsingFormat(const WideString& value,
+ static double ParseDate(v8::Isolate* isolate,
+ const WideString& value,
+ bool* bWrongFormat);
+ static double ParseDateAsGMT(v8::Isolate* isolate, const WideString& value);
+ static double ParseDateUsingFormat(v8::Isolate* isolate,
+ const WideString& value,
const WideString& format,
bool* bWrongFormat);
diff --git a/fxjs/cjs_publicmethods_embeddertest.cpp b/fxjs/cjs_publicmethods_embeddertest.cpp
index a21a938..c595eb4 100644
--- a/fxjs/cjs_publicmethods_embeddertest.cpp
+++ b/fxjs/cjs_publicmethods_embeddertest.cpp
@@ -32,80 +32,80 @@
// 1968
bWrongFormat = false;
- date = CJS_PublicMethods::ParseDateUsingFormat(L"06/25/1968", L"mm/dd/yyyy",
- &bWrongFormat);
+ date = CJS_PublicMethods::ParseDateUsingFormat(isolate(), L"06/25/1968",
+ L"mm/dd/yyyy", &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(-47865600000, date);
EXPECT_FALSE(bWrongFormat);
// 1968
bWrongFormat = false;
- date = CJS_PublicMethods::ParseDateUsingFormat(L"25061968", L"ddmmyyyy",
- &bWrongFormat);
+ date = CJS_PublicMethods::ParseDateUsingFormat(isolate(), L"25061968",
+ L"ddmmyyyy", &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(-47865600000, date);
EXPECT_FALSE(bWrongFormat);
// 1968
bWrongFormat = false;
- date = CJS_PublicMethods::ParseDateUsingFormat(L"19680625", L"yyyymmdd",
- &bWrongFormat);
+ date = CJS_PublicMethods::ParseDateUsingFormat(isolate(), L"19680625",
+ L"yyyymmdd", &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(-47865600000, date);
EXPECT_FALSE(bWrongFormat);
// 1985
bWrongFormat = false;
- date = CJS_PublicMethods::ParseDateUsingFormat(L"31121985", L"ddmmyyyy",
- &bWrongFormat);
+ date = CJS_PublicMethods::ParseDateUsingFormat(isolate(), L"31121985",
+ L"ddmmyyyy", &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(504835200000.0, date);
EXPECT_FALSE(bWrongFormat);
// 2085, the other '85.
bWrongFormat = false;
- date = CJS_PublicMethods::ParseDateUsingFormat(L"311285", L"ddmmyy",
- &bWrongFormat);
+ date = CJS_PublicMethods::ParseDateUsingFormat(isolate(), L"311285",
+ L"ddmmyy", &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(3660595200000.0, date);
EXPECT_FALSE(bWrongFormat);
// 1995
bWrongFormat = false;
- date = CJS_PublicMethods::ParseDateUsingFormat(L"01021995", L"ddmmyyyy",
- &bWrongFormat);
+ date = CJS_PublicMethods::ParseDateUsingFormat(isolate(), L"01021995",
+ L"ddmmyyyy", &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(791596800000.0, date);
EXPECT_FALSE(bWrongFormat);
// 2095, the other '95.
bWrongFormat = false;
- date = CJS_PublicMethods::ParseDateUsingFormat(L"010295", L"ddmmyy",
- &bWrongFormat);
+ date = CJS_PublicMethods::ParseDateUsingFormat(isolate(), L"010295",
+ L"ddmmyy", &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(3947356800000.0, date);
EXPECT_FALSE(bWrongFormat);
// 2005
bWrongFormat = false;
- date = CJS_PublicMethods::ParseDateUsingFormat(L"01022005", L"ddmmyyyy",
- &bWrongFormat);
+ date = CJS_PublicMethods::ParseDateUsingFormat(isolate(), L"01022005",
+ L"ddmmyyyy", &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(1107216000000.0, date);
EXPECT_FALSE(bWrongFormat);
// 2005
bWrongFormat = false;
- date = CJS_PublicMethods::ParseDateUsingFormat(L"010205", L"ddmmyy",
- &bWrongFormat);
+ date = CJS_PublicMethods::ParseDateUsingFormat(isolate(), L"010205",
+ L"ddmmyy", &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(1107216000000.0, date);
EXPECT_FALSE(bWrongFormat);
// 2005 in a different format. https://crbug.com/436572
bWrongFormat = false;
- date = CJS_PublicMethods::ParseDateUsingFormat(L"050201", L"yymmdd",
- &bWrongFormat);
+ date = CJS_PublicMethods::ParseDateUsingFormat(isolate(), L"050201",
+ L"yymmdd", &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(1107216000000.0, date);
EXPECT_FALSE(bWrongFormat);
diff --git a/fxjs/cjs_util.cpp b/fxjs/cjs_util.cpp
index 0a27b57..b938854 100644
--- a/fxjs/cjs_util.cpp
+++ b/fxjs/cjs_util.cpp
@@ -376,7 +376,8 @@
WideString sDate = pRuntime->ToWideString(params[1]);
double dDate = FX_GetDateTime();
if (sDate.GetLength() > 0)
- dDate = CJS_PublicMethods::ParseDateUsingFormat(sDate, sFormat, nullptr);
+ dDate = CJS_PublicMethods::ParseDateUsingFormat(pRuntime->GetIsolate(),
+ sDate, sFormat, nullptr);
if (isnan(dDate))
return CJS_Result::Success(pRuntime->NewUndefined());
diff --git a/fxjs/js_define.cpp b/fxjs/js_define.cpp
index c994b1d..4a50442 100644
--- a/fxjs/js_define.cpp
+++ b/fxjs/js_define.cpp
@@ -27,8 +27,7 @@
CFXJS_Engine::SetObjectPrivate(obj, nullptr);
}
-double JS_DateParse(const WideString& str) {
- v8::Isolate* pIsolate = v8::Isolate::GetCurrent();
+double JS_DateParse(v8::Isolate* pIsolate, const WideString& str) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope scope(pIsolate);
diff --git a/fxjs/js_define.h b/fxjs/js_define.h
index 9067980..a4314d7 100644
--- a/fxjs/js_define.h
+++ b/fxjs/js_define.h
@@ -18,7 +18,7 @@
class CJS_Object;
-double JS_DateParse(const WideString& str);
+double JS_DateParse(v8::Isolate* pIsolate, const WideString& str);
// Some JS methods have the bizarre convention that they may also be called
// with a single argument which is an object containing the actual arguments