{"record":{"id":"3dfb9a71be11df3e","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-api-acroform-3dfb9a","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.API.__acroform__.clearBit","messagePattern":"Invalid arguments passed to jsPDF\\.API\\.__acroform__\\.clearBit","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/acroform.js","lineNumber":100,"sourceCode":"\n  if (isNaN(number) || isNaN(bitPosition)) {\n    throw new Error(\n      \"Invalid arguments passed to jsPDF.API.__acroform__.setBit\"\n    );\n  }\n  var bitMask = 1 << bitPosition;\n\n  number |= bitMask;\n\n  return number;\n});\n\nvar clearBit = (jsPDFAPI.__acroform__.clearBit = function(number, bitPosition) {\n  number = number || 0;\n  bitPosition = bitPosition || 0;\n\n  if (isNaN(number) || isNaN(bitPosition)) {\n    throw new Error(\n      \"Invalid arguments passed to jsPDF.API.__acroform__.clearBit\"\n    );\n  }\n  var bitMask = 1 << bitPosition;\n\n  number &= ~bitMask;\n\n  return number;\n});\n\nvar getBit = (jsPDFAPI.__acroform__.getBit = function(number, bitPosition) {\n  if (isNaN(number) || isNaN(bitPosition)) {\n    throw new Error(\n      \"Invalid arguments passed to jsPDF.API.__acroform__.getBit\"\n    );\n  }\n  return (number & (1 << bitPosition)) === 0 ? 0 : 1;\n});","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/acroform.js#L82-L118","documentation":"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.","triggerScenarios":"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.","commonSituations":"Toggling boolean AcroForm attributes after a bad F/Ff assignment; programmatic bit manipulation with unvalidated inputs.","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)`."],"exampleFix":"// before\nfield.F = jsPDF.API.__acroform__.clearBit(field.F, badPos);\n\n// after\nvar pos = Number(badPos);\nif (isFinite(pos)) {\n  field.F = jsPDF.API.__acroform__.clearBit(field.F, pos);\n}","handlingStrategy":"type-guard","validationCode":"function safeClearBit(number, bitPosition) {\n  number = Number(number) || 0;\n  bitPosition = Number(bitPosition);\n  if (!isFinite(bitPosition)) throw new Error('bitPosition must be a finite number');\n  return jsPDF.API.__acroform__.clearBit(number, bitPosition);\n}","typeGuard":"function areFiniteNumbers(a, b) {\n  return typeof a === 'number' && isFinite(a) &&\n         typeof b === 'number' && isFinite(b);\n}","tryCatchPattern":"try {\n  val = jsPDF.API.__acroform__.clearBit(val, pos);\n} catch (e) {\n  if (/__acroform__.clearBit/.test(e.message)) {\n    pos = Number(pos) || 0; val = val || 0;\n    val = jsPDF.API.__acroform__.clearBit(val, pos);\n  } else throw e;\n}","preventionTips":["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."],"tags":["acroform","validation","bit-ops","internal"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}