Remove ELEM_HIDDEN____() macro.

Shuffle hidden elements to end of table with 0xffffffff hash
code, so they can't be found.

Change-Id: Ia05b56cc56c58d5ac00785712276b080814a0935
Reviewed-on: https://pdfium-review.googlesource.com/c/47110
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fxfa/fxfa_basic.h b/xfa/fxfa/fxfa_basic.h
index 430aed3..c2865bd 100644
--- a/xfa/fxfa/fxfa_basic.h
+++ b/xfa/fxfa/fxfa_basic.h
@@ -113,12 +113,9 @@
 enum class XFA_Element : int16_t {
   Unknown = -1,
 #undef ELEM____
-#undef ELEM_HIDDEN____
 #define ELEM____(a, b, c, d) c,
-#define ELEM_HIDDEN____(a, b) a,
 #include "xfa/fxfa/parser/elements.inc"
 #undef ELEM____
-#undef ELEM_HIDDEN____
 };
 
 enum class XFA_AttributeType : uint8_t {
diff --git a/xfa/fxfa/fxfa_basic_unittest.cpp b/xfa/fxfa/fxfa_basic_unittest.cpp
index d2a49cc..ad174d1 100644
--- a/xfa/fxfa/fxfa_basic_unittest.cpp
+++ b/xfa/fxfa/fxfa_basic_unittest.cpp
@@ -7,59 +7,40 @@
 #include "core/fxcrt/bytestring.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
-TEST(FXFABasic, AttrHashMatchesString) {
+namespace {
+
+void HashTestCase(uint32_t hash, const char* str, uint32_t* so_far) {
+  if (hash != 0xffffffffu) {
+    EXPECT_EQ(hash, FX_HashCode_GetAsIfW(str, false)) << str;
+    EXPECT_LT(*so_far, hash) << hash;
+  } else {
+    EXPECT_NE(hash, FX_HashCode_GetAsIfW(str, false)) << str;
+  }
+  *so_far = hash;
+}
+
+}  // namespace
+
+TEST(FXFABasic, AttrHashTest) {
+  uint32_t so_far = 0;
 #undef ATTR____
-#define ATTR____(a, b, c, d) EXPECT_EQ(a, FX_HashCode_GetAsIfW(b, false));
+#define ATTR____(a, b, c, d) HashTestCase(a, b, &so_far);
 #include "xfa/fxfa/parser/attributes.inc"
 #undef ATTR____
 }
 
-TEST(FXFABasic, AttrHashOrder) {
+TEST(FXFABasic, ValueHashTest) {
   uint32_t so_far = 0;
-#undef ATTR____
-#define ATTR____(a, b, c, d) \
-  EXPECT_LT(so_far, a);      \
-  so_far = a;
-#include "xfa/fxfa/parser/attributes.inc"
-#undef ATTR____
-}
-
-TEST(FXFABasic, ValueHashMatchesString) {
 #undef VALUE____
-#define VALUE____(a, b, c) EXPECT_EQ(a, FX_HashCode_GetAsIfW(b, false));
+#define VALUE____(a, b, c) HashTestCase(a, b, &so_far);
 #include "xfa/fxfa/parser/attribute_values.inc"
 #undef VALUE____
 }
 
-TEST(FXFABasic, ValueHashOrder) {
-  uint32_t so_far = 0;
-#undef VALUE____
-#define VALUE____(a, b, c) \
-  EXPECT_LT(so_far, a);    \
-  so_far = a;
-#include "xfa/fxfa/parser/attribute_values.inc"
-#undef VALUE____
-}
-
-TEST(FXFABasic, ElementHashMatchesString) {
-#undef ELEM____
-#undef ELEM_HIDDEN____
-#define ELEM____(a, b, c, d) EXPECT_EQ(a, FX_HashCode_GetAsIfW(b, false));
-#define ELEM_HIDDEN____(a, b)
-#include "xfa/fxfa/parser/elements.inc"
-#undef ELEM____
-#undef ELEM_HIDDEN____
-}
-
-TEST(FXFABasic, ElementHashOrder) {
+TEST(FXFABasic, ElementHashTest) {
   uint32_t so_far = 0;
 #undef ELEM____
-#undef ELEM_HIDDEN____
-#define ELEM____(a, b, c, d) \
-  EXPECT_LT(so_far, a);      \
-  so_far = a;
-#define ELEM_HIDDEN____(a, b)
+#define ELEM____(a, b, c, d) HashTestCase(a, b, &so_far);
 #include "xfa/fxfa/parser/elements.inc"
 #undef ELEM____
-#undef ELEM_HIDDEN____
 }
diff --git a/xfa/fxfa/parser/element_attributes.inc b/xfa/fxfa/parser/element_attributes.inc
index ebc0ec7..c4062ff 100644
--- a/xfa/fxfa/parser/element_attributes.inc
+++ b/xfa/fxfa/parser/element_attributes.inc
@@ -354,23 +354,6 @@
 ELEM_ATTR____(ContentArea, Use, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(ContentArea, Relevant, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(ContentArea, Usehref, &CJX_Object::ScriptAttributeString)
-ELEM_ATTR____(EventPseudoModel, FullText, &CJX_EventPseudoModel::fullText)
-ELEM_ATTR____(EventPseudoModel, Reenter, &CJX_EventPseudoModel::reenter)
-ELEM_ATTR____(EventPseudoModel, PrevContentType, &CJX_EventPseudoModel::prevContentType)
-ELEM_ATTR____(EventPseudoModel, SoapFaultString, &CJX_EventPseudoModel::soapFaultString)
-ELEM_ATTR____(EventPseudoModel, NewContentType, &CJX_EventPseudoModel::newContentType)
-ELEM_ATTR____(EventPseudoModel, Modifier, &CJX_EventPseudoModel::modifier)
-ELEM_ATTR____(EventPseudoModel, SelEnd, &CJX_EventPseudoModel::selEnd)
-ELEM_ATTR____(EventPseudoModel, PrevText, &CJX_EventPseudoModel::prevText)
-ELEM_ATTR____(EventPseudoModel, SoapFaultCode, &CJX_EventPseudoModel::soapFaultCode)
-ELEM_ATTR____(EventPseudoModel, NewText, &CJX_EventPseudoModel::newText)
-ELEM_ATTR____(EventPseudoModel, Change, &CJX_EventPseudoModel::change)
-ELEM_ATTR____(EventPseudoModel, Shift, &CJX_EventPseudoModel::shift)
-ELEM_ATTR____(EventPseudoModel, keyDown, &CJX_EventPseudoModel::keyDown)
-ELEM_ATTR____(EventPseudoModel, selStart, &CJX_EventPseudoModel::selStart)
-ELEM_ATTR____(EventPseudoModel, CommitKey, &CJX_EventPseudoModel::commitKey)
-ELEM_ATTR____(EventPseudoModel, Target, &CJX_EventPseudoModel::target)
-ELEM_ATTR____(EventPseudoModel, cancelAction, &CJX_EventPseudoModel::cancelAction)
 ELEM_ATTR____(WsdlAddress, Use, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(WsdlAddress, Usehref, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Solid, Use, &CJX_Object::ScriptAttributeString)
@@ -509,17 +492,6 @@
 ELEM_ATTR____(Handler, Type, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Handler, Version, &CJX_Handler::version)
 ELEM_ATTR____(Handler, Usehref, &CJX_Object::ScriptAttributeString)
-ELEM_ATTR____(HostPseudoModel, Name, &CJX_HostPseudoModel::name)
-ELEM_ATTR____(HostPseudoModel, ValidationsEnabled, &CJX_HostPseudoModel::validationsEnabled)
-ELEM_ATTR____(HostPseudoModel, Title, &CJX_HostPseudoModel::title)
-ELEM_ATTR____(HostPseudoModel, Platform, &CJX_HostPseudoModel::platform)
-ELEM_ATTR____(HostPseudoModel, Version, &CJX_HostPseudoModel::version)
-ELEM_ATTR____(HostPseudoModel, Variation, &CJX_HostPseudoModel::variation)
-ELEM_ATTR____(HostPseudoModel, Language, &CJX_HostPseudoModel::language)
-ELEM_ATTR____(HostPseudoModel, AppType, &CJX_HostPseudoModel::appType)
-ELEM_ATTR____(HostPseudoModel, CalculationsEnabled, &CJX_HostPseudoModel::calculationsEnabled)
-ELEM_ATTR____(HostPseudoModel, CurrentPage, &CJX_HostPseudoModel::currentPage)
-ELEM_ATTR____(HostPseudoModel, NumPages, &CJX_HostPseudoModel::numPages)
 ELEM_ATTR____(Presence, Desc, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Presence, Lock, &CJX_Object::ScriptAttributeBool)
 ELEM_ATTR____(Record, Desc, &CJX_Object::ScriptAttributeString)
@@ -567,7 +539,6 @@
 ELEM_ATTR____(WebClient, Name, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(WebClient, Desc, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(WebClient, Lock, &CJX_Object::ScriptAttributeBool)
-ELEM_ATTR____(LayoutPseudoModel, Ready, &CJX_LayoutPseudoModel::ready)
 ELEM_ATTR____(Producer, Desc, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Producer, Lock, &CJX_Object::ScriptAttributeBool)
 ELEM_ATTR____(Corner, Use, &CJX_Object::ScriptAttributeString)
@@ -652,10 +623,6 @@
 ELEM_ATTR____(Signing, Use, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Signing, Type, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Signing, Usehref, &CJX_Object::ScriptAttributeString)
-ELEM_ATTR____(DataWindow, RecordsBefore, &CJX_DataWindow::recordsBefore)
-ELEM_ATTR____(DataWindow, CurrentRecordNumber, &CJX_DataWindow::currentRecordNumber)
-ELEM_ATTR____(DataWindow, RecordsAfter, &CJX_DataWindow::recordsAfter)
-ELEM_ATTR____(DataWindow, IsDefined, &CJX_DataWindow::isDefined)
 ELEM_ATTR____(Script, Use, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Script, ContentType, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Script, RunAt, &CJX_Object::ScriptAttributeString)
@@ -1010,7 +977,6 @@
 ELEM_ATTR____(Line, Slope, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Line, Usehref, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Line, Hand, &CJX_Object::ScriptAttributeString)
-ELEM_ATTR____(List, Length, &CJX_List::length)
 ELEM_ATTR____(Source, Db, &CJX_Source::db)
 ELEM_ATTR____(Source, Use, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Source, Usehref, &CJX_Object::ScriptAttributeString)
@@ -1036,6 +1002,40 @@
 ELEM_ATTR____(Items, Presence, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Items, Save, &CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Items, Usehref, &CJX_Object::ScriptAttributeString)
+ELEM_ATTR____(EventPseudoModel, FullText, &CJX_EventPseudoModel::fullText)
+ELEM_ATTR____(EventPseudoModel, Reenter, &CJX_EventPseudoModel::reenter)
+ELEM_ATTR____(EventPseudoModel, PrevContentType, &CJX_EventPseudoModel::prevContentType)
+ELEM_ATTR____(EventPseudoModel, SoapFaultString, &CJX_EventPseudoModel::soapFaultString)
+ELEM_ATTR____(EventPseudoModel, NewContentType, &CJX_EventPseudoModel::newContentType)
+ELEM_ATTR____(EventPseudoModel, Modifier, &CJX_EventPseudoModel::modifier)
+ELEM_ATTR____(EventPseudoModel, SelEnd, &CJX_EventPseudoModel::selEnd)
+ELEM_ATTR____(EventPseudoModel, PrevText, &CJX_EventPseudoModel::prevText)
+ELEM_ATTR____(EventPseudoModel, SoapFaultCode, &CJX_EventPseudoModel::soapFaultCode)
+ELEM_ATTR____(EventPseudoModel, NewText, &CJX_EventPseudoModel::newText)
+ELEM_ATTR____(EventPseudoModel, Change, &CJX_EventPseudoModel::change)
+ELEM_ATTR____(EventPseudoModel, Shift, &CJX_EventPseudoModel::shift)
+ELEM_ATTR____(EventPseudoModel, keyDown, &CJX_EventPseudoModel::keyDown)
+ELEM_ATTR____(EventPseudoModel, selStart, &CJX_EventPseudoModel::selStart)
+ELEM_ATTR____(EventPseudoModel, CommitKey, &CJX_EventPseudoModel::commitKey)
+ELEM_ATTR____(EventPseudoModel, Target, &CJX_EventPseudoModel::target)
+ELEM_ATTR____(EventPseudoModel, cancelAction, &CJX_EventPseudoModel::cancelAction)
+ELEM_ATTR____(HostPseudoModel, Name, &CJX_HostPseudoModel::name)
+ELEM_ATTR____(HostPseudoModel, ValidationsEnabled, &CJX_HostPseudoModel::validationsEnabled)
+ELEM_ATTR____(HostPseudoModel, Title, &CJX_HostPseudoModel::title)
+ELEM_ATTR____(HostPseudoModel, Platform, &CJX_HostPseudoModel::platform)
+ELEM_ATTR____(HostPseudoModel, Version, &CJX_HostPseudoModel::version)
+ELEM_ATTR____(HostPseudoModel, Variation, &CJX_HostPseudoModel::variation)
+ELEM_ATTR____(HostPseudoModel, Language, &CJX_HostPseudoModel::language)
+ELEM_ATTR____(HostPseudoModel, AppType, &CJX_HostPseudoModel::appType)
+ELEM_ATTR____(HostPseudoModel, CalculationsEnabled, &CJX_HostPseudoModel::calculationsEnabled)
+ELEM_ATTR____(HostPseudoModel, CurrentPage, &CJX_HostPseudoModel::currentPage)
+ELEM_ATTR____(HostPseudoModel, NumPages, &CJX_HostPseudoModel::numPages)
+ELEM_ATTR____(LayoutPseudoModel, Ready, &CJX_LayoutPseudoModel::ready)
+ELEM_ATTR____(DataWindow, RecordsBefore, &CJX_DataWindow::recordsBefore)
+ELEM_ATTR____(DataWindow, CurrentRecordNumber, &CJX_DataWindow::currentRecordNumber)
+ELEM_ATTR____(DataWindow, RecordsAfter, &CJX_DataWindow::recordsAfter)
+ELEM_ATTR____(DataWindow, IsDefined, &CJX_DataWindow::isDefined)
+ELEM_ATTR____(List, Length, &CJX_List::length)
 ELEM_ATTR____(Object, ClassName, &CJX_Object::className)
 ELEM_ATTR____(ListDuplicate, Length, &CJX_List::length)
 ELEM_ATTR____(Tree, Name, &CJX_Object::ScriptAttributeString)
diff --git a/xfa/fxfa/parser/elements.inc b/xfa/fxfa/parser/elements.inc
index 28f6461..c7689e4 100644
--- a/xfa/fxfa/parser/elements.inc
+++ b/xfa/fxfa/parser/elements.inc
@@ -4,6 +4,9 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+// NOTE: A hash of 0xFFFFFFFF is reserved for an item that can not be looked up
+// by name, and the corresponding name placeholder must not hash to it.
+
 ELEM____(0x0023ee3u, "ps", Ps, Node)
 ELEM____(0x0025363u, "to", To, Node)
 ELEM____(0x002587eu, "ui", Ui, Node)
@@ -69,7 +72,6 @@
 ELEM____(0x23e27b84u, "typefaces", Typefaces, Node)
 ELEM____(0x23f4aa75u, "subjectDNs", SubjectDNs, Node)
 ELEM____(0x240d5e8eu, "issuers", Issuers, Node)
-ELEM_HIDDEN____(SignaturePseudoModel, Object)
 ELEM____(0x24a52f8au, "wsdlConnection", WsdlConnection, Node)
 ELEM____(0x254ebd07u, "debug", Debug, Node)
 ELEM____(0x2655c66au, "delta", Delta, Unknown)
@@ -103,7 +105,6 @@
 ELEM____(0x3e1c91c5u, "adjustData", AdjustData, Node)
 ELEM____(0x3e7a9408u, "autoSave", AutoSave, Node)
 ELEM____(0x3ecead94u, "contentArea", ContentArea, Placeholder2)
-ELEM_HIDDEN____(EventPseudoModel, Object)
 ELEM____(0x3fadaec0u, "wsdlAddress", WsdlAddress, Placeholder4)
 ELEM____(0x40623b5bu, "solid", Solid, Node)
 ELEM____(0x41f0bd76u, "dateTimeSymbols", DateTimeSymbols, Node)
@@ -135,7 +136,6 @@
 ELEM____(0x5436d198u, "window", Window, Node)
 ELEM____(0x5473b6dcu, "localeSet", LocaleSet, Node)
 ELEM____(0x56ae179eu, "handler", Handler, Placeholder4)
-ELEM_HIDDEN____(HostPseudoModel, Object)
 ELEM____(0x570ce835u, "presence", Presence, Node)
 ELEM____(0x5779d65fu, "record", Record, Node)
 ELEM____(0x59c8f27du, "embed", Embed, Node)
@@ -154,7 +154,6 @@
 ELEM____(0x67fe7334u, "traversal", Traversal, Node)
 ELEM____(0x6894589cu, "silentPrint", SilentPrint, Node)
 ELEM____(0x68a16bbdu, "webClient", WebClient, Node)
-ELEM_HIDDEN____(LayoutPseudoModel, Object)
 ELEM____(0x6a4bc084u, "producer", Producer, Node)
 ELEM____(0x6a9e04c9u, "corner", Corner, Node)
 ELEM____(0x6ccd7274u, "msgId", MsgId, Node)
@@ -184,7 +183,6 @@
 ELEM____(0x803d5bbcu, "acrobat", Acrobat, Node)
 ELEM____(0x821d6569u, "validationMessaging", ValidationMessaging, Node)
 ELEM____(0x830e688fu, "signing", Signing, Node)
-ELEM_HIDDEN____(DataWindow, Object)
 ELEM____(0x83dab9f5u, "script", Script, Node)
 ELEM____(0x8411ebcdu, "addViewerPreferences", AddViewerPreferences, Node)
 ELEM____(0x8777642eu, "alwaysEmbed", AlwaysEmbed, Node)
@@ -219,7 +217,6 @@
 ELEM____(0xa4f7b88fu, "compressObjectStream", CompressObjectStream, Node)
 ELEM____(0xa65f5d17u, "dataValue", DataValue, Node)
 ELEM____(0xa6caaa89u, "accessibleContent", AccessibleContent, Node)
-ELEM_HIDDEN____(TreeList, Placeholder1)
 ELEM____(0xa94cc00bu, "includeXDPContent", IncludeXDPContent, Node)
 ELEM____(0xa9b081a1u, "xmlConnection", XmlConnection, Node)
 ELEM____(0xab2a3b74u, "validateApprovalSignatures", ValidateApprovalSignatures, Node)
@@ -265,7 +262,6 @@
 ELEM____(0xd1227e6fu, "trace", Trace, Node)
 ELEM____(0xd1532876u, "float", Float, Placeholder3)
 ELEM____(0xd17a6c30u, "renderPolicy", RenderPolicy, Node)
-ELEM_HIDDEN____(LogPseudoModel, Object)
 ELEM____(0xd58aa962u, "destination", Destination, Node)
 ELEM____(0xd6e27f1du, "value", Value, Node)
 ELEM____(0xd7a14462u, "bookend", Bookend, Node)
@@ -305,7 +301,6 @@
 ELEM____(0xf1433e88u, "lockDocument", LockDocument, Node)
 ELEM____(0xf54eb997u, "breakAfter", BreakAfter, Node)
 ELEM____(0xf616da28u, "line", Line, Node)
-ELEM_HIDDEN____(List, ListDuplicate)
 ELEM____(0xf7055fb1u, "source", Source, Node)
 ELEM____(0xf7eebe1cu, "occur", Occur, Node)
 ELEM____(0xf8d10d97u, "pickTrayByPDFSize", PickTrayByPDFSize, Node)
@@ -316,12 +311,20 @@
 ELEM____(0xfc78159fu, "numberSymbol", NumberSymbol, Node)
 ELEM____(0xfcbd606cu, "tagged", Tagged, Node)
 ELEM____(0xff063802u, "items", Items, Node)
-ELEM_HIDDEN____(Object, Unknown)
-ELEM_HIDDEN____(ListDuplicate, Object)
-ELEM_HIDDEN____(Placeholder1, ListDuplicate)
-ELEM_HIDDEN____(Tree, Object)
-ELEM_HIDDEN____(Node, Tree)
-ELEM_HIDDEN____(Placeholder2, Node)
-ELEM_HIDDEN____(Placeholder3, Node)
-ELEM_HIDDEN____(Model, Node)
-ELEM_HIDDEN____(Placeholder4, Node)
+ELEM____(0xffffffffu, "******", SignaturePseudoModel, Object)
+ELEM____(0xffffffffu, "******", EventPseudoModel, Object)
+ELEM____(0xffffffffu, "******", HostPseudoModel, Object)
+ELEM____(0xffffffffu, "******", LayoutPseudoModel, Object)
+ELEM____(0xffffffffu, "******", DataWindow, Object)
+ELEM____(0xffffffffu, "******", TreeList, Placeholder1)
+ELEM____(0xffffffffu, "******", LogPseudoModel, Object)
+ELEM____(0xffffffffu, "******", List, ListDuplicate)
+ELEM____(0xffffffffu, "******", Object, Unknown)
+ELEM____(0xffffffffu, "******", ListDuplicate, Object)
+ELEM____(0xffffffffu, "******", Placeholder1, ListDuplicate)
+ELEM____(0xffffffffu, "******", Tree, Object)
+ELEM____(0xffffffffu, "******", Node, Tree)
+ELEM____(0xffffffffu, "******", Placeholder2, Node)
+ELEM____(0xffffffffu, "******", Placeholder3, Node)
+ELEM____(0xffffffffu, "******", Model, Node)
+ELEM____(0xffffffffu, "******", Placeholder4, Node)
diff --git a/xfa/fxfa/parser/xfa_basic_data.cpp b/xfa/fxfa/parser/xfa_basic_data.cpp
index 4302866..1cf9fcc 100644
--- a/xfa/fxfa/parser/xfa_basic_data.cpp
+++ b/xfa/fxfa/parser/xfa_basic_data.cpp
@@ -160,12 +160,9 @@
 
 const ElementRecord g_ElementTable[] = {
 #undef ELEM____
-#undef ELEM_HIDDEN____
 #define ELEM____(a, b, c, d) {a, XFA_Element::c},
-#define ELEM_HIDDEN____(a, b)
 #include "xfa/fxfa/parser/elements.inc"
 #undef ELEM____
-#undef ELEM_HIDDEN____
 };
 
 struct AttributeRecord {
@@ -197,12 +194,9 @@
 
 const XFA_Element g_XFAScriptParents[] = {
 #undef ELEM____
-#undef ELEM_HIDDEN____
 #define ELEM____(a, b, c, d) XFA_Element::d,
-#define ELEM_HIDDEN____(a, b) XFA_Element::b,
 #include "xfa/fxfa/parser/elements.inc"
 #undef ELEM____
-#undef ELEM_HIDDEN____
 };
 
 struct ElementAttributeRecord {