Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
76a5aed
Use `Map.prototype.getOrInsert()` in the `getNewAnnotationsMap` helper
Snuffleupagus Feb 21, 2026
210c969
Use `Map.prototype.getOrInsert()` in the `#collectFieldObjects` method
Snuffleupagus Feb 21, 2026
3940855
Use `Map.prototype.getOrInsert()` in the `_getPageAdvance` method
Snuffleupagus Feb 21, 2026
3e7ad8d
Use `Map.prototype.getOrInsert()` in the `#collectParents` method
Snuffleupagus Feb 21, 2026
c7bdf5b
Use `Map.prototype.getOrInsertComputed()` in the `ensureDebugMetadata…
Snuffleupagus Feb 21, 2026
0d8bc68
Add missing license header in `src/display/canvas_dependency_tracker.js`
Snuffleupagus Feb 21, 2026
956eb10
Use `FinalizationRegistry` unconditionally in the `src/scripting_api/…
Snuffleupagus Feb 21, 2026
2631750
Merge pull request #20702 from Snuffleupagus/getNewAnnotationsMap-get…
Snuffleupagus Feb 22, 2026
e62a990
Merge pull request #20704 from Snuffleupagus/getPageAdvance-getOrInsert
Snuffleupagus Feb 22, 2026
ad0a310
Merge pull request #20706 from Snuffleupagus/ensureDebugMetadata-getO…
Snuffleupagus Feb 22, 2026
8189ca3
Merge pull request #20703 from Snuffleupagus/#collectFieldObjects-get…
timvandermeij Feb 22, 2026
a5a27a5
Merge pull request #20705 from Snuffleupagus/#collectParents-getOrInsert
timvandermeij Feb 22, 2026
a8b1c8b
Remove the leading slash in windows file path when instrumenting js f…
calixteman Feb 21, 2026
1df6367
Merge pull request #20710 from calixteman/normalize_path
calixteman Feb 22, 2026
cc516d0
Merge pull request #20709 from Snuffleupagus/scripting-unconditional-…
timvandermeij Feb 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/core/core_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,7 @@ function getNewAnnotationsMap(annotationStorage) {
if (!key.startsWith(AnnotationEditorPrefix)) {
continue;
}
let annotations = newAnnotationsByPage.get(value.pageIndex);
if (!annotations) {
annotations = [];
newAnnotationsByPage.set(value.pageIndex, annotations);
}
annotations.push(value);
newAnnotationsByPage.getOrInsert(value.pageIndex, []).push(value);
}
return newAnnotationsByPage.size > 0 ? newAnnotationsByPage : null;
}
Expand Down
5 changes: 1 addition & 4 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -1892,10 +1892,7 @@ class PDFDocument {
orphanFields.put(fieldRef, parentRef);
}

