summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript/Consts.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-09-11 13:04:48 -0700
committerTom Sepez <tsepez@chromium.org>2015-09-11 13:04:48 -0700
commitf9e40aec10263f9445d69598657f42550294d653 (patch)
treeeb20eaef0841334b14266b4a83efe34ade7b1b0e /fpdfsdk/src/javascript/Consts.cpp
parentdf4de98c06075b0e491ac645f2d118a6813cedc9 (diff)
downloadpdfium-f9e40aec10263f9445d69598657f42550294d653.tar.xz
Fix strings, remove stringify macros, void return types for Consts.h.
Replace multiple #defines of the same strings with externs. Fix strings mangled by interaction of # and clang-format. Remove macros as possible. Make more JS_ functions void and simplify. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1342433002 .
Diffstat (limited to 'fpdfsdk/src/javascript/Consts.cpp')
-rw-r--r--fpdfsdk/src/javascript/Consts.cpp125
1 files changed, 68 insertions, 57 deletions
diff --git a/fpdfsdk/src/javascript/Consts.cpp b/fpdfsdk/src/javascript/Consts.cpp
index b534d2b393..9574c44730 100644
--- a/fpdfsdk/src/javascript/Consts.cpp
+++ b/fpdfsdk/src/javascript/Consts.cpp
@@ -129,60 +129,62 @@ IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype, zoomtype)
/* ------------------------------ CJS_GlobalConsts ------------------------- */
-#define DEFINE_GLOBAL_CONST(pIsolate, const_name, const_value) \
- if (JS_DefineGlobalConst( \
- pIsolate, JS_WIDESTRING(const_name), \
- JS_NewString(pIsolate, JS_WIDESTRING(const_value)))) { \
- return -1; \
- }
+static void DefineGlobalConstString(v8::Isolate* pIsolate,
+ const wchar_t* pConstName,
+ const wchar_t* pValue) {
+ JS_DefineGlobalConst(pIsolate, pConstName, JS_NewString(pIsolate, pValue));
+}
-int CJS_GlobalConsts::DefineJSObjects(v8::Isolate* pIsolate) {
- DEFINE_GLOBAL_CONST(pIsolate, IDS_GREATER_THAN, Invalid value
- : must be greater than or equal to % s.);
- DEFINE_GLOBAL_CONST(
- pIsolate, IDS_GT_AND_LT, Invalid value
- : must be greater than or equal to % s and less than or equal to % s.);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_LESS_THAN, Invalid value
- : must be less than or equal to % s.);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_INVALID_MONTH, **Invalid**);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_INVALID_DATE, Invalid date / time
- : please ensure that the date / time exists.Field);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_INVALID_VALUE,
- The value entered does not match the format of the field);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_AM, am);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_PM, pm);
- DEFINE_GLOBAL_CONST(
- pIsolate, IDS_MONTH_INFO,
- January[1] February[2] March[3] April[4] May[5] June[6] July[7] August
- [8] September[9] October[10] November[11] December[12] Sept[9] Jan
- [1] Feb[2] Mar[3] Apr[4] Jun[6] Jul[7] Aug[8] Sep[9] Oct[10] Nov
- [11] Dec[12]);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_STARTUP_CONSOLE_MSG, ** ^ _ ^ **);
-
- return 0;
+void CJS_GlobalConsts::DefineJSObjects(v8::Isolate* pIsolate) {
+ DefineGlobalConstString(
+ pIsolate, L"IDS_GREATER_THAN",
+ L"Invalid value: must be greater than or equal to % s.");
+ DefineGlobalConstString(
+ pIsolate, L"IDS_GT_AND_LT",
+ L"Invalid value: must be greater than or equal to % s "
+ L"and less than or equal to % s.");
+ DefineGlobalConstString(pIsolate, L"IDS_LESS_THAN",
+ L"Invalid value: must be less than or equal to % s.");
+ DefineGlobalConstString(pIsolate, L"IDS_INVALID_MONTH", L"**Invalid**");
+ DefineGlobalConstString(
+ pIsolate, L"IDS_INVALID_DATE",
+ L"Invalid date / time: please ensure that the date / time exists.Field");
+ DefineGlobalConstString(
+ pIsolate, L"IDS_INVALID_VALUE",
+ L"The value entered does not match the format of the field");
+ DefineGlobalConstString(pIsolate, L"IDS_AM", L"am");
+ DefineGlobalConstString(pIsolate, L"IDS_PM", L"pm");
+ DefineGlobalConstString(
+ pIsolate, L"IDS_MONTH_INFO",
+ L"January[1] February[2] March[3] April[4] May[5] "
+ L"June[6] July[7] August[8] September[9] October[10] "
+ L"November[11] December[12] Sept[9] Jan[1] Feb[2] Mar[3] "
+ L"Apr[4] Jun[6] Jul[7] Aug[8] Sep[9] Oct[10] Nov[11] "
+ L"Dec[12]");
+ DefineGlobalConstString(pIsolate, L"IDS_STARTUP_CONSOLE_MSG", L"** ^ _ ^ **");
}
/* ------------------------------ CJS_GlobalArrays ------------------------ */
-#define DEFINE_GLOBAL_ARRAY(pIsolate) \
- int size = FX_ArraySize(ArrayContent); \
- \
- CJS_Array array(pIsolate); \
- for (int i = 0; i < size; i++) \
- array.SetElement(i, CJS_Value(pIsolate, ArrayContent[i])); \
- \
- CJS_PropValue prop(pIsolate); \
- prop << array; \
- if (JS_DefineGlobalConst(pIsolate, (const wchar_t*)ArrayName, \
- prop.ToV8Value()) < 0) { \
- return -1; \
+void DefineGlobalConstStringArray(v8::Isolate* pIsolate,
+ const wchar_t* sConstName,
+ const wchar_t** pValues,
+ size_t nValues) {
+ CJS_Array array(pIsolate);
+ for (size_t i = 0; i < nValues; ++i) {
+ array.SetElement(i, CJS_Value(pIsolate, pValues[i]));
}
+ CJS_PropValue prop(pIsolate);
+ prop << array;
+ JS_DefineGlobalConst(pIsolate, sConstName, prop.ToV8Value());
+}
-int CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
+void CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
{
const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_DOT_SEP";
const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*\\.?\\d*"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
@@ -192,14 +194,16 @@ int CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
L"[+-]?\\.\\d+", /* -.1 */
L"[+-]?\\d+\\." /* -1. */
};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_COMMA_SEP";
const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*,?\\d*"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
@@ -209,31 +213,36 @@ int CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
L"[+-]?[.,]\\d+", /* -,1 */
L"[+-]?\\d+[.,]" /* -1, */
};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_ZIP_ENTRY";
const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_ZIP_COMMIT";
const FX_WCHAR* ArrayContent[] = {L"\\d{5}"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_ZIP4_ENTRY";
const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}(\\.|[- ])?\\d{0,4}"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_ZIP4_COMMIT";
const FX_WCHAR* ArrayContent[] = {L"\\d{5}(\\.|[- ])?\\d{4}"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
@@ -251,7 +260,8 @@ int CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
*/
L"011(\\.|[- \\d])*" /* international */
};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
@@ -262,22 +272,23 @@ int CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */
L"011(\\.|[- \\d])*" /* international */
};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_SSN_ENTRY";
const FX_WCHAR* ArrayContent[] = {
L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_SSN_COMMIT";
const FX_WCHAR* ArrayContent[] = {
L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
-
- return 0;
}