parallax/jsPDF · error · Error
Invalid arguments passed to jsPDF.API.__acroform__.clearBit
Error message
Invalid arguments passed to jsPDF.API.__acroform__.clearBit
What it means
Thrown by the AcroForm clearBit(number, bitPosition) helper when either argument is NaN. clearBit clears a single bit on an integer field-flag value (the inverse of setBit) and is exposed at jsPDF.API.__acroform__.clearBit. Same NaN guard and same defaulting behavior as setBit.
Source
Thrown at src/modules/acroform.js:100
if (isNaN(number) || isNaN(bitPosition)) {
throw new Error(
"Invalid arguments passed to jsPDF.API.__acroform__.setBit"
);
}
var bitMask = 1 << bitPosition;
number |= bitMask;
return number;
});
var clearBit = (jsPDFAPI.__acroform__.clearBit = function(number, bitPosition) {
number = number || 0;
bitPosition = bitPosition || 0;
if (isNaN(number) || isNaN(bitPosition)) {
throw new Error(
"Invalid arguments passed to jsPDF.API.__acroform__.clearBit"
);
}
var bitMask = 1 << bitPosition;
number &= ~bitMask;
return number;
});
var getBit = (jsPDFAPI.__acroform__.getBit = function(number, bitPosition) {
if (isNaN(number) || isNaN(bitPosition)) {
throw new Error(
"Invalid arguments passed to jsPDF.API.__acroform__.getBit"
);
}
return (number & (1 << bitPosition)) === 0 ? 0 : 1;
});View on GitHub (pinned to a3930ce03a)
Solutions
- Validate both arguments are finite numbers before calling clearBit.
- Keep F/Ff strictly numeric to ensure downstream clearBit calls receive valid numbers.
- Coerce defensively: `clearBit(Number(x)||0, Number(p)||0)`.
Example fix
// before
field.F = jsPDF.API.__acroform__.clearBit(field.F, badPos);
// after
var pos = Number(badPos);
if (isFinite(pos)) {
field.F = jsPDF.API.__acroform__.clearBit(field.F, pos);
} Defensive patterns
Strategy: type-guard
Validate before calling
function safeClearBit(number, bitPosition) {
number = Number(number) || 0;
bitPosition = Number(bitPosition);
if (!isFinite(bitPosition)) throw new Error('bitPosition must be a finite number');
return jsPDF.API.__acroform__.clearBit(number, bitPosition);
} Type guard
function areFiniteNumbers(a, b) {
return typeof a === 'number' && isFinite(a) &&
typeof b === 'number' && isFinite(b);
} Try / catch
try {
val = jsPDF.API.__acroform__.clearBit(val, pos);
} catch (e) {
if (/__acroform__.clearBit/.test(e.message)) {
pos = Number(pos) || 0; val = val || 0;
val = jsPDF.API.__acroform__.clearBit(val, pos);
} else throw e;
} Prevention
- Coerce both arguments to finite numbers before calling clearBit.
- Maintain numeric F/Ff so boolean setters can clear bits.
- Avoid direct helper calls; use the boolean properties.
When it happens
Trigger: Calling clearBit with NaN or a non-numeric value that does not collapse under the `|| 0` default; indirectly via AcroForm property setters (e.g. showWhenPrinted -> clearBitForPdf -> clearBit) when the underlying _F flag is NaN.
Common situations: Toggling boolean AcroForm attributes after a bad F/Ff assignment; programmatic bit manipulation with unvalidated inputs.
Related errors
- Invalid arguments passed to jsPDF.API.__acroform__.setBit
- Invalid arguments passed to jsPDF.API.__acroform__.getBit
- Invalid arguments passed to jsPDF.API.__acroform__.getBitFor
- Invalid arguments passed to jsPDF.API.__acroform__.setBitFor
- Invalid arguments passed to jsPDF.API.__acroform__.clearBitF
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/3dfb9a71be11df3e.
Report an issue: GitHub.