{"record":{"id":"1e41336de02474d5","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-api-acroform","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.API.__acroform__.setBit","messagePattern":"Invalid arguments passed to jsPDF\\.API\\.__acroform__\\.setBit","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/acroform.js","lineNumber":84,"sourceCode":"};\n\nvar createFormXObject = function(formObject) {\n  var xobj = new AcroFormXObject();\n  var height = AcroFormAppearance.internal.getHeight(formObject) || 0;\n  var width = AcroFormAppearance.internal.getWidth(formObject) || 0;\n  xobj.BBox = [0, 0, Number(f2(width)), Number(f2(height))];\n  return xobj;\n};\n\n/**\n * Bit-Operations\n */\nvar setBit = (jsPDFAPI.__acroform__.setBit = 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__.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    );","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/acroform.js#L66-L102","documentation":"Thrown by the AcroForm setBit(number, bitPosition) helper when either argument is NaN after coercion. setBit is an internal bit-manipulation utility (exposed at jsPDF.API.__acroform__.setBit) that sets a single bit on an integer field-flag value. It defaults both args to 0, so NaN only occurs when a caller explicitly passes undefined/non-numeric that survives the `|| 0` default (e.g. the literal value NaN, or a string).","triggerScenarios":"Calling jsPDF.API.__acroform__.setBit(value, pos) with NaN, or indirectly when an AcroForm boolean property setter (e.g. showWhenPrinted) is toggled while _F/_Ff already became NaN from a previous bad assignment.","commonSituations":"Programmatically building AcroForm fields and passing a non-numeric flag accumulator; a prior isNaN failure leaving a flag field as NaN that then propagates into setBit.","solutions":["Ensure both arguments are finite numbers (coerce with Number() and guard) before calling setBit.","Never assign non-numeric values to F/Ff on AcroForm fields, since those feed the bit helpers.","If using the helper directly, sanitize inputs: `setBit(Number(x)||0, Number(p)||0)`."],"exampleFix":"// before\nfield.F = jsPDF.API.__acroform__.setBit(field.F, maybeUndefined);\n\n// after\nvar pos = Number(maybeUndefined);\nif (isFinite(pos)) {\n  field.F = jsPDF.API.__acroform__.setBit(field.F, pos);\n}","handlingStrategy":"type-guard","validationCode":"function safeSetBit(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__.setBit(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__.setBit(val, pos);\n} catch (e) {\n  if (/__acroform__.setBit/.test(e.message)) {\n    pos = Number(pos) || 0; val = val || 0;\n    val = jsPDF.API.__acroform__.setBit(val, pos);\n  } else throw e;\n}","preventionTips":["Never pass undefined/NaN to bit helpers; coerce first.","Keep F/Ff numeric so downstream setBit calls get valid inputs.","Prefer the high-level boolean properties over direct setBit calls."],"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"}