{"record":{"id":"4c37e8482d83b869","repo":"mozilla/pdf.js","slug":"invalid-cfunction-in-afsimple","errorCode":null,"errorMessage":"Invalid cFunction in AFSimple","messagePattern":"Invalid cFunction in AFSimple","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/scripting_api/aform.js","lineNumber":363,"sourceCode":"    const value2 = this.AFMakeNumber(nValue2);\n    if (value2 === null) {\n      throw new Error(\"Invalid nValue2 in AFSimple\");\n    }\n\n    switch (cFunction) {\n      case \"AVG\":\n        return (value1 + value2) / 2;\n      case \"SUM\":\n        return value1 + value2;\n      case \"PRD\":\n        return value1 * value2;\n      case \"MIN\":\n        return Math.min(value1, value2);\n      case \"MAX\":\n        return Math.max(value1, value2);\n    }\n\n    throw new Error(\"Invalid cFunction in AFSimple\");\n  }\n\n  AFSimple_Calculate(cFunction, cFields) {\n    const actions = {\n      AVG: args => Math.sumPrecise(args) / args.length,\n      SUM: args => Math.sumPrecise(args),\n      PRD: args => args.reduce((acc, value) => acc * value, 1),\n      MIN: args => Math.min(...args),\n      MAX: args => Math.max(...args),\n    };\n\n    if (!(cFunction in actions)) {\n      throw new TypeError(\"Invalid function in AFSimple_Calculate\");\n    }\n\n    const event = globalThis.event;\n    const values = [];\n","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/aform.js#L345-L381","documentation":"Thrown by AFSimple when cFunction is not one of AVG, SUM, PRD, MIN, or MAX. After validating both numeric operands, the function switches on the operation name and hits the default branch for any unrecognized operation. It is a content/script error from the PDF's form logic, not an API-misuse error by the embedding app.","triggerScenarios":"A PDF form script calls AFSimple('UNKNOWN', v1, v2) where the operation is not in the supported set.","commonSituations":"A typo or unsupported operation in the form script; an authoring tool emitting a non-standard cFunction.","solutions":["Repair or report the PDF form script.","Update PDF.js; additional operations may be supported over time.","Tolerate scripting failures at the embedding level so the form stays usable.","If authoring the PDF, use only AVG/SUM/PRD/MIN/MAX."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await runFormScript(...);\n} catch (e) {\n  if (/Invalid cFunction in AFSimple/.test(e.message)) { /* unsupported op; skip */ }\n}","preventionTips":["Treat unsupported AForm operations as non-fatal content issues.","Repair authoring-side PDFs that emit non-standard operations.","Update PDF.js to pick up added operations.","Keep the form working when a single calculation is unsupported."],"tags":["aform","scripting","calculation","pdf-content"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}