{"record":{"id":"816ca1cf0ea6b738","repo":"mozilla/pdf.js","slug":"invalid-nvalue1-in-afsimple","errorCode":null,"errorMessage":"Invalid nValue1 in AFSimple","messagePattern":"Invalid nValue1 in AFSimple","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/scripting_api/aform.js","lineNumber":342,"sourceCode":"        );\n      }\n    } else if (bGreaterThan) {\n      if (value < nGreaterThan) {\n        err = this._util.printf(GlobalConstants.IDS_GREATER_THAN, nGreaterThan);\n      }\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);","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/aform.js#L324-L360","documentation":"Thrown by AFSimple when AFMakeNumber(nValue1) returns null, i.e. nValue1 cannot be coerced to a number. AFSimple performs arithmetic (AVG/SUM/PRD/MIN/MAX) and requires both operands to be numeric, so a non-coercible first operand is rejected. It executes within the sandboxed PDF-JS form environment.","triggerScenarios":"A PDF form script calls AFSimple(cFunction, nValue1, nValue2) where nValue1 is a non-numeric, non-coercible value (e.g. an object or unparseable string).","commonSituations":"A field value is empty or a non-numeric string that AFMakeNumber cannot parse; a malformed form script passes the wrong argument type.","solutions":["Repair or report the PDF form script; the error is content-driven.","Update PDF.js to benefit from any future coercion leniency.","Let the embedding app tolerate scripting failures so the rest of the form still works.","If authoring the PDF, pass numeric values to AFSimple."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await runFormScript(...);\n} catch (e) {\n  if (/Invalid nValue1 in AFSimple/.test(e.message)) { /* skip calculation */ }\n}","preventionTips":["Isolate sandbox scripting errors from the rendering pipeline.","Repair PDFs whose form scripts pass non-numeric values to AFSimple.","Update PDF.js for improved coercion.","Keep forms functional even when a calculation throws."],"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"}