mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-10 01:56:15 +08:00
Assertion failures throw an assert.AssertionError with Node 24.22's generatedMessage, code, actual, expected, operator and diff properties, in Node's key order. new AssertionError(options) validates its options and builds Node's message from operator, actual and expected. AssertionError type annotations, instanceof and assert.throws(fn, AssertionError) compile. Failure paths record actual, expected and operator before they throw; passing assertions do no extra work. The deep forms lower through a per-type function that returns the verdict, so the operands stay call temporaries. assert.equal and notEqual inspect their operands only when they fail. Values without a checked-dynamic form, and values whose type can be cyclic, record undefined.
24 lines
956 B
C
24 lines
956 B
C
/* BigInt's node:assert scalar adapter. It lives in its own translation
|
|
* unit because it needs both optional runtime families: BigInt-only builds
|
|
* must not pull scr_assert.c, and assert-only builds must not pull
|
|
* scr_bigint.c. */
|
|
#include "scr_runtime.h"
|
|
|
|
void scr_assert_eq_bigint(ScrBigInt *a, ScrBigInt *b, bool negated, bool deep,
|
|
ScrStr *msg, bool has_msg) {
|
|
bool same = scr_bigint_eq(a, b);
|
|
if ((negated && !same) || (!negated && same)) return;
|
|
scr_assert_record(scr_dyn_new_bigint(a), scr_dyn_new_bigint(b), scr_assert_eq_operator(negated, deep));
|
|
ScrStr *ia = scr_bigint_inspect(a);
|
|
if (negated) {
|
|
scr_assert_neq_fail(ia->data, ia->len, deep, msg, has_msg);
|
|
scr_str_release(ia);
|
|
return;
|
|
}
|
|
ScrStr *ib = scr_bigint_inspect(b);
|
|
scr_assert_eq_fail(ia->data, ia->len, ib->data, ib->len, 0, false, true, deep,
|
|
msg, has_msg);
|
|
scr_str_release(ia);
|
|
scr_str_release(ib);
|
|
}
|