if (!promises.has(name)) {
promises.set(name, []);
}
promises.get(name).push(
promises.getOrInsert(name, []).push(
AnnotationFactory.create(
xref,
fieldRef,
Expand Down
7 changes: 1 addition & 6 deletions src/core/struct_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,7 @@ class StructTreeRoot {
for (const element of elements) {
if (element.structTreeParentId) {
const id = parseInt(element.structTreeParentId.split("_mc")[1], 10);
let elems = idToElements.get(id);
if (!elems) {
elems = [];
idToElements.set(id, elems);
}
elems.push(element);
idToElements.getOrInsert(id, []).push(element);
}
}

Expand Down
31 changes: 20 additions & 11 deletions src/display/canvas_dependency_tracker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/* Copyright 2025 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Util } from "../shared/util.js";

const FORCED_DEPENDENCY_LABEL = "__forcedDependency";
Expand Down Expand Up @@ -50,17 +65,11 @@ class BBoxReader {
}
}

const ensureDebugMetadata = (map, key) => {
if (!map) {
return undefined;
}
let value = map.get(key);
if (!value) {
value = { dependencies: new Set(), isRenderingOperation: false };
map.set(key, value);
}
return value;
};
const ensureDebugMetadata = (map, key) =>
map?.getOrInsertComputed(key, () => ({
dependencies: new Set(),
isRenderingOperation: false,
}));

/**
* @typedef {"lineWidth" | "lineCap" | "lineJoin" | "miterLimit" | "dash" |
Expand Down
24 changes: 10 additions & 14 deletions src/scripting_api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,14 @@ class App extends PDFObject {
);

this._timeoutIds = new WeakMap();
if (typeof FinalizationRegistry !== "undefined") {
// About setTimeOut/setInterval return values (specs):
// The return value of this method must be held in a
// JavaScript variable.
// Otherwise, the timeout object is subject to garbage-collection,
// which would cause the clock to stop.
this._timeoutIdsRegistry = new FinalizationRegistry(
this._cleanTimeout.bind(this)
);
} else {
this._timeoutIdsRegistry = null;
}
// About setTimeOut/setInterval return values (specs):
// The return value of this method must be held in a
// JavaScript variable.
// Otherwise, the timeout object is subject to garbage-collection,
// which would cause the clock to stop.
this._timeoutIdsRegistry = new FinalizationRegistry(
this._cleanTimeout.bind(this)
);

this._timeoutCallbackIds = new Map();
this._timeoutCallbackId = USERACTIVATION_CALLBACKID + 1;
Expand Down Expand Up @@ -113,12 +109,12 @@ class App extends PDFObject {
const timeout = Object.create(null);
const id = { callbackId, interval };
this._timeoutIds.set(timeout, id);
this._timeoutIdsRegistry?.register(timeout, id);
this._timeoutIdsRegistry.register(timeout, id);
return timeout;
}

_unregisterTimeout(timeout) {
this._timeoutIdsRegistry?.unregister(timeout);
this._timeoutIdsRegistry.unregister(timeout);

const data = this._timeoutIds.get(timeout);
if (!data) {
Expand Down
10 changes: 9 additions & 1 deletion test/webserver.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,15 @@ class WebServer {

// Transform with Babel and istanbul plugin
const result = babel.transformSync(content, {
filename: fileURL.pathname,
// On Windows, the file URL starts with a slash (e.g.
// /C:/path/to/file.js).
// This leading slash makes the file path invalid and causes the
// instrumentation to fail, so we need to remove it before passing the
// path.
filename:
process.platform === "win32"
? fileURL.pathname.substring(1)
: fileURL.pathname,
plugins: ["babel-plugin-istanbul"],
sourceMaps: false,
});
Expand Down
15 changes: 4 additions & 11 deletions web/pdf_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2270,10 +2270,7 @@ class PDFViewer {
this.update();
}

/**
* @private
*/
_getPageAdvance(currentPageNumber, previous = false) {
#getPageAdvance(currentPageNumber, previous = false) {
switch (this._scrollMode) {
case ScrollMode.WRAPPED: {
const { views } = this._getVisiblePages(),
Expand All @@ -2284,11 +2281,7 @@ class PDFViewer {
if (percent === 0 || widthPercent < 100) {
continue;
}
let yArray = pageLayout.get(y);
if (!yArray) {
pageLayout.set(y, (yArray ||= []));
}
yArray.push(id);
pageLayout.getOrInsert(y, []).push(id);
}
// Find the row of the current page.
for (const yArray of pageLayout.values()) {
Expand Down Expand Up @@ -2379,7 +2372,7 @@ class PDFViewer {
return false;
}
const advance =
this._getPageAdvance(currentPageNumber, /* previous = */ false) || 1;
this.#getPageAdvance(currentPageNumber, /* previous = */ false) || 1;

this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
return true;
Expand All @@ -2396,7 +2389,7 @@ class PDFViewer {
return false;
}
const advance =
this._getPageAdvance(currentPageNumber, /* previous = */ true) || 1;
this.#getPageAdvance(currentPageNumber, /* previous = */ true) || 1;

this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
return true;
Expand Down
Loading