Bug 1594138 - Added assertThrowsInstanceOf function to helpers.js. r=dom-workers-and-storage-reviewers,ttung

Differential Revision: https://phabricator.services.mozilla.com/D62767

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Simon Giesecke 2020-02-19 14:45:10 +00:00
Родитель cecac7d080
Коммит 69c43374e7
1 изменённых файлов: 31 добавлений и 0 удалений

Просмотреть файл

@ -323,6 +323,37 @@ function* assertEventuallyWithGC(conditionFunctor, message) {
ok(false, message + " (even after " + maxGC + " garbage collections)");
}
// Asserts that a functor `f` throws an exception that is an instance of
// `ctor`. If it doesn't throw, or throws a different type of exception, this
// throws an Error, including the optional `msg` given.
// Otherwise, it returns the message of the exception.
//
// TODO This is DUPLICATED from https://searchfox.org/mozilla-central/rev/cfd1cc461f1efe0d66c2fdc17c024a203d5a2fd8/js/src/tests/shell.js#163
// This should be moved to a more generic place, as it is in no way specific
// to IndexedDB.
function assertThrowsInstanceOf(f, ctor, msg) {
var fullmsg;
try {
f();
} catch (exc) {
if (exc instanceof ctor) {
return exc.message;
}
fullmsg = `Assertion failed: expected exception ${ctor.name}, got ${exc}`;
}
if (fullmsg === undefined) {
fullmsg = `Assertion failed: expected exception ${
ctor.name
}, no exception thrown`;
}
if (msg !== undefined) {
fullmsg += " - " + msg;
}
throw new Error(fullmsg);
}
function isWasmSupported() {
let testingFunctions = SpecialPowers.Cu.getJSTestingFunctions();
return testingFunctions.wasmIsSupported();