Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/parser/htmlparser/nsElementTable.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "nsElementTable.h"
8
9
struct HTMLElement
10
{
11
#ifdef DEBUG
12
  nsHTMLTag mTagID;
13
#endif
14
  bool mIsBlock;
15
  bool mIsContainer;
16
};
17
18
#ifdef DEBUG
19
#define ELEM(tag, block, container) { eHTMLTag_##tag, block, container },
20
#else
21
#define ELEM(tag, block, container) { block, container },
22
#endif
23
24
#define ____ false    // This makes the table easier to read.
25
26
// Note that the mIsBlock field disagrees with
27
// https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements for
28
// the following elements: center, details, dialog, dir, dt, figcaption,
29
// listing, menu, multicol, noscript, output, summary, tfoot, video.
30
//
31
// mrbkap thinks that the field values were pulled from the old HTML4 DTD and
32
// then got modified in mostly random ways to make the old parser's behavior
33
// compatible with the web. So it might make sense to change the mIsBlock
34
// values for the abovementioned tags at some point.
35
//
36
static const HTMLElement gHTMLElements[] = {
37
  // clang-format off
38
  ELEM(unknown,     ____, ____)
39
  ELEM(a,           ____, true)
40
  ELEM(abbr,        ____, true)
41
  ELEM(acronym,     ____, true)
42
  ELEM(address,     true, true)
43
  ELEM(applet,      ____, true)
44
  ELEM(area,        ____, ____)
45
  ELEM(article,     true, true)
46
  ELEM(aside,       true, true)
47
  ELEM(audio,       ____, true)
48
  ELEM(b,           ____, true)
49
  ELEM(base,        ____, ____)
50
  ELEM(basefont,    ____, ____)
51
  ELEM(bdi,         ____, true)
52
  ELEM(bdo,         ____, true)
53
  ELEM(bgsound,     ____, ____)
54
  ELEM(big,         ____, true)
55
  ELEM(blockquote,  true, true)
56
  ELEM(body,        ____, true)
57
  ELEM(br,          ____, ____)
58
  ELEM(button,      ____, true)
59
  ELEM(canvas,      ____, true)
60
  ELEM(caption,     ____, true)
61
  ELEM(center,      true, true)
62
  ELEM(cite,        ____, true)
63
  ELEM(code,        ____, true)
64
  ELEM(col,         ____, ____)
65
  ELEM(colgroup,    ____, true)
66
  ELEM(data,        ____, true)
67
  ELEM(datalist,    ____, true)
68
  ELEM(dd,          ____, true)
69
  ELEM(del,         ____, true)
70
  ELEM(details,     true, true)
71
  ELEM(dfn,         ____, true)
72
  ELEM(dialog,      true, true)
73
  ELEM(dir,         true, true)
74
  ELEM(div,         true, true)
75
  ELEM(dl,          true, true)
76
  ELEM(dt,          ____, true)
77
  ELEM(em,          ____, true)
78
  ELEM(embed,       ____, ____)
79
  ELEM(fieldset,    true, true)
80
  ELEM(figcaption,  ____, true)
81
  ELEM(figure,      true, true)
82
  ELEM(font,        ____, true)
83
  ELEM(footer,      true, true)
84
  ELEM(form,        true, true)
85
  ELEM(frame,       ____, ____)
86
  ELEM(frameset,    ____, true)
87
  ELEM(h1,          true, true)
88
  ELEM(h2,          true, true)
89
  ELEM(h3,          true, true)
90
  ELEM(h4,          true, true)
91
  ELEM(h5,          true, true)
92
  ELEM(h6,          true, true)
93
  ELEM(head,        ____, true)
94
  ELEM(header,      true, true)
95
  ELEM(hgroup,      true, true)
96
  ELEM(hr,          true, ____)
97
  ELEM(html,        ____, true)
98
  ELEM(i,           ____, true)
99
  ELEM(iframe,      ____, true)
100
  ELEM(image,       ____, ____)
101
  ELEM(img,         ____, ____)
102
  ELEM(input,       ____, ____)
103
  ELEM(ins,         ____, true)
104
  ELEM(kbd,         ____, true)
105
  ELEM(keygen,      ____, ____)
106
  ELEM(label,       ____, true)
107
  ELEM(legend,      ____, true)
108
  ELEM(li,          true, true)
109
  ELEM(link,        ____, ____)
110
  ELEM(listing,     true, true)
111
  ELEM(main,        true, true)
112
  ELEM(map,         ____, true)
113
  ELEM(mark,        ____, true)
114
  ELEM(marquee,     ____, true)
115
  ELEM(menu,        true, true)
116
  ELEM(menuitem,    ____, true)
117
  ELEM(meta,        ____, ____)
118
  ELEM(meter,       ____, true)
119
  ELEM(multicol,    true, true)
120
  ELEM(nav,         true, true)
121
  ELEM(nobr,        ____, true)
122
  ELEM(noembed,     ____, true)
123
  ELEM(noframes,    ____, true)
124
  ELEM(noscript,    ____, true)
125
  ELEM(object,      ____, true)
126
  ELEM(ol,          true, true)
127
  ELEM(optgroup,    ____, true)
128
  ELEM(option,      ____, true)
129
  ELEM(output,      ____, true)
130
  ELEM(p,           true, true)
131
  ELEM(param,       ____, ____)
132
  ELEM(picture,     ____, true)
133
  ELEM(plaintext,   ____, true)
134
  ELEM(pre,         true, true)
135
  ELEM(progress,    ____, true)
136
  ELEM(q,           ____, true)
137
  ELEM(rb,          ____, true)
138
  ELEM(rp,          ____, true)
139
  ELEM(rt,          ____, true)
140
  ELEM(rtc,         ____, true)
141
  ELEM(ruby,        ____, true)
142
  ELEM(s,           ____, true)
143
  ELEM(samp,        ____, true)
144
  ELEM(script,      ____, true)
145
  ELEM(section,     true, true)
146
  ELEM(select,      ____, true)
147
  ELEM(small,       ____, true)
148
  ELEM(slot,        ____, true)
149
  ELEM(source,      ____, ____)
150
  ELEM(span,        ____, true)
151
  ELEM(strike,      ____, true)
152
  ELEM(strong,      ____, true)
153
  ELEM(style,       ____, true)
154
  ELEM(sub,         ____, true)
155
  ELEM(summary,     true, true)
156
  ELEM(sup,         ____, true)
157
  ELEM(table,       true, true)
158
  ELEM(tbody,       ____, true)
159
  ELEM(td,          ____, true)
160
  ELEM(textarea,    ____, true)
161
  ELEM(tfoot,       ____, true)
162
  ELEM(th,          ____, true)
163
  ELEM(thead,       ____, true)
164
  ELEM(template,    ____, true)
165
  ELEM(time,        ____, true)
166
  ELEM(title,       ____, true)
167
  ELEM(tr,          ____, true)
168
  ELEM(track,       ____, ____)
169
  ELEM(tt,          ____, true)
170
  ELEM(u,           ____, true)
171
  ELEM(ul,          true, true)
172
  ELEM(var,         ____, true)
173
  ELEM(video,       ____, true)
174
  ELEM(wbr,         ____, ____)
175
  ELEM(xmp,         ____, true)
176
  ELEM(text,        ____, ____)
177
  ELEM(whitespace,  ____, ____)
178
  ELEM(newline,     ____, ____)
179
  ELEM(comment,     ____, true)
180
  ELEM(entity,      ____, true)
181
  ELEM(doctypeDecl, ____, true)
182
  ELEM(markupDecl,  ____, true)
183
  ELEM(instruction, ____, true)
184
  ELEM(userdefined, ____, true)
185
  // clang-format on
186
};
187
188
#undef ELEM
189
#undef ____
190
191
bool
192
nsHTMLElement::IsContainer(nsHTMLTag aId)
193
0
{
194
0
  return gHTMLElements[aId].mIsContainer;
195
0
}
196
197
bool
198
nsHTMLElement::IsBlock(nsHTMLTag aId)
199
0
{
200
0
  return gHTMLElements[aId].mIsBlock;
201
0
}
202
203
#ifdef DEBUG
204
void
205
CheckElementTable()
206
{
207
  for (nsHTMLTag t = eHTMLTag_unknown;
208
       t <= eHTMLTag_userdefined;
209
       t = nsHTMLTag(t + 1)) {
210
    MOZ_ASSERT(gHTMLElements[t].mTagID == t,
211
               "gHTMLElements entries does match tag list.");
212
  }
213
}
214
#endif