The README rewrite renamed or merged several headings that comments still cited. Each comment now names the current heading. Line number citations of README become headings too, and one test name drops its line numbers. The e2e workflow's citations of "In CI" are dropped, because no section has what they pointed at. Its comment also corrects what it says about required jobs and open reports. The comment on withLock() no longer states a Firefox private window exception, because the manifest keeps the extension out of those windows. Two comments also take corrections from reviews: the cases with no total in DeleteAddress's warning, and the screens that say a swap's amount could not be decoded. Model: opus-5-5
27 lines
984 B
JavaScript
27 lines
984 B
JavaScript
// `navigator.locks` for the unit tests, which run on node, where there is none.
|
|
//
|
|
// One lock per name: granted in the order it was asked for, and let go when
|
|
// the callback settles, whether it resolved or rejected. That is what the
|
|
// browser's own does for the one call the extension makes,
|
|
// `navigator.locks.request(name, callback)`. Every module a test file loads
|
|
// shares it, as the extension's background and its pages share the browser's
|
|
// (README, "Stored data").
|
|
//
|
|
// Run before each test file by `setupFiles` in package.json.
|
|
|
|
// For each name, a promise that settles once the last request for it has
|
|
// let the lock go.
|
|
const released = new Map();
|
|
|
|
function request(name, callback) {
|
|
const previous = released.get(name) || Promise.resolve();
|
|
const result = previous.then(() => callback({ name, mode: "exclusive" }));
|
|
released.set(
|
|
name,
|
|
result.catch(() => {}),
|
|
);
|
|
return result;
|
|
}
|
|
|
|
globalThis.navigator = { locks: { request } };
|