summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/lib/asserts.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/lib/asserts.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
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.js87
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);
+ };
+}