Repository: mozilla/pdf.js
File: src/core/worker.js (JavaScript)

Code before:
    });

    handler.on("GetAttachments", function (data) {
      return pdfManager.ensureCatalog("attachments");
    });

    handler.on("GetDocJSActions", function (data) {
      return pdfManager.ensureCatalog("jsActions");
    });

    handler.on("GetPageJSActions", function ({ pageIndex }) {
      return pdfManager
        .getPage(pageIndex)
        .then(page => pdfManager.ensure(page, "jsActions"));
    });

    handler.on("GetEditableAnnotations", async function ({ pageIndexToSkip }) {
      const [numPages, annotationGlobals] = await Promise.all([
        pdfManager.ensureDoc("numPages"),
        pdfManager.ensureDoc("annotationGlobals"),
      ]);

      if (!annotationGlobals) {
        return null;
      }
      const types = new Set(["FreeText", "Stamp", "Ink", "Highlight"]);
      const pagePromises = [];
      const annotationPromises = [];
      let task = null;
      try {
        for (let i = 0, ii = numPages; i < ii; i++) {
          if (pageIndexToSkip?.has(i)) {
            continue;
          }
          if (!task) {
            task = new WorkerTask(`GetEditableAnnotations: page ${i}`);
            startWorkerTask(task);
          }
          pagePromises.push(
            pdfManager.getPage(i).then(async page => {
              if (!page) {
                return [];
              }
              return (
                page.collectAnnotationByType(
                  handler,
                  task,
                  types,
                  annotationPromises,
                  annotationGlobals
                ) || []

Review comment (suggestion):
Is there a way to avoid hardcoding this list here? Can we use the annotation constants for example? I'm a bit concerned it's easy to forget to update this if we add support for more annotation types.

Code after:
    });

    handler.on("GetAttachments", function (data) {
      return pdfManager.ensureCatalog("attachments");
    });

    handler.on("GetDocJSActions", function (data) {
      return pdfManager.ensureCatalog("jsActions");
    });

    handler.on("GetPageJSActions", function ({ pageIndex }) {
      return pdfManager
        .getPage(pageIndex)
        .then(page => pdfManager.ensure(page, "jsActions"));
    });

    handler.on(
      "GetAnnotationsByType",
      async function ({ types, pageIndexesToSkip }) {
        const [numPages, annotationGlobals] = await Promise.all([
          pdfManager.ensureDoc("numPages"),
          pdfManager.ensureDoc("annotationGlobals"),
        ]);

        if (!annotationGlobals) {
          return null;
        }
        const pagePromises = [];
        const annotationPromises = [];
        let task = null;
        try {
          for (let i = 0, ii = numPages; i < ii; i++) {
            if (pageIndexesToSkip?.has(i)) {
              continue;
            }
            if (!task) {
              task = new WorkerTask("GetAnnotationsByType");
              startWorkerTask(task);
            }
            pagePromises.push(
              pdfManager.getPage(i).then(async page => {
                if (!page) {
                  return [];
                }
                return (
                  page.collectAnnotationsByType(
                    handler,
                    task,
                    types,
                    annotationPromises,
                    annotationGlobals