{"record":{"id":"963ae0afb7839dc5","repo":"mozilla/pdf.js","slug":"invalid-nvalue2-in-afsimple","errorCode":null,"errorMessage":"Invalid nValue2 in AFSimple","messagePattern":"Invalid nValue2 in AFSimple","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/scripting_api/aform.js","lineNumber":347,"sourceCode":"      }\n    } else if (value > nLessThan) {\n      err = this._util.printf(GlobalConstants.IDS_LESS_THAN, nLessThan);\n    }\n    if (err) {\n      this._app.alert(err);\n      event.rc = false;\n    }\n  }\n\n  AFSimple(cFunction, nValue1, nValue2) {\n    const value1 = this.AFMakeNumber(nValue1);\n    if (value1 === null) {\n      throw new Error(\"Invalid nValue1 in AFSimple\");\n    }\n\n    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","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/aform.js#L329-L365","documentation":"Thrown by AFSimple when AFMakeNumber(nValue2) returns null, i.e. the second operand cannot be coerced to a number. Identical in intent to the nValue1 check: both arithmetic operands must be numeric. Runs inside the sandboxed PDF-JS form environment.","triggerScenarios":"A PDF form script calls AFSimple(cFunction, nValue1, nValue2) where nValue2 is non-coercible to a number.","commonSituations":"An empty or non-numeric field value passed as the second operand; a malformed form script.","solutions":["Repair or report the PDF form script; the error originates in PDF content.","Update PDF.js for any improved tolerance.","Ensure the embedding app degrades gracefully on scripting errors.","If authoring the PDF, pass numeric values for both operands."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await runFormScript(...);\n} catch (e) {\n  if (/Invalid nValue2 in AFSimple/.test(e.message)) { /* skip calculation */ }\n}","preventionTips":["Isolate sandbox scripting errors from rendering.","Repair PDFs whose form scripts pass non-numeric second operands.","Update PDF.js for improved coercion.","Ensure forms stay usable when a calculation fails."],"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"}