Skip to content

Set the omit-default-module-path=false wasm-bindgen option#1

Merged
calixteman merged 1 commit intomozilla:mainfrom
nicolo-ribaudo:omit-default-module-path
May 13, 2025
Merged

Set the omit-default-module-path=false wasm-bindgen option#1
calixteman merged 1 commit intomozilla:mainfrom
nicolo-ribaudo:omit-default-module-path

Conversation

@nicolo-ribaudo
Copy link
Contributor

This is the diff in the generated code:

--- ./my_output_dir2/qcms.js    2025-05-13 16:15:28.664573459 +0200
+++ ./my_output_dir/qcms.js     2025-05-13 16:13:45.219869438 +0200
@@ -235,9 +235,7 @@
         }
     }
 
-    if (typeof module_or_path === 'undefined') {
-        module_or_path = new URL('qcms_bg.wasm', import.meta.url);
-    }
+
     const imports = __wbg_get_imports();
 
     if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {

I would ideally like to remove the whole __wbg_init exported function (and __wbg_load, used by it), since pdf.js does not need it and thus it's just dead code, but there isn't an easy way to do it with wasm-pack/wasm-bindgen.

This PR mostly solves the annoyance of having to add the comment for bundlers in the pdf.js build process.

Copy link
Collaborator

@calixteman calixteman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

@calixteman calixteman merged commit 22490a3 into mozilla:main May 13, 2025
@nicolo-ribaudo nicolo-ribaudo deleted the omit-default-module-path branch May 13, 2025 14:29
calixteman added a commit to calixteman/pdf.js that referenced this pull request May 13, 2025
thomashackl pushed a commit to thomashackl/pdf.js that referenced this pull request Jun 5, 2025
thomashackl pushed a commit to thomashackl/pdf.js that referenced this pull request Jun 5, 2025
commit 96de0bf
Author: Thomas Hackl <hackl@data-quest.de>
Date:   Thu May 8 11:51:45 2025 +0200

    Changes for Stud.IP integration

commit 5189123
Author: Calixte Denizet <calixte.denizet@gmail.com>
Date:   Tue Jun 3 19:38:35 2025 +0200

    Update Puppeteer to version 24.10.0

commit 4800039
Author: Tim van der Meij <timvandermeij@gmail.com>
Date:   Sun Jun 1 20:26:12 2025 +0200

    Bump the stable version in `pdfjs.config`

commit 0d862db
Author: Tim van der Meij <timvandermeij@gmail.com>
Date:   Sun May 25 15:26:36 2025 +0200

    Fix intermittent failure in the "supports specifying a custom origin" viewer integration test

    The problem in the original code is that `getTextAt` is called too
    early and therefore returns unexpected text content. This can happen
    because we call `increaseScale` and then wait for the page's text layer
    to be visible, but it can take some time before the zoom actually
    occurs/completes in the viewer and in the meantime the old (pre-zoom)
    text layer may still be visible, causing us to continue too soon because
    we don't validate that we're dealing with the post-zoom text layer.

    This commit fixes the issue by simply waiting for the expected text to
    show up at the given origin coordinates, which makes the test work
    independent of viewer actions/timing.

commit 8a620f3
Author: Calixte Denizet <calixte.denizet@gmail.com>
Date:   Thu May 22 20:54:16 2025 +0200

    [Editor] Change mode when double clicking on an editor

    It was only possible to double click on a FreeText editor while being in ink mode (or any other).

commit 9956533
Author: Calixte Denizet <calixte.denizet@gmail.com>
Date:   Mon May 26 19:11:24 2025 +0200

    Fix the colors of disabled buttons in the dialogs

commit 8ccc660
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Tue May 20 13:38:05 2025 +0200

    Move the `PDFObjects` class to its own file

    This isn't directly part of the official API, and having this class in its own file could help avoid future changes (e.g. issue 18148) affecting the size of the `src/display/api.js` file unnecessarily.

commit 00768ee
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Tue May 20 13:23:38 2025 +0200

    Move a few helper functions/classes out of the `src/display/api.js` file

    Given that this file represents the official API, it's difficult to avoid it becoming fairly large as we add new functionality. However, it also contains a couple of smaller (and internal) helpers that we can move into a new utils-file.

    Also, we inline the `DEFAULT_RANGE_CHUNK_SIZE` constant since it's only used *once* and its value has never been changed in over a decade.

commit 62e7b1b
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Wed May 21 16:47:20 2025 +0200

    Use nullish coalescing in the `Catalog.prototype.numPages` getter

commit a5b3c3c
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Wed May 21 11:34:32 2025 +0200

    Replace semi-private fields/methods with actual private ones in `src/core/catalog.js`

    Additionally, move a couple of "public" fields out of the class constructor and initialize them directly instead.

commit d10371d
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Fri May 23 13:53:44 2025 +0200

    Ignore empty paths when optimizing `constructPath` operations (issue 19971)

    Note how we're handling empty paths in [src/display/canvas.js](https://github.com/mozilla/pdf.js/blob/a8e05d82e23056ddc2c28f83854b6f74ffa4bebc/src/display/canvas.js#L1423-L1428), hence we need add similar code in the `QueueOptimizer` as well.

commit 425de6d
Author: Nicolò Ribaudo <nribaudo@igalia.com>
Date:   Mon May 19 19:33:14 2025 +0200

    Show the op dispatched by constructPath in the debugger

    The `constructPath` op receives as arguments not only the
    information to construct the path, but also the op to apply
    the path to (such as "fill", or "stroke").

    This commit updates the Stepper tool in the debugger to decode
    that op, showing its name rather than just its numeric ID.

commit 888e360
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Mon May 19 11:54:32 2025 +0200

    Improve how the PDF.js version/commit information is exposed in the *built* files

    To make it easier to tell which PDF.js version/commit that the *built* files correspond to, they have (since many years) included `pdfjsVersion` and `pdfjsBuild` constants with that information.

    As currently implemented this has a few shortcomings:
     - It requires manually adding the code, with its preprocessor statements, in all relevant files.

     - It requires ESLint disable statements, since it's obviously unused code.

     - Being unused, this code is removed in the minified builds.

     - This information would be more appropriate as comments, however Babel discards all comments during building.

     - It would be helpful to have this information at the top of the *built* files, however it's being moved during building.

    To address all of these issues, we'll instead utilize Webpack to insert the version/commit information as a comment placed just after the license header.

commit 117c40f
Author: calixteman <cdenizet@mozilla.com>
Date:   Thu May 22 14:08:31 2025 +0200

    Revert "Minify the js code when building for Firefox (bug 1965003)"

commit ffa3c89
Author: Calixte Denizet <calixte.denizet@gmail.com>
Date:   Mon May 19 16:48:23 2025 +0200

    Don't create a useless subarray when getting image data from a flate stream

commit 345f344
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Mon May 19 17:57:28 2025 +0200

    Bump library version to `5.3`

commit 68ad7b1
Author: Calixte Denizet <calixte.denizet@gmail.com>
Date:   Mon May 19 13:53:35 2025 +0200

    Remove all the useless subarrays when using qcms.

    It reduces the memory use and the newly added function `getRgbHex` is 4 times faster.

commit a328dc9
Author: Calixte Denizet <calixte.denizet@gmail.com>
Date:   Mon May 19 17:05:37 2025 +0200

    Fix pdfjsPreloadedWorker when it's undefined

commit b097714
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Mon May 19 13:19:45 2025 +0200

    Simplify how we handle Type3 fonts without a /FontDescriptor dictionary

    Part of this is very old code, which we can now simplify a little bit.

commit 68a3807
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Mon May 19 12:52:54 2025 +0200

    Support Type3 fonts with an incomplete /FontDescriptor dictionary (issue 19954)

    We have a fallback for the common case of Type3 fonts without a /FontDescriptor dictionary, however we also need to handle the case where it's present but lacking the required /FontName entry.

commit 4f57137
Author: Calixte Denizet <calixte.denizet@gmail.com>
Date:   Sun May 18 19:58:21 2025 +0200

    Create the css color to use with the canvas in the worker

    It slightly reduces the time spent to draw and the memory used.

commit f630b49
Author: Tim van der Meij <timvandermeij@gmail.com>
Date:   Sun May 18 15:55:01 2025 +0200

    Fix missing `await` for asynchronous method calls in the integration tests

    The `Page.evaluate()` and `Mouse.click()` APIs in Puppeteer both return
    a promise; see https://pptr.dev/api/puppeteer.page.evaluate and
    https://pptr.dev/api/puppeteer.mouse.click, and should therefore be
    awaited before proceeding in tests to make sure that the test's behavior
    is deterministic and avoid intermittent failures.

    The following command was used to find potential places to fix:
    `grep -nEr "[^await|return] page\." test/integration/*`

commit fa4defd
Author: Tim van der Meij <timvandermeij@gmail.com>
Date:   Sun May 18 14:19:13 2025 +0200

    Fix intermittent failure in the stamp editor's undo-related integration tests

    The clipboard, used via the `copyImage` helper function, is a shared
    resource, so access to it cannot happen concurrently because it could
    result in tests overwriting each other's contents. Most tests using
    the clipboard are therefore run sequentially, but only the stamp
    editor's undo-related tests weren't, so this commit fixes the issue
    by running those tests sequentially too.

commit 66b8104
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Sun May 18 10:49:02 2025 +0200

    Remove Node.js-specific checks when using the Fetch API

    Given that Node.js has full support for the Fetch API since version 21, see the "History" data at https://nodejs.org/api/globals.html#fetch, it seems unnecessary for us to manually check for various globals before using it.

    Since our primary development target is browsers in general, and Firefox in particular, being able to remove Node.js-specific compatibility code is always helpful.

    Note that we still, for now, support Node.js version 20 and if the relevant globals are not available then Errors will instead be thrown from within the `PDFFetchStream` class.

commit bcfd178
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Sun May 18 10:16:46 2025 +0200

    Use private fields in the `PDFDataRangeTransport` class

commit b129ebc
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Fri May 16 13:52:53 2025 +0200

    Ensure that the viewer clears the `workerPort` option when using "fake" workers

    Without this "fake" workers may be ignored in the API, which isn't really what you want when manually providing the `disableWorker=true` hash parameter. (Note that this requires the `pdfBugEnabled` option/preference to be set as well.)

    Also, after the changes in PR 19810 we can just load the "fake" worker directly in development mode and don't need to manually assign it to the global scope.

commit 0237f10
Author: Tim van der Meij <timvandermeij@gmail.com>
Date:   Sat May 17 15:58:38 2025 +0200

    Update translations to the most recent versions

commit a43ad93
Author: Tim van der Meij <timvandermeij@gmail.com>
Date:   Sat May 17 15:49:10 2025 +0200

    Update dependencies to the most recent versions

commit 89bacf1
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Sat May 17 15:41:04 2025 +0200

    Utilize private fields and methods more in the `PDFWorker` class

    This replaces, wherever possible, the old semi-private fields and methods with actually private ones.

commit be824d3
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Sat May 17 15:23:55 2025 +0200

    Replace `PDFWorker.fromPort` with a generic `PDFWorker.create` method

    This allows us to simply invoke `PDFWorker.create` unconditionally from the `getDocument` function, without having to manually check if a global `workerPort` is available first.

commit c5bd953
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Sun May 11 16:23:50 2025 +0200

    Add a couple of new `eslint-plugin-unicorn` rules

    The recent `eslint-plugin-unicorn` update added, and replaced, a few rules that seem useful for us; please refer to https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v59.0.0

    Note that none of the following rules required any code-changes:
     - Replace `no-array-push-push` with `prefer-single-call`, see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-single-call.md

     - Add `no-unnecessary-slice-end`, see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-unnecessary-slice-end.md

     - Add `no-unnecessary-array-flat-depth`, see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-unnecessary-array-flat-depth.md

     - Add `no-unnecessary-array-splice-count`, see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-unnecessary-array-splice-count.md

commit 6ec404b
Author: studystill <chenghuiyue@outlook.com>
Date:   Fri May 16 15:16:26 2025 +0800

    chore: remove redundant word in comment

    Signed-off-by: studystill <chenghuiyue@outlook.com>

commit fdf341e
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Sun May 11 15:01:09 2025 +0200

    Enable the `unicorn/prefer-import-meta-properties` ESLint plugin rule

    Given that we require Node.js versions `>=20.16.0 || >=22.3.0` using this should be fine, based on the "History" data in https://nodejs.org/api/esm.html#importmetadirname respectively https://nodejs.org/api/esm.html#importmetafilename.

    Please also see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-import-meta-properties.md

commit fe73ba3
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Thu May 15 15:23:50 2025 +0000

    Bump undici from 6.21.1 to 6.21.3

    Bumps [undici](https://github.com/nodejs/undici) from 6.21.1 to 6.21.3.
    - [Release notes](https://github.com/nodejs/undici/releases)
    - [Commits](nodejs/undici@v6.21.1...v6.21.3)

    ---
    updated-dependencies:
    - dependency-name: undici
      dependency-version: 6.21.3
      dependency-type: indirect
    ...

    Signed-off-by: dependabot[bot] <support@github.com>

commit d473b09
Author: Calixte Denizet <calixte.denizet@gmail.com>
Date:   Thu May 15 18:13:53 2025 +0200

    Use the worker created in the child actor (bug 1966721)

commit 2573365
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Thu May 15 19:30:43 2025 +0200

    Allow using the `workerPort` option in Firefox

commit a14384f
Author: Calixte Denizet <calixte.denizet@gmail.com>
Date:   Thu May 15 17:47:10 2025 +0200

    Minify the js code when building for Firefox (bug 1965003)

    It helps to improve the loading time in the worker by around 25% on Windows, Mac and Android.

commit 2cb5a68
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Thu May 15 10:26:29 2025 +0200

    Prefer the /Metadata, when available, in the document properties dialog (bug 1966086)

commit a5d1e65
Author: Nicolò Ribaudo <nribaudo@igalia.com>
Date:   Tue May 13 14:06:44 2025 +0200

    Remove unused OpenJPEG wasm fallback logic

    Emscripten generates code that allows the caller to provide the Wasm
    module (thorugh Module.instantiateWasm), with a fallback in case
    .instantiateWasm is not provided. We always define instantiateWasm, so
    we can hard-code the check and let our dead code elimination logic
    remove the unused fallback.

    This commit also improved the dead code elimination logic so that if
    a function declaration becomes unused as a result of removing dead
    code, the function itself is removed.

commit ba13328
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Wed Apr 23 23:03:58 2025 +0200

    Run CI tests in Node.js version 24

    Node.js version 24 was just released, see https://github.com/nodejs/release#release-schedule, hence we should run tests in that version in order to help catch any possible issues as soon as possible.
    Also, since version 23 will reach EOL (end-of-life) in less than a month we stop running tests in that version.

commit 8de68a3
Author: Calixte Denizet <calixte.denizet@gmail.com>
Date:   Tue May 13 19:12:17 2025 +0200

    [Editor] Keep aspect ratio when rescaling an image before being processed for a signature (bug 1962819)

commit acace16
Author: Calixte Denizet <calixte.denizet@gmail.com>
Date:   Tue May 13 16:44:12 2025 +0200

    Update qcms build

    It's a follow-up of mozilla/pdf.js.qcms#1.

commit e56f31d
Author: Nicolò Ribaudo <nribaudo@igalia.com>
Date:   Tue May 13 12:52:29 2025 +0200

    Preserve webpack/vite ignore comments when minifying

    They were removed in the minified build, but the code that made the comments necessary was still there (just minified). This commit updates the Terser config to preserve them.

    The default value of Terser's `comments` option is [`/@preserve|@copyright|@lic|@cc_on|^\**!/i`](https://github.com/terser/terser/blob/d528103b7c00735ca7736a2a8ad27188e93c0c90/lib/output.js#L178C12-L178C53), however the only type of comment it was actually matching in our case is `@lic`, for the license header in minified files. Thus the new regexp is `/@lic|webpackIgnore|@vite-ignore/i`.

commit 95904a3
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Sat May 10 15:42:29 2025 +0200

    Reduce duplication when computing the maximum canvas pixels

    *This is something that occurred to me when reviewing the latest PDF.js update in mozilla-central.*

    Currently we duplicate essentially the same code in both the `OutputScale.prototype.limitCanvas` and `PDFPageDetailView.prototype.update` methods, which seems unnecessary, and to avoid that we introduce a new `OutputScale.capPixels` method that is used to compute the maximum canvas pixels.

commit 7448e37
Author: Calixte Denizet <calixte.denizet@gmail.com>
Date:   Fri May 9 21:46:17 2025 +0200

    Decode appearance keys of checkboxes

commit 0974fcd
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Sat May 10 11:38:06 2025 +0200

    Improve validation in the `Catalog.prototype.openAction` getter

    When the /OpenAction data is an Array we're currently using it as-is which could theoretically cause problems in corrupt PDF documents, hence we ensure that a "raw" destination is actually valid. (This change is covered by existing unit-tests.)

    *Note:* In the Dictionary case we're using the `Catalog.parseDestDictionary` method, which already handles all of the necessary validation.

commit c2ef405
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Wed May 7 17:31:10 2025 +0200

    Shorten the `PDFDocument.prototype.fieldObjects` getter slightly

    The effect is probably not even measurable, however this patch ever so slightly reduces the asynchronicity in the `fieldObjects` getter. These changes should be safe since:

     - We're inside of the `PDFDocument`-class and the `annotationGlobals`-getter, which will always return a (shadowed) Promise and won't throw `MissingDataException`s, can be accessed directly without going through the `BasePdfManager`-instance.

     - The `acroForm`-dictionary can be accessed through the `annotationGlobals`-data, removing the need to "manually" look it up and thus the need for using `Promise.all` here.

     - We can also lookup the /Fields-data, in the `acroForm`-dictionary, synchronously since the initial `formInfo.hasFields` check guarantees that it's available.

commit 7bf65e6
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Wed May 7 13:41:50 2025 +0200

    Use object destructuring a bit more in the `src/core/document.js` file

commit c0c9902
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Wed May 7 13:41:44 2025 +0200

    Replace a number of semi-private fields with actual private ones in `src/core/document.js`

    These are fields that can be moved out of their class constructors, and be initialized directly.

commit 8546ce0
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Wed May 7 13:41:36 2025 +0200

    Replace a number of semi-private methods with actual private ones in `src/core/document.js`

    There's a few remaining cases that are used with either cached getters or `BasePdfManager.prototype.ensure`-methods, and those cannot be converted.

commit c054ab3
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Wed May 7 13:41:29 2025 +0200

    Add a `Page` helper method to create a `PartialEvaluator`-instance

    Currently we repeat the same identical code five times in the `Page`-class when creating a `PartialEvaluator`-instance, which given the number of parameters it needs seems like unnecessary duplication.

commit f11f67a
Author: Calixte Denizet <calixte.denizet@gmail.com>
Date:   Wed May 7 19:07:21 2025 +0200

    Add a pref in order to cap the canvas area to a factor of the window one (bug 1958015)

    This way it helps to reduce the overall canvas dimensions and make the rendering faster.
    The drawback is that when scrolling, the page can be blurry in waiting for the rendering.

    The default value is 200% on desktop and will be 100% for GeckoView.

commit 0bedd32
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Thu May 8 12:37:08 2025 +0200

    Update l10n files

commit 1ae0355
Author: Jonas Jenwald <jonas.jenwald@gmail.com>
Date:   Thu May 8 12:34:01 2025 +0200

    Update the Firefox repository used in `external/importL10n/locales.mjs`

    The https://github.com/mozilla/gecko-dev repository has been deprecated in favour of https://github.com/mozilla-firefox/firefox, hence we should tweak the l10n-update script accordingly.

commit bb7944c
Author: Thomas Hackl <hackl@data-quest.de>
Date:   Thu Jun 5 07:54:46 2025 +0200

    fine tune after functional review

commit 1d3816b
Author: Thomas Hackl <hackl@data-quest.de>
Date:   Thu May 8 11:51:45 2025 +0200

    Changes for Stud.IP integration

# Conflicts:
#	web/app.js
nanalucky pushed a commit to nanalucky/pdf.js that referenced this pull request Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants