diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/lib/asserts.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/lib/asserts.js')
-rw-r--r-- | js/src/jit-test/lib/asserts.js | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/js/src/jit-test/lib/asserts.js b/js/src/jit-test/lib/asserts.js new file mode 100644 index 0000000000..f0b3fe3bff --- /dev/null +++ b/js/src/jit-test/lib/asserts.js @@ -0,0 +1,87 @@ +/* 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/. */ + + +load(libdir + "non262.js"); + +if (typeof assertWarning === 'undefined') { + var assertWarning = function assertWarning(f, pattern) { + enableLastWarning(); + + // Verify that a warning is issued. + clearLastWarning(); + f(); + var warning = getLastWarning(); + clearLastWarning(); + + disableLastWarning(); + + if (warning) { + if (!warning.message.match(pattern)) { + throw new Error(`assertWarning failed: "${warning.message}" does not match "${pattern}"`); + } + return; + } + + throw new Error("assertWarning failed: no warning"); + }; +} + +if (typeof assertNoWarning === 'undefined') { + var assertNoWarning = function assertNoWarning(f, msg) { + enableLastWarning(); + + // Verify that no warning is issued. + clearLastWarning(); + f(); + var warning = getLastWarning(); + clearLastWarning(); + + disableLastWarning(); + + if (warning) { + if (msg) { + print("assertNoWarning: " + msg); + } + + throw Error("assertNoWarning: Unexpected warning when calling: " + f); + } + }; +} + +if (typeof assertErrorMessage === 'undefined') { + var assertErrorMessage = function assertErrorMessage(f, ctor, test) { + try { + f(); + } catch (e) { + // Propagate non-specific OOM errors, we never test for these with + // assertErrorMessage, as there is no meaningful ctor. + if (e === "out of memory") + throw e; + if (!(e instanceof ctor)) + throw new Error("Assertion failed: expected exception " + ctor.name + ", got " + e); + if (typeof test == "string") { + if (test != e.message) + throw new Error("Assertion failed: expected " + test + ", got " + e.message); + } else { + if (!test.test(e.message)) + throw new Error("Assertion failed: expected " + test.toString() + ", got " + e.message); + } + return; + } + throw new Error("Assertion failed: expected exception " + ctor.name + ", no exception thrown"); + }; +} + +if (typeof assertTypeErrorMessage === 'undefined') { + var assertTypeErrorMessage = function assertTypeErrorMessage(f, test) { + assertErrorMessage(f, TypeError, test); + }; +} + +if (typeof assertRangeErrorMessage === 'undefined') { + var assertRangeErrorMessage = function assertRangeErrorMessage(f, test) { + assertErrorMessage(f, RangeError, test); + }; +} |