gecko/layout/generic/frame-verify.js
Ms2ger 909e2c851d Bug 1172536 - Stop using for each loops in layout; r=roc
These are SpiderMonkey-proprietary legacy feature which has been deprecated
and is expected to be removed in due course.

This commit also fixes a number of bugs in test_bug708874.xul. In particular,
because of the semicolon after the for head, the (alleged) loop body was only
executed for the final element of the array ({}), and because each of the
functions under test threw an exception, only the first call was executed.

I do not know of a way to test the changes in frame-verify.js, so I can't
guarantee they actually work.
2015-06-20 09:16:51 +02:00

96 lines
2.5 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* graph-frameclasses.js: a dehydra script to collect information about
* the class hierarchy of frame types.
*/
function inheritsFrom(t, baseName)
{
let name = t.name;
if (name == baseName)
return true;
for (let base of t.bases)
if (inheritsFrom(base.type, baseName))
return true;
return false;
}
let output = [];
function process_type(t)
{
if ((t.kind == "class" || t.kind == "struct")) {
if (!t.isIncomplete && inheritsFrom(t, 'nsIFrame')) {
if (inheritsFrom(t, 'nsISupports'))
warning("nsIFrame derivative %s inherits from nsISupports but is not refcounted.".format(t.name), t.loc);
let nonFrameBases = [];
output.push('CLASS-DEF: %s'.format(t.name));
for (let base of t.bases) {
if (inheritsFrom(base.type, 'nsIFrame')) {
output.push('%s -> %s;'.format(base.type.name, t.name));
}
else if (base.type.name != 'nsQueryFrame') {
nonFrameBases.push(base.type.name);
}
}
output.push('%s [label="%s%s"];'.format(t.name, t.name,
nonFrameBases.map(b => "\\n(%s)".format(b)).join('')));
}
}
}
let frameIIDRE = /::kFrameIID$/;
let queryFrameRE = /^do_QueryFrame::operator/;
/* A list of class names T that have do_QueryFrame<T> used */
let needIDs = [];
/* A map of class names that have a kFrameIID declared */
let haveIDs = {};
// We match up needIDs with haveIDs at the end because static variables are
// not present in the .members array of a type
function process_tree_decl(d)
{
d = dehydra_convert(d);
if (d.name && frameIIDRE.exec(d.name)) {
haveIDs[d.memberOf.name] = 1;
}
}
function process_cp_pre_genericize(d)
{
d = dehydra_convert(d);
if (queryFrameRE.exec(d.name) && d.template === undefined) {
let templtype = d.type.type.type;
while (templtype.typedef !== undefined)
templtype = templtype.typedef;
needIDs.push([templtype.name, d.loc]);
}
}
function input_end()
{
for (let [name, loc] of needIDs) {
if (!haveIDs.hasOwnProperty(name)) {
error("nsQueryFrame<%s> found, but %s::kFrameIID is not declared".format(name, name), loc);
}
}
if (output.length > 0) {
write_file(sys.aux_base_name + '.framedata', output.join('\n'));
}
}