Skip to content

Commit 0d9fecc

Browse files
saschanazfoolip
authored andcommitted
Validate IDLs in idl_test() (#18382)
This ignores errors that are still too frequent.
1 parent 120c6c0 commit 0d9fecc

File tree

2 files changed

+137
-23
lines changed

2 files changed

+137
-23
lines changed

resources/idlharness.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ IdlArray.prototype.is_excluded_by_options = function (name, options)
236236

237237
IdlArray.prototype.add_dependency_idls = function(raw_idls, options)
238238
{
239-
const parsed_idls = WebIDL2.parse(raw_idls);
239+
return this.internal_add_dependency_idls(WebIDL2.parse(raw_idls), options);
240+
};
241+
242+
IdlArray.prototype.internal_add_dependency_idls = function(parsed_idls, options)
243+
{
240244
const new_options = { only: [] }
241245

242246
const all_deps = new Set();
@@ -3335,16 +3339,30 @@ function idl_test(srcs, deps, idl_setup_func) {
33353339
srcs = (srcs instanceof Array) ? srcs : [srcs] || [];
33363340
deps = (deps instanceof Array) ? deps : [deps] || [];
33373341
var setup_error = null;
3342+
const validationIgnored = [
3343+
"constructor-member",
3344+
"dict-arg-default",
3345+
"require-exposed"
3346+
];
33383347
return Promise.all(
3339-
srcs.concat(deps).map(function(spec) {
3340-
return fetch_spec(spec);
3341-
}))
3342-
.then(function(idls) {
3348+
srcs.concat(deps).map(fetch_spec))
3349+
.then(function(results) {
3350+
const astArray = results.map(result =>
3351+
WebIDL2.parse(result.idl, { sourceName: result.spec })
3352+
);
3353+
test(() => {
3354+
const validations = WebIDL2.validate(astArray)
3355+
.filter(v => !validationIgnored.includes(v.ruleName));
3356+
if (validations.length) {
3357+
const message = validations.map(v => v.message).join("\n\n");
3358+
throw new Error(message);
3359+
}
3360+
}, "idl_test validation");
33433361
for (var i = 0; i < srcs.length; i++) {
3344-
idl_array.add_idls(idls[i]);
3362+
idl_array.internal_add_idls(astArray[i]);
33453363
}
33463364
for (var i = srcs.length; i < srcs.length + deps.length; i++) {
3347-
idl_array.add_dependency_idls(idls[i]);
3365+
idl_array.internal_add_dependency_idls(astArray[i]);
33483366
}
33493367
})
33503368
.then(function() {
@@ -3379,6 +3397,6 @@ function fetch_spec(spec) {
33793397
throw new IdlHarnessError("Error fetching " + url + ".");
33803398
}
33813399
return r.text();
3382-
});
3400+
}).then(idl => ({ spec, idl }));
33833401
}
33843402
// vim: set expandtab shiftwidth=4 tabstop=4 foldmarker=@{,@} foldmethod=marker:

resources/webidl2/lib/webidl2.js

Lines changed: 111 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)