fix(browser-files): stop binding file pickers to the options object (R-2.4)
EnhancedFilePicker and the download adapter captured showOpenFilePicker
and showSaveFilePicker with `.bind(options)`. A Window operation throws
TypeError("Illegal invocation") when `this` is not the Window, so passing
`window.showOpenFilePicker` / `window.showSaveFilePicker` as-is failed on
every call.
Both are now captured with `.bind(undefined)`. They are still captured at
construction, and Web IDL maps an undefined receiver to the global object,
so the native functions can be injected directly.
Verified: "calls an injected window picker without rebinding its
receiver" and "calls an injected window save picker without rebinding its
receiver" use a fake picker that throws "Illegal invocation" unless `this`
is undefined or globalThis. Both failed before the fix (ok:false) and pass
now. check:architecture, check:types:app, check:types:test, lint,
test:component pass. test:unit passes except removal-fixture, which needs
generated artifacts/release files that a fresh worktree lacks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a80b153163
commit
de954d2ebf
@@ -431,8 +431,11 @@ export class EnhancedFilePicker implements DisposableFilePicker {
|
||||
if (typeof options.showOpenFilePicker !== "function") {
|
||||
throw new TypeError("Enhanced file picker API is invalid.");
|
||||
}
|
||||
// Bound to undefined, not to options: `window.showOpenFilePicker` throws
|
||||
// "Illegal invocation" for any other receiver, and Web IDL maps an
|
||||
// undefined receiver to the global object.
|
||||
this.#showOpenFilePicker =
|
||||
options.showOpenFilePicker.bind(options);
|
||||
options.showOpenFilePicker.bind(undefined);
|
||||
this.#captureHandles =
|
||||
options.vault.captureHandles.bind(options.vault);
|
||||
this.#releaseFile = options.vault.release.bind(options.vault);
|
||||
|
||||
@@ -224,8 +224,11 @@ export function createDownloadDeliveryAdapter(
|
||||
: {}),
|
||||
...(originalShowSaveFilePicker
|
||||
? {
|
||||
// Bound to undefined, not to options: `window.showSaveFilePicker`
|
||||
// throws "Illegal invocation" for any other receiver, and Web IDL
|
||||
// maps an undefined receiver to the global object.
|
||||
showSaveFilePicker:
|
||||
originalShowSaveFilePicker.bind(options),
|
||||
originalShowSaveFilePicker.bind(undefined),
|
||||
}
|
||||
: {}),
|
||||
...(originalIntegrityVerifier
|
||||
|
||||
Reference in New Issue
Block a user