Provide better logging from CJS_PublicMethods's AlertIfPossible().
Providing the name of the currently executing public method made
diagnosing failures easier in an unrelated CL.
-- consistently name one argument while at it.
Change-Id: I81d27004e6342b4e199c13fe08be9409005d1d53
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/75810
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Daniel Hosseinian <dhoss@chromium.org>
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index 02dced8..a557221 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -94,11 +94,14 @@
return result;
}
-void AlertIfPossible(CJS_EventContext* pContext, const WideString& swMsg) {
+void AlertIfPossible(CJS_EventContext* pContext,
+ const WideString& wsCaller,
+ const WideString& wsMsg) {
CPDFSDK_FormFillEnvironment* pFormFillEnv = pContext->GetFormFillEnv();
- if (pFormFillEnv)
- pFormFillEnv->JS_appAlert(swMsg, WideString(), JSPLATFORM_ALERT_BUTTON_OK,
+ if (pFormFillEnv) {
+ pFormFillEnv->JS_appAlert(wsMsg, wsCaller, JSPLATFORM_ALERT_BUTTON_OK,
JSPLATFORM_ALERT_ICON_STATUS);
+ }
}
#if !defined(OS_ANDROID)
@@ -712,7 +715,7 @@
if (!IsNumber(swTemp)) {
pEvent->Rc() = false;
WideString sError = JSGetStringFromID(JSMessage::kInvalidInputError);
- AlertIfPossible(pContext, sError);
+ AlertIfPossible(pContext, L"AFNumber_Keystroke", sError);
return CJS_Result::Failure(sError);
}
// It happens after the last keystroke and before validating,
@@ -900,7 +903,7 @@
if (std::isnan(dDate)) {
WideString swMsg = WideString::Format(
JSGetStringFromID(JSMessage::kParseDateError).c_str(), sFormat.c_str());
- AlertIfPossible(pContext, swMsg);
+ AlertIfPossible(pContext, L"AFDate_FormatEx", swMsg);
return CJS_Result::Failure(JSMessage::kParseDateError);
}
@@ -971,7 +974,7 @@
if (bWrongFormat || std::isnan(dRet)) {
WideString swMsg = WideString::Format(
JSGetStringFromID(JSMessage::kParseDateError).c_str(), sFormat.c_str());
- AlertIfPossible(pContext, swMsg);
+ AlertIfPossible(pContext, L"AFDate_KeystrokeEx", swMsg);
pEvent->Rc() = false;
}
return CJS_Result::Success();
@@ -1101,7 +1104,7 @@
return CJS_Result::Success();
if (valEvent.GetLength() > wstrMask.GetLength()) {
- AlertIfPossible(pContext,
+ AlertIfPossible(pContext, L"AFSpecial_KeystrokeEx",
JSGetStringFromID(JSMessage::kParamTooLongError));
pEvent->Rc() = false;
return CJS_Result::Success();
@@ -1113,7 +1116,7 @@
break;
}
if (iIndex != wstrMask.GetLength()) {
- AlertIfPossible(pContext,
+ AlertIfPossible(pContext, L"AFSpecial_KeystrokeEx",
JSGetStringFromID(JSMessage::kInvalidInputError));
pEvent->Rc() = false;
}
@@ -1129,20 +1132,22 @@
size_t combined_len = valEvent.GetLength() + wChange.GetLength() +
pEvent->SelStart() - pEvent->SelEnd();
if (combined_len > wstrMask.GetLength()) {
- AlertIfPossible(pContext, JSGetStringFromID(JSMessage::kParamTooLongError));
+ AlertIfPossible(pContext, L"AFSpecial_KeystrokeEx",
+ JSGetStringFromID(JSMessage::kParamTooLongError));
pEvent->Rc() = false;
return CJS_Result::Success();
}
if (iIndexMask >= wstrMask.GetLength() && !wChange.IsEmpty()) {
- AlertIfPossible(pContext, JSGetStringFromID(JSMessage::kParamTooLongError));
+ AlertIfPossible(pContext, L"AFSpecial_KeystrokeEx",
+ JSGetStringFromID(JSMessage::kParamTooLongError));
pEvent->Rc() = false;
return CJS_Result::Success();
}
for (size_t i = 0; i < wChange.GetLength(); ++i) {
if (iIndexMask >= wstrMask.GetLength()) {
- AlertIfPossible(pContext,
+ AlertIfPossible(pContext, L"AFSpecial_KeystrokeEx",
JSGetStringFromID(JSMessage::kParamTooLongError));
pEvent->Rc() = false;
return CJS_Result::Success();
@@ -1230,7 +1235,8 @@
if (std::isnan(dDate)) {
WideString swMsg = WideString::Format(
JSGetStringFromID(JSMessage::kParseDateError).c_str(), sFormat.c_str());
- AlertIfPossible(pRuntime->GetCurrentEventContext(), swMsg);
+ AlertIfPossible(pRuntime->GetCurrentEventContext(), L"AFParseDateEx",
+ swMsg);
return CJS_Result::Failure(JSMessage::kParseDateError);
}
return CJS_Result::Success(pRuntime->NewNumber(dDate));
@@ -1413,7 +1419,7 @@
}
if (!swMsg.IsEmpty()) {
- AlertIfPossible(pContext, swMsg);
+ AlertIfPossible(pContext, L"AFRange_Validate", swMsg);
pEvent->Rc() = false;
}
return CJS_Result::Success();
diff --git a/testing/resources/javascript/public_methods_expected.txt b/testing/resources/javascript/public_methods_expected.txt
index 17abeff..70cd8ee 100644
--- a/testing/resources/javascript/public_methods_expected.txt
+++ b/testing/resources/javascript/public_methods_expected.txt
@@ -21,11 +21,11 @@
Alert: **********************
Alert: PASS: AFDate_KeystrokeEx() threw AFDate_KeystrokeEx: AFDate_KeystrokeEx's parameter size not correct
Alert: PASS: AFDate_KeystrokeEx(1, 2) threw AFDate_KeystrokeEx: AFDate_KeystrokeEx's parameter size not correct
-[icon=3,type=0]: The input value can't be parsed as a valid date/time (2).
+AFDate_KeystrokeEx[icon=3,type=0]: The input value can't be parsed as a valid date/time (2).
Alert: PASS: AFDate_KeystrokeEx(2) = x
-[icon=3,type=0]: The input value can't be parsed as a valid date/time (blooey).
+AFDate_KeystrokeEx[icon=3,type=0]: The input value can't be parsed as a valid date/time (blooey).
Alert: PASS: AFDate_KeystrokeEx('blooey') = x
-[icon=3,type=0]: The input value can't be parsed as a valid date/time (m/d).
+AFDate_KeystrokeEx[icon=3,type=0]: The input value can't be parsed as a valid date/time (m/d).
Alert: PASS: AFDate_KeystrokeEx('m/d') = x
Alert: **********************
Alert: PASS: AFExtractNums() threw AFExtractNums: Incorrect number of parameters passed to function.
@@ -50,7 +50,7 @@
Alert: **********************
Alert: PASS: AFNumber_Keystroke() threw AFNumber_Keystroke: Incorrect number of parameters passed to function.
Alert: PASS: AFNumber_Keystroke(1) threw AFNumber_Keystroke: Incorrect number of parameters passed to function.
-[icon=3,type=0]: The input value is invalid.
+AFNumber_Keystroke[icon=3,type=0]: The input value is invalid.
Alert: PASS: AFNumber_Keystroke(1, 2) threw AFNumber_Keystroke: The input value is invalid.
Alert: PASS: AFNumber_Keystroke(1, 2) = 123
Alert: PASS: AFNumber_Keystroke(1, 2, 3) = 123
@@ -277,19 +277,19 @@
Alert: **********************
Alert: PASS: AFPercent_Keystroke() threw AFPercent_Keystroke: Incorrect number of parameters passed to function.
Alert: PASS: AFPercent_Keystroke(1) threw AFPercent_Keystroke: Incorrect number of parameters passed to function.
-[icon=3,type=0]: The input value is invalid.
+AFNumber_Keystroke[icon=3,type=0]: The input value is invalid.
Alert: PASS: AFPercent_Keystroke(1, 0) threw AFPercent_Keystroke: The input value is invalid.
Alert: PASS: AFPercent_Keystroke(1, 0) = .123
Alert: **********************
Alert: PASS: AFRange_Validate() threw AFRange_Validate: Incorrect number of parameters passed to function.
Alert: PASS: AFRange_Validate(1, 2, 3, 4, 5) threw AFRange_Validate: Incorrect number of parameters passed to function.
-[icon=3,type=0]: The input value must be greater than or equal to 2 and less than or equal to 4.
+AFRange_Validate[icon=3,type=0]: The input value must be greater than or equal to 2 and less than or equal to 4.
Alert: PASS: AFRange_Validate(true, 2, true, 4) = 1
-[icon=3,type=0]: The input value must be greater than or equal to 2 and less than or equal to 4.
+AFRange_Validate[icon=3,type=0]: The input value must be greater than or equal to 2 and less than or equal to 4.
Alert: PASS: AFRange_Validate(true, 2, true, 4) = 5
-[icon=3,type=0]: The input value must be greater than or equal to 2.
+AFRange_Validate[icon=3,type=0]: The input value must be greater than or equal to 2.
Alert: PASS: AFRange_Validate(true, 2, false, 4) = 1
-[icon=3,type=0]: The input value must be less than or equal to 4.
+AFRange_Validate[icon=3,type=0]: The input value must be less than or equal to 4.
Alert: PASS: AFRange_Validate(false, 2, true, 4) = 5
Alert: PASS: AFRange_Validate(true, 2, true, 4) = 3
Alert: PASS: AFRange_Validate(false, 2, true, 4) = 1
@@ -345,11 +345,11 @@
Alert: **********************
Alert: PASS: AFSpecial_KeystrokeEx() threw AFSpecial_KeystrokeEx: Incorrect number of parameters passed to function.
Alert: PASS: AFSpecial_KeystrokeEx('') = 12345
-[icon=3,type=0]: The input value is invalid.
+AFSpecial_KeystrokeEx[icon=3,type=0]: The input value is invalid.
Alert: PASS: AFSpecial_KeystrokeEx('9999') = 123
-[icon=3,type=0]: The input value is too long.
+AFSpecial_KeystrokeEx[icon=3,type=0]: The input value is too long.
Alert: PASS: AFSpecial_KeystrokeEx('9999') = 12345
-[icon=3,type=0]: The input value is invalid.
+AFSpecial_KeystrokeEx[icon=3,type=0]: The input value is invalid.
Alert: PASS: AFSpecial_KeystrokeEx('9999') = abcd
Alert: PASS: AFSpecial_KeystrokeEx('9999') = 1234
Alert: PASS: AFSpecial_KeystrokeEx('XXXX') = abcd
@@ -385,13 +385,13 @@
Alert: PASS: AFSpecial_KeystrokeEx() threw AFSpecial_KeystrokeEx: Incorrect number of parameters passed to function.
Alert: PASS: AFSpecial_KeystrokeEx('') = 12345
Alert: PASS: AFSpecial_KeystrokeEx('9999') = 123
-[icon=3,type=0]: The input value is too long.
+AFSpecial_KeystrokeEx[icon=3,type=0]: The input value is too long.
Alert: PASS: AFSpecial_KeystrokeEx('9999') = 12345
-[icon=3,type=0]: The input value is too long.
+AFSpecial_KeystrokeEx[icon=3,type=0]: The input value is too long.
Alert: PASS: AFSpecial_KeystrokeEx('9999') = abcd
-[icon=3,type=0]: The input value is too long.
+AFSpecial_KeystrokeEx[icon=3,type=0]: The input value is too long.
Alert: PASS: AFSpecial_KeystrokeEx('9999') = 1234
-[icon=3,type=0]: The input value is too long.
+AFSpecial_KeystrokeEx[icon=3,type=0]: The input value is too long.
Alert: PASS: AFSpecial_KeystrokeEx('XXXX') = abcd
Alert: **********************
Alert: PASS: AFMergeChange() threw AFMergeChange: Incorrect number of parameters passed to function.