{"record":{"id":"f53ac65d00629662","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-api-acroform-f53ac6","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.API.__acroform__.getBit","messagePattern":"Invalid arguments passed to jsPDF\\.API\\.__acroform__\\.getBit","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/acroform.js","lineNumber":113,"sourceCode":"var 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});\n\n/*\n * Ff starts counting the bit position at 1 and not like javascript at 0\n */\nvar getBitForPdf = (jsPDFAPI.__acroform__.getBitForPdf = function(\n  number,\n  bitPosition\n) {\n  if (isNaN(number) || isNaN(bitPosition)) {\n    throw new Error(\n      \"Invalid arguments passed to jsPDF.API.__acroform__.getBitForPdf\"\n    );\n  }","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/acroform.js#L95-L131","documentation":"Thrown by the AcroForm getBit(number, bitPosition) helper when either argument is NaN. getBit reads a single bit and returns 0 or 1; it is exposed at jsPDF.API.__acroform__.getBit. Unlike set/clearBit it does not default the args to 0, so passing undefined directly produces NaN and triggers the throw.","triggerScenarios":"Calling getBit(undefined, pos) or getBit(number, undefined); reading a boolean AcroForm property (e.g. via getBitForPdf, which delegates here) when the flag value or position is NaN.","commonSituations":"Querying field flags before they are initialized; passing a position computed from a missing config value.","solutions":["Pass only finite numbers to getBit; default the value to 0 if unknown.","Ensure F/Ff are initialized to numeric values before any flag read.","Use getBitForPdf with validated positions (1-based)."],"exampleFix":"// before\nvar on = jsPDF.API.__acroform__.getBit(field.F, undefinedPos);\n\n// after\nvar pos = Number(undefinedPos);\nvar on = isFinite(pos) ? jsPDF.API.__acroform__.getBit(field.F || 0, pos) : 0;","handlingStrategy":"type-guard","validationCode":"function safeGetBit(number, bitPosition) {\n  number = Number(number) || 0;\n  if (!isFinite(Number(bitPosition))) return 0;\n  return jsPDF.API.__acroform__.getBit(number, 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  return jsPDF.API.__acroform__.getBit(val, pos);\n} catch (e) {\n  if (/__acroform__.getBit/.test(e.message)) return 0;\n  throw e;\n}","preventionTips":["Initialize F/Ff to 0/4 before any getBit read.","Default the value argument to 0 when unknown.","Validate positions are finite numbers before reading bits."],"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"